コード例 #1
0
        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;
                _KTDTPNRepo = new KTDTPNRepo();
                //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_DTPN obj = new KT_DTPN();
                    obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                    obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                    obj.DIA_CHI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI"), "");
                    obj.DIA_CHI_GH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI_GH"), "");
                    obj.MA_SO_THUE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_SO_THUE"), "");
                    obj.LIEN_HE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "LIEN_HE"), "");
                    obj.DIEN_THOAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIEN_THOAI"), "");
                    obj.TK_NH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_NH"), "");
                    obj.TEN_TKNH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TKNH"), "");
                    obj.MA_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TT"), "");
                    obj.TEN_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TT"), "");
                    obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), "");
                    obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), "");
                    obj.CK_PT = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "CK_PT"), 0);
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                    _KTDTPNRepo.Create(obj);
                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_DTPN obj = _KTDTPNRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                        obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                        obj.DIA_CHI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI"), "");
                        obj.DIA_CHI_GH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIA_CHI_GH"), "");
                        obj.MA_SO_THUE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_SO_THUE"), "");
                        obj.LIEN_HE = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "LIEN_HE"), "");
                        obj.DIEN_THOAI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DIEN_THOAI"), "");
                        obj.TK_NH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_NH"), "");
                        obj.TEN_TKNH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TKNH"), "");
                        obj.MA_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TT"), "");
                        obj.TEN_TT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TT"), "");
                        obj.MA_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_NHOM"), "");
                        obj.TEN_NHOM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_NHOM"), "");
                        obj.CK_PT = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "CK_PT"), 0);
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                        obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                        _KTDTPNRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #2
0
        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)
                {
                    _KTDTPNRepo = new KTDTPNRepo();
                    KT_DTPN obj = new KT_DTPN();
                    obj.MA_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN"), "");
                    obj.TEN_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DTPN"), "");
                    obj.DIA_CHI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DIA_CHI"), "");
                    obj.DIA_CHI_GH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DIA_CHI_GH"), "");
                    obj.MA_SO_THUE = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_SO_THUE"), "");
                    obj.LIEN_HE = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LIEN_HE"), "");
                    obj.DIEN_THOAI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DIEN_THOAI"), "");
                    obj.TK_NH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TK_NH"), "");
                    obj.TEN_TKNH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TKNH"), "");
                    obj.MA_TT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TT"), "");
                    obj.TEN_TT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TT"), "");
                    obj.MA_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_NHOM"), "");
                    obj.TEN_NHOM = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_NHOM"), "");
                    obj.CK_PT = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "CK_PT"), 0);
                    obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0);

                    _KTDTPNRepo.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);
            }
        }