Ejemplo n.º 1
0
 private void Save_Data(bool msg)
 {
     try
     {
         _KTDMKURepo = new KTDMKURepo();
         int i = 0;
         foreach (int pos in _listUpdate)
         {
             int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
             KT_DMKU obj = _KTDMKURepo.GetById(id);
             if (obj != null)
             {
                 obj.SO_KU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_KU"), "");
                 obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_HD"), "");
                 obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), "");
                 obj.MA_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN"), "");
                 obj.TEN_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DTPN"), "");
                 obj.NOI_DUNG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NOI_DUNG"), "");
                 obj.GT_KU_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_KU_VND"), 0);
                 obj.GT_KU_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_KU_USD"), 0);
                 DateTime? temp = null;
                 if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KU"), DateTime.MinValue) != DateTime.MinValue)
                     temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KU"), DateTime.MinValue);
                 obj.NGAY_KU = temp;
                 temp = null;
                 if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue)
                     temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue);
                 obj.NGAY_HD = temp;
                 temp = null;
                 if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_DH"), DateTime.MinValue) != DateTime.MinValue)
                     temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_DH"), DateTime.MinValue);
                 obj.NGAY_DH = temp;
                 obj.HANMUC_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HANMUC_VND"), 0);
                 obj.HANMUC_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HANMUC_USD"), 0);
                 obj.LAI_SUAT_VAY = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LAI_SUAT_VAY"), 0);
                 obj.GT_HD_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_HD_VND"), 0);
                 obj.GT_HD_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_HD_USD"), 0);
                 obj.GHI_CHU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GHI_CHU"), "");
                 _KTDMKURepo.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);
     }
 }
Ejemplo n.º 2
0
 private void Load_Data()
 {
     try
     {
         _KTDMKURepo = new KTDMKURepo();
         gridData.DataSource = _KTDMKURepo.GetAll();
         //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString);
         //gridData.DataSource = null;
         //gridData.DataSource = _db.KT_DMKUs;
         //gridData.RefreshDataSource();
         //gridView1.RefreshData();
     }
     catch (Exception) { }
 }
Ejemplo n.º 3
0
        private void Remove_Data()
        {
            try
            {
                //if (_listUpdate.Count > 0)
                //{
                //    MessageBox.Show("Hãy thực hiện lưu trước khi xóa!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //    return;
                //}
                Save_Data(false);

                _KTDMKURepo = new KTDMKURepo();
                int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);

                _KTDMKURepo.Remove(id);

                //MessageBox.Show("Xóa dòng ID:" + Id + " thành công!", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Load_Data();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 4
0
        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;

                //validation
                GridColumn so_kuCol = view.Columns["SO_KU"];
                GridColumn so_hdCol = view.Columns["SO_HD"];
                GridColumn ma_tkCol = view.Columns["MA_TK"];
                GridColumn ma_dtpnCol = view.Columns["MA_DTPN"];
                string so_ku = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, so_kuCol), "");
                string so_hd = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, so_hdCol), "");
                string ma_tk = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tkCol), "");
                string ma_dtpn = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_dtpnCol), "");
                if (so_ku.Trim().Length == 0 || so_hd.Trim().Length == 0 || ma_tk.Trim().Length == 0 || ma_dtpn.Trim().Length == 0)
                {
                    e.Valid = false;
                    if (so_ku.Trim().Length == 0)
                        view.SetColumnError(so_kuCol, "Số khế ước không được rổng");
                    if (so_hd.Trim().Length == 0)
                        view.SetColumnError(so_hdCol, "Số hợp đồng không được rổng");
                    if (ma_tk.Trim().Length == 0)
                        view.SetColumnError(ma_tkCol, "Mã tài khoản không được rổng");
                    if (ma_dtpn.Trim().Length == 0)
                        view.SetColumnError(ma_dtpnCol, "Mã đối tượng pháp nhân không được rổng");

                    return;
                }
                _KTDMKURepo = new KTDMKURepo();

                //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_DMKU obj = new KT_DMKU();
                    obj.SO_KU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_KU"), "");
                    obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), "");
                    obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), "");
                    obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                    obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                    obj.NOI_DUNG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NOI_DUNG"), "");
                    obj.GT_KU_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_KU_VND"), 0);
                    obj.GT_KU_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_KU_USD"), 0);
                    DateTime? temp = null;
                    if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_KU"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_KU"), DateTime.MinValue);
                    obj.NGAY_KU = temp;
                    temp = null;
                    if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue);
                    obj.NGAY_HD = temp;
                    temp = null;
                    if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_DH"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_DH"), DateTime.MinValue);
                    obj.NGAY_DH = temp;
                    obj.HANMUC_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "HANMUC_VND"), 0);
                    obj.HANMUC_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "HANMUC_USD"), 0);
                    obj.LAI_SUAT_VAY = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LAI_SUAT_VAY"), 0);
                    obj.GT_HD_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_HD_VND"), 0);
                    obj.GT_HD_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_HD_USD"), 0);
                    obj.GHI_CHU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "GHI_CHU"), "");

                    _KTDMKURepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_DMKU obj = _KTDMKURepo.GetById(id);
                    if (obj != null)
                    {
                        obj.SO_KU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_KU"), "");
                        obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), "");
                        obj.MA_TK = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TK"), "");
                        obj.MA_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DTPN"), "");
                        obj.TEN_DTPN = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DTPN"), "");
                        obj.NOI_DUNG = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "NOI_DUNG"), "");
                        obj.GT_KU_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_KU_VND"), 0);
                        obj.GT_KU_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_KU_USD"), 0);
                        DateTime? temp = null;
                        if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_KU"), DateTime.MinValue) != DateTime.MinValue)
                            temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_KU"), DateTime.MinValue);
                        obj.NGAY_KU = temp;
                        temp = null;
                        if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue)
                            temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_HD"), DateTime.MinValue);
                        obj.NGAY_HD = temp;
                        temp = null;
                        if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_DH"), DateTime.MinValue) != DateTime.MinValue)
                            temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_DH"), DateTime.MinValue);
                        obj.NGAY_DH = temp;
                        obj.HANMUC_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "HANMUC_VND"), 0);
                        obj.HANMUC_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "HANMUC_USD"), 0);
                        obj.LAI_SUAT_VAY = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "LAI_SUAT_VAY"), 0);
                        obj.GT_HD_VND = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_HD_VND"), 0);
                        obj.GT_HD_USD = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "GT_HD_USD"), 0);
                        obj.GHI_CHU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "GHI_CHU"), "");

                        _KTDMKURepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Ejemplo n.º 5
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)
                {
                    _KTDMKURepo = new KTDMKURepo();
                    KT_DMKU obj = new KT_DMKU();
                    obj.SO_KU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_KU"), "");
                    obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_HD"), "");
                    obj.MA_TK = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TK"), "");
                    obj.MA_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_DTPN"), "");
                    obj.TEN_DTPN = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_DTPN"), "");
                    obj.NOI_DUNG = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NOI_DUNG"), "");
                    obj.GT_KU_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_KU_VND"), 0);
                    obj.GT_KU_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_KU_USD"), 0);
                    DateTime? temp = null;
                    if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KU"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_KU"), DateTime.MinValue);
                    obj.NGAY_KU = temp;
                    temp = null;
                    if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_HD"), DateTime.MinValue);
                    obj.NGAY_HD = temp;
                    temp = null;
                    if (Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_DH"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "NGAY_DH"), DateTime.MinValue);
                    obj.NGAY_DH = temp;
                    obj.HANMUC_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HANMUC_VND"), 0);
                    obj.HANMUC_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "HANMUC_USD"), 0);
                    obj.LAI_SUAT_VAY = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "LAI_SUAT_VAY"), 0);
                    obj.GT_HD_VND = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_HD_VND"), 0);
                    obj.GT_HD_USD = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GT_HD_USD"), 0);
                    obj.GHI_CHU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "GHI_CHU"), ""); 

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