|
Do you want to send data to another computer with a given IP-Adress?
Well for the take a look at socket-programming:
Sockets in C#[^]
------------------------------
Author of Primary ROleplaying SysTem
How do I take my coffee? Black as midnight on a moonless night.
War doesn't determine who's right. War determines who's left.
|
|
|
|
|
If I understand the question.
1. Learn how TCP and sockets work.
2. Write code to send a message via a socket.
3. Write code to receive a message via a socket.
4. Create a message that contains the data above. Note that the message contains it. It is not just the data.
5. Put all of the above together to solve your problem.
Note that steps 1-4 have NOTHING to do with GUI elements of any kind. So your code for 2-4 must not have any text boxes, nor list views nor check boxes.
|
|
|
|
|
Suppose structured
public struct stNhanVien
{
public WhatType? Picture;
public string FullName;
public DateTime BirthDay;
}
Can save images to a structured text file (note: do not store the path of the image), to save the image of the structure of text files will have style? one example of this?
|
|
|
|
|
Yes/no. "Saving" objects (and structs) is done via a technique called serialization[^]. The buil-in classes can serialize to Xml, or binary - and you can plugin your own format, if required.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
A 'structured text file' usually means fixed record length. That's not good for storing variable length data, like images.
However what you've posted there is a non-fixed-length structure. So I'm not quite sure what you're trying to do. Dumping a list of that struct to file would be 'structured', but not a 'text file'.
The Image class[^] is serialisable, so if you're using serialisation to persist and restore data, then you can just put an Image (or an Image subtype, e.g. Bitmap) into your struct.
|
|
|
|
|
Suppose I have the structure
public struct st Staff
{
public Bitmap Picture;
public string FullName;
public DateTime BirthDay;
}
in my save button code
Path = @"C:\data\database.dat";
FileStream fs;
try
{
fs = new FileStream(path, FileMode.Create);
}
catch (Exception ex)
{
MessageBox.Show("Error: " + ex.Message);
return;
}
BinaryWriter bw = new BinaryWriter(fs);
Staff = new Staff();
Staff.Picture = (Bitmap)pictureBox1.Image;
Staff.FullName = txtFullName.Text;
Staff.BirthDay = DateTime.Parse(mskNgaysinh.Text);
for (int i = 0; i < list.Count; i++)
{
Staff = (Staff)list[i];
bw.Write(Staff.Picture);
bw.Write(Staff.FullName);
bw.Write(Staff.BirthDay.ToBinary());
}
bw.Flush();
bw.Close();
fs.Close();
I get an error at this line
bw.Write(Staff.Picture); // warning error: The best overloaded method match for 'System.IO.BinaryWriter.Write(bool)' has some invalid arguments
I wonder in the text file can save the Bitmap type? or to switch to the new chain store? if it is correct on how?
modified 21-Nov-12 22:34pm.
|
|
|
|
|
|
Errrm what? There seems to be a missing question there. Is it hiding behind the smiley? Tell it to come out so we can all have a go.
|
|
|
|
|
Which is the better place to declare variable ?
1>Inside try block
2>Outside before try block
|
|
|
|
|
Sibasis jena123 wrote: 1>Inside try block
2>Outside before try block
Based on theory, I'd say that it needs to be within the block, to limit it's scope as much as possible.
Bastard Programmer from Hell
if you can't read my code, try converting it here[^]
|
|
|
|
|
|
if we want that variable inside the catch or final block we have to declare out side the try block .
If we want it only in try block then variable should be declared inside try block .
|
|
|
|
|
asuming you mean
if we want that variable outside the catch or final block we have to declare out side the try block .
If we want it only in try block then variable should be declared inside try block .
yes
|
|
|
|
|
The answer is that it really depends. If your variable doesn't need to be seen in the catch or finally block, and doesn't have scope that extends beyond the try/catch/finally block, then scope it inside the try part. If its scope can't be limited then you have no choice other than to declare it outside.
|
|
|
|
|
It depends on the usage , if we need our variable needed in catch then declare it outside else declare it inside the block
HariHaran.
Enjoy coding
|
|
|
|
|
That's not the whole answer. The correct answer is that if the variable will only ever be used in the try part, then you can declare it there - if it needs to exist in the catch, finally or outside the scope of the exception handling, then it has to be declared outside.
|
|
|
|
|
Variables should always be defined in the tightest scope that they are needed for. This is an extension of the principle that says you should have class instance variables not static or global ones, and that you should have function/procedure local variables not instance ones.
So if the variable's only used inside the block, declare it inside. That's true whether it's a try, an if, a while or whatever.
You can even scope sections of code simply to create a localisation region, e.g.
void SomeMethod(){
{
int a = 1;
Console.WriteLine(a);
}
{
string a = "test";
Console.WriteLine(a);
}
}
That is not generally something that people recommend, though.
|
|
|
|
|
BobJanova wrote: You can even scope sections of code simply to create a localisation region
Indeed, and whenever I've seen this done, this tells me that the method should have been split into separate methods.
|
|
|
|
|
The only time I've done something which is technically that is scoping case: blocks in a message dispatching switch. (It's in the game lobby library that I posted on here, I think.) A true short method fundamentalist would have each case do nothing but call a method to handle the individual case, but I'm not one of those.
Yeah, generally it's an indication of muddled thinking and that something is actually two separate operations.
|
|
|
|
|
BobJanova wrote: in a ... switch
That's the only occaision I've ever needed it too
|
|
|
|
|
I have a question about setting up permissions on a sql server 2008 r2 datbase.
I basically wrote and enhanced some C# 2008 and C# 2010 console applications that connected to my test sql server 2008 r2 database. On my test database, I must all full right my default.
My 3 applications were deployed to a user acceptance testing environment that includes a user acceptance sql server 2008 r2 standard database.
The user accpetance database was set up by the network administrator at my small company. He is the only one at my small company that knows a little bit about the dba roles and has locked down permissions.
Due to the facts above, I would like to know what should I be aware that may need to have permissions setup for. My questions includes the followinng:
1. When to decide if role(s) need to be setup and how to setup the roles. When I ran my applications on my test database, I had the integrated security set to true. I did not need to supply the user name and password in the connection strings to the database. My user account was setup to have a role in the database.
Due to what I just said, will I need to have setup roles for the console applications to run on their own? If so, What kind of roles need to be setup and how do you setup these roles?
2. I setup 3 new tables that are under the dbo schema. Do I need to have permissions setup so people and/or roles can have read, write, update and/or execute permissions? If so, how do you setup these permissions?
3. I have also created 2 stored procedures that are used to access the 3 new tables that I setup. Thus do these stored procedures need to have read, write, update and/or execute permissions on them setup?
4. Do statistics (explain plans) need to be run on this database that has hardly evern been used before? If so, how do you accomplisth this goal?
5. Are there other items I need to consider? If so, what are the items and what do I do to resolve those issues?
If you can any part of my questions above, I would appreciate hearing what your answer is also.
|
|
|
|
|
sc steinhayse wrote: I have a question about setting up permissions on a sql server 2008 r2 datbase.
I basically wrote and enhanced some C# 2008 and C# 2010 console applications that connected to my test sql server 2008 r2 database. On my test database, I must all full right my default.
Do you have a business case that mandates these applications need DBO to run?
Or are you just granting DBO to make sure they run right?
* I suggest you start by granting the least permissions and changing those permissions until the application executes. Then understand what it is about the code that requires the elevated permissions and try to rework it so that you can run at lower permissions. This is tedious but vitally important.
My 3 applications were deployed to a user acceptance testing environment that includes a user acceptance sql server 2008 r2 standard database.
The user accpetance database was set up by the network administrator at my small company. He is the only one at my small company that knows a little bit about the dba roles and has locked down permissions.
Due to the facts above, I would like to know what should I be aware that may need to have permissions setup for. My questions includes the followinng:
1. When to decide if role(s) need to be setup and how to setup the roles.
Roles are a business case. Do you need Admins, Editors, Readers, Etc... The ASP.Net Membership provider can implement role based security with some configuration code.
When I ran my applications on my test database, I had the integrated security set to true. I did not need to supply the user name and password in the connection strings to the database. My user account was setup to have a role in the database.
Actually integrated security means you are on a domain or using LDAP/Etc... so you don't need to pass in user/pass it's just authenticating you with your domain permissions.
Due to what I just said, will I need to have setup roles for the console applications to run on their own? If so, What kind of roles need to be setup and how do you setup these roles?
What do you mean by "run on their own"? Application permissions depend on who is signed in. So for example you could create a user {console_app_name}.dbo and grant DBO to that account. Then any user passing that username/password combination will have DBO on that applications database.
2. I setup 3 new tables that are under the dbo schema. Do I need to have permissions setup so people and/or roles can have read, write, update and/or execute permissions? If so, how do you setup these permissions?
In the web.config you specify the security. So if you want to granulate on each user then use integrated security. If you want all users to have DBO via your application then connect using an account you created that has DBO on the application DB and tables.
3. I have also created 2 stored procedures that are used to access the 3 new tables that I setup. Thus do these stored procedures need to have read, write, update and/or execute permissions on them setup?
Yes they do. Google "grant execute SQL Server".
4. Do statistics (explain plans) need to be run on this database that has hardly evern been used before? If so, how do you accomplisth this goal?
I'd recommend using a very robust web stats package that is trivial to setup on IIS. Google "AWSTATS for IIS"
5. Are there other items I need to consider? If so, what are the items and what do I do to resolve those issues?
Vast topic. Backups need to be considered as well as coding best practices. This is a big topic and you should find all you need at the ASP.Net (http://www.asp.net) websit.
If you can any part of my questions above, I would appreciate hearing what your answer is also.
There have been joys too great to be described in words, and there have been griefs upon which I have not dared to dwell, and with these in mind I say, climb if you will, but remember that courage and strength are naught without prudence, and that a momentary negligence may destroy the happiness of a lifetime. Do nothing in haste, look well to each step, and from the beginning think what may be the end. - Edward Whymper
Climb On!
|
|
|
|
|
Hi Everyone,
Just wondering if there is a good class in .NET that can convert a Text string to a Code128 text string, then off course that text needs to be in Code128 font.
Any input on this would be greatly appreciated. I understand that others might have already written. This is also fine as long as what is written is future ready if you know what I mean.
|
|
|
|
|
If you want it as a string, then you will indeed need a Code128 font. A simple google search should be able to find you one for that.
If you want it as an image, this article[^] works pretty well.
I wasn't, now I am, then I won't be anymore.
|
|
|
|
|
class, struct , interface, can we say they are C# objects?
|
|
|
|