Exemplo n.º 1
0
 public static void save_KMPOS(KhuyenMaiPOS obj,CTKhuyenMaiPOS objCT,List<DieuKienKhuyenMaiPOS> objDK,List<ExceptionPOS> objEX=null)
 {
     using (var model= new SGCoopSTEntities())
     {
         using(var trans= model.Database.BeginTransaction())
         {
             try
             {
                 model.KhuyenMaiPOS.Add(obj);
                 model.CTKhuyenMaiPOS.Add(objCT);
                 model.DieuKienKhuyenMaiPOS.AddRange(objDK);
                 if (objEX.Count!=0)
                 {
                     model.ExceptionPOS.AddRange(objEX);
                 }
                 model.SaveChanges();
                 trans.Commit();
             }
             catch (DbEntityValidationException ex)
             {
                 trans.Rollback();
                 List<string> errorMessages = new List<string>();
                 foreach (DbEntityValidationResult validationResult in ex.EntityValidationErrors)
                 {
                     string entityName = validationResult.Entry.Entity.GetType().Name;
                     foreach (DbValidationError error in validationResult.ValidationErrors)
                     {
                         errorMessages.Add(entityName + "." + error.PropertyName + ": " + error.ErrorMessage);
                     }
                 }
                 throw new Exception(errorMessages.ToString());
             }
         }
     }
 }
Exemplo n.º 2
0
 public static CTKhuyenMaiPOS load(CTKhuyenMaiPOS obj)
 {
     using (var model = new SGCoopSTEntities())
     {
         var objct = from l in model.CTKhuyenMaiPOS where l.MaDotKhuyenMai == obj.MaDotKhuyenMai select l;
         return objct.FirstOrDefault();
     }
 }
Exemplo n.º 3
0
 public static void del_KMPOS(KhuyenMaiPOS obj, CTKhuyenMaiPOS objCT, List<DieuKienKhuyenMaiPOS> objDK, List<ExceptionPOS> objEX)
 {
     using(var model= new SGCoopSTEntities())
     {
         using(var trans= model.Database.BeginTransaction())
             try
             {
                 model.Entry(obj).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objCT).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objEX).State = System.Data.Entity.EntityState.Deleted;
                 model.Entry(objDK).State = System.Data.Entity.EntityState.Deleted;
                 model.SaveChanges();
                 trans.Commit();
             }
             catch (Exception ex)
             {
                 trans.Rollback();
                 throw new Exception(ex.Message);
             }
     }
 }
Exemplo n.º 4
0
        void add()
        {
            objCT = new CTKhuyenMaiPOS(); lstDK = new List<DieuKienKhuyenMaiPOS>(); lstEX = new List<ExceptionPOS>(); objKM = new KhuyenMaiPOS(); lst_KM_ST = new List<KhuyenMai_SieuThi>();
            try
            {
                if (check_detail()==true)
                {
                    string _GuidCT = Guid.NewGuid().ToString();
                    int _STT = Create_Number();

                    set_object(_GuidCT, _STT);

                    CTLKhuyenMaiPOS.save_KMPOS(objKM, objCT, lstDK, lstEX);
                    MessageBox.Show("Đã lưu","Thông báo", MessageBoxButtons.OK,MessageBoxIcon.Information);
                    clear_form();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message.ToArray().ToString());
            }
        }
Exemplo n.º 5
0
 void update()
 {
     try
     {
         if (check_detail() == true)
         {
             string _GuidCT = objCT.CTKhuyenMaiID;
             int _STT = objCT.STT;
             if (lstDK != null)
                 CTLDieuKienKhuyenMaiPOS.delete(lstDK);
             if (lstEX!= null)
                 CTLExceptionPOS.delete(lstEX);
             objCT = new CTKhuyenMaiPOS(); lstDK = new List<DieuKienKhuyenMaiPOS>(); lstEX = new List<ExceptionPOS>(); objKM = new KhuyenMaiPOS();
             objKM.MaNVCapNhat = CurrentUser.MaNV;
             set_object(_GuidCT, _STT);
             CTLKhuyenMaiPOS.update_KMPOS(objKM, objCT, lstDK, lstEX);
             MessageBox.Show("Đã lưu", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.Close();
             //clear_form();
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message.ToString());
     }
 }
Exemplo n.º 6
0
        void load_data_update()
        {
            txtTenDotKhuyenMai.Text = objKM.TenDotKhuyenMai;
            cboKhuyenMai.SelectedItem = objKM.HinhThucKM.ToString().Trim();
            chkCombo.Checked = bool.Parse(objKM.IsCombo.ToString());
            chkLoaiTruSKU.Checked = bool.Parse(objKM.IsExept.ToString());
            dateTuNgay.Value = objKM.TuNgay;
            dateDenNgay.Value = objKM.DenNgay;
            chkDaApDung.Checked = objKM.DaApDung;
            chkDaThucHien.Checked = bool.Parse(objKM.DaThucHien.ToString());

            //*******load CTKhuyenMaiPOS************************************//
            objCT = new CTKhuyenMaiPOS();
            objCT.MaDotKhuyenMai = objKM.MaDotKhuyenMai;
            objCT = CTLCTKhuyenMaiPOS.load(objCT);

            txtDKCongDiem.Text = objCT.DieuKien;
            txtDiemThuongGioiHan.Text = objCT.DiemThuongGioiHan.ToString();
            txtGiaTriHoaDon.Text = format_value(objCT.GiaTriTongHoaDon.ToString().Replace(".00", ""));
            txtGhiChu.Text = objCT.GhiChu;

            //******load DieuKienKhuyenMai POS*****************************//
            objDK = new DieuKienKhuyenMaiPOS();
            objDK.CTKhuyenMaiID = objCT.CTKhuyenMaiID;

            lstDK = new List<DieuKienKhuyenMaiPOS>();
            lstDK = CTLDieuKienKhuyenMaiPOS.Load(objDK);
            if(lstDK.Count>0)
            {
                dgvDieuKienKM.AutoGenerateColumns = false;
                dgvDieuKienKM.DataSource = lstDK;
            }

            //*****load ExceptionPOS**************************************//
            if(objKM.IsExept==true)
            {
                objEX = new ExceptionPOS();
                objEX.MaDotKhuyenMai = objKM.MaDotKhuyenMai;
                lstEX = new List<ExceptionPOS>();
                lstEX = CTLExceptionPOS.Load(objEX);
                if(lstEX.Count>0)
                {
                    dgvExPOS.AutoGenerateColumns = false;
                    dgvExPOS.DataSource = lstEX;
                }
            }
        }