|
Every member of your class needs to be serializable or marked with [NonSerialized]. You cannot serialize streams, so they'll need the [NonSerialized] attribute for sure. If you really want your object to contain the binary content of all those files, you should read the data into byte array members probably. However, that sounds clunky, especially if the jpg files are right there, all your object needs to remember is their names, right? Let me know if I'm not understanding your question right.
Matt Gerrans
-- modified at 17:26 Thursday 13th October, 2005
|
|
|
|
|
Actually, I plan to use the file that is outputted as flashcard sets. Meaning it should contain all the information as the original jpegs and also on how to display them. This way, I won't have to distribute (to my friends) hundreds of jpeg files which could get moved, deleted, etc. This is why I wanted to stream the contents of the jpeg file into an array, and then save the array to a file.ext. I didn't realize you couldn't serialize streams :p So I guess I would have to dump the data into a byte array. You're right, it does sound a little clunky. I was thinking of using zip files, but then they wouldn't necesarrily come out in the right pairs (front and back.) This is the only other option I could think of.
Thanks for your input
|
|
|
|
|
Hi
I have a general question regarding validation of an objects attributes. I am working on a web application and involved in developing the business layer code. Given the fact that I am relatively new to web development, I had this question: Do I do the validation of the object's attributes before doing any action in the business layer? For example, if I have an user class in my business layer with 5 attributes, and some methods like select, delete, insert, update etc which are instance methods. So, before inserting the actual user into the database, do I need to write validation code in the insertmethod to see if the 5 attributes are not null? I am not sure if this needs to be done at the presentation layer or the business layer.
Any comments please?
Thanks
|
|
|
|
|
Probably you should have your validations on three levels. Each has its own purpose:
1. Validate on the user interface, to provide a speedy answer to the user, and to avoid hitting the server unnecessarily. This may not include all the validations, only those that are quick and simple to do on the UI layer.
2. Validate on the business rules layer, to enforce the business rules. This includes all rules, with the possible exception of referential integrity, that can be delegated to the database server. Here you can call any method and do the most complicated validations.
3. Validate on the database server. The objective is to enforce a minimum sanity on the data, like required fields and referential integrity. Theoretically all validation could be done here, using constraints, stored procedures and triggers, but I think it is more productive to use Visual Studio for coding logic. If you can be sure all database access will be through your code, you can keep the validation at this level simple. Anyway, this layer of validation is a safety net.
Good luck.
Fernando Correia
|
|
|
|
|
I've been searching around for an easy way of saving a formatted RTF box as an html file. I found a DLL that costs 250 bucks... but I'm sure there's an easier (cheaper) solution out there...
anyone got any advice?
|
|
|
|
|
I don't know any good solution, but I wrote a (very simple) RTF to HTML converter a while back. It doesn't support images or table or anything like that, only plain formatting.
|
|
|
|
|
what about colors and fonts and everything?
|
|
|
|
|
There are several RTF-to-HTML converters on the web if you're willing to spend a few hundred dollars.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Cops & Robbers
Judah Himango
|
|
|
|
|
I am creating an ASP.Net web application using C#. In one of my page, I need to load a list of a thousand names to be display in a DataGrid table. The table has 3 columns, a first name column, last name column, and a third column containing a delete link. The table can be sorted by first name or last name. When EnableViewState is set to true, it takes up to 1 minute to load the info into the DataGrid and display the table. When I set EnableViewState to false, it takes about 15 seconds to load the table, but I cannot sort the table anymore. I have set breakpoint in my sort command code, but it never gets hit when I click the first or last name link to sort the table. Setting a breakpoint in the IniatializeComponent show that the sort event was triggered, but my sort code is never called. I have no idea what's going on and would appreciate any help.
|
|
|
|
|
Please don't double post.
---
b { font-weight: normal; }
|
|
|
|
|
How do you access jpgs bitmaps and icons in a resource file?
|
|
|
|
|
I have a previous post here[^] that might help.
Enjoy.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Thank you very much for your help.
I have tried your code, it compiles but I get the error "Stream is not a valid resource file"
I created a MyResources.RES file using RC.exe and compiled the app with the following command line :
csc /debug- /t:winexe /win32res:MyResources.RES /w:4 /o+ *.cs
It seems to embed the resources in the exe as it much larger than if i do not have the /win3res switch
any idea why it won't work?
|
|
|
|
|
Assuming you're not creating the resource you're consuming (if you were, I would suggest saving a lot of hassle and just using the ResourceWriter type), and you're stuck with a Win32 resource, you should be able to use the ResourceManager type to get what you need if, as your example suggests, you're embedding the resource in your application assembly.
Example (where the byte array is your serialized image stream):
public byte[] Binary(string key)
{
ResourceManager resManager = new ResourceManager("[ASSEMBLYNAME]", This.GetType().Assembly);
return (byte[]) resManager.GetObject(key);
}
Here[^] is a link with a little more info.
Hope this helps.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
Using win32 resources looks very complicated (looked your url)
Maybe I am going about it all the wrong way.
What is the best way to use icons and jpgs/bmps in a c# application?
Would I need to have seperate files to keep with the exe or can they be embedded into the exe?
At the moment I have 6 BMPs that I use in an image list for use on a listview, and at the moment I have the exe and the 6 BMP files in the same folder so i can access them.
I also would like to add an icon the exe and the status bar and stop using the default one.
Would I need to have seperate file(s) to the exe to allow this?
Thanks again for your help
|
|
|
|
|
Using Win32 resources is not particularly complicated in general, but the .Net Framework does not have stellar legacy support built in.
See the link in my initial post, using ResourceWriter and ResourceReader. It should do exactly what you're suggesting, and provides examples for how to read from and write to .resources files.
You can put more than one resource in a .resources file; they are added in key/value pairs.
Good luck.
The most exciting phrase to hear in science, the one that heralds the most discoveries, is not 'Eureka!' ('I found it!') but 'That's funny...’
|
|
|
|
|
OK thanks for all your help
I will try getting this working using your original post
|
|
|
|
|
I have two TextBoxes. I have a button that calls a method that will use the
input from the text boxes ONLY if a number is entered. How do I do I do this?
Tried for several nights-- but I keep crashing on non-numerical input...
--thanks in advance
|
|
|
|
|
Void OnButtonClick(...)
{
Try
{
int i = Convert.ToInt(textbox.Text);
}
catch
{
return
}
DoSomething();
}
|
|
|
|
|
Dan- thanks. I have already tried the code you've shown. My problem is that BOTH text boxes are "tied" to the button event-- so I keep getting an infnite loop of two MessageBoxes (each from the catch statements of the two TextBoxes)
when there is an invalid entry....
|
|
|
|
|
I'm not sure I follow you here. Are you doing your check event when the button is clicked, or when a user modifies the content of eitehr box?
|
|
|
|
|
Ok Here's what I did...program crashes on invalid input and I get endless Message boxes that won't close on 'OK'. Thanks...
This is driving me nuts....
///////////////////////////////
void DrawComplexNumber1(Graphics g)
{
Pen p = c_xy.GetNextPen();
p.DashStyle = DashStyle.Dot;
c_xy.SetOrigin(xIndent + graphRect.Width/2, yIndent + graphRect.Y/2);
try
{
cmplxValue1.Real = Convert.ToDouble(textComplex_1Real.Text);
}
catch
{
MessageBox.Show("Error!");
}
try
{
cmplxValue1.Imaginary = Convert.ToDouble(textComplex_1Imaginary.Text);
}
catch
{
MessageBox.Show("Error!");
}
g.DrawLine(p, 250, 250, (float)(250 + (xIndent * cmplxValue1.Real)), (float)(250 - (yIndent * cmplxValue1.Imaginary)));
//////////////////////////////////////////////
private void complex_1OK_Click_1(object sender, System.EventArgs e)
{
drawLine1 = !drawLine1;
Invalidate();
}
/////////////////////////////////////////Paint Handler
....
if(drawLine1)
DrawComplexNumber1(e.Graphics);
}
|
|
|
|
|
hi
How about using int32.parse(textbox.text) ?
Banshi Khinchi
|
|
|
|
|
You see the following code :
private void button1_Click(object sender, System.EventArgs e)
{
int number = 0;
try
{
number = System.Convert.ToInt32(textBox1.Text);
}
catch(Exception ex)
{
System.Windows.Forms.MessageBox.Show("Input is not a number !");
textBox1.Focus();
return;
}
DoSomething(number);
}
private void DoSomething(int iNumber)
{
// Your code is here ...
}
with textBox1, textBox2 are two instances of TextBox class and button1 is a instance of Button class.
NPS.
|
|
|
|
|
Handle the Validating event for both text boxes:
private void TextBox_Validating(object sender, CancelEventArgs e)
{
TextBox textBox = sender as TextBox;
if(textBox == null)
return;
if(textBox.TextLength == 0)
return;
bool error = false;
try
{
int n = Convert.ToInt32(textBox);
if(n < 0 || n > 100)
error = true;
}
catch(FormatException)
{
error = true;
}
finally
{
if(error)
{
MessageBox.Show("Please enter a valid number");
textBox.SelectAll();
textBox.Focus();
e.Cancel = true;
}
}
} When the user tries to take focus away from the control, its contents will be validated. If invalid, the user won't be allowed to leave the control unless he corrects it or leaves it empty.
Then in you button handler, just validate that the text boxes have anything. If they do, it's surely a valid number.
I hope this helps!
-- LuisR
Luis Alonso Ramos
Intelectix - Chihuahua, Mexico
Not much here: My CP Blog!
The amount of sleep the average person needs is five more minutes. -- Vikram A Punathambekar, Aug. 11, 2005
|
|
|
|