コード例 #1
0
 private void Save_Data(bool msg)
 {
     try
     {
         _KTDGBNgayRepo = new KTDGBNgayRepo();
         int i = 0;
         foreach (int pos in _listUpdate)
         {
             int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
             KT_DGB_Ngay obj = _KTDGBNgayRepo.GetById(id);
             if (obj != null)
             {
                 DateTime? temp = null;
                 if (Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_AD"), DateTime.MinValue) != DateTime.MinValue)
                     temp = Utils.CDateDef(gridView1.GetRowCellValue(pos, "NGAY_AD"), DateTime.MinValue);
                 obj.NGAY_AD = temp;
                 obj.MA_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MA_DM"), "");
                 obj.TEN_DM = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TEN_DM"), "");
                 obj.DON_VI = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DON_VI"), "");
                 obj.DGBAN1 = Utils.CIntDef(gridView1.GetRowCellValue(pos, "DGBAN1"), 0);
                 obj.DGBAN2 = Utils.CIntDef(gridView1.GetRowCellValue(pos, "DGBAN2"), 0);
                 obj.DGBAN3 = Utils.CIntDef(gridView1.GetRowCellValue(pos, "DGBAN3"), 0);
                 obj.DGBAN4 = Utils.CIntDef(gridView1.GetRowCellValue(pos, "DGBAN4"), 0);
                 obj.DGBAN5 = Utils.CIntDef(gridView1.GetRowCellValue(pos, "DGBAN5"), 0);
                 obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), "");
                 obj.TRANG_THAI = Utils.CIntDef(gridView1.GetRowCellValue(pos, "TRANG_THAI"), 0);
                 
                 _KTDGBNgayRepo.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);
     }
 }
コード例 #2
0
 private void Save_Tick()
 {
     try
     {
         _KTDGBNgayRepo = new KTDGBNgayRepo();
         int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID").ToString(), 0);
         KT_DGB_Ngay obj = _KTDGBNgayRepo.GetById(id);
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _KTDGBNgayRepo.Update(obj);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
コード例 #3
0
        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;
                //}

                _KTDGBNgayRepo = new KTDGBNgayRepo();
                //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_DGB_Ngay obj = new KT_DGB_Ngay();

                    DateTime? temp = null;
                    if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_AD"), DateTime.MinValue) != DateTime.MinValue)
                        temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_AD"), DateTime.MinValue);
                    obj.NGAY_AD = temp;
                    obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), "");
                    obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), "");
                    obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), "");
                    obj.DGBAN1 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN1"), 0);
                    obj.DGBAN2 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN2"), 0);
                    obj.DGBAN3 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN3"), 0);
                    obj.DGBAN4 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN4"), 0);
                    obj.DGBAN5 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN5"), 0);
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                    obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                    _KTDGBNgayRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
                    KT_DGB_Ngay obj = _KTDGBNgayRepo.GetById(id);
                    if (obj != null)
                    {
                        DateTime? temp = null;
                        if (Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_AD"), DateTime.MinValue) != DateTime.MinValue)
                            temp = Utils.CDateDef(view.GetRowCellValue(e.RowHandle, "NGAY_AD"), DateTime.MinValue);
                        obj.NGAY_AD = temp;
                        obj.MA_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MA_DM"), "");
                        obj.TEN_DM = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TEN_DM"), "");
                        obj.DON_VI = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DON_VI"), "");
                        obj.DGBAN1 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN1"), 0);
                        obj.DGBAN2 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN2"), 0);
                        obj.DGBAN3 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN3"), 0);
                        obj.DGBAN4 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN4"), 0);
                        obj.DGBAN5 = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "DGBAN5"), 0);
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");
                        obj.TRANG_THAI = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "TRANG_THAI"), 0);

                        _KTDGBNgayRepo.Update(obj);
                    }

                }
                Load_Data();
            }
            catch (Exception ex)
            {
                e.Valid = false;
                MessageBox.Show(ex.Message, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }