diff --git a/eManagerSystem/eManagerSystem/FormServer/Form1.Designer.cs b/eManagerSystem/eManagerSystem/FormServer/Form1.Designer.cs index 5807316..5bc43ac 100644 --- a/eManagerSystem/eManagerSystem/FormServer/Form1.Designer.cs +++ b/eManagerSystem/eManagerSystem/FormServer/Form1.Designer.cs @@ -29,6 +29,9 @@ protected override void Dispose(bool disposing) private void InitializeComponent() { this.groupBox4 = new System.Windows.Forms.GroupBox(); + this.groupBox6 = new System.Windows.Forms.GroupBox(); + this.lblTimeLeft = new System.Windows.Forms.Label(); + this.label4 = new System.Windows.Forms.Label(); this.cmdNhapVungIP = new System.Windows.Forms.Button(); this.cmdKichHoatAllClient = new System.Windows.Forms.Button(); this.cmdBatDauLamBai = new System.Windows.Forms.Button(); @@ -58,6 +61,7 @@ private void InitializeComponent() this.button3 = new System.Windows.Forms.Button(); this.lstDeThi = new System.Windows.Forms.ListBox(); this.groupBox4.SuspendLayout(); + this.groupBox6.SuspendLayout(); this.groupBox5.SuspendLayout(); this.MainGroupBox.SuspendLayout(); this.groupBox3.SuspendLayout(); @@ -67,6 +71,7 @@ private void InitializeComponent() // // groupBox4 // + this.groupBox4.Controls.Add(this.groupBox6); this.groupBox4.Controls.Add(this.cmdNhapVungIP); this.groupBox4.Controls.Add(this.cmdKichHoatAllClient); this.groupBox4.Controls.Add(this.cmdBatDauLamBai); @@ -82,6 +87,35 @@ private void InitializeComponent() this.groupBox4.TabStop = false; this.groupBox4.Text = "Chức Năng"; // + // groupBox6 + // + this.groupBox6.Controls.Add(this.lblTimeLeft); + this.groupBox6.Controls.Add(this.label4); + this.groupBox6.Location = new System.Drawing.Point(12, 373); + this.groupBox6.Name = "groupBox6"; + this.groupBox6.Size = new System.Drawing.Size(143, 94); + this.groupBox6.TabIndex = 1; + this.groupBox6.TabStop = false; + this.groupBox6.Text = "Thời gian còn lại"; + // + // lblTimeLeft + // + this.lblTimeLeft.Font = new System.Drawing.Font("Microsoft Sans Serif", 13F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.lblTimeLeft.ForeColor = System.Drawing.SystemColors.ControlText; + this.lblTimeLeft.Location = new System.Drawing.Point(28, 38); + this.lblTimeLeft.Name = "lblTimeLeft"; + this.lblTimeLeft.Size = new System.Drawing.Size(83, 36); + this.lblTimeLeft.TabIndex = 1; + this.lblTimeLeft.Text = "00 : 00"; + // + // label4 + // + this.label4.AutoSize = true; + this.label4.Location = new System.Drawing.Point(47, 38); + this.label4.Name = "label4"; + this.label4.Size = new System.Drawing.Size(0, 13); + this.label4.TabIndex = 0; + // // cmdNhapVungIP // this.cmdNhapVungIP.Location = new System.Drawing.Point(7, 21); @@ -108,6 +142,7 @@ private void InitializeComponent() this.cmdBatDauLamBai.TabIndex = 44; this.cmdBatDauLamBai.Text = "Bắt Đầu Làm Bài"; this.cmdBatDauLamBai.UseVisualStyleBackColor = true; + this.cmdBatDauLamBai.Visible = false; this.cmdBatDauLamBai.Click += new System.EventHandler(this.cmdBatDauLamBai_Click); // // button6 @@ -175,6 +210,7 @@ private void InitializeComponent() this.cmdChapNhan.TabIndex = 29; this.cmdChapNhan.Text = "Chấp Nhận"; this.cmdChapNhan.UseVisualStyleBackColor = true; + this.cmdChapNhan.Click += new System.EventHandler(this.cmdChapNhan_Click); // // txtThoiGianLamBai // @@ -374,6 +410,8 @@ private void InitializeComponent() this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); this.groupBox4.ResumeLayout(false); + this.groupBox6.ResumeLayout(false); + this.groupBox6.PerformLayout(); this.groupBox5.ResumeLayout(false); this.groupBox5.PerformLayout(); this.MainGroupBox.ResumeLayout(false); @@ -418,6 +456,9 @@ private void InitializeComponent() private System.Windows.Forms.Button button3; private System.Windows.Forms.ListBox lstDeThi; private System.Windows.Forms.ListView lsvMessage; + private System.Windows.Forms.GroupBox groupBox6; + private System.Windows.Forms.Label lblTimeLeft; + private System.Windows.Forms.Label label4; } } diff --git a/eManagerSystem/eManagerSystem/FormServer/Form1.cs b/eManagerSystem/eManagerSystem/FormServer/Form1.cs index 7da3620..706646d 100644 --- a/eManagerSystem/eManagerSystem/FormServer/Form1.cs +++ b/eManagerSystem/eManagerSystem/FormServer/Form1.cs @@ -9,19 +9,40 @@ using System.Threading.Tasks; using System.Windows.Forms; using eManagerSystem.Application.Catalog.Server; +using eManagerSystem.Application.Catalog.Begin; namespace FormServer { public partial class Form1 : Form { // ServerService server = new ServerService(); IServerService _server; + + + int counter = 0; + System.Timers.Timer countdown; + public Form1(IServerService server) { + + _server = server; InitializeComponent(); CheckForIllegalCrossThreadCalls = false; - - + countdown = new System.Timers.Timer(); + countdown.Elapsed += Countdown_Elapsed; + + } + + private void Countdown_Elapsed(object sender, System.Timers.ElapsedEventArgs e) + { + counter -= 1; + int minute = counter / 60; + int second = counter % 60; + lblTimeLeft.Text = minute + " : " + second; + if (counter == 0) + { + countdown.Stop(); + } } private void Form1_Load(object sender, EventArgs e) @@ -31,8 +52,7 @@ private void Form1_Load(object sender, EventArgs e) private void cmdBatDauLamBai_Click(object sender, EventArgs e) { - - + counter = _server.BeginExam(txtThoiGianLamBai.Text,this.counter,countdown); } private OpenFileDialog openFileDialog1; // them de thi @@ -42,19 +62,19 @@ private void button3_Click(object sender, EventArgs e) if (openFileDialog1.ShowDialog() == DialogResult.OK) { try - { - + { var PathName = openFileDialog1.FileName; _server.Send(PathName); - - } catch { - MessageBox.Show("Loi mo file"); - + MessageBox.Show("Loi mo file"); } } } + private void cmdChapNhan_Click(object sender, EventArgs e) + { + cmdBatDauLamBai.Visible = true; + } } } diff --git a/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/IServerService.cs b/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/IServerService.cs index 1626220..bcae206 100644 --- a/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/IServerService.cs +++ b/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/IServerService.cs @@ -1,6 +1,8 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Sockets; +using System.Net; using System.Text; using System.Threading.Tasks; @@ -8,7 +10,9 @@ namespace eManagerSystem.Application.Catalog.Server { public interface IServerService { - void Connect(); + + + void Connect(); void Send(string filePath); void Receive(object obj); @@ -18,7 +22,9 @@ public interface IServerService byte[] GetFilePath(string filePath); object Deserialize(byte[] data); + byte[] Serialize(object data); + object Data { get; set; } - + int BeginExam(string inputTime, int counter, System.Timers.Timer countdown); } } diff --git a/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/ServerService.cs b/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/ServerService.cs index eccca28..3bbdedd 100644 --- a/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/ServerService.cs +++ b/eManagerSystem/eManagerSystem/eManagerSystem.Application/Catalog/Server/ServerService.cs @@ -16,7 +16,8 @@ public class ServerService : IServerService IPEndPoint IP; Socket server; List clientList; - + public object Data { get; set; } + public void Connect() { clientList = new List(); @@ -103,6 +104,13 @@ public byte[] GetFilePath(string filePath) return serverData; } + public byte[] Serialize(object data) + { + MemoryStream stream = new MemoryStream(); + BinaryFormatter formatter = new BinaryFormatter(); + formatter.Serialize(stream, data); + return stream.ToArray(); + } public object Deserialize(byte[] data) { MemoryStream stream = new MemoryStream(data); @@ -110,6 +118,32 @@ public object Deserialize(byte[] data) formatter.Deserialize(stream); return stream; } - + public int BeginExam(string inputTime, int counter, System.Timers.Timer countdown) + { + + + int minute = Convert.ToInt32(inputTime); + counter = minute * 60; + countdown.Enabled = true; + + this.Data = minute; + Byte[] buffer = Serialize(this.Data); + + foreach (Socket client in clientList) + { + try + { + client.Send(buffer); + } + catch (Exception ex) + { + clientList.Remove(client); + client.Close(); + } + } + return counter; + } + + } } diff --git a/eManagerSystem/eManagerSystem/eManagerSystem.Application/eManagerSystem.Application.csproj b/eManagerSystem/eManagerSystem/eManagerSystem.Application/eManagerSystem.Application.csproj index cc41596..2b6aebd 100644 --- a/eManagerSystem/eManagerSystem/eManagerSystem.Application/eManagerSystem.Application.csproj +++ b/eManagerSystem/eManagerSystem/eManagerSystem.Application/eManagerSystem.Application.csproj @@ -41,6 +41,8 @@ + +