예제 #1
0
        /// <summary>
        /// Writes out buffered entries in a log activity that was entered with requireConfirm set to true.
        /// </summary>
        public void Confirm(Func <object> value = null)
        {
            confirmed = true;

            value = value ?? (() => true);

            if (confirmations == null)
            {
                confirmations = new ConfirmationList();
            }

            long?elapsedMilliseconds = null;

            if (stopwatch != null)
            {
                elapsedMilliseconds = stopwatch.ElapsedMilliseconds;
            }

            confirmations.Add(new Confirmation(value, elapsedMilliseconds));

            if (requireConfirm)
            {
                requireConfirm = false;
                while (buffer.Count > 0)
                {
                    Log.Write(buffer.Dequeue());
                }
            }
        }
예제 #2
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);
        }
예제 #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 AfterStoreChangedEventArgs(bool success, Exception exception, ConfirmationList confirmationList)
 {
     this.exception = exception;
     this.confirmationList = confirmationList;
     this.success = success;
 }
 public BeforeStoreChangedEventArgs(string jsonData, ConfirmationList confirmationList, XmlNode callbackParams)
     : this(jsonData, confirmationList)
 {
     this.ajaxPostBackParams = callbackParams;
 }
 public BeforeStoreChangedEventArgs(string jsonData, ConfirmationList confirmationList)
 {
     this.jsonData = jsonData;
     this.cancel = false;
     this.confirmationList = confirmationList;
 }
예제 #7
0
        public void ProcessRequest(HttpContext context)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext     db               = new NorthwindDataContext();
                StoreDataHandler         dataHandler      = new StoreDataHandler(context);
                ChangeRecords <Supplier> data             = dataHandler.ObjectData <Supplier>();
                ConfirmationList         confirmationList = dataHandler.BuildConfirmationList("SupplierID");

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                    confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    supplier.TemporaryID = supplier.SupplierID;
                    db.Suppliers.InsertOnSubmit(supplier);
                }

                db.SubmitChanges();

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

                foreach (Supplier supplier in data.Deleted)
                {
                    confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Updated)
                {
                    confirmationList[supplier.SupplierID.ToString()].ConfirmRecord();
                }

                foreach (Supplier supplier in data.Created)
                {
                    confirmationList[supplier.TemporaryID.ToString()].ConfirmRecord(supplier.SupplierID.ToString());
                }


                StoreResponseData response = new StoreResponseData();
                response.Confirmation = confirmationList;

                sr.Data = response.ToString();
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Msg     = e.Message;
            }

            sr.Write();
        }