Пример #1
0
        private void Save_Data(bool msg)
        {
            try
            {
                _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo();
                int i = 0;
                foreach (int pos in _listUpdate)
                {
                    int id = Utils.CIntDef(gridView1.GetRowCellValue(pos, "ID"), 0);
                    KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MADM_ME = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MADM_ME"), "");
                        obj.MADM_CON = Utils.CStrDef(gridView1.GetRowCellValue(pos, "MADM_CON"), "");
                        obj.TENDM_ME = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TENDM_ME"), "");
                        obj.TENDM_CON = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TENDM_CON"), "");
                        obj.SL = Utils.CIntDef(gridView1.GetRowCellValue(pos, "SL"), 0);
                        obj.TK_DU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "TK_DU"), "");
                        obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(pos, "DANH_DAU"), "");

                        _KTDMCauThanhSPRepo.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
     {
         _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo();
         int id = Utils.CIntDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "ID"), 0);
         KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id);
         if (obj != null)
         {
             obj.DANH_DAU = Utils.CStrDef(gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "DANH_DAU"), "").Trim() == "T" ? "" : "T";
             _KTDMCauThanhSPRepo.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 madm_meCol = view.Columns["MADM_ME"];
                GridColumn madm_conCol = view.Columns["MADM_CON"];
                string madm_me = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_meCol), "");
                string madm_con = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, madm_conCol), "");
                if (madm_me.Trim().Length == 0 || madm_con.Trim().Length == 0)
                {
                    e.Valid = false;
                    if (madm_me.Trim().Length == 0)
                        view.SetColumnError(madm_meCol, "Mã danh mục mẹ không được rổng");
                    if (madm_con.Trim().Length == 0)
                        view.SetColumnError(madm_conCol, "Mã danh mục con không được rổng");

                    return;
                }
                _KTDMCauThanhSPRepo = new KTDMCauThanhSPRepo();
                //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_DMCauThanhSP obj = new KT_DMCauThanhSP();
                    obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), "");
                    obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), "");
                    obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), "");
                    obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), "");
                    obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0);
                    obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), "");
                    obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                    _KTDMCauThanhSPRepo.Create(obj);

                }
                //Cũ thì update
                else
                {
                    int id = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "ID"), 0);
                    KT_DMCauThanhSP obj = _KTDMCauThanhSPRepo.GetById(id);
                    if (obj != null)
                    {
                        obj.MADM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_ME"), "");
                        obj.MADM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "MADM_CON"), "");
                        obj.TENDM_ME = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_ME"), "");
                        obj.TENDM_CON = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TENDM_CON"), "");
                        obj.SL = Utils.CIntDef(view.GetRowCellValue(e.RowHandle, "SL"), 0);
                        obj.TK_DU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "TK_DU"), "");
                        obj.DANH_DAU = Utils.CStrDef(view.GetRowCellValue(e.RowHandle, "DANH_DAU"), "");

                        _KTDMCauThanhSPRepo.Update(obj);
                    }

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