コード例 #1
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);
            }
        }
コード例 #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)
                {
                    _KTDGBNgayRepo = new KTDGBNgayRepo();
                    KT_DGB_Ngay obj = new KT_DGB_Ngay();

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

                    _KTDGBNgayRepo.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);
            }
        }
コード例 #3
0
 partial void UpdateKT_DGB_Ngay(KT_DGB_Ngay instance);
コード例 #4
0
 partial void DeleteKT_DGB_Ngay(KT_DGB_Ngay instance);
コード例 #5
0
 partial void InsertKT_DGB_Ngay(KT_DGB_Ngay instance);