예제 #1
0
        public AjaxStoreResult SaveCustomersWithConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext     db               = this.DBContext;
                StoreDataHandler         dataHandler      = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <Customer> data             = dataHandler.ObjectData <Customer>();
                ConfirmationList         confirmationList = dataHandler.BuildConfirmationList("CustomerID");

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    //customer.TemporaryID = customer.CustomerID;
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();

                //ideally we should confirm after each operation
                //but LINQ make batch submit of changes

                foreach (Customer customer in data.Deleted)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Updated)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Created)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }


                ajaxStoreResult.SaveResponse.ConfirmationList = confirmationList;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success      = false;
                ajaxStoreResult.SaveResponse.ErrorMessage = e.Message;
            }

            return(ajaxStoreResult);
        }
예제 #2
0
 public override void ExecuteResult(ControllerContext context)
 {
     if (isExport)
     {
         ExportResult exportResult = new ExportResult(data, exportFormat);
         exportResult.ExecuteResult(context);
     }
     else
     {
         AjaxStoreResult storeResult = new AjaxStoreResult(data, totalCount);
         storeResult.ExecuteResult(context);
     }
 }
예제 #3
0
        public ActionResult ChucvuList_Save()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                QLVBEntities             db               = this.DBContext;
                StoreDataHandler         dataHandler      = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <DMCHUCVU> data             = dataHandler.ObjectData <DMCHUCVU>();
                ConfirmationList         confirmationList = dataHandler.BuildConfirmationList("MACHUCVU");

                foreach (DMCHUCVU c in data.Deleted)
                {
                    db.DMCHUCVUs.Attach(c);
                    db.DMCHUCVUs.DeleteObject(c);
                }

                foreach (DMCHUCVU c in data.Created)
                {
                    db.DMCHUCVUs.AddObject(c);
                }

                foreach (DMCHUCVU c in data.Updated)
                {
                    var orgRecord = db.DMCHUCVUs.Single(p => p.MACHUCVU == c.MACHUCVU);
                    db.DMCHUCVUs.ApplyCurrentValues(c);
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                int nCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);

                if (nCode == -2146233087)
                {
                    ajaxStoreResult.SaveResponse.Message = "Trùng mã chức năng.";
                }
                else
                {
                    ajaxStoreResult.SaveResponse.Message = e.InnerException.Message;
                }
            }

            return(ajaxStoreResult);
        }
예제 #4
0
        public ActionResult SoVanbanList_Save()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                QLVBEntities           db          = this.DBContext;
                StoreDataHandler       dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <DMSOVB> data        = dataHandler.ObjectData <DMSOVB>();

                foreach (DMSOVB c in data.Deleted)
                {
                    db.DMSOVBs.Attach(c);
                    db.DMSOVBs.DeleteObject(c);
                }

                foreach (DMSOVB c in data.Created)
                {
                    c.IDSOVB = GetNewDanhmucID();
                    db.DMSOVBs.AddObject(c);
                }

                foreach (DMSOVB c in data.Updated)
                {
                    var orgRecord = db.DMSOVBs.Single(p => p.IDSOVB == c.IDSOVB);
                    db.DMSOVBs.ApplyCurrentValues(c);
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                int nCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);

                ajaxStoreResult.SaveResponse.Message = e.InnerException.Message;
            }

            return(ajaxStoreResult);
        }
예제 #5
0
        public AjaxStoreResult SaveCustomersWithoutConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext     db          = this.DBContext;
                StoreDataHandler         dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <Customer> data        = dataHandler.ObjectData <Customer>();

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                ajaxStoreResult.SaveResponse.Message = e.Message;
            }

            return(ajaxStoreResult);
        }
