protected void btnSaveTestCase_Click(object sender, EventArgs e) { DatabaseDAO dao = new DatabaseDAO(); objProblemsTestCase = new BUS.BUS_ProblemsTestCases(dao); objProblemsTestCase.ProblemId = getHdf(hdfID); dao.BeginTransaction(); long maxPoint = long.Parse(txtMaximumPoints.Text); try { long sumPoin = 0; objProblemsTestCase.DeleteByProblemId(); for (int i = 1; i < tbTestCase.Rows.Count; i++) { DevExpress.Web.ASPxCheckBox ckb = (DevExpress.Web.ASPxCheckBox)tbTestCase.Rows[i].Cells[0].Controls[0]; DevExpress.Web.ASPxSpinEdit spn = (DevExpress.Web.ASPxSpinEdit)tbTestCase.Rows[i].Cells[1].Controls[0]; if (ckb.Checked) { objProblemsTestCase.FileName = ckb.Text; objProblemsTestCase.Point = long.Parse(spn.Value.ToString()); objProblemsTestCase.Insert(); sumPoin += objProblemsTestCase.Point; } } if (sumPoin != maxPoint) { //dao.RollBack(); HELPER.Client.Alert(this, "Tổng điểm các bộ test (" + sumPoin + ") không bằng số điểm tối đa (" + maxPoint + ")!"); } //HELPER.Client.Alert(this, "Soos bộ test: " + tbTestCase.Rows.Count); dao.EndTransaction(); // initTableTestCase(); } catch (Exception ex) { dao.RollBack(); HELPER.Client.Alert(this, "Lỗi cập nhật bộ test: " + ex.ToString()); } }
private void initTableTestCase() { TableItemStyle headerStyle = new TableItemStyle(); headerStyle.Font.Bold = true; headerStyle.HorizontalAlign = HorizontalAlign.Center; headerStyle.VerticalAlign = VerticalAlign.Middle; //headerStyle.BackColor = Color.Gray; TableRow headerRow = new TableRow(); // Create a header for the table. TableCell header = new TableCell(); header.ApplyStyle(headerStyle); header.Text = "Bộ test"; // Add the header to a new row. headerRow.Cells.Add(header); header = new TableCell(); header.Text = "Điểm"; header.ApplyStyle(headerStyle); headerRow.Cells.Add(header); // Add the header row to the table. tbTestCase.Rows.AddAt(0, headerRow); string path = Server.MapPath(CConstant.C_DIRECTORY_TESTCASES); string[] arrTests = Directory.GetFiles(path) .Select(Path.GetFileName) .Where(file => file.ToUpper().EndsWith("IN") && File.Exists(path + file.ToUpper().Replace("IN", "OUT"))) .ToArray(); hdfX.Set("listTestCases", arrTests); string[] listTestCases = (string[])hdfX.Get("listTestCases"); DataTable dt = objProblemsTestCase.LoadByProblemID(getHdf(hdfID)); List <DataRow> list = dt.AsEnumerable().ToList(); for (int i = 0; i < arrTests.Length; i++) { TableRow tbRow = new TableRow(); TableCell tbCell = new TableCell(); DevExpress.Web.ASPxCheckBox ckb = new DevExpress.Web.ASPxCheckBox(); ckb.Text = arrTests[i].Replace(".IN", ""); ckb.Attributes.Add("runat", "server"); //ckb.ID = "ckb" + i; ckb.Width = Unit.Pixel(200); tbCell.Controls.Add(ckb); tbRow.Cells.Add(tbCell); tbCell = new TableCell(); DevExpress.Web.ASPxSpinEdit spn = new DevExpress.Web.ASPxSpinEdit(); spn.Attributes.Add("runat", "server"); //spn.ID = "spn" + i; spn.Width = Unit.Pixel(100); spn.MinValue = 0; spn.MaxValue = 9999999999999999999; spn.Number = 0; spn.DisplayFormatString = "#,###"; tbCell.Controls.Add(spn); tbRow.Cells.Add(tbCell); tbTestCase.Rows.Add(tbRow); string lsTrim = ckb.Text.ToUpper(); for (int j = 0; j < list.Count; j++) { if (list[j].ItemArray[2].ToString().ToUpper() == lsTrim) { ckb.Checked = true; spn.Value = list[j].ItemArray[3].ToString(); } } //tbTestCase.DataBind(); //tbTestCase.Dispose(); } }