110,536
社区成员
发帖
与我相关
我的任务
分享
namespace ClassLibrary
{
[Serializable]
public class User
{
private string uname = "";
private string name = "";
private string pwd = "";
private string department = "";
//private Role role = null;
public string Username
{
get { return uname; }
set { uname = value; }
}
public string Name
{
get { return name; }
set { name = value; }
}
public string Password
{
get { return pwd; }
set { pwd = value; }
}
//public Role Role
//{
// get { return role; }
// set { role = value; }
//}
public string Department
{
get { return department; }
set { department = value; }
}
}
}
namespace ClassLibrary
{
[Serializable]
public class ScanfAppTaskInfo
{
//private User user=null;
private string use = "";
private string des="";
private string cls="";
private string filename="";
private string scanfRes="";
private string appOpn="";
private int pages=0;
private int counts=0;
private DataTable dtper = null;
//public User User
//{
// get { return user; }
// set { user = value; }
//}
public string Use
{
get { return use; }
set { use = value; }
}
public string Des
{
get { return des; }
set { des = value; }
}
public string Cls
{
get { return cls; }
set { cls = value; }
}
public string Filename
{
get { return filename; }
set { filename = value; }
}
public string ScanfRes
{
get { return scanfRes; }
set { scanfRes = value; }
}
public string AppOpn
{
get { return appOpn; }
set { appOpn = value; }
}
public int Pages
{
get { return pages; }
set { pages = value; }
}
public int Counts
{
get { return counts; }
set { counts = value; }
}
public DataTable Dtperson
{
get { return dtper; }
set { dtper = value; }
}
}
}
user.Username = tbName.Text.Trim();
user.Password = tbPwd.Text.Trim();
//contactWithServer.User = user;
try
{
byte[] command = Encoding.ASCII.GetBytes("Login"); //命令
byte[] cmd = new byte[20];
for (int i = 0; i < command.Length; i++)
{
cmd[i]=command[i];
}
memStream = new MemoryStream();
formatter.Serialize(memStream, user);
byte[] data = memStream.ToArray(); //将User对象发送给服务器
memStream.Flush();
byte[] buffer = new byte[cmd.Length + data.Length];
Array.Copy(cmd,0,buffer,0,cmd.Length);
Array.Copy(data,0,buffer,cmd.Length,data.Length);
contactWithServer.sendMsg(buffer,buffer.Length);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
}
finally
{
memStream.Close();
}
[code=csharp]buff = new byte[data.Length - leng];
for (int j = 0; j < data.Length - leng; j++)
buff[j] = data[leng + j];
memStream = new MemoryStream(buff);
memStream.Seek(0, SeekOrigin.Begin);
obj = formatter.Deserialize(memStream);
memStream.Close();
if (obj != null && obj is User)
user = (User)obj;
try
{
buffer = new byte[data.Length - leng];
for (int j = 0; j < data.Length - leng; j++)
buffer[j] = data[leng + j];
memStream = new MemoryStream(buffer);
memStream.Seek(0, SeekOrigin.Begin);
obj = formatter.Deserialize(memStream);
memStream.Close();
if (obj != null && obj is ScanfAppTaskInfo)
sataskinfo = (ScanfAppTaskInfo)obj;
MessageBox.Show(sataskinfo.ScanfRes);
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
MessageBox.Show(ex.StackTrace);
MessageBox.Show(ex.Source);
}