Пример #1
0
        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;
                _KTTKRepo = new KTTKRepo();
                //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_TK obj = new KT_TK();
                    obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), "");
                    obj.TEN_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TK"), "");
                    obj.VND_DU_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_DU_NO"), 0);
                    obj.VND_DU_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_DU_CO"), 0);
                    obj.VND_PS_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_PS_NO"), 0);
                    obj.VND_PS_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_PS_CO"), 0);
                    obj.VND_CK_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_CK_NO"), 0);
                    obj.VND_CK_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_CK_CO"), 0);
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                    _KTTKRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_TK obj = _KTTKRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), "");
                        obj.TEN_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TK"), "");
                        obj.VND_DU_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_DU_NO"), 0);
                        obj.VND_DU_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_DU_CO"), 0);
                        obj.VND_PS_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_PS_NO"), 0);
                        obj.VND_PS_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_PS_CO"), 0);
                        obj.VND_CK_NO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_CK_NO"), 0);
                        obj.VND_CK_CO = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "VND_CK_CO"), 0);
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                        _KTTKRepo.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)
                {
                    _KTTKRepo = new KTTKRepo();
                    KT_TK obj = new KT_TK();
                    obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), "");
                    obj.TEN_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TK"), "");
                    obj.VND_DU_NO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_DU_NO"), 0);
                    obj.VND_DU_CO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_DU_CO"), 0);
                    obj.VND_PS_NO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_PS_NO"), 0);
                    obj.VND_PS_CO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_PS_CO"), 0);
                    obj.VND_CK_NO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_CK_NO"), 0);
                    obj.VND_CK_CO = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "VND_CK_CO"), 0);
                    obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "");

                    _KTTKRepo.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);
            }
        }
 partial void UpdateKT_TK(KT_TK instance);
 partial void DeleteKT_TK(KT_TK instance);
 partial void InsertKT_TK(KT_TK instance);