private void dgvStudent_CellContentClick(object sender, DataGridViewCellEventArgs e) { int columnClicked = e.ColumnIndex; int rowClicked = e.RowIndex; if (ListStudent.Count == 0 || rowClicked < 0 || rowClicked > ListStudent.Count - 1) { return; } if (columnClicked == dgvStudent.Columns[nameof(StudentDTO.Close)].Index && rowClicked >= 0) { string studentCode = dgvStudent.Rows[rowClicked].Cells[dgvStudent.Columns[nameof(StudentDTO.StudentCode)].Index].Value.ToString(); DialogResult result = MessageBox.Show(Constant.REMOVE_STUDENT_MESSAGE + studentCode, "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { StudentDTO removeStudent = ListStudent.Where(f => f.StudentCode == studentCode).FirstOrDefault(); ListStudent.Remove(removeStudent); ResetDataGridViewDataSourceWithDto(removeStudent, Constant.ACTION_REMOVE); } } //else if (Constant.PRACTICAL_STATUS[2].Equals(PracticalExamStatus)) //{ // StudentDTO dto = ListStudent[rowClicked]; // DialogResult result = MessageBox.Show(Constant.REEVALUATE_STUDENT_MESSAGE + dto.StudentCode, "RE-Evaluate", MessageBoxButtons.YesNo, MessageBoxIcon.Question); // if (result == DialogResult.Yes) // { // var appDomainDir = Util.GetProjectDirectory(); // var destinationPath = Path.Combine(appDomainDir + Constant.SCRIPT_FILE_PATH); // string listStudentPath = destinationPath + "\\" + PracticalExamCode + "\\" + Constant.SUMISSION_FOLDER_NAME; // listStudentPath = listStudentPath + "\\" + dto.StudentCode + Constant.ZIP_EXTENSION; // Task.Run(async delegate // { // string message = await SendFile(listStudentPath, dto.StudentCode, dto.ScriptCode); // Console.WriteLine(message); // } // ); // } //} }
private void UpdateRecord(StudentDTO dto) { try { for (int i = 0; i < this.dgvStudent.RowCount; i++) { var getStudentId = this.dgvStudent[1, i].Value.ToString(); if (getStudentId.Equals(dto.StudentCode)) { this.dgvStudent[4, i].Value = dto.Status; this.dgvStudent[5, i].Value = dto.TotalPoint; this.dgvStudent[6, i].Value = dto.SubmitTime; this.dgvStudent[7, i].Value = dto.EvaluateTime; this.dgvStudent[8, i].Value = dto.Result; this.dgvStudent[9, i].Value = dto.ErrorMsg; break; } } } catch (Exception ex) { Util.LogException("UpdateRecord", ex.Message); } }
private void ReadFile(StudentDTO dto) { try { string practicalExam = PracticalExamCode; var appDomainDir = Util.GetProjectDirectory(); var destinationPath = Path.Combine(appDomainDir + Constant.SCRIPT_FILE_PATH); string listStudentPath = destinationPath + "\\" + practicalExam + "\\" + Constant.STUDENT_LIST_FILE_NAME; string newCSV = ""; string[] readAllText = File.ReadAllLines(listStudentPath); foreach (var item in readAllText) { if (item.Contains(dto.StudentCode)) { newCSV += dto.NO + "," + dto.StudentCode + "," + dto.StudentName + "," + dto.ScriptCode + "," + dto.SubmitTime + "," + dto.EvaluateTime + "," + "0" + "," + dto.Result + "(correct)," + dto.TotalPoint + "," + dto.ErrorMsg; if (dto.ListQuestions != null) { foreach (KeyValuePair <string, string> items in dto.ListQuestions) { newCSV += "," + items.Key + ":" + items.Value; } } newCSV += "\r\n"; } else { newCSV += item + "\r\n"; } } File.WriteAllText(listStudentPath, newCSV); } catch (Exception ex) { Util.LogException("ReadFile", ex.Message); } }
private void ResetDataGridViewDataSourceWithDto(StudentDTO dto, string action) { try { switch (action) { case Constant.ACTION_ADD: this.InvokeEx(f => AddRecord(dto)); break; case Constant.ACTION_REMOVE: this.InvokeEx(f => RemoveRecord(dto)); break; case Constant.ACTION_UPDATE: this.InvokeEx(f => UpdateRecord(dto)); break; } } catch (Exception ex) { Util.LogException("ResetDataGridViewDataSourceWithDto", ex.Message); } }
public PointDetailMsgBox(StudentDTO studentDTO) { InitializeComponent(); this.studentDTO = studentDTO; DisplayResultMessage(); }
// Return submission API - document questions - expired time to student private void ReturnWebserviceURL(string ipAddress, int port, string studentCode) { try { // Student's TCP information TcpClient tcpClient = new System.Net.Sockets.TcpClient(ipAddress, port); string scriptCode = ""; string message; if (IsConnected(ipAddress)) { message = Constant.EXISTED_IP_MESSAGE; Util.SendMessage(System.Text.Encoding.Unicode.GetBytes(message), tcpClient); } else { count++; bool isSent = false; StudentDTO student = ListStudent.Where(t => t.StudentCode == studentCode).FirstOrDefault(); StudentDTO studentDisconnected = ListStudentBackUp.Where(t => t.StudentCode == studentCode).FirstOrDefault(); if (student != null) { student.TcpClient = tcpClient; student.Status = Constant.STATUSLIST[0]; // Exam code scriptCode = student.ScriptCode; ResetDataGridViewDataSourceWithDto(student, Constant.ACTION_UPDATE); } else if (studentDisconnected != null) { StudentDTO studentDTO = (StudentDTO)studentDisconnected.Shallowcopy(); studentDTO.TcpClient = tcpClient; studentDTO.Status = Constant.STATUSLIST[0]; studentDTO.NO = ListStudent.Count + 1; ListStudent.Add(studentDTO); scriptCode = studentDTO.ScriptCode; ResetDataGridViewDataSourceWithDto(studentDTO, Constant.ACTION_ADD); } else { MessageBox.Show("Student not in class is connecting"); return; } //ResetDataGridViewDataSource(); while (!isSent) { try { // Cập nhật giao diện ở đây message = "=" + submissionURL + "=" + scriptCode + "=" + PracticalExamCode; //SendMessage(ipAddress, port, message); var messageEncode = Util.Encode(message, "SE1267"); messageEncode = Constant.RETURN_URL_CODE + messageEncode; Util.SendMessage(System.Text.Encoding.Unicode.GetBytes(messageEncode), tcpClient); //byte[] bytes = File.ReadAllBytes(@"D:\Capstone_WF_Lecturer\PE2A_WF_LECTURER\submission\PracticalExams\Practical_Java_SE1269_05022020\TestScripts\Java_SE1269_05_02_2020_De1.java"); //Util.sendMessage(bytes, tcpClient); isSent = true; } catch (Exception e) { // resent message } } } } catch (Exception ex) { Util.LogException("ReturnWebserviceURL", ex.Message); } }
private void GetListStudentFromCSV(string practicalExamCode) { try { string practicalExam = practicalExamCode; int count = 0; var appDomainDir = Util.GetProjectDirectory(); var destinationPath = Path.Combine(appDomainDir + Constant.SCRIPT_FILE_PATH); string listStudentPath = destinationPath + "\\" + practicalExam + "\\" + Constant.STUDENT_LIST_FILE_NAME; using (var reader = new StreamReader(listStudentPath)) { while (!reader.EndOfStream) { var line = reader.ReadLine(); if (count != 0) { StudentDTO dto = new StudentDTO(); try { var values = line.Split(','); dto.StudentCode = values[Constant.STUDENT_CODE_INDEX]; dto.StudentName = values[Constant.STUDENT_NAME_INDEX]; dto.ScriptCode = values[Constant.SCRIPT_CODE_INDEX]; dto.SubmitTime = values[Constant.SUBMITTED_TIME_INDEX]; dto.EvaluateTime = values[Constant.EVALUATED_TIME_INDEX]; dto.CodingConvention = values[Constant.CODING_CONVENTION_INDEX]; dto.Result = values[Constant.RESULT_INDEX]; dto.TotalPoint = values[Constant.TOTAL_POINT_INDEX]; dto.ErrorMsg = values[Constant.ERROR_INDEX]; Dictionary <string, string> listQuestion = new Dictionary <string, string>(); try { int index = Constant.QUESTION_DETAIL_INDEX; while (true) { string nextQuestion = values[index]; string[] tempQuestion = nextQuestion.Split(':'); listQuestion.Add(tempQuestion[0], tempQuestion[1] + ":" + tempQuestion[2]); index++; } } catch (Exception e) { // end reading quesiton } dto.ListQuestions = listQuestion; } catch (Exception ex) { Util.LogException("GetListStudentFromCSV", ex.Message); } StudentList.Add(dto); } count++; } } } catch (Exception ex) { Util.LogException("GetListStudentFromCSV", ex.Message); } // /* // * // * This block is for release app // * // */ // //var projectNameDir = Path.GetDirectoryName(AppDomain.CurrentDomain.BaseDirectory); // //var destinationPath = Path.Combine(projectNameDir + Constant.SCRIPT_FILE_PATH); //foreach (StudentDTO dto in listStudent) //{ // Console.WriteLine(dto.StudentName); //} }