예제 #6
0
        public ActionResult NhanvienList_Save()
        {
            string          sMaNhanvien;
            int             nNhanvienID;
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                QLVBEntities               db          = this.DBContext;
                StoreDataHandler           dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <DMNHANVIEN> data        = dataHandler.ObjectData <DMNHANVIEN>();
                var qrChucvu = from cn in db.DMCHUCVUs.Where(cn => cn.MACHUCNANG != "01" && cn.MACHUCNANG != "02")
                               select cn;

                foreach (DMNHANVIEN c in data.Deleted)
                {
                    db.DMNHANVIENs.Attach(c);
                    db.DMNHANVIENs.DeleteObject(c);
                }

                foreach (DMNHANVIEN c in data.Created)
                {
                    if (IsUserNameExist(c.USERNAME))
                    {
                        throw new Exception("Tên đăng nhập đã được sử dụng " + c.TEN + "(" + c.USERNAME + ")");
                    }

                    if (qrChucvu.Any(p => p.MACHUCVU == c.CHUCVU) && c.MAPHONG.Length == 0)
                    {
                        throw new Exception("Chưa chọn phòng cho nhân viên " + c.TEN);
                    }

                    nNhanvienID = GetNewNhanvienID();
                    string s = c.MAPHONG;
                    if (s.Length == 0)
                    {
                        s = "00";
                    }
                    sMaNhanvien = s + nNhanvienID.ToString("D6");

                    c.MANV = sMaNhanvien;
                    db.DMNHANVIENs.AddObject(c);
                }

                foreach (DMNHANVIEN c in data.Updated)
                {
                    if (qrChucvu.Any(p => p.MACHUCVU == c.CHUCVU) && c.MAPHONG.Length == 0)
                    {
                        throw new Exception("Chưa chọn phòng cho nhân viên " + c.TEN);
                    }

                    var orgRecord = db.DMNHANVIENs.Single(p => p.MANV == c.MANV);

                    //string sCurMaNV = c.MANV;
                    //sCurMaNV = sCurMaNV.Substring(2);
                    //sCurMaNV = c.MAPHONG + sCurMaNV;
                    db.DMNHANVIENs.ApplyCurrentValues(c);
                }

                db.SaveChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                int nCode = System.Runtime.InteropServices.Marshal.GetHRForException(e);

                if (e.InnerException != null)
                {
                    ajaxStoreResult.SaveResponse.Message = e.InnerException.Message;
                }
                else
                {
                    ajaxStoreResult.SaveResponse.Message = e.Message;
                }
            }

            return(ajaxStoreResult);
        }
예제 #7
0
        public AjaxStoreResult SaveCustomersWithConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext db = this.DBContext;
                StoreDataHandler dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords<Customer> data = dataHandler.ObjectData<Customer>();
                ConfirmationList confirmationList = dataHandler.BuildConfirmationList("CustomerID");

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();

                //ideally we should confirm after each operation
                //but LINQ can make batch submit of changes

                foreach (Customer customer in data.Deleted)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Updated)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }

                foreach (Customer customer in data.Created)
                {
                    confirmationList[customer.CustomerID].ConfirmRecord();
                }


                ajaxStoreResult.SaveResponse.ConfirmationList = confirmationList;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                ajaxStoreResult.SaveResponse.Message = e.Message;
            }

            return ajaxStoreResult;
        }
예제 #8
0
        public AjaxStoreResult SaveCustomersWithoutConfirmation()
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                NorthwindDataContext db = this.DBContext;
                StoreDataHandler dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords<Customer> data = dataHandler.ObjectData<Customer>();

                foreach (Customer customer in data.Deleted)
                {
                    db.Customers.Attach(customer);
                    db.Customers.DeleteOnSubmit(customer);
                }

                foreach (Customer customer in data.Updated)
                {
                    db.Customers.Attach(customer);
                    db.Refresh(RefreshMode.KeepCurrentValues, customer);
                }

                foreach (Customer customer in data.Created)
                {
                    db.Customers.InsertOnSubmit(customer);
                }

                db.SubmitChanges();
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                ajaxStoreResult.SaveResponse.Message = e.Message;
            }

            return ajaxStoreResult;
        }