partial void DeleteKT_CTLenhSX(KT_CTLenhSX instance);
partial void UpdateKT_CTLenhSX(KT_CTLenhSX instance);
private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e) { try { GridView view = sender as GridView; //validation GridColumn ma_lenhCol = view.Columns["MA_LENH_SX"]; //GridColumn ma_nhomCol = view.Columns["MA_NHOM"]; string ma_lenh = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_lenhCol), ""); //string ma_nhom = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_nhomCol), ""); if (ma_lenh.Trim().Length == 0) { e.Valid = false; if (ma_lenh.Trim().Length == 0) view.SetColumnError(ma_lenhCol, "Mã lệnh sản xuất không được rổng"); //if (ma_nhom.Trim().Length == 0) // view.SetColumnError(ma_nhomCol, "Mã nhóm không được rổng"); return; } _KTCTLenhSXRepo = new KTCTLenhSXRepo(); //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_CTLenhSX obj = new KT_CTLenhSX(); obj.MA_LENH_SX = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_LENH_SX"), ""); obj.TEN_LENH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_LENH"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_LENH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_LENH"), DateTime.MinValue); obj.NGAY_LENH = temp; obj.ND_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "ND_HD"), ""); obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), ""); obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCTLenhSXRepo.Create(obj); } //Cũ thì update else { int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0); KT_CTLenhSX obj = _KTCTLenhSXRepo.GetById(id); if (obj != null) { obj.MA_LENH_SX = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_LENH_SX"), ""); obj.TEN_LENH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_LENH"), ""); DateTime? temp = null; if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_LENH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_LENH"), DateTime.MinValue); obj.NGAY_LENH = temp; obj.ND_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "ND_HD"), ""); obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), ""); obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), ""); obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), ""); obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), ""); obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), ""); obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0); _KTCTLenhSXRepo.Update(obj); } } Load_Data(); } catch (Exception ex) { e.Valid = false; MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
partial void InsertKT_CTLenhSX(KT_CTLenhSX instance);
private void Save_Duplicate() { try { if (MessageBox.Show("Bạn có muốn copy dòng này thành dòng mới?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { _KTCTLenhSXRepo = new KTCTLenhSXRepo(); KT_CTLenhSX obj = new KT_CTLenhSX(); obj.MA_LENH_SX = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_LENH_SX"), ""); obj.TEN_LENH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_LENH"), ""); DateTime? temp = null; if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_LENH"), DateTime.MinValue) != DateTime.MinValue) temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_LENH"), DateTime.MinValue); obj.NGAY_LENH = temp; obj.ND_HD = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ND_HD"), ""); obj.MA_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN"), ""); obj.TEN_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DTPN"), ""); obj.MA_DM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DM"), ""); obj.TEN_DM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DM"), ""); obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), ""); obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DON_VI"), ""); obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), ""); obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0); _KTCTLenhSXRepo.Create(obj); MessageBox.Show("Đã copy dòng này vào cuối bảng!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error); } }