protected void grvData_CustomButtonCallback(object sender, DevExpress.Web.ASPxGridViewCustomButtonCallbackEventArgs e) { long id = long.Parse(grvData.GetRowValues(e.VisibleIndex, grvData.KeyFieldName).ToString()); if (e.ButtonID == "GridEdit") { setHdf(hdfID, id); setMode(CGlobal.FunctionMode.EditMode); initFuncMode(); } else if (e.ButtonID == "GridDelete") { DatabaseDAO dao = new DatabaseDAO(); objProblemsTestCase = new BUS.BUS_ProblemsTestCases(dao); obj = new BUS.BUS_Problems(dao); BUS.BUS_ProblemsInContest objProblemsInContest = new BUS.BUS_ProblemsInContest(dao); try { dao.BeginTransaction(); objProblemsTestCase.ProblemId = id; objProblemsTestCase.DeleteByProblemId(); objProblemsInContest.DeleteByProblem(id); obj.Delete(id); dao.EndTransaction(); setMode(CGlobal.FunctionMode.SearchMode); initFuncMode(); } catch (Exception ex) { dao.RollBack(); HELPER.CError.ErrorType err = HELPER.CError.Parse(ex.Message); if (err == CError.ErrorType.InUse) { HELPER.Client.Alert(this, "Dữ liệu đã được sử dụng. Không thể xóa được!"); } else { HELPER.Client.Alert(this, "Lỗi xóa dữ liệu!"); } } } }
protected void btnSave_Click(object sender, EventArgs e) { DatabaseDAO dao = new DatabaseDAO(); objContest = new BUS.BUS_Contests(dao); objProbInContest = new BUS.BUS_ProblemsInContest(dao); try { dao.BeginTransaction(); HELPER.CWebPage.BindProperty(objContest, pnEdit); try { //objContest.StartTime = objContest.StartTime.Date.AddMinutes(txtStartTime.DateTime.TimeOfDay.TotalMinutes); //objContest.EndTime = objContest.EndTime.Date.AddMinutes(txtEndTime.DateTime.TimeOfDay.TotalMinutes); if (txtIsLimitTime.Checked) { objContest.StartTime = dteStartTime.Date.AddMinutes(txtStartTime.DateTime.TimeOfDay.TotalMinutes); objContest.EndTime = dteEndTime.Date.AddMinutes(txtEndTime.DateTime.TimeOfDay.TotalMinutes); if (objContest.StartTime > objContest.EndTime) { HELPER.Client.Alert(this, "Thời gian bắt đầu phải trước thời gian kết thúc!"); return; } } else { objContest.StartTime = DateTime.MinValue; objContest.EndTime = DateTime.MinValue; } } catch (Exception) { objContest.StartTime = DateTime.MinValue; objContest.EndTime = DateTime.MinValue; } FMode = getMode(); long id = 0; if (FMode == CGlobal.FunctionMode.AddMode) { id = objContest.Insert(); setHdf(hdfID, id); objProbInContest.ContestsId = id; } else if (FMode == CGlobal.FunctionMode.EditMode) { id = getHdf(hdfID); objContest.Id = id; objProbInContest.ContestsId = id; objContest.Update(); objProbInContest.DeleteByContest(); } DataTable dtChecked = objProbInContest.LoadByContestID(id); List <DataRow> list = dtChecked.AsEnumerable().ToList(); foreach (ListEditItem item in cblProblems.Items) { if (item.Selected) { objProbInContest.ProblemsId = long.Parse(item.Value.ToString()); objProbInContest.Insert(); } } dao.EndTransaction(); setMode(CGlobal.FunctionMode.SearchMode); initFuncMode(); } catch (Exception ex) { dao.RollBack(); HELPER.CError.ErrorType err = HELPER.CError.Parse(ex.Message); if (err == CError.ErrorType.Duplicate) { HELPER.Client.Alert(this, "Dữ liệu đã tồn tại!"); } else { HELPER.Client.Alert(this, "Lỗi cấp nhật CSDL!" + err.ToString()); } } }