コード例 #1
0
        protected void kurumstore_AfterRecordUpdated(object sender, BeforeStoreChangedEventArgs e)
        {
            var    result = false;
            string json   = e.DataHandler.JsonData;

            if (json == "[]")
            {
                return;
            }
            StoreDataHandler dataHandler = new StoreDataHandler(json);
            List <KurumDto>  list        = dataHandler.ObjectData <KurumDto>();

            foreach (var item in list)
            {
                switch (e.Action)
                {
                case StoreAction.Create:
                    e.Cancel = true;
                    break;

                case StoreAction.Update:
                    guncelle(item);
                    e.Cancel = true;
                    break;
                }
            }
        }
コード例 #2
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List<TestPerson> persons = handler.ObjectData<TestPerson>();

            if (handler.Action == StoreAction.Create)
            {
                foreach (TestPerson created in persons)
                {
                    TestPerson.AddPerson(created);
                }                
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (TestPerson deleted in persons)
                {
                    TestPerson.DeletePerson(deleted.Id.Value);
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (TestPerson updated in persons)
                {
                    TestPerson.UpdatePerson(updated);
                }                
            }

            return handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(persons) : (ActionResult)this.Content("");
        }
コード例 #3
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <TestPerson> persons = handler.ObjectData <TestPerson>();

            if (handler.Action == StoreAction.Create)
            {
                foreach (TestPerson created in persons)
                {
                    TestPerson.AddPerson(created);
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (TestPerson deleted in persons)
                {
                    TestPerson.DeletePerson(deleted.Id.Value);
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (TestPerson updated in persons)
                {
                    TestPerson.UpdatePerson(updated);
                }
            }

            return(handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(persons) : (ActionResult)this.Content(""));
        }
コード例 #4
0
        public ActionResult BrigadeHandleChanges(StoreDataHandler handler)
        {
            List <Brigade> items        = handler.ObjectData <Brigade>();
            string         errorMessage = null;

            if (handler.Action == StoreAction.Update)
            {
                items.ForEach(i =>
                {
                    brigadeRepository.Update(i);
                });
            }

            try
            {
                brigadeRepository.Save();
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action == StoreAction.Update ? (ActionResult)this.Store(items) : (ActionResult)this.Content(""));;
        }
コード例 #5
0
        public ActionResult RequestHandleChanges(StoreDataHandler handler)
        {
            String         data         = handler.JsonData;
            List <Request> requests     = handler.ObjectData <Request>();
            string         errorMessage = null;

            if (handler.Action == StoreAction.Update)
            {
                requests?.ForEach(r =>
                {
                    requestRepository.Update(r);
                });
            }

            try
            {
                requestRepository.Save();
            }
            catch (Exception e)
            {
                errorMessage = e.Message;
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action == StoreAction.Update ? (ActionResult)this.Store(requests) : (ActionResult)this.Content(""));;
        }
コード例 #6
0
ファイル: DataController.cs プロジェクト: quocuy/coolite-mvc
        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);
        }
コード例 #7
0
        protected void BeforeStroreChanged(object sender, BeforeStoreChangedEventArgs e)
        {
            var  json        = e.DataHandler.JsonData;
            var  dataHandler = new StoreDataHandler(json);
            var  data        = dataHandler.ObjectData <DIC_MySecondDictionary>();
            var  edit        = (DIC_MySecondDictionaryEdit)BaseMainPage.LoadControl(Page, "DIC_MySecondDictionaryEdit");
            var  reloadData  = false;
            bool isValid     = true;

            e.Cancel = true;

            BeforeSaveValidate(data, ref isValid);
            if (!isValid)
            {
                foreach (var row in data)
                {
                    X.AddScript($"setTimeout(function(){{ #{{store}}.getById({row.id}).setDirty(); }}, 100);");
                }
                X.AddScript("#{grid}.view.loadMask.hide();");
                return;
            }

            foreach (var row in data)
            {
                switch (e.Action)
                {
                case StoreAction.Update:
                    // todo: подумать о том как показать ошибки
                    reloadData |= edit.EditRowFromGrid(row);
                    break;

                case StoreAction.Create:
                    // todo: подумать о том как показать ошибки
                    edit.InsertRowFromGrid(row);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
                }
            }

            var result = source.View.GetSelect()
                         .Where(r => data.Contains(r.Item))
                         .Select(source.View.GetFullModelDataExpression);

            if (reloadData)
            {
                store.Reload();
            }
            else
            {
                e.ResponseRecords.AddRange(result);
            }

            X.AddScript("#{grid}.view.loadMask.hide();");
            AfterSave(data.Select(r => r.id));
        }
コード例 #8
0
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request["action"];

            if (string.IsNullOrEmpty(action) || Store.Action(action) == StoreAction.Read)
            {
                this.ReturnData(context);
                return;
            }

            StoreResponseData sr = new StoreResponseData();

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(context);
                List<Supplier> dataList = dataHandler.ObjectData<Supplier>();
                StoreAction storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier);
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    sr.Data = JSON.Serialize(dataList);
                    sr.Return();
                    return;
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            sr.Return();
        }
コード例 #9
0
        public void ProcessRequest(HttpContext context)
        {
            string action = context.Request["action"];

            if (string.IsNullOrEmpty(action) || Store.Action(action) == StoreAction.Read)
            {
                this.ReturnData(context);
                return;
            }

            StoreResponseData sr = new StoreResponseData();

            try
            {
                NorthwindDataContext db          = new NorthwindDataContext();
                StoreDataHandler     dataHandler = new StoreDataHandler(context);
                List <Supplier>      dataList    = dataHandler.ObjectData <Supplier>();
                StoreAction          storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier);
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    sr.Data = JSON.Serialize(dataList);
                    sr.Return();
                    return;
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            sr.Return();
        }
コード例 #10
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <Citizen> citizens     = handler.ObjectData <Citizen>();
            string         errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                try
                {
                    foreach (Citizen created in citizens)
                    {
                        repo.Create(created);
                    }
                }catch (Exception e)
                {
                    errorMessage = e.Message;
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (Citizen deleted in citizens)
                {
                    repo.Delete(deleted.Id);
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == deleted.id);
                    //db.citizens.Remove(citizen);
                    //await db.SaveChangesAsync();
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (Citizen updated in citizens)
                {
                    try
                    {
                        repo.Update(updated);
                    }
                    catch (Exception e)
                    {
                        errorMessage = e.Message;
                    }
                    //citizen citizen = await db.citizens.FirstOrDefaultAsync(c => c.id == updated.id);
                    //CitizenHelper.CitizenUpdate(citizen, updated);
                    //await db.SaveChangesAsync();
                }
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(citizens) : (ActionResult)this.Content(""));
        }
コード例 #11
0
ファイル: AdminController.cs プロジェクト: ping203/qlvb
        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);
        }
コード例 #12
0
        public ActionResult SaveCode(int taskId)
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);

            try
            {
                StoreDataHandler     dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords <Code> obj         = dataHandler.ObjectData <Code>();

                Task task = taskRepository.Get(taskId);
                foreach (Code code in obj.Updated)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.SaveOrUpdate(code);
                    }
                }

                foreach (Code code in obj.Created)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.SaveOrUpdate(code);
                    }
                }

                foreach (Code code in obj.Deleted)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.Delete(code);
                    }
                }
                codeRepository.DbContext.CommitChanges();
                ajaxStoreResult.SaveResponse.Success = true;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success      = false;
                ajaxStoreResult.SaveResponse.ErrorMessage = e.Message;
                codeRepository.DbContext.RollbackTransaction();
            }
            return(ajaxStoreResult);
        }
コード例 #13
0
        public Coolite.Ext.Web.Response SaveGameSimpleVersionList(string data)//保存GameSimpleVersionList
        {
            Response sr = new Response(true);

            if (VerirySecurityIP(GetIP4Address()))
            {
                sr.Success = false;
                sr.Msg     = msgNoSafe;
                Log.Warn(msgNoSafe + Context.Request.UserHostAddress + "<>" + GSSServerIP + "");
                return(sr);
            }

            try
            {
                GameCoreDBDataContext db          = new GameCoreDBDataContext();
                StoreDataHandler      dataHandler = new StoreDataHandler(data);
                ChangeRecords <T_GameSimpleVersionList> dataList = dataHandler.ObjectData <T_GameSimpleVersionList>();

                foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Deleted)
                {
                    db.T_GameSimpleVersionList.Attach(GameSimpleVersionList);
                    db.T_GameSimpleVersionList.DeleteOnSubmit(GameSimpleVersionList);
                }

                foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Updated)
                {
                    db.T_GameSimpleVersionList.Attach(GameSimpleVersionList);
                    db.Refresh(RefreshMode.KeepCurrentValues, GameSimpleVersionList);
                }

                foreach (T_GameSimpleVersionList GameSimpleVersionList in dataList.Created)
                {
                    db.T_GameSimpleVersionList.InsertOnSubmit(GameSimpleVersionList);
                }

                db.SubmitChanges();
            }
            catch (Exception ex)
            {
                sr.Success = false;
                sr.Msg     = ex.Message;
                Log.Warn("SaveGameSimpleVersionList", ex);
            }

            return(sr);
        }
コード例 #14
0
        public object SaveSuppliers(string data, string action)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext db          = new NorthwindDataContext();
                StoreDataHandler     dataHandler = new StoreDataHandler(data);
                List <Supplier>      dataList    = dataHandler.ObjectData <Supplier>();
                StoreAction          storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier);
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    return(dataList.ToList <Supplier, SerializableEntity <Supplier> >());
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            return(sr);
        }
コード例 #15
0
        public object SaveSuppliers(string data, string action)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(data);
                List<Supplier> dataList = dataHandler.ObjectData<Supplier>();
                StoreAction storeAction = Store.Action(action);

                foreach (Supplier supplier in dataList)
                {
                    if (storeAction == StoreAction.Destroy)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Suppliers.DeleteOnSubmit(supplier);
                    }
                    else if (storeAction == StoreAction.Update)
                    {
                        db.Suppliers.Attach(supplier);
                        db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                    }
                    else if (storeAction == StoreAction.Create)
                    {
                        db.Suppliers.InsertOnSubmit(supplier); 
                    }
                }

                db.SubmitChanges();

                if (storeAction != StoreAction.Destroy)
                {
                    return dataList.ToList<Supplier, SerializableEntity<Supplier>>();
                }
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Message = e.Message;
            }

            return sr;
        }
コード例 #16
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List<TestPerson> persons = handler.ObjectData<TestPerson>();
            string errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                foreach (TestPerson created in persons)
                {
                    TestPerson.AddPerson(created);
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (TestPerson deleted in persons)
                {
                    TestPerson.DeletePerson(deleted.Id.Value);
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (TestPerson updated in persons)
                {
                    try
                    {
                        TestPerson.UpdatePerson(updated);
                    }
                    catch(Exception e)
                    {
                        errorMessage = e.Message;
                    }
                }
            }

            if (errorMessage != null)
            {
                return this.Store(errorMessage);
            }

            return handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(persons) : (ActionResult)this.Content("");
        }
コード例 #17
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <TestPerson> persons      = handler.ObjectData <TestPerson>();
            string            errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                foreach (TestPerson created in persons)
                {
                    TestPerson.AddPerson(created);
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (TestPerson deleted in persons)
                {
                    TestPerson.DeletePerson(deleted.Id.Value);
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (TestPerson updated in persons)
                {
                    try
                    {
                        TestPerson.UpdatePerson(updated);
                    }
                    catch (Exception e)
                    {
                        errorMessage = e.Message;
                    }
                }
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action != StoreAction.Destroy ? (ActionResult)this.Store(persons) : (ActionResult)this.Content(""));
        }
コード例 #18
0
ファイル: AdminController.cs プロジェクト: ping203/qlvb
        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);
        }
コード例 #19
0
        public ActionResult HandleChanges(StoreDataHandler handler)
        {
            List <Driver> drivers      = handler.ObjectData <Driver>();
            string        errorMessage = null;

            if (handler.Action == StoreAction.Create)
            {
                foreach (Driver created in drivers)
                {
                    driver_repository.InsertObject(created);
                }
            }
            else if (handler.Action == StoreAction.Destroy)
            {
                foreach (Driver deleted in drivers)
                {
                    driver_repository.DeleteObject(deleted.DRIVER_ID);
                }
            }
            else if (handler.Action == StoreAction.Update)
            {
                foreach (Driver updated in drivers)
                {
                    try {
                        driver_repository.UpdateObject(updated);
                    } catch (Exception e) {
                        errorMessage = e.Message;
                    }
                }
            }

            if (errorMessage != null)
            {
                return(this.Store(errorMessage));
            }

            return(handler.Action != StoreAction.Destroy ? ( ActionResult )this.Store(drivers) : ( ActionResult )this.Content(""));
        }
コード例 #20
0
        public Coolite.Ext.Web.Response SaveSuppliers(string data)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext     db          = new NorthwindDataContext();
                StoreDataHandler         dataHandler = new StoreDataHandler(data);
                ChangeRecords <Supplier> dataList    = dataHandler.ObjectData <Supplier>();

                foreach (Supplier supplier in dataList.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }

                foreach (Supplier supplier in dataList.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

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

                db.SubmitChanges();
            }
            catch (Exception e)
            {
                sr.Success = false;
                sr.Msg     = e.Message;
            }

            return(sr);
        }
コード例 #21
0
        public XResponse SaveSuppliers(string data)
        {
            Response sr = new Response(true);

            try
            {
                NorthwindDataContext db = new NorthwindDataContext();
                StoreDataHandler dataHandler = new StoreDataHandler(data);
                ChangeRecords<Supplier> dataList = dataHandler.ObjectData<Supplier>();

                foreach (Supplier supplier in dataList.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }

                foreach (Supplier supplier in dataList.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

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

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

            return sr;
        }
コード例 #22
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>();

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }

                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

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

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

            sr.Write();
        }
コード例 #23
0
ファイル: SuppliersSave.ashx.cs プロジェクト: pgodwin/Ext.net
        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>();

                foreach (Supplier supplier in data.Deleted)
                {
                    db.Suppliers.Attach(supplier);
                    db.Suppliers.DeleteOnSubmit(supplier);
                }
                
                foreach (Supplier supplier in data.Updated)
                {
                    db.Suppliers.Attach(supplier);
                    db.Refresh(RefreshMode.KeepCurrentValues, supplier);
                }

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

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

            sr.Write();
        }
コード例 #24
0
ファイル: DataController.cs プロジェクト: vrjaroslav/Ext.net
        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);
        }
コード例 #25
0
ファイル: AdminController.cs プロジェクト: ping203/qlvb
        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);
        }
コード例 #26
0
ファイル: DataController.cs プロジェクト: pgodwin/Ext.net
        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;
        }
コード例 #27
0
ファイル: DataController.cs プロジェクト: pgodwin/Ext.net
        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;
        }
コード例 #28
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();
        }
コード例 #29
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.Message = e.Message;
            }

            sr.Write();
        }
コード例 #30
0
        public ActionResult SaveCode(int taskId)
        {
            AjaxStoreResult ajaxStoreResult = new AjaxStoreResult(StoreResponseFormat.Save);
            try
            {
                StoreDataHandler dataHandler = new StoreDataHandler(HttpContext.Request["data"]);
                ChangeRecords<Code> obj = dataHandler.ObjectData<Code>();

                Task task = taskRepository.Get(taskId);
                foreach (Code code in obj.Updated)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.SaveOrUpdate(code);
                    }
                }

                foreach (Code code in obj.Created)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.SaveOrUpdate(code);
                    }
                }

                foreach (Code code in obj.Deleted)
                {
                    code.Task = task;
                    if (code.IsValid())
                    {
                        codeRepository.Delete(code);
                    }
                }
                codeRepository.DbContext.CommitChanges();
                ajaxStoreResult.SaveResponse.Success = true;
            }
            catch (Exception e)
            {
                ajaxStoreResult.SaveResponse.Success = false;
                ajaxStoreResult.SaveResponse.ErrorMessage = e.Message;
                codeRepository.DbContext.RollbackTransaction();
            }
            return ajaxStoreResult;
        }