コード例 #1
0
 private void Load_Data()
 {
     try
     {
         _KTCTTPRepo = new KTCTTPRepo();
         gridData.DataSource = _KTCTTPRepo.GetAll();
         //_db = new dbVstoreAppDataContext(Const.builder.ConnectionString);
         //gridData.DataSource = null;
         //gridData.DataSource = _db.KT_DMHHs;
         //gridData.RefreshDataSource();
         //gridView1.RefreshData();
     }
     catch (Exception) { }
 }
コード例 #2
0
 private void Save_Data(bool msg)
 {
     try
     {
         _KTCTTPRepo = new KTCTTPRepo();
         int i = 0;
         foreach (int pos in _listUpdate)
         {
             int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
             KT_CTTP obj = _KTCTTPRepo.GetById(id);
             if (obj != null)
             {
                 obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_CT"), "");
                 obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_CT"), "");
                 DateTime? temp = null;
                 if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_HD"), DateTime.MinValue) != DateTime.MinValue)
                     temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_HD"), DateTime.MinValue);
                 obj.NGAY_HD = temp;
                 obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(pos, "SO_HD"), "");
                 obj.MA_TP = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_TP"), "");
                 obj.TEN_TP = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_TP"), "");
                 obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DON_VI"), "");
                 obj.SL_DH = Utils.CDblDef(gridView1.GetRowCellValue(pos, "SL_DH"), 0);
                 obj.DG_DH = Utils.CDblDef(gridView1.GetRowCellValue(pos, "DG_DH"), 0);
                 obj.TT_DH = Utils.CDblDef(gridView1.GetRowCellValue(pos, "TT_DH"), 0);
                 //obj.tk_no = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DTPN_NO"), "");
                 obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), "");
                 obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"), 0);
                 obj.MA_KH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_KH"), "");
                 obj.TEN_KH = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_KH"), "");
                 
                 _KTCTTPRepo.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);
     }
 }
コード例 #3
0
 private void Save_Tick()
 {
     try
     {
         _KTCTTPRepo = new KTCTTPRepo();
         int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0);
         KT_CTTP obj = _KTCTTPRepo.GetById(id);
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _KTCTTPRepo.Update(obj);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #4
0
        private void gridView1_ValidateRow(object sender, DevExpress.XtraGrid.Views.Base.ValidateRowEventArgs e)
        {
            try
            {
                GridView view = sender as GridView;

                ////validation
                GridColumn ma_tpCol = view.Columns["MA_TP"];
                GridColumn ma_ctCol = view.Columns["MA_CT"];
                string ma_tp = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_tpCol), "");
                string ma_ct = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, ma_ctCol), "");
                if (ma_tp.Trim().Length == 0 || ma_ct.Trim().Length == 0)
                {
                    e.Valid = false;
                    if (ma_tp.Trim().Length == 0)
                        view.SetColumnError(ma_tpCol, "Mã thành phẩm không được rổng");
                    if (ma_ct.Trim().Length == 0)
                        view.SetColumnError(ma_ctCol, "Mã công trình không được rổng");

                    return;
                }

                _KTCTTPRepo = new KTCTTPRepo();
                //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_CTTP obj = new KT_CTTP();

                    obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), "");
                    obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), "");
                    DateTime? 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;
                    obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), "");
                    obj.MA_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TP"), "");
                    obj.TEN_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TP"), "");
                    obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), "");
                    obj.SL_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SL_DH"), 0);
                    obj.DG_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DG_DH"), 0);
                    obj.TT_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TT_DH"), 0);
                    //obj.tk_no = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DTPN_NO"), "");
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);
                    obj.MA_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_KH"), "");
                    obj.TEN_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_KH"), "");

                    _KTCTTPRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
                    KT_CTTP obj = _KTCTTPRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MA_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_CT"), "");
                        obj.TEN_CT = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_CT"), "");
                        DateTime? 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;
                        obj.SO_HD = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "SO_HD"), "");
                        obj.MA_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_TP"), "");
                        obj.TEN_TP = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_TP"), "");
                        obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), "");
                        obj.SL_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "SL_DH"), 0);
                        obj.DG_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "DG_DH"), 0);
                        obj.TT_DH = Utils.CDblDef(view.GetRowCellValue(e.RowHandle, "TT_DH"), 0);
                        //obj.tk_no = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DTPN_NO"), "");
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                        obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);
                        obj.MA_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_KH"), "");
                        obj.TEN_KH = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_KH"), "");

                        _KTCTTPRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #5
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);

                int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
                _KTCTTPRepo = new KTCTTPRepo();
                _KTCTTPRepo.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);
            }
        }
コード例 #6
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)
                {
                    _KTCTTPRepo = new KTCTTPRepo();
                    KT_CTTP obj = new KT_CTTP();

                    obj.MA_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_CT"), "");
                    obj.TEN_CT = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_CT"), "");
                    DateTime? 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;
                    obj.SO_HD = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SO_HD"), "");
                    obj.MA_TP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_TP"), "");
                    obj.TEN_TP = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_TP"), "");
                    obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DON_VI"), "");
                    obj.SL_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "SL_DH"), 0);
                    obj.DG_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DG_DH"), 0);
                    obj.TT_DH = Utils.CDblDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TT_DH"), 0);
                    //obj.tk_no = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DTPN_NO"), "");
                    obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TRANG_THAI"), 0);
                    obj.MA_KH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MA_KH"), "");
                    obj.TEN_KH = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "TEN_KH"), "");

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