|
As I said in my original reply it's been a while so I don't know the exact code.
But normally you should have an instance of your report
and that instance should have a open method in which you can pass the objects pagesettings and printersettings
pagesettings[^]
printersettings[^]
|
|
|
|
|
Dear all,
I'm trying to get my computer to listen on a port and pass on the received data ( after some modification ) over Multicast. I'm receiving data on the socket every second. I wrote the code below and it works perfect.
The problem that I require some assistance with is pretty simply. Everytime a string of data is received, the socket is closed and new socket is opened to wait for the next string. When the next string of data comes in, it gets processed and the socket is closed again. This means that after a period of time, lots of socket connections are made. One of them is active and the others are in a TIME_WAIT state ( and that list keeps growing ) Is there a way around this ?
Int32 port = 31008;
IPAddress localAddr = IPAddress.Any;
server = new TcpListener(localAddr, port);
server.Start();
Byte[] bytes = new Byte[256];
String data = null;
while (true)
{
client = server.AcceptTcpClient();
data = null;
NetworkStream stream = client.GetStream();
int i;
while ((i = stream.Read(bytes, 0, bytes.Length)) != 0)
{
data = System.Text.Encoding.ASCII.GetString(bytes, 0, i);
data = data.ToUpper();
byte[] msg = System.Text.Encoding.ASCII.GetBytes(data);
SendMulticast(MultiCastIP, MultiCastPort, msg);
}
client.Close();
}
kind regards,
Rick
|
|
|
|
|
The TIME_WAIT state for a period of time is normal/default socket behavior.
If you're absolutely sure all data is sent, then you may be able to set the
LingerState to on/0sec:
LingerOption lingerOption = new LingerOption (true, 0);
client.LingerState = lingerOption;
You also should call Close() on your NetworkStream
Mark
Mark Salsbery
Microsoft MVP - Visual C++
|
|
|
|
|
Hi all,
My question is that.. Report.rdlc is class ? how to i format the report at runtime such as i want change the fontstyle before print the report while runing the program.
thanks.
|
|
|
|
|
Hi,
as the title indicates I want to mark a field in a child class with a NonSerialized attribute so that it won't be serialized. Simply put:
[Serializable]
class Parent
{
protected int SomeField;
}
[Serializable]
class Child : Parent
{
[NonSerialized]
protected int SomeField;
}
Of course this does not work, but also the new keyword does not help me because it only hides the field and does not overwrite it. Is there any other way to achieve the desired effect?
Regards
Dust Signs
The number you dialed is imaginary. Please turn your phone by 90 degrees and try again
|
|
|
|
|
I thought NonSerialized is intended for this purpose, or what whould you expect?
|
|
|
|
|
Hi,
of course you are right, but I need this as the parent class saves information in this field which the child classes do not need anymore because they compute it dynamically. And of course we are not talking about an int field, but about an array of a more complex data type which would consume up to 20 or 30 KB per instance which would be serialized and "thrown away" after deserialization as it has to be recomputed anyways. I hope this helps to better understand the purpose of what I want to achieve.
Dust Signs
The number you dialed is imaginary. Please turn your phone by 90 degrees and try again
|
|
|
|
|
If you don't want to store it, but on deserialization want to get default values. Then maybe the OnDeserializedAttribute can be of use...
http://msdn.microsoft.com/en-us/library/system.runtime.serialization.ondeserializedattribute.aspx
|
|
|
|
|
Thanks for the link, this seems quite useful. But this does not solve my problem: the parent class has to save the field whereas the child classes don't have to save it, so how do I declare the field in the child classes? As I said I cannot mark it as NonSerialized in the parent class as it needs to be saved there.
Dust Signs
The number you dialed is imaginary. Please turn your phone by 90 degrees and try again
|
|
|
|
|
maybe something like this could be usefull?!
[OnDeserializing()]
internal void OnDeserializingMethod(StreamingContext context)
{
this.nonserializedmember = reInitialise();
foreach (Child c in this.childs) {
child.newNonserializedValue = this.nonserializedmember;
}
}
|
|
|
|
|
I just answered this question myself . I just had to use OnSerializing and OnSerialized to set the field to null and reset it to its old value respectively. Thank you very much for your help.
Regards,
Dust Signs
The number you dialed is imaginary. Please turn your phone by 90 degrees and try again
|
|
|
|
|
No prob
|
|
|
|
|
I just don't get it why is it so complex to make a simple update...
I want trough a procedure to modify all the rows in a table like so: suppose I have a table with colums a, b, and c. c is identified by a and b. The procedure has the parameters a,b and c.
a,b,c
Example: UpdateazaCantCont(1,3,5) must add 5 to the old value of c. So if one row in the database table values are 1,3,8 the new values must be 1,3,13.
Please help me, because I'm in an death stop in my project!
The procedure i've wrote gives me no error, but it doesnt do anything.
Here's the code I have written:
private void UpdateazaCantCont(string aVal, string bVal, int cVal)
{
DataSet mds = new DataSet();
OleDbDataAdapter mda = new OleDbDataAdapter("select * from table where a='" + aVal + "'and b='" + bVal + "'", sirConex);
mda.Fill(mds,"continut_locatie");
DataTable t = mds.Tables[0];
DataRow[] r = t.Select("a='"+aVal+"b='"+ bVal + "'");
for (int i=0; i<r.length;>
string sirUpdate = "Update table set c=c+'"+cVal+"'where a='" + aVal + " and b='" + bVal + "'";
OleDbConnection myConex = new OleDbConnection(sirConex);
OleDbCommand cmd = new OleDbCommand(sirUpdate, myConex);
cmd.CommandText = sirUpdate;
mda.UpdateCommand = cmd;
try
{
mda.Update(mds, "table");
}
catch (Exception ex)
{
MessageBox.Show("Eroare: " + ex);
}
}
|
|
|
|
|
First of all, because aVal and bVal are strings, it's possible I can erase your database. Do you know about SQL Injection ?
Second, why use a dataset to get back a single value ?
Third, NEVER assume that an array has any values in it, without checking.
Fourth, what's the point of doing a select when you already have only those values in the table ?
you seem to be some of the way along, although you could do all of this in a stored proc and with 3 lines of code on the C# side.
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Thanks for your reply. Can you tell me those 3 lines?
|
|
|
|
|
http://www.codeproject.com/KB/cs/simplecodeasp.aspx
[^]
Probably more than 3 lines, given you need one line for each of your three params. but still, a lot more readable. Of course, you also need to write the proc...
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Hi,
Currently i am doing a project related to file encryption using c#. I new to the c# programming actually. I used microsoft visual c# express 2008. I had combine some of the code from internet reference, but i am facing a problem where program highlight "cs.Close();" and show
IndexOutOfRangeException was unhandled when decrypt button is clicked. The file decryption is unsuccessful due to this exception i think. Is there anybody know how to solve for this problem? Any suggestion on how to change the code? The code of my project is as below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
openFD.Title = "Insert a File";
openFD.InitialDirectory = "F://";
openFD.FileName = "";
DialogResult result = openFD.ShowDialog();
string filename;
filename = openFD.FileName;
if (result == DialogResult.OK)
{
textBox2.Text = filename;
}
else
{
return;
}
}
private void button2_Click(object sender, EventArgs e)
{
string password = textBox1.Text;
string salt_value = "abcdefg";
string hash = "sha1";
int passwordIterations = 10;
string initVector = "@1A2C5D1F286AB54";
int keySize = 128;
Encrypt(@"filename", @"C:\Encrypted.ppt", password, salt_value, hash, passwordIterations, initVector, keySize);
}
public static void Encrypt(string _inputFile, string _outputFile, string password, string salt_value, string hash, int passwordIteration, string initVector, int keySize)
{
if (password.Length > 8)
password = password.Substring(0, 8);
else if (password.Length < 8)
{
int add = 8 - password.Length;
for (int i = 0; i < add; i++)
password = password + i;
}
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] salt_valueBytes = Encoding.ASCII.GetBytes(salt_value);
PasswordDeriveBytes key = new PasswordDeriveBytes(password, salt_valueBytes, hash, passwordIteration);
byte[] keyBytes = key.GetBytes(keySize / 8);
FileStream fsCrypt = new FileStream(_outputFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
RMCrypto.Mode = CipherMode.CBC;
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateEncryptor(keyBytes, initVectorBytes), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(_inputFile, FileMode.OpenOrCreate);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
cs = null;
fsIn = null;
}
private void button3_Click(object sender, EventArgs e)
{
openFD.Title = "Insert a File";
openFD.InitialDirectory = "F://";
openFD.FileName = "";
DialogResult result = openFD.ShowDialog();
string filename;
filename = openFD.FileName;
if (result == DialogResult.OK)
{
textBox3.Text = filename;
}
else
{
return;
}
}
private void button4_Click(object sender, EventArgs e)
{
string password = textBox1.Text;
string salt_value = "abcdefg";
string hash = "sha1";
int passwordIterations = 10;
string initVector = "@1A2C5D1F286AB54";
int keySize = 128;
Decrypt(@"filename", @"C:\Decrypted.ppt", password, salt_value, hash, passwordIterations, initVector, keySize);
}
public static void Decrypt(string _inputFile, string _outputFile, string password, string salt_value, string hash, int passwordIteration, string initVector, int keySize)
{
if (password.Length > 8)
password = password.Substring(0, 8);
else if (password.Length < 8)
{
int add = 8 - password.Length;
for (int i = 0; i < add; i++)
password = password + i;
}
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] salt_valueBytes = Encoding.ASCII.GetBytes(salt_value);
PasswordDeriveBytes key = new PasswordDeriveBytes(password, salt_valueBytes, hash, passwordIteration);
byte[] keyBytes = key.GetBytes(keySize /8);
FileStream fsCrypt = new FileStream(_outputFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
RMCrypto.Mode = CipherMode.CBC;
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateDecryptor(keyBytes, initVectorBytes), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(_inputFile, FileMode.OpenOrCreate);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
cs.Close();~IndexOutOfRangeException was unhandled
fsIn.Close();
fsCrypt.Close();
cs = null;
fsIn = null;
fsCrypt = null;
}
}
}
The source code can be download from the link below:
http://cid-1caedb18b83acfa1.skydrive...Encryption.rar
If I am not disturbing,please guide. Thanks a lot!
Regards,
sf
|
|
|
|
|
I recommend you learn some basics before trying to copy and paste code you don't understand. Assuming someone wants to trawl through this and find the error, how does that help you learn ?
Christian Graus
Driven to the arms of OSX by Vista.
|
|
|
|
|
Yaya..Thanks for your advice. I am trying hard to find out what problem with my code but the result is still the same. Is there any idea on which part do i need to focus with?
Regards,
cat ang
|
|
|
|
|
cat ang wrote: I am trying hard to find out what problem with my code
There is no obvious logical structure for a start. I don't know where to start reading to determine your problem.
|
|
|
|
|
Decrypt button? Which one is that? All the buttons are named Button1, Button2, etc. That isn't descriptive and while you might know which is the "Decrypt button", I do not. Please, for the love of all things, learn how to name things properly.
|
|
|
|
|
Sorry about that. This is my first time to post a thread, it is my careless.
i had rename my code and it is as below:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using System.IO;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void browseForFileToEncrypt_Click_1(object sender, EventArgs e)
{
openFD.Title = "Insert a File";
openFD.InitialDirectory = "F://";
openFD.FileName = "";
DialogResult result = openFD.ShowDialog();
string filename;
filename = openFD.FileName;
if (result == DialogResult.OK)
{
textBox2.Text = filename;
}
else
{
return;
}
}
private void btnFileEncryption_Click_1(object sender, EventArgs e)
{
string password = textBox1.Text;
string salt_value = "abcdefg";
string hash = "sha1";
int passwordIterations = 10;
string initVector = "@1A2C5D1F286AB54";
int keySize = 128;
Encrypt(@"filename", @"C:\Encrypted.ppt", password, salt_value, hash, passwordIterations, initVector, keySize);
}
public static void Encrypt(string _inputFile, string _outputFile, string password, string salt_value, string hash, int passwordIteration, string initVector, int keySize)
{
if (password.Length > 8)
password = password.Substring(0, 8);
else if (password.Length < 8)
{
int add = 8 - password.Length;
for (int i = 0; i < add; i++)
password = password + i;
}
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] salt_valueBytes = Encoding.ASCII.GetBytes(salt_value);
PasswordDeriveBytes key = new PasswordDeriveBytes(password, salt_valueBytes, hash, passwordIteration);
byte[] keyBytes = key.GetBytes(keySize / 8);
FileStream fsCrypt = new FileStream(_outputFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
RMCrypto.Mode = CipherMode.CBC;
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateEncryptor(keyBytes, initVectorBytes), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(_inputFile, FileMode.OpenOrCreate);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
fsIn.Close();
cs.Close();
fsCrypt.Close();
cs = null;
fsIn = null;
}
private void browseForFileToDecrypt_Click_1(object sender, EventArgs e)
{
openFD.Title = "Insert a File";
openFD.InitialDirectory = "F://";
openFD.FileName = "";
DialogResult result = openFD.ShowDialog();
string filename;
filename = openFD.FileName;
if (result == DialogResult.OK)
{
textBox3.Text = filename;
}
else
{
return;
}
}
private void btnFileDecryption_Click_1(object sender, EventArgs e)
{
string password = textBox1.Text;
string salt_value = "abcdefg";
string hash = "sha1";
int passwordIterations = 10;
string initVector = "@1A2C5D1F286AB54";
int keySize = 128;
Decrypt(@"filename", @"C:\Decrypted.ppt", password, salt_value, hash, passwordIterations, initVector, keySize);
}
public static void Decrypt(string _inputFile, string _outputFile, string password, string salt_value, string hash, int passwordIteration, string initVector, int keySize)
{
if (password.Length > 8)
password = password.Substring(0, 8);
else if (password.Length < 8)
{
int add = 8 - password.Length;
for (int i = 0; i < add; i++)
password = password + i;
}
byte[] initVectorBytes = Encoding.ASCII.GetBytes(initVector);
byte[] salt_valueBytes = Encoding.ASCII.GetBytes(salt_value);
PasswordDeriveBytes key = new PasswordDeriveBytes(password, salt_valueBytes, hash, passwordIteration);
byte[] keyBytes = key.GetBytes(keySize / 8);
FileStream fsCrypt = new FileStream(_outputFile, FileMode.Create);
RijndaelManaged RMCrypto = new RijndaelManaged();
RMCrypto.Mode = CipherMode.CBC;
CryptoStream cs = new CryptoStream(fsCrypt, RMCrypto.CreateDecryptor(keyBytes, initVectorBytes), CryptoStreamMode.Write);
FileStream fsIn = new FileStream(_inputFile, FileMode.OpenOrCreate);
int data;
while ((data = fsIn.ReadByte()) != -1)
cs.WriteByte((byte)data);
cs.Close();
fsIn.Close();
fsCrypt.Close();
cs = null;
fsIn = null;
fsCrypt = null;
}
}
}
The link for this program is:
http://cid-1caedb18b83acfa1.skydrive.live.com/self.aspx/Public/File%20Encryption.rar[^]
Please give me some advice on it. Thanks ya
Regards,
cat ang
|
|
|
|
|
how to display X axis values on top of graph while the y axis displayed top to bottom values?
|
|
|
|
|
|
in my form i have several buttons(say 5)that call the same method, in the method i want to identify wich button is clicked and depending on that i decide what to do.how can i identify the button that is clicked
|
|
|
|
|