Пример #1
0
 public ActionResult BatchUpdatePartial(MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     foreach (var item in batchValues.Insert)
     {
         if (batchValues.IsValid(item))
         {
             BatchEditRepository.InsertNewItem(item, batchValues);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var item in batchValues.Update)
     {
         if (batchValues.IsValid(item))
         {
             BatchEditRepository.UpdateItem(item, batchValues);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var itemKey in batchValues.DeleteKeys)
     {
         BatchEditRepository.DeleteItem(itemKey, batchValues);
     }
     return(PartialView("_GridViewPartial", BatchEditRepository.GridData));
 }
Пример #2
0
 public ActionResult BatchUpdateRoomsPartial(MVCxGridViewBatchUpdateValues <Room, int> batchValues)
 {
     foreach (var item in batchValues.Insert)
     {
         if (batchValues.IsValid(item))
         {
             Company.InsertRoom(item);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var item in batchValues.Update)
     {
         if (batchValues.IsValid(item))
         {
             Company.UpdateRoom(item);
         }
         else
         {
             batchValues.SetErrorText(item, "Correct validation errors");
         }
     }
     foreach (var itemKey in batchValues.DeleteKeys)
     {
         Company.RemoveRoomByID(itemKey);
     }
     return(PartialView("GridViewPartialView", Company.OfficeRooms));
 }
        public ActionResult BatchEditingUpdateModelPerson(MVCxGridViewBatchUpdateValues <Person, int> batchValues)
        {
            foreach (var person in batchValues.Update)
            {
                if (batchValues.IsValid(person))
                {
                    PersonsList.UpdatePerson(person);
                }
                else
                {
                    batchValues.SetErrorText(person, "Correct validation errors");
                }
            }

            foreach (var person in batchValues.Insert)
            {
                if (batchValues.IsValid(person))
                {
                    PersonsList.AddPerson(person);
                }
                else
                {
                    batchValues.SetErrorText(person, "Correct validation errors");
                }
            }

            foreach (var personID in batchValues.DeleteKeys)
            {
                PersonsList.DeletePerson(personID);
            }
            return(PartialView("GridViewPartial", PersonsList.GetPersons()));
        }
Пример #4
0
        public ActionResult BatchEditingUpdateModel(MVCxGridViewBatchUpdateValues <EditableProduct, Guid> updateValues)
        {
            var dataContextModelContracts = GetDataContextModelContracts();

            // Insert all added values.
            foreach (var contract in updateValues.Insert)
            {
                if (updateValues.IsValid(contract))
                {
                    try
                    {
                        InsertContract(contract, dataContextModelContracts);
                        Db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(contract, e.Message);
                    }
                }
            }
            // Update all edited values.
            //get sum of all total values
            foreach (var contract in updateValues.Update)
            {
                if (updateValues.IsValid(contract))
                {
                    try
                    {
                        var product = UpdateContract(contract);
                        Db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(contract, e.Message);
                    }
                }
                else
                {
                    updateValues.SetErrorText(contract, "Исправьте ошибки заполнения формы");
                }
            }

            // Delete all values that were deleted on the client side from the data source.
            foreach (var ContrGUID in updateValues.DeleteKeys)
            {
                try
                {
                    DeleteContract(ContrGUID, dataContextModelContracts);
                    Db.SaveChanges();
                }
                catch (Exception e)
                {
                    updateValues.SetErrorText(ContrGUID, e.Message);
                }
            }
            var parenttableid = Session["parenttableid"] as string;
            var quarterhlight = Session["quarterhlight"] as string;

            return(BatchEditingPartial(parenttableid, quarterhlight));
        }
Пример #5
0
        public ActionResult BatchEditingUpdateModel(MVCxGridViewBatchUpdateValues <EditableContract, Guid> updateValues)
        {
            var dataContextModelContracts = GetDataContextModelContracts();

            // Insert all added values.
            foreach (var contract in updateValues.Insert)
            {
                if (updateValues.IsValid(contract))
                {
                    try
                    {
                        InsertContract(contract, dataContextModelContracts);
                        Db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(contract, e.Message);
                    }
                }
            }
            // Update all edited values.
            foreach (var contract in updateValues.Update)
            {
                if (updateValues.IsValid(contract))
                {
                    try
                    {
                        UpdateContract(contract);
                        Db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(contract, e.Message);
                    }
                }
            }

            // Delete all values that were deleted on the client side from the data source.
            foreach (var ContrGUID in updateValues.DeleteKeys)
            {
                try
                {
                    DeleteContract(ContrGUID, dataContextModelContracts);
                    Db.SaveChanges();
                }
                catch (Exception e)
                {
                    updateValues.SetErrorText(ContrGUID, e.Message);
                }
            }
            var parenttableid  = Session["parenttableid"] as string;
            var contractstatus = Session["contractstatus"] as string;

            return(BatchEditingPartial(parenttableid, contractstatus));
        }
Пример #6
0
        public void UpdateItem(HovisMillingPortal.Models.t_Milling_Bacs_Detail postedItem, MVCxGridViewBatchUpdateValues <HovisMillingPortal.Models.t_Milling_Bacs_Detail, int> batchValues, System.Int64 headerrecid)
        {
            var britishZone  = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
            var adjusteddate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, britishZone);
            var headermodel  = db.t_Milling_Bacs_Header.FirstOrDefault(e => e.HeaderRecid == headerrecid);
            var item         = db.t_Milling_Bacs_Detail.First(i => i.DetailRecid == postedItem.DetailRecid);

            // DDFrequency 7 is AUDDIS
            if (item.DDFrequency == 7)
            {
                if (postedItem.ClaimedAmount != 0)
                {
                    batchValues.SetErrorText(postedItem, "Cannot have a value for AUDDIS....");
                    return;
                }
            }

            //We need to check if qty is zero
            if (postedItem.ClaimedAmount == null)
            {
                batchValues.SetErrorText(postedItem, "you must enter an amount or zero....");
                return;
            }

            if (postedItem.ClaimedAmount < 0)
            {
                batchValues.SetErrorText(postedItem, "cannot be less than zero....");
                return;
            }

            if (User.Identity.Name != null)
            {
                postedItem.LastChangedBy = User.Identity.Name;
            }
            postedItem.LastChangedDate = adjusteddate;

            var modelItem = db.t_Milling_Bacs_Detail.Find(postedItem.DetailRecid);

            try
            {
                if (modelItem != null)
                {
                    modelItem.ClaimedAmount   = postedItem.ClaimedAmount;
                    modelItem.LastChangedBy   = postedItem.LastChangedBy;
                    modelItem.LastChangedDate = postedItem.LastChangedDate;
                    db.SaveChanges();
                }
            }
            catch (Exception e)
            {
                batchValues.SetErrorText(postedItem, e.Message);
            }
        }
Пример #7
0
        private ActionResult ResultHandler(string errMsg, BA02AModel master, MVCxGridViewBatchUpdateValues <BA02BModel, int> updateValues)
        {
            if (errMsg == "")
            {
                TempData["SelectedItemKey"] = master.BA02A_ID;
                TempData["SaveSuccess"]     = true;
                return(RedirectToAction("RedirectIndex"));
            }
            else
            {
                for (int i = 0; i < updateValues.Insert.Count; i++)
                {
                    ModelState.AddModelError($"Insert[{i}].IsValid", "Error");
                }

                for (int i = 0; i < updateValues.Update.Count; i++)
                {
                    ModelState.AddModelError($"Update[{i}].IsValid", "Error");
                }

                var deleteIDStrList = "";
                for (int i = 0; i < updateValues.DeleteKeys.Count; i++)
                {
                    updateValues.SetErrorText(updateValues.DeleteKeys[i], "Unable to delete!");
                    deleteIDStrList += updateValues.DeleteKeys[i] + ",";
                }
                ViewData["DeleteIDList"] = deleteIDStrList;
                errMsg                 = "存儲失敗<br/>" + errMsg;
                ViewData["ErrMsg"]     = errMsg = errMsg.Substring(0, errMsg.Length - 5);
                ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", master);

                return(PartialView("_DetailGrid", BA02Business.FromEntity(_Service.GetByMasterKey(master.BA02A_ID))));
            }
        }
Пример #8
0
        public ActionResult GridViewOrderListBatchUpdate(MVCxGridViewBatchUpdateValues <Item, object> updateValues)
        {
            var model = ItemRepository.Data;
            // Insert all added values.
            var newId = model.Count > 0 ? model.Max(i => i.ItemID): 0;

            foreach (var item in updateValues.Insert)
            {
                try {
                    model.Add(new Item {
                        ItemID = ++newId, ItemName = item.ItemName, ItemDescription = item.ItemDescription
                    });
                } catch (Exception e) {
                    updateValues.SetErrorText(item, e.Message);
                }
            }
            // Update all edited values.
            foreach (var item in updateValues.Update)
            {
                try {
                    var modelItem = model.FirstOrDefault(it => it.ItemID == item.ItemID);
                    if (modelItem != null)
                    {
                        this.UpdateModel(modelItem);
                    }
                } catch (Exception e) {
                    updateValues.SetErrorText(item, e.Message);
                }
            }
            // Delete all values that were deleted on the client side from the data source.
            foreach (var ItemID in updateValues.DeleteKeys)
            {
                try {
                    var item = model.FirstOrDefault(it => it.ItemID == Convert.ToInt32(ItemID));
                    if (item != null)
                    {
                        model.Remove(item);
                    }
                } catch (Exception e) {
                    updateValues.SetErrorText(ItemID, e.Message);
                }
            }
            return(PartialView("_GridViewOrderListPartial", model.ToList()));
        }
 public static void DeleteItem(int itemKey, MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     try {
         var item = GridData.First(i => i.Id == itemKey);
         GridData.Remove(item);
     }
     catch (Exception e) {
         batchValues.SetErrorText(itemKey, e.Message);
     }
 }
 public static void UpdateItem(GridDataItem postedItem, MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     try {
         var editedItem = GridData.First(i => i.Id == postedItem.Id);
         LoadNewValues(editedItem, postedItem);
     }
     catch (Exception e) {
         batchValues.SetErrorText(postedItem, e.Message);
     }
 }
        public ActionResult AmountsSave(uint id, MVCxGridViewBatchUpdateValues <PromotionSum, int> updateValues)
        {
            foreach (var itemId in updateValues.DeleteKeys)
            {
                var item = DbSession.Query <PromotionPercent>().FirstOrDefault(r => r.Id == itemId);
                if (item != null)
                {
                    DbSession.Delete(item);
                }
            }

            var promotion = DbSession.Query <ProducerPromotion>().First(r => r.Id == id);

            foreach (var item in updateValues.Insert)
            {
                if (updateValues.IsValid(item))
                {
                    try {
                        item.Promotion = promotion;
                        DbSession.Save(item);
                    } catch (Exception ex) {
                        updateValues.SetErrorText(item, ex.Message);
                    }
                }
            }

            foreach (var item in updateValues.Update)
            {
                if (updateValues.IsValid(item))
                {
                    try {
                        var record = DbSession.Query <PromotionSum>().First(r => r.Id == item.Id);
                        record.DealerSum = item.DealerSum;
                        record.MemberSum = item.MemberSum;
                        record.Quantity  = item.Quantity;
                    } catch (Exception ex) {
                        updateValues.SetErrorText(item, ex.Message);
                    }
                }
            }

            return(GridAmounts(id));
        }
Пример #12
0
 protected void UpdateTagTemplate(TBL_TAG_TEMP tagTemp, MVCxGridViewBatchUpdateValues <TBL_TAG_TEMP, int> updateValues)
 {
     try
     {
         if (!tagTemplateService.IsTagTemplateExist(tagTemp))
         {
             tagTemplateService.UpdateTagTemplate(tagTemp);
             tagTemplateService.SaveTagTemplate();
         }
         else
         {
             updateValues.SetErrorText(tagTemp, "Bu isimde şirket bulunmaktadır.");
         }
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(tagTemp, e.Message);
     }
 }
Пример #13
0
 protected void InsertProduct(InventoryItem product, MVCxGridViewBatchUpdateValues <InventoryItem, object> updateValues)
 {
     try
     {
         //NorthwindDataProvider.InsertProduct(product);
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(product, e.Message);
     }
 }
Пример #14
0
 protected void DeleteProduct(object productID, MVCxGridViewBatchUpdateValues <InventoryItem, object> updateValues)
 {
     try
     {
         //NorthwindDataProvider.DeleteProduct(productID);
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(productID, e.Message);
     }
 }
Пример #15
0
 protected void DeleteTag(int defId, MVCxGridViewBatchUpdateValues <TBL_ALARM_TEMP, int> updateValues)
 {
     try
     {
         alarmDefinitionService.DeleteAlarmDefinition(defId, User.Identity.GetUserId());
         alarmDefinitionService.SaveAlarmDefinition();
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(defId, e.Message);
     }
 }
Пример #16
0
 protected void DeleteTagTemplate(int templateId, MVCxGridViewBatchUpdateValues <TBL_TAG_TEMP, int> updateValues)
 {
     try
     {
         tagTemplateService.DeleteTagTemplate(templateId, User.Identity.GetUserId());
         tagTemplateService.SaveTagTemplate();
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(templateId, e.Message);
     }
 }
Пример #17
0
 protected void InsertTagTemplate(TBL_TAG_TEMP tagTemp, MVCxGridViewBatchUpdateValues <TBL_TAG_TEMP, int> updateValues)
 {
     try
     {
         if (!tagTemplateService.IsTagTemplateExist(tagTemp))
         {
             tagTemp.CREATED_DATE = DateTime.Now;
             tagTemp.UPDATE_USER  = User.Identity.GetUserId();
             tagTemplateService.CreateTagTemplate(tagTemp);
             tagTemplateService.SaveTagTemplate();
         }
         else
         {
             updateValues.SetErrorText(tagTemp, "Bu isimde şirket bulunmaktadır.");
         }
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(tagTemp, e.Message);
     }
 }
 protected void DeleteProduct(int EMPID, MVCxGridViewBatchUpdateValues <object, int> updateValues)
 {
     try
     {
         var subs = from m in db.Subs
                    select m.SubjID;
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(EMPID, e.Message);
     }
 }
        /* save all changes to a data base in this action */
        public bool UpdateAllValues(MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues, MainModel mainModel)
        {
            if (batchValues != null)
            {
                foreach (var item in batchValues.Insert)
                {
                    if (batchValues.IsValid(item))
                    {
                        BatchEditRepository.InsertNewItem(item, batchValues);
                    }
                    else
                    {
                        batchValues.SetErrorText(item, "Correct validation errors");
                    }
                }
                foreach (var item in batchValues.Update)
                {
                    if (batchValues.IsValid(item))
                    {
                        BatchEditRepository.UpdateItem(item, batchValues);
                    }
                    else
                    {
                        batchValues.SetErrorText(item, "Correct validation errors");
                    }
                }
                foreach (var itemKey in batchValues.DeleteKeys)
                {
                    BatchEditRepository.DeleteItem(itemKey, batchValues);
                }
            }
            bool result = false;

            if (mainModel != null)
            {
                //custom actions
                result = true;
            }
            return(result && (batchValues == null || batchValues.EditorErrors.Count == 0));
        }
Пример #20
0
 protected void UpdateTagTemplateDet(TagTempDetGridModel tagTempDet, MVCxGridViewBatchUpdateValues <TagTempDetGridModel, int> updateValues)
 {
     try
     {
         TBL_TAG_TEMP_DET entity = Mapper.Map <TagTempDetGridModel, TBL_TAG_TEMP_DET>(tagTempDet);
         tagTemplateDetService.UpdateTagTemplateDet(entity);
         tagTemplateDetService.SaveTagTemplateDet();
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(tagTempDet, e.Message);
     }
 }
 public static void InsertNewItem(GridDataItem postedItem, MVCxGridViewBatchUpdateValues <GridDataItem, int> batchValues)
 {
     try {
         var newItem = new GridDataItem()
         {
             Id = GridData.Count
         };
         LoadNewValues(newItem, postedItem);
         GridData.Add(newItem);
     }
     catch (Exception e) {
         batchValues.SetErrorText(postedItem, e.Message);
     }
 }
Пример #22
0
 protected void InsertTag(TBL_ALARM_TEMP tag, MVCxGridViewBatchUpdateValues <TBL_ALARM_TEMP, int> updateValues)
 {
     try
     {
         //tag.CREATED_DATE = DateTime.Now;
         //tag.UPDATE_USER = User.Identity.GetUserId();
         //alarmDefinitionService.CreateAlarmDefinition(tag);
         //alarmDefinitionService.SaveAlarmDefinition();
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(tag, e.Message);
     }
 }
Пример #23
0
        public ActionResult BatchUpdatePartial(MVCxGridViewBatchUpdateValues <HovisMillingPortal.Models.t_Milling_Bacs_Detail, int> batchValues, System.Int64 headerrecid)
        {
            var britishZone  = TimeZoneInfo.FindSystemTimeZoneById("GMT Standard Time");
            var adjusteddate = TimeZoneInfo.ConvertTime(DateTime.Now, TimeZoneInfo.Local, britishZone);

            foreach (var item in batchValues.Insert)
            {
                if (batchValues.IsValid(item))
                {
                    InsertNewItem(item, batchValues, headerrecid);
                }
                else
                {
                    batchValues.SetErrorText(item, "Correct validation errors");
                }
            }
            foreach (var item in batchValues.Update)
            {
                if (batchValues.IsValid(item))
                {
                    UpdateItem(item, batchValues, headerrecid);
                }
                else
                {
                    batchValues.SetErrorText(item, "Correct validation errors");
                }
            }
            foreach (var itemKey in batchValues.DeleteKeys)
            {
                DeleteItem(itemKey, batchValues, headerrecid);
            }

            var model = db.t_Milling_Bacs_Detail.Where(s => s.HeaderRecid == headerrecid).ToList();

            return(PartialView("_BacsDetailsGridViewPartial", model));
        }
Пример #24
0
 protected void InsertTagTemplateDet(TagTempDetGridModel tagTempDet, MVCxGridViewBatchUpdateValues <TagTempDetGridModel, int> updateValues)
 {
     try
     {
         TBL_TAG_TEMP_DET entity = Mapper.Map <TagTempDetGridModel, TBL_TAG_TEMP_DET>(tagTempDet);
         entity.CREATED_DATE = DateTime.Now;
         entity.UPDATE_USER  = User.Identity.GetUserId();
         tagTemplateDetService.CreateTagTemplateDet(entity);
         tagTemplateDetService.SaveTagTemplateDet();
     }
     catch (Exception e)
     {
         updateValues.SetErrorText(tagTempDet, e.Message);
     }
 }
 public ActionResult LegalEntityLimitsSave(uint id, MVCxGridViewBatchUpdateValues <LegalEntityLimitViewModel, int> updateValues)
 {
     foreach (var item in updateValues.Update)
     {
         if (updateValues.IsValid(item))
         {
             try {
                 var limit = DbSession.Query <LegalEntityLimit>().First(r => r.Id == item.LimitId);
                 limit.MinSum = item.MinSum;
             } catch (Exception ex) {
                 updateValues.SetErrorText(item, ex.Message);
             }
         }
     }
     return(GridLegalEntityLimits(id));
 }
        public ActionResult EditConditionsBatch(uint id,
                                                MVCxGridViewBatchUpdateValues <ConditionsGridViewModel, int> updateValues)
        {
            foreach (var item in updateValues.Update)
            {
                if (updateValues.IsValid(item))
                {
                    try {
                        var condition = DbSession.Query <PromotionProduct>().Single(r => r.Id == item.ConditionId);
                        condition.Price         = item.Price;
                        condition.DealerPercent = item.DealerPercent;
                        condition.MemberPercent = item.MemberPercent;
                    } catch (Exception ex) {
                        updateValues.SetErrorText(item, ex.Message);
                    }
                }
            }
            var model = GetConditionsViewModel(id);

            return(PartialView("partials/_ConditionsGridView", model));
        }
Пример #27
0
        private ActionResult ResultHandler(string errMsg, TR01AModel master, MVCxGridViewBatchUpdateValues <TR01BModel, int> updateValues)
        {
            if (errMsg == "")
            {
                ViewData["IsSuccess"] = "true";
                var result = TR01Business.FromEntity(_Service.GetMany(x => x.VOU_NO == master.VOU_NO));
                ViewData["MasterForm"] = ReadViewHelper.PartialView(this, "_MasterForm", result.Item1);
                return(PartialView("_DetailGrid", result.Item2));
            }
            else
            {
                for (int i = 0; i < updateValues.Insert.Count; i++)
                {
                    ModelState.AddModelError($"Insert[{i}].IsValid", "Error");
                }
                for (int i = 0; i < updateValues.Update.Count; i++)
                {
                    ModelState.AddModelError($"Update[{i}].IsValid", "Error");
                }
                var deleteIDStrList = "";
                for (int i = 0; i < updateValues.DeleteKeys.Count; i++)
                {
                    updateValues.SetErrorText(updateValues.DeleteKeys[i], "Unable to delete!");
                    deleteIDStrList += updateValues.DeleteKeys[i] + ",";
                }
                if (master.EntityState == EntityState.Added)
                {
                    master.VOU_NO = "系統產生";
                }

                errMsg = "存儲失敗<br/>" + errMsg;
                ViewData["DeleteIDList"] = deleteIDStrList;
                ViewData["ErrMsg"]       = errMsg.Substring(0, errMsg.Length - 5);
                ViewData["MasterForm"]   = ReadViewHelper.PartialView(this, "_MasterForm", master);
                return(PartialView("_DetailGrid", new List <TR01BModel>()));
            }
        }
        public ActionResult BatchEditingUpdateModel(MVCxGridViewBatchUpdateValues <PreFertilizanteBaseTotal, object> updateValues)
        {
            FTPresupuestoEntities dbContext = new FTPresupuestoEntities();
            int    empresaId     = -1;
            int    sucursalId    = -1;
            string tipoClienteId = "";
            int    verPptoId     = -1;

            foreach (var FertilizanteBTF in updateValues.Update)
            {
                var modelItemF = dbContext.PreFertilizanteBaseTotal.FirstOrDefault(it => it.Oid == FertilizanteBTF.Oid);
                empresaId     = modelItemF.Clave_Empresa;
                sucursalId    = modelItemF.Clave_Sucursal;
                tipoClienteId = modelItemF.Tipocliente;
                verPptoId     = (int)modelItemF.VersionPresupuestoId;
                break;
            }

            var model =
                dbContext.PreFertilizanteBaseTotal
                .Where(p => p.Clave_Empresa == empresaId && p.Clave_Sucursal == sucursalId && p.Tipocliente == tipoClienteId && p.VersionPresupuestoId == verPptoId)
                .ToList();

            #region INSERT

            // Insert all added values.
            foreach (var FertilizanteBT in updateValues.Insert)
            {
                if (updateValues.IsValid(FertilizanteBT))
                {
                    try
                    {
                        model.Add(FertilizanteBT);
                        dbContext.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(FertilizanteBT, e.Message);
                    }
                }
            }

            #endregion

            #region UPDATE

            // Update all edited values.
            if (updateValues.Update.Count > 0)
            {
                foreach (var FertilizanteBT in updateValues.Update)
                {
                    if (updateValues.IsValid(FertilizanteBT))
                    {
                        try
                        {
                            bool cambioIncTons = false;
                            bool cambioIncMG   = false;
                            var  modelItem     = model.FirstOrDefault(it => it.Oid == FertilizanteBT.Oid);
                            if (modelItem != null)
                            {
                                if (modelItem.PtjeIncEspecificoTons != FertilizanteBT.PtjeIncEspecificoTons)
                                {
                                    cambioIncTons = true;
                                }
                                if (modelItem.PtjeIncEspecificoMG != FertilizanteBT.PtjeIncEspecificoMG)
                                {
                                    cambioIncMG = true;
                                }

                                modelItem.PtjeIncEspecificoTons = FertilizanteBT.PtjeIncEspecificoTons;
                                modelItem.PtjeIncEspecificoMG   = FertilizanteBT.PtjeIncEspecificoMG;

                                // TOMA VALORES MENSUALES Y SOBRE ESE HACE LOS CALCULOS
                                var     modelMeses = dbContext.PreFertilizanteMensual.Where(m => m.BaseTotalId == modelItem.Oid).ToList();
                                decimal?toneladas  = 0m;
                                decimal?ventas     = 0m;
                                decimal?margen     = 0m;
                                decimal incTons    = (decimal)modelItem.PtjeIncEspecificoTons / 100m;
                                decimal incMG      = (decimal)modelItem.PtjeIncEspecificoMG / 100m;
                                foreach (var itemMes in modelMeses)
                                {
                                    if (!itemMes.ToneladaManual)
                                    {
                                        itemMes.Toneladas = itemMes.ToneladasBase * (1m + incTons);
                                    }
                                    itemMes.Importe = itemMes.Toneladas * itemMes.PrecioVenta;
                                    if (!itemMes.PtjeMargenManual)
                                    {
                                        if (cambioIncMG)
                                        {
                                            if (incMG != 0m)
                                            {
                                                itemMes.PtjeMargen = modelItem.PtjeIncEspecificoMG;
                                            }
                                            else
                                            {
                                                itemMes.PtjeMargen = itemMes.PtjeMargenBase;
                                            }
                                        }
                                    }
                                    itemMes.Margen = itemMes.Importe * (((decimal)itemMes.PtjeMargen) / 100m);
                                    //itemMes.Margen = itemMes.Importe * ((decimal)itemMes.PtjeMargen);
                                    switch (itemMes.Mes)
                                    {
                                    case 1:
                                        modelItem.EneImporte = itemMes.Importe;
                                        modelItem.EneMargen  = itemMes.Margen;
                                        modelItem.EneTons    = itemMes.Toneladas;
                                        break;

                                    case 2:
                                        modelItem.FebImporte = itemMes.Importe;
                                        modelItem.FebMargen  = itemMes.Margen;
                                        modelItem.FebTons    = itemMes.Toneladas;
                                        break;

                                    case 3:
                                        modelItem.MarImporte = itemMes.Importe;
                                        modelItem.MarMargen  = itemMes.Margen;
                                        modelItem.MarTons    = itemMes.Toneladas;
                                        break;

                                    case 4:
                                        modelItem.AbrImporte = itemMes.Importe;
                                        modelItem.AbrMargen  = itemMes.Margen;
                                        modelItem.AbrTons    = itemMes.Toneladas;
                                        break;

                                    case 5:
                                        modelItem.MayImporte = itemMes.Importe;
                                        modelItem.MayMargen  = itemMes.Margen;
                                        modelItem.MayTons    = itemMes.Toneladas;
                                        break;

                                    case 6:
                                        modelItem.JunImporte = itemMes.Importe;
                                        modelItem.JunMargen  = itemMes.Margen;
                                        modelItem.JunTons    = itemMes.Toneladas;
                                        break;

                                    case 7:
                                        modelItem.JulImporte = itemMes.Importe;
                                        modelItem.JulMargen  = itemMes.Margen;
                                        modelItem.JulTons    = itemMes.Toneladas;
                                        break;

                                    case 8:
                                        modelItem.AgoImporte = itemMes.Importe;
                                        modelItem.AgoMargen  = itemMes.Margen;
                                        modelItem.AgoTons    = itemMes.Toneladas;
                                        break;

                                    case 9:
                                        modelItem.SepImporte = itemMes.Importe;
                                        modelItem.SepMargen  = itemMes.Margen;
                                        modelItem.SepTons    = itemMes.Toneladas;
                                        break;

                                    case 10:
                                        modelItem.OctImporte = itemMes.Importe;
                                        modelItem.OctMargen  = itemMes.Margen;
                                        modelItem.OctTons    = itemMes.Toneladas;
                                        break;

                                    case 11:
                                        modelItem.NovImporte = itemMes.Importe;
                                        modelItem.NovMargen  = itemMes.Margen;
                                        modelItem.NovTons    = itemMes.Toneladas;
                                        break;

                                    case 12:
                                        modelItem.DicImporte = itemMes.Importe;
                                        modelItem.DicMargen  = itemMes.Margen;
                                        modelItem.DicTons    = itemMes.Toneladas;
                                        break;

                                    default:
                                        break;
                                    }
                                    toneladas += itemMes.Toneladas;
                                    ventas    += itemMes.Importe;
                                    margen    += itemMes.Margen;
                                }

                                modelItem.PresupuestoTons   = toneladas;
                                modelItem.PresupuestoVentas = ventas;
                                modelItem.PresupuestoMargen = margen;

                                // SE INICIALIZA A 0 EL PTJEINCRMENETOGENERALTONS PARA QUE SE SI SE CAMBIA ESE PTJE NO AFECTE EL INCREMENTO INDIVIDUAL
                                if (cambioIncTons)
                                {
                                    modelItem.PtjeIncGeneralTons = 0d;
                                }
                                // SE ACTUALIZA LA BD
                                dbContext.SaveChanges();
                            }
                        }
                        catch (Exception e)
                        {
                            updateValues.SetErrorText(FertilizanteBT, e.Message);
                        }
                    }
                }
            }

            #endregion

            #region Delete

            // Delete all values that were deleted on the client side from the data source.
            foreach (var oID in updateValues.DeleteKeys)
            {
                try
                {
                    long FertilizanteID = Convert.ToInt64(oID);
                    var  item           = model.FirstOrDefault(it => it.Oid == FertilizanteID);
                    if (item != null)
                    {
                        model.Remove(item);
                    }
                    dbContext.SaveChanges();
                }
                catch (Exception e)
                {
                    updateValues.SetErrorText(oID, e.Message);
                }
            }

            #endregion

            //var modelRecargado = FTPresupuestoProvider.GetFertilizantesBaseTotal(empresaId, sucursalId);

            ejercicioCerrado    = FTPresupuestoProvider.getVersionPresupuestoEstatus(enumTipoDePresupuesto.FERTILIZANTES);
            ViewData["cerrado"] = (ejercicioCerrado ? "S" : "N");
            return(PartialView("_GridViewFertilizantesPartial", model.OrderBy(x => x.Desc_Grupo).ThenBy(x => x.Desc_Familia).ToList()));
        }
        public ActionResult BatchEditingUpdateGastosDetalleMesesModel(MVCxGridViewBatchUpdateValues <PreGastoDetalleMensual, object> updateValues)
        {
            IRepositoryWrapper _REPO = new RepositoryWrapper();

            long gtoDeptoID   = -1;
            int  gtoUnidadID  = -1;
            long gtoBaseID    = -1;
            int  gtoDetalleID = -1;

            foreach (var gastoBTF in updateValues.Update)
            {
                gtoDeptoID = gastoBTF.Oid;

                var modelOid = _REPO.GastoDetalle.Find(gtoDeptoID);
                if (modelOid != null)
                {
                    gtoBaseID    = modelOid.BaseTotalId;
                    gtoDeptoID   = modelOid.BaseDepartamentoId;
                    gtoUnidadID  = modelOid.UnidadId;
                    gtoDetalleID = modelOid.DetalleId;
                    break;
                }
            }
            // SE CARGAN DE LA DB LOS MESES DEL DETALLE DEL DEPARTAMENTO
            var modelGastoDepto = _REPO.GastoDepartamento.GetGastoAndRelatedById(gtoDeptoID);

            if (modelGastoDepto == null)
            {
                modelGastoDepto = new PreGastoDepartamento();
                PreGastoUnidad GastoUnidad = new PreGastoUnidad();
                GastoUnidad.PreGastoDetalleMensual.Add(new PreGastoDetalleMensual());
                modelGastoDepto.PreGastoUnidad.Add(GastoUnidad);
            }
            var modelGastoUnidad = modelGastoDepto.PreGastoUnidad.Where(u => u.UnidadId == gtoUnidadID).SingleOrDefault();
            var model            = modelGastoUnidad.PreGastoDetalleMensual.Where(d => d.DetalleId == gtoDetalleID).ToList();

            // SE CARGAN DE LA BD EL RESTO DE LOS DETALLES DEL DEPARTAMENTO
            var restoUnidad  = modelGastoDepto.PreGastoUnidad.Where(u => u.UnidadId != gtoUnidadID).ToList();
            var restoDetalle = modelGastoUnidad.PreGastoDetalleMensual.Where(d => d.DetalleId != gtoDetalleID).ToList();

            DescripcionProducto _gasto = _unitOfWork.GetRepositoryInstance <Pre_GastosBase>().GetAllRecordsIQueryable()
                                         .Where(a => a.Oid == gtoBaseID)
                                         .Select(g => new DescripcionProducto {
                Familia = g.Desc_Area, Producto = g.NSubcuenta
            })
                                         .FirstOrDefault();

            //var modelBaseTotal = db.Pre_GastosBase.FirstOrDefault(a => a.Oid == oID);
            if (_gasto == null)
            {
                _gasto          = new DescripcionProducto();
                _gasto.Familia  = "";
                _gasto.Producto = "";
            }

            ViewData["Articulo"] = string.Format("{0}<br>{1}", _gasto.Familia, _gasto.Producto);

            #region Insert

            // Insert all added values.
            foreach (var gastoBT in updateValues.Insert)
            {
                if (updateValues.IsValid(gastoBT))
                {
                    try
                    {
                        model.Add(gastoBT);
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        updateValues.SetErrorText(gastoBT, e.Message);
                    }
                }
            }

            #endregion

            #region Update

            // Update all edited values.
            if (updateValues.Update.Count > 0)
            {
                foreach (var gastoBT in updateValues.Update)
                {
                    if (updateValues.IsValid(gastoBT))
                    {
                        try
                        {
                            var modelItem = model.FirstOrDefault(it => it.Oid == gastoBT.Oid);
                            if (modelItem != null)
                            {
                                modelItem.MontoManual = false;
                                if (modelItem.Monto != gastoBT.Monto && gastoBT.Monto != gastoBT.MontoBase)
                                {
                                    modelItem.MontoManual = true;
                                }
                                modelItem.Monto = gastoBT.Monto;

                                //db.PreGastoDepartamento.FirstOrDefault(a => a.Oid == gtoDeptoID);

                                if (modelGastoDepto != null)
                                {
                                    // SE INICIALIZA CON EL MONTO DEL MES
                                    decimal importeMes       = modelItem.Monto;
                                    decimal importeMesUnidad = modelItem.Monto;
                                    // SE SUMAN LOS MONTOS DEL MISMO MES DEL RESTO DE DETALLES DEL DEPARTAMENTO
                                    foreach (var OtraUnidad in restoUnidad)
                                    {
                                        foreach (var montoResto in OtraUnidad.PreGastoDetalleMensual.Where(r => r.Mes == modelItem.Mes).Select(x => x.Monto))
                                        {
                                            importeMes += montoResto;
                                        }
                                    }
                                    foreach (var montoResto in restoDetalle.Where(r => r.Mes == modelItem.Mes).Select(x => x.Monto))
                                    {
                                        importeMes       += montoResto;
                                        importeMesUnidad += montoResto;
                                    }


                                    switch (modelItem.Mes)
                                    {
                                    case 1:
                                        //modelGastoDepto.EneImporte = modelItem.Monto;
                                        modelGastoDepto.EneImporte  = importeMes;
                                        modelGastoUnidad.EneImporte = importeMesUnidad;
                                        break;

                                    case 2:
                                        modelGastoDepto.FebImporte  = importeMes;
                                        modelGastoUnidad.FebImporte = importeMesUnidad;
                                        break;

                                    case 3:
                                        modelGastoDepto.MarImporte  = importeMes;
                                        modelGastoUnidad.MarImporte = importeMesUnidad;
                                        break;

                                    case 4:
                                        modelGastoDepto.AbrImporte  = importeMes;
                                        modelGastoUnidad.AbrImporte = importeMesUnidad;
                                        break;

                                    case 5:
                                        modelGastoDepto.MayImporte  = importeMes;
                                        modelGastoUnidad.MayImporte = importeMesUnidad;
                                        break;

                                    case 6:
                                        modelGastoDepto.JunImporte  = importeMes;
                                        modelGastoUnidad.JunImporte = importeMesUnidad;
                                        break;

                                    case 7:
                                        modelGastoDepto.JulImporte  = importeMes;
                                        modelGastoUnidad.JulImporte = importeMesUnidad;
                                        break;

                                    case 8:
                                        modelGastoDepto.AgoImporte  = importeMes;
                                        modelGastoUnidad.AgoImporte = importeMesUnidad;
                                        break;

                                    case 9:
                                        modelGastoDepto.SepImporte  = importeMes;
                                        modelGastoUnidad.SepImporte = importeMesUnidad;
                                        break;

                                    case 10:
                                        modelGastoDepto.OctImporte  = importeMes;
                                        modelGastoUnidad.OctImporte = importeMesUnidad;
                                        break;

                                    case 11:
                                        modelGastoDepto.NovImporte  = importeMes;
                                        modelGastoUnidad.NovImporte = importeMesUnidad;
                                        break;

                                    case 12:
                                        modelGastoDepto.DicImporte  = importeMes;
                                        modelGastoUnidad.DicImporte = importeMesUnidad;
                                        break;

                                    default:
                                        break;
                                    }
                                }
                                decimal?importe       = 0m;
                                decimal?importeUnidad = 0m;
                                // SE SUMAN LOS MONTOS DEL DETALLE QUE SE ACTUALIZO
                                foreach (var itemMes in model)
                                {
                                    importe       += itemMes.Monto;
                                    importeUnidad += itemMes.Monto;
                                }
                                // SE SUMAN LOS MONTOS DEL RESTO DE DETALLE DEL DEPARTAMENTO
                                foreach (var itemMesRestoDetalle in restoDetalle)
                                {
                                    importe       += itemMesRestoDetalle.Monto;
                                    importeUnidad += itemMesRestoDetalle.Monto;
                                }
                                foreach (var itemMesResto in restoUnidad)
                                {
                                    importe += itemMesResto.Monto;
                                }

                                // SE APLICA EL IMPORTE TOTAL EN LOS GASTOS DEPARTAMENTO
                                modelGastoDepto.Monto  = importe ?? 0m;
                                modelGastoUnidad.Monto = importeUnidad ?? 0m;
                            }
                        }
                        catch (Exception e)
                        {
                            updateValues.SetErrorText(gastoBT, e.Message);
                        }
                    }
                }
                var resultado = _REPO.GastoDepartamento.AddUpdate(modelGastoDepto);
                if (!resultado.Item1)
                {
                    throw new Exception(string.Join(Environment.NewLine, resultado.Item2));
                }
            }

            #endregion

            #region Delete

            // Delete all values that were deleted on the client side from the data source.
            foreach (var oID in updateValues.DeleteKeys)
            {
                try
                {
                    long gastoID = Convert.ToInt64(oID);
                    var  item    = model.FirstOrDefault(it => it.Oid == gastoID);
                    if (item != null)
                    {
                        model.Remove(item);
                    }
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    updateValues.SetErrorText(oID, e.Message);
                }
            }

            #endregion


            IRepositoryWrapper _repository = new RepositoryWrapper();

            //var deptoAndUnidad = _REPO.GastoDepartamento
            //    .GetGastoByDepartamentoAndUnidadAndDetalle(model[0].BaseTotalId, model[0].DepartamentoId);

            var deptoAndUnidad = _repository.GastoDepartamento
                                 .GetGastoByDepartamentoAnUnidad(model[0].BaseTotalId, model[0].DepartamentoId);
            if (deptoAndUnidad == null)
            {
                deptoAndUnidad = new PreGastoDepartamento();
                PreGastoUnidad unidad = new PreGastoUnidad();
                unidad.PreGastoDetalleMensual.Add(new PreGastoDetalleMensual());
                deptoAndUnidad.PreGastoUnidad.Add(unidad);
            }
            var unidadAndDetalle = deptoAndUnidad.PreGastoUnidad
                                   .Where(u => u.UnidadId == model[0].UnidadId).SingleOrDefault();

            var modelActualizado = unidadAndDetalle.PreGastoDetalleMensual.Where(d => d.DetalleId == model[0].DetalleId);
            //deptoAndUnidad.PreGastoUnidadMensual.Where(x => x.UnidadId == model[0].UnidadId);

            return(PartialView("_GridViewGastosDetalleMesesPartial", modelActualizado.ToList()));
        }
Пример #30
0
        /// <summary>Both master and detail has change</summary>
        /// <param name="batchData">contain updata、insert、delete list</param>
        /// <param name="master"></param>
        /// <returns></returns>
        public ActionResult DetailGridBatchUpdate(MVCxGridViewBatchUpdateValues <TR01BViewModel, int> updateValues, TR01AViewModel master)
        {
            string errMsg     = "";
            int    errorCount = 0;
            int    TR01A_ID   = master.TR01A_ID;

            //Validation
            ValidateMaster(master);

            for (int i = 0; i < updateValues.Insert.Count; i++)
            {
                if (updateValues.IsValid(updateValues.Insert[i]) == false)
                {
                    errorCount++;
                }
                //if (updateValues.Insert[i].REM_MM.Length > 10)
                //{
                //    errorCount++;
                //    ModelState.AddModelError($"Update[{i}].REM_MM", "REM_MM太長");//display error in cell
                //}
            }

            for (int i = 0; i < updateValues.Update.Count; i++)
            {
                if (updateValues.IsValid(updateValues.Update[i]) == false)
                {
                    errorCount++;
                }
                //if (updateValues.Update[i].REM_MM.Length > 10)
                //{
                //    errorCount++;
                //    ModelState.AddModelError($"Update[{i}].REM_MM", "REM_MM太長");//display error in cell
                //}
            }

            //Save
            if (errorCount == 0 && ModelState.IsValid)
            {
                var TR01A = MasterToEntity(master);

                var addList = new List <TR01B>();
                foreach (var item in updateValues.Insert)
                {
                    var TR01B = new TR01B();
                    item.CREATE_USER = "******";
                    item.CREATE_DATE = DateTime.Now;
                    item.ToDomain(TR01B);
                    addList.Add(TR01B);
                }

                var updateList = new List <TR01B>();
                foreach (var item in updateValues.Update)
                {
                    var TR01B = new TR01B();
                    TR01B            = _Service.GetD(x => x.TR01B_ID == item.TR01B_ID);
                    item.CREATE_USER = TR01B.CREATE_USER;
                    item.CREATE_DATE = TR01B.CREATE_DATE;
                    item.UPDATE_USER = "******";
                    item.UPDATE_DATE = DateTime.Now;
                    item.ToDomain(TR01B);
                    updateList.Add(TR01B);
                }

                errMsg = _Service.UpdateMD(TR01A, addList, updateList, updateValues.DeleteKeys);
            }

            //Result
            if (errMsg.Length > 0 || !ModelState.IsValid)
            {
                for (int i = 0; i < updateValues.Insert.Count; i++)
                {
                    ModelState.AddModelError($"Insert[{i}].IsValid", "Error");
                }

                for (int i = 0; i < updateValues.Update.Count; i++)
                {
                    ModelState.AddModelError($"Update[{i}].IsValid", "Error");
                }

                string deleteIDStrList = "";
                for (int i = 0; i < updateValues.DeleteKeys.Count; i++)
                {
                    updateValues.SetErrorText(updateValues.DeleteKeys[i], "Unable to delete!");
                    deleteIDStrList += updateValues.DeleteKeys[i] + ",";
                }
                ViewData["EditErrorMsg"] = "Failure" + "<br />" + errMsg;
                ViewData["DeleteIDList"] = deleteIDStrList;
                ViewData["MasterForm"]   = ReadViewHelper.PartialView(this, "_MasterForm", master);
                return(PartialView("_DetailGrid", GetTR01BList(TR01A_ID)));
            }
            else
            {
                SetTempData(master.TR01A_ID);
                return(RedirectToAction("Index"));
            }
        }