private void Save_Data(bool msg) { try { _KTDGBTheoNhomDTRepo = new KTDGBTheoNhomDTRepo(); int i = 0; foreach (int pos in _listUpdate) { int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0); KT_DGBTheoNhomDT obj = _KTDGBTheoNhomDTRepo.GetById(id); if (obj != null) { obj.MA_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "STT"), ""); obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_TK"), ""); obj.TEN_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DON_VI"), ""); obj.MA_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_NHOM"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), ""); obj.DGBAN1 = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DGBAN1"), 0); obj.DGBAN2 = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DGBAN2"), 0); obj.DGBAN3 = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DGBAN3"), 0); obj.DGBAN4 = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DGBAN4"), 0); obj.DGBAN5 = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DGBAN5"), 0); _KTDGBTheoNhomDTRepo.Update(obj); i++; } } _listUpdate = new List<int>(); //if (i > 0 && msg) //{ // MessageBox.Show("Lưu thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); //} } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void Save_Tick() { try { _KTDGBTheoNhomDTRepo = new KTDGBTheoNhomDTRepo(); int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0); KT_DGBTheoNhomDT obj = _KTDGBTheoNhomDTRepo.GetById(id); if (obj != null) { obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T"; _KTDGBTheoNhomDTRepo.Update(obj); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; //validation //GridColumn sttCol = view.Columns["STT"]; //GridColumn ma_nhomCol = view.Columns["MA_NHOM"]; //string stt = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, sttCol), ""); //string ma_nhom = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_nhomCol), ""); //if (stt.Trim().Length == 0 || ma_nhom.Trim().Length == 0 ) //{ // e.Valid = false; // if (stt.Trim().Length == 0) // view.SetColumnError(sttCol, "STT không được rổng"); // if (ma_nhom.Trim().Length == 0) // view.SetColumnError(ma_nhomCol, "Mã nhóm không được rổng"); // return; //} _KTDGBTheoNhomDTRepo = new KTDGBTheoNhomDTRepo(); //Kiểm tra đây là dòng dữ liệu mới hay cũ, nếu là mới thì mình insert if (view.IsNewItemRow(e.RowHandle)) { //e.RowHandle trả về giá trị int là thứ tự của dòng hiện tại KT_DGBTheoNhomDT obj = new KT_DGBTheoNhomDT(); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "STT"), ""); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.DGBAN1 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN1"), 0); obj.DGBAN2 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN3"), 0); obj.DGBAN4 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN4"), 0); obj.DGBAN5 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN5"), 0); _KTDGBTheoNhomDTRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_DGBTheoNhomDT obj = _KTDGBTheoNhomDTRepo.GetById(id); if (obj != null) { obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "STT"), ""); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), ""); obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.DGBAN1 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN1"), 0); obj.DGBAN2 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN3"), 0); obj.DGBAN4 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN4"), 0); obj.DGBAN5 = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DGBAN5"), 0); _KTDGBTheoNhomDTRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }