Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

58 changes: 42 additions & 16 deletions eManagerSystemClient/eManagerSystemClient/clientForm/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ public partial class Form1 : Form
public Form1()
{
InitializeComponent();

}

IPEndPoint IP;
Expand All @@ -38,24 +37,20 @@ public void Connect()
{
MessageBox.Show("Khong the ket noi toi server");
return;

}
Thread listen = new Thread(Receive);
listen.IsBackground = true;
listen.Start();


}

public void Send(string message)
{
if (message != String.Empty)
{
client.Send(Serialize(message));
}

}


public void Receive()
{
try
Expand All @@ -75,14 +70,15 @@ public void Receive()
throw er;
// Close();
}


}

delegate void SetTextCallback(string text);

private void SetText(string text)
{



// InvokeRequired required compares the thread ID of the
// calling thread to the thread ID of the creating thread.
// If these threads are different, it returns true.
Expand All @@ -98,7 +94,6 @@ private void SetText(string text)
}



public void Close()
{
client.Close();
Expand All @@ -108,13 +103,11 @@ private byte[] Serialize(object data)
{
MemoryStream memoryStream = new MemoryStream();
BinaryFormatter formatter = new BinaryFormatter();

formatter.Serialize(memoryStream, data);
return memoryStream.ToArray();
}



private string SaveFile(byte[] data, int dataLength)
{
string pathSave = "D:/";
Expand All @@ -140,16 +133,49 @@ private void Form1_Load(object sender, EventArgs e)

private void lblDeThi_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.lblDeThi.LinkVisited = true;
this.lblDeThi.LinkVisited = true;
System.Diagnostics.Process.Start(this.lblDeThi.Text);
}
public void SenFile(string filePath)
{
try
{
if (filePath != String.Empty)
{
// client.Send(GetFilePath(filePath));

}
}
catch
{
MessageBox.Show("file không tồn tại");
return;

// Navigate to a URL.
//System.Diagnostics.Process.Start(this.lblDeThi.Text);
}


}
public byte[] GetFilePath(string filePath)
{
// var name = Path.GetFileName(filePath);
byte[] fNameByte = Encoding.ASCII.GetBytes(filePath);
byte[] fileData = File.ReadAllBytes(filePath);
byte[] serverData = new byte[4 + fNameByte.Length + fileData.Length];
byte[] fNameLength = BitConverter.GetBytes(fNameByte.Length);
fNameLength.CopyTo(serverData, 0);
fNameByte.CopyTo(serverData, 4);
fileData.CopyTo(serverData, 4 + fNameByte.Length);
return serverData;
}
}

private void cmdNopBaiThi_Click(object sender, EventArgs e)
{
string filePath = @"D:\1812860.docx";
SenFile(filePath);


}
}



}