private void metroButton2_Click(object sender, EventArgs e) { if (!String.IsNullOrEmpty(cbLever.Text) && !String.IsNullOrEmpty(txtQuestion.Text) && !String.IsNullOrEmpty(txtA.Text) && !String.IsNullOrEmpty(txtB.Text) && !String.IsNullOrEmpty(cbTrue.Text)) { OjQuestion tablequestion = new OjQuestion(); tablequestion.Number1 = Number; tablequestion.Lever1 = cbLever.Text; tablequestion.Question1 = txtQuestion.Text; tablequestion.AnswerTrue1 = cbTrue.Text; tablequestion.A1 = txtA.Text; tablequestion.B1 = txtB.Text; tablequestion.C1 = txtC.Text; tablequestion.D1 = txtD.Text; tablequestion.Grammar1 = CbGrammar.Text; xmlBll.UpdateQuestion(tablequestion); loadData(); } else { MessageBox.Show(" Not Null Value Lever, Question , Answer A, Answer B, Answer True !", " Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } this.Close(); }
void Search() { if (!String.IsNullOrEmpty(txtNumberSearch.Text)) { try { Number = Convert.ToInt32(txtNumberSearch.Text); OjQuestion tableQuestion = xmlBll.Search(Number); cbLever.Text = tableQuestion.Lever1; txtQuestion.Text = tableQuestion.Question1; cbTrue.Text = tableQuestion.AnswerTrue1; txtA.Text = tableQuestion.A1; txtB.Text = tableQuestion.B1; txtC.Text = tableQuestion.C1; txtD.Text = tableQuestion.D1; CbGrammar.Text = tableQuestion.Grammar1; } catch (Exception) { MessageBox.Show(" In the database does not exist this value ", " Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } else { MessageBox.Show("Value Number Null", " Erro", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
// UpDate Dữ liệu vào XmlQuestions public void UpdateQuestion(OjQuestion tableQuestion) { try { XmlDocument = XDocument.Load(filenameXmlQuestion); IEnumerable <XElement> old = (from q in XmlDocument.Element("Questions").Elements("Question") where (q.Element("Number").Value.ToString() == tableQuestion.Number1.ToString()) select q); foreach (XElement item in old) { item.SetElementValue("ContentQuestion", tableQuestion.Question1); item.SetElementValue("Lever", tableQuestion.Lever1); item.SetElementValue("AnswerTrue", tableQuestion.AnswerTrue1); item.SetElementValue("B", tableQuestion.B1); item.SetElementValue("C", tableQuestion.C1); item.SetElementValue("D", tableQuestion.D1); item.SetElementValue("Grammar", tableQuestion.Grammar1); } XmlDocument.Save(filenameXmlQuestion); } catch (Exception) { } }
public async Task <string> UploadOj(OjQuestion question, OjTestCaseTable ojTestCaseTable) { question.Id = daoUtils.GUID(); ojTestCaseTable.OjId = question.Id; await using var tx = await dbContext.Database.BeginTransactionAsync(); var count = await dbContext.OjQuestions.CountAsync(); question.OrderId = count + 1; await dbContext.OjQuestions.AddAsync(question); await dbContext.SaveChangesAsync(); ojTestCaseTable.OjId = question.Id; await dbContext.OjTestCaseTables.AddAsync(ojTestCaseTable); await dbContext.SaveChangesAsync(); await tx.CommitAsync(); return(question.Id); }
// Insert Dữ liệu vào XmlQuestions public void InsertQuestion(OjQuestion tablequestion) { try { XmlDocument = XDocument.Load(filenameXmlQuestion); XElement NewQuestion = new XElement("Question", new XElement("Number", tablequestion.Number1.ToString()), new XElement("Lever", tablequestion.Lever1), new XElement("ContentQuestion", tablequestion.Question1), new XElement("AnswerTrue", tablequestion.AnswerTrue1), new XElement("A", tablequestion.A1), new XElement("B", tablequestion.B1), new XElement("C", tablequestion.C1), new XElement("D", tablequestion.D1), new XElement("Grammar", tablequestion.Grammar1)); XmlDocument.Root.Add(NewQuestion); XmlDocument.Save(filenameXmlQuestion); } catch (Exception) { } }
public async Task <bool> UploadOj(OjTestCaseSet ojTestCaseSet) { if (!ojTestCaseSet.IsValidTestSet()) { return(false); } var question = new OjQuestion { Content = ojTestCaseSet.Content, CreateTime = DateTime.Now, Difficulty = ojTestCaseSet.Difficulty, Title = ojTestCaseSet.Title, Code = ojTestCaseSet.OjCode }; var testCaseTable = new OjTestCaseTable { TestCaseSetJson = JsonConvert.SerializeObject(ojTestCaseSet) }; await ojDao.UploadOj(question, testCaseTable); return(true); }
private void UcQuestions_Load(object sender, EventArgs e) { switch (infoTest.NumberQuestions) { case 10: { Minute = 2; second = 0; break; } case 20: { Minute = 4; second = 0; break; } case 30: { Minute = 10; second = 0; break; } case 50: { Minute = 20; second = 0; break; } case 100: { Minute = 40; second = 0; break; } } timer1.Start(); //Load Questions List <OjQuestion> Datatable = xmlBLL.DataQuestionsByLever(infoTest.Lever); /*LoadData.Instance.LoadDataQuetion()*/; if (Datatable.Count < infoTest.NumberQuestions) { MessageBox.Show("không đủ câu hỏi trong cơ sở dữ liệu", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Error); instance = null; infoTest.Lever = null; infoTest.NumberQuestions = 0; return; } int[] random = ArrayRandom(infoTest.NumberQuestions, Datatable.Count); int number = 1; int height = 0; for (int i = 0; i < infoTest.NumberQuestions; i++) { OjQuestion Item = Datatable[random[i]]; UCQuestion UcQ = new UCQuestion(); UcQ.Location = new Point(0, height); UcQ.Number = number; UcQ.Question1 = Item.Question1; UcQ.A1 = Item.A1; UcQ.B1 = Item.B1; UcQ.C1 = Item.C1; UcQ.D1 = Item.D1; UcQ.AnswerTrue1 = Item.AnswerTrue1.Trim(); pnlQuestions.Controls.Add(UcQ); height += 277; number += 1; } this.Enabled = true; }