protected override void Save() { dgv.EndEdit(); if (!IsValid(dgv)) { MsgBox.Show("請先修正錯誤"); return; } List <ExamCode> newList = new List <ExamCode>(); foreach (DataGridViewRow row in dgv.Rows) { if (row.IsNewRow) { continue; } ExamCode ec = new ExamCode(); ec.ExamName = "" + row.Cells[chExamName.Index].Value; ec.Code = "" + row.Cells[chCode.Index].Value; newList.Add(ec); } _accessHelper.DeletedValues(_list.ToArray()); _accessHelper.InsertValues(newList.ToArray()); ExamCodeMapper.Instance.Reload(); this.DialogResult = DialogResult.OK; }
private void AddExamCode(object sender, EventArgs e) { try { var examCodeAdded = sender as ExamCodeListViewModel; using (var context = new QLThiTracNghiemDataContext()) { // Get examCodeId var examCodeIds = context.ExamCodes.Select(ec => ec.ExamCodeId.Substring(2)).ToList(); var examCodeId = examCodeIds.Select(id => int.Parse(id)).Max() + 1; examCodeAdded.ExamCodeId = $"DE{examCodeId:D6}"; var examCode = new ExamCode { ExamCodeId = examCodeAdded.ExamCodeId, NumberOfQuestions = examCodeAdded.NumberOfQuestions, SubjectId = examCodeAdded.SubjectId, GradeId = examCodeAdded.GradeId, IsPracticeExam = examCodeAdded.IsPracticeExam }; context.ExamCodes.InsertOnSubmit(examCode); context.SubmitChanges(); List <ExamCode_Question> examCode_Questions = new List <ExamCode_Question>(); foreach (var id in view.AddExamCodeQuestionIds) { var examCode_Question = new ExamCode_Question { ExamCodeId = examCodeAdded.ExamCodeId, QuestionId = id }; examCode_Questions.Add(examCode_Question); } context.ExamCode_Questions.InsertAllOnSubmit(examCode_Questions); context.SubmitChanges(); } view.AddExamCodeMessage = "Succeed"; } catch (Exception ex) { Debug.WriteLine(ex.ToString()); view.AddExamCodeMessage = "Failed"; } }
public async Task <string> GetResult(string registeredNumber, ExamCode examCode, int maxTries = 100) { if (string.IsNullOrEmpty(registeredNumber)) { Console.WriteLine("Registered number cant be empty!"); return(null); } Dictionary <string, string> postData = new Dictionary <string, string>() { { "prn", registeredNumber }, { "exam_id", ((int)examCode).ToString() }, { "btnresult", "Get Result" } }; return(await ExecuteRequestAsync(postData, maxTries).ConfigureAwait(false)); }