public ActionResult BookPackItemOperationGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Qiyas.BusinessLogicLayer.Entity.PPM.BookPackItemOperation item) { item.BookPackItemOperationID = BookPackItemOperationList.Count + 1; item.BookPackItemID = 1; foreach (ModelState modelState in ViewData.ModelState.Values) { modelState.Errors.Clear(); } ModelState.SetModelValue("BookPackItemID", new ValueProviderResult(1, "1", System.Globalization.CultureInfo.CurrentCulture)); if (ModelState.IsValid) { try { bool isValid = true; if (BookRepackPackageItemList.Count == 0) { ViewData["EditError"] = Resources.MainResource.NoRepackItemsSelected; isValid = false; var modelError = new BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic().GetByBookPackID(PackID); return(PartialView("_RepackGridViewPartial", modelError)); } if (item.PackingCalculationTypeID == 2) { if (item.PackingParentID == 0) { ViewData["EditError"] = Resources.MainResource.EnterPackingParentID; isValid = false; } } int totalPackage = TotalPackages(item); BusinessLogicLayer.Entity.PPM.BookPackItem packItem = new BusinessLogicLayer.Entity.PPM.BookPackItem(PackID); BusinessLogicLayer.Entity.PPM.BookPackingOperation package = new BusinessLogicLayer.Entity.PPM.BookPackingOperation(packItem.BookPackingOperationID.Value); BusinessLogicLayer.Entity.PPM.BookPrintingOperation printingOperation = new BusinessLogicLayer.Entity.PPM.BookPrintingOperation(PrintingOperationID); BusinessLogicLayer.Entity.PPM.PackagingType ptype = new BusinessLogicLayer.Entity.PPM.PackagingType(item.PackagingTypeID.Value); var itemExists = (from c in BookPackItemOperationList where c.PackagingTypeID == item.PackagingTypeID select c).FirstOrDefault(); if (itemExists == null) { if (printingOperation != null) { BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic logic = new BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic(); int totalItems = GetTotalBooksForModel(true); int currentTotal = ptype.BooksPerPackage == 3 && ptype.ExamModelCount == 1 ? GetTotalItemsA3() : GetTotalItems(); int totalPrint = (totalPackage * ptype.BooksPerPackage.Value + currentTotal); int count = new BusinessLogicLayer.Components.PPM.ExamLogic().GetExamModelCount(printingOperation.ExamID.Value); if (count > 1) { totalItems = totalItems * count; } if (totalItems < totalPrint) { isValid = false; ViewData["EditError"] = Resources.MainResource.TotalPackGreaterThanOverallTotal; } } if (isValid) { BusinessLogicLayer.Entity.PPM.BookPackItemOperation entity = new BusinessLogicLayer.Entity.PPM.BookPackItemOperation(); entity.BookPackItemOperationID = BookPackItemOperationList.Count + 1; entity.AllocatedFrom = item.AllocatedFrom; entity.BookPackItemID = packItem.BookPackItemID; entity.PackingParentID = package.BookPackingOperationID; entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.Name = item.Name; entity.PackingParentID = item.PackingParentID; entity.PackageTotal = totalPackage; entity.PackagingTypeID = item.PackagingTypeID; entity.PackingCalculationTypeID = item.PackingCalculationTypeID; entity.PackingValue = item.PackingValue; BookPackItemOperationList.Add(entity); } } else { ViewData["EditError"] = "لا يمكن ادخال نوع الحزمة مرتين"; } } catch (Exception e) { ViewData["EditError"] = e.Message; } } else { string msgError = ""; foreach (ModelState modelState in ViewData.ModelState.Values) { foreach (ModelError error in modelState.Errors) { msgError += error.ErrorMessage + " "; } } ViewData["EditError"] = msgError; } var model = BookPackItemOperationList; return(PartialView("_BookPackItemOperationGridViewPartial", model)); }
private int TotalPackages(BusinessLogicLayer.Entity.PPM.BookPackItemOperation item) { int total = 0; BusinessLogicLayer.Entity.PPM.PackagingType ptype = new BusinessLogicLayer.Entity.PPM.PackagingType(item.PackagingTypeID.Value); if (ptype == null) { return(0); } BusinessLogicLayer.Entity.PPM.BookPrintingOperation printingOperation = new BusinessLogicLayer.Entity.PPM.BookPrintingOperation(PrintingOperationID); if (printingOperation == null) { return(0); } bool isA3 = ptype.BooksPerPackage == 3 && ptype.ExamModelCount == 1; int totalItems = GetTotalBooksForModel(isA3); int countExams = new BusinessLogicLayer.Components.PPM.ExamLogic().GetExamModelCount(printingOperation.ExamID.Value); if (item.PackingCalculationTypeID == 1) { double t = item.PackingValue.Value / 100.00; total = Convert.ToInt32(Math.Ceiling(totalItems * t)); total = total / (ptype.ExamModelCount.Value * ptype.BooksPerPackage.Value); if (ptype.ExamModelCount == 1) { total = total * countExams; } else { total = total * ptype.ExamModelCount.Value; } } else if (item.PackingCalculationTypeID == 2) { BusinessLogicLayer.Entity.PPM.BookPackItemOperation operation = new BusinessLogicLayer.Entity.PPM.BookPackItemOperation(item.PackingParentID.Value); if (operation == null) { return(0); } totalItems = operation.PackageTotal.Value; if (operation.PackingCalculationTypeID == 1) { double t = item.PackingValue.Value / 100.00; total = Convert.ToInt32(Math.Ceiling(totalItems * t)); total = total / (ptype.ExamModelCount.Value * ptype.BooksPerPackage.Value); if (ptype.ExamModelCount == 1) { total = total * countExams; } else { total = total * ptype.ExamModelCount.Value; } } else if (operation.PackingCalculationTypeID == 2) { BusinessLogicLayer.Entity.PPM.BookPackItemOperation operation2 = new BusinessLogicLayer.Entity.PPM.BookPackItemOperation(operation.PackingParentID.Value); if (operation2 == null) { return(0); } totalItems = operation2.PackageTotal.Value; if (operation2.PackingCalculationTypeID == 1) { double t = item.PackingValue.Value / 100.00; total = Convert.ToInt32(Math.Ceiling(totalItems * t)); } else if (operation2.PackingCalculationTypeID == 3) { total = item.PackingValue.Value; } } else if (operation.PackingCalculationTypeID == 3) { if (ptype.ExamModelCount == 1) { total = item.PackingValue.Value / (ptype.BooksPerPackage.Value * ptype.ExamModelCount.Value); total = total * countExams; } else { total = item.PackingValue.Value / (ptype.BooksPerPackage.Value); //total = total * ptype.ExamModelCount.Value; } } } else if (item.PackingCalculationTypeID == 3) { if (ptype.ExamModelCount == 1) { total = item.PackingValue.Value / (ptype.BooksPerPackage.Value * ptype.ExamModelCount.Value); total = total * countExams; } else { total = item.PackingValue.Value / (ptype.BooksPerPackage.Value); //total = total * ptype.ExamModelCount.Value; } } return(total); }
private void AddItemToPack(List <BusinessLogicLayer.Entity.PPM.BookPackItem> items, List <BusinessLogicLayer.Entity.PPM.PackagingType> packageTypes, List <BusinessLogicLayer.Entity.PPM.BookPackItemOperation> packing, List <BusinessLogicLayer.Entity.PPM.BookPackItemOperation> oldPacks, BusinessLogicLayer.Entity.PPM.BookPrintingOperation model, BusinessLogicLayer.Entity.PPM.Exam exam, ref int count, ref int serial, BusinessLogicLayer.Entity.PPM.BookPackItemOperation pack, BusinessLogicLayer.Entity.PPM.BookPackItem parentItem) { serial = 1; if (parentItem.OperationStatusID != 8) { parentItem.OperationStatusID = 8; parentItem.Save(); } BusinessLogicLayer.Entity.PPM.BookPackingOperation packOperation = new BusinessLogicLayer.Entity.PPM.BookPackingOperation(parentItem.BookPackingOperationID.Value); var packType = (from x in packageTypes where x.PackagingTypeID == pack.PackagingTypeID select x).FirstOrDefault(); var exists = (from x in oldPacks where x.BookPackItemOperationID == pack.BookPackItemOperationID select x).FirstOrDefault(); int bookStart = 0; int bookLast = 0; if (exists == null || !exists.HasObject) { for (int i = 0; i < pack.PackageTotal.Value; i++) { BusinessLogicLayer.Entity.PPM.BookPackItem item = new BusinessLogicLayer.Entity.PPM.BookPackItem(); item.BookPackingOperationID = packOperation.BookPackingOperationID; item.BookPackItemOperationID = pack.BookPackItemOperationID; item.BookPackItemID = PackID; item.OperationStatusID = 7; item.PackSerial = serial; string modelCode = ""; List <BusinessLogicLayer.Entity.PPM.BookPackItemModel> itemModels = new List <BusinessLogicLayer.Entity.PPM.BookPackItemModel>(); bookStart = bookLast + 1; bookLast += bookStart + (i + 1) * packType.BooksPerPackage.Value; bool addModelsToCount = true; foreach (BusinessLogicLayer.Entity.PPM.ExamModelItem examModel in exam.ExamModels) { if (packType.ExamModelCount > 1) { BusinessLogicLayer.Entity.PPM.BookPackItemModel newModel = new BusinessLogicLayer.Entity.PPM.BookPackItemModel(); newModel.BookPackItemID = item.BookPackItemID; newModel.ExamModelID = examModel.ExamModelID; modelCode += examModel.ExamModelID + "-"; item.StartBookSerial = bookStart; item.LastBookSerial = bookLast; itemModels.Add(newModel); } else { itemModels = new List <BusinessLogicLayer.Entity.PPM.BookPackItemModel>(); BusinessLogicLayer.Entity.PPM.BookPackItem itemUnit = new BusinessLogicLayer.Entity.PPM.BookPackItem(); item.BookPackingOperationID = packOperation.BookPackingOperationID; item.BookPackItemOperationID = pack.BookPackItemOperationID; item.BookPackItemID = PackID; itemUnit.OperationStatusID = 7; itemUnit.StartBookSerial = bookStart; itemUnit.LastBookSerial = bookLast; itemUnit.PackSerial = serial; //itemUnit.PackCode = PrintingOperationID + "-" + pack.BookPackingOperationID + "-" + pack.PackagingTypeID + "-" + examModel.ExamModelID + "-" + serial; itemUnit.PackCode = RandomString(12); BusinessLogicLayer.Entity.PPM.BookPackItemModel newModel = new BusinessLogicLayer.Entity.PPM.BookPackItemModel(); newModel.BookPackItemID = item.BookPackItemID; newModel.ExamModelID = examModel.ExamModelID; modelCode += examModel.ExamModelID + "-"; itemModels.Add(newModel); itemUnit.ItemModels = itemModels; items.Add(itemUnit); if (addModelsToCount) { i += exam.ExamModels.Count - 1; addModelsToCount = false; } //serial++; } } if (packType.ExamModelCount > 1) { if (!string.IsNullOrEmpty(modelCode)) { modelCode = modelCode.Remove(modelCode.Length - 1, 1); } //item.PackCode = PrintingOperationID + "-" + pack.BookPackingOperationID + "-" + pack.PackagingTypeID + "-" + modelCode + "-" + serial; item.PackCode = RandomString(12); item.ItemModels = itemModels; items.Add(item); } serial++; ///TODO: Add Pack Items for Sub Packs } } }
private void AddItemToPack(List <BusinessLogicLayer.Entity.PPM.BookPackItem> items, List <BusinessLogicLayer.Entity.PPM.PackagingType> packageTypes, List <BusinessLogicLayer.Entity.PPM.BookPackItemOperation> packing, List <BusinessLogicLayer.Entity.PPM.BookPackItemOperation> oldPacks, BusinessLogicLayer.Entity.PPM.BookPrintingOperation model, BusinessLogicLayer.Entity.PPM.Exam exam, ref int count, ref int serial, BusinessLogicLayer.Entity.PPM.BookPackItemOperation pack, BusinessLogicLayer.Entity.PPM.BookPackItem parentItem, int parentRepackID) { serial = 1; BusinessLogicLayer.Components.PPM.BookPackItemLogic BookPackItemLogic = new BusinessLogicLayer.Components.PPM.BookPackItemLogic(); foreach (BusinessLogicLayer.Entity.PPM.BookRepackPackageItem vparentItem in BookRepackPackageItemList) { parentItem = new BusinessLogicLayer.Entity.PPM.BookPackItem(vparentItem.BookPackItemID.Value); int i = 0; var packType = (from x in packageTypes where x.PackagingTypeID == pack.PackagingTypeID select x).FirstOrDefault(); var exists = (from x in oldPacks where x.BookPackItemOperationID == pack.BookPackItemOperationID select x).FirstOrDefault(); BusinessLogicLayer.Entity.PPM.BookPackingOperation packOperation = new BusinessLogicLayer.Entity.PPM.BookPackingOperation(parentItem.BookPackingOperationID.Value); if (i >= pack.PackageTotal.Value) { break; } if (exists == null || !exists.HasObject) { int bookStart = 0; int bookLast = BookPackItemLogic.GetLastBookSerialForRePackedItem(parentItem.BookPackItemID); if (bookLast == 0) { bookLast = 1; } var oldPackageCount = BookPackItemLogic.GetPackageBooksCount(parentItem.BookPackItemID); int remaining = oldPackageCount; bool isFirst = true; while (remaining > 0) { BusinessLogicLayer.Entity.PPM.BookPackItem item = new BusinessLogicLayer.Entity.PPM.BookPackItem(); item.BookPackingOperationID = packOperation.BookPackingOperationID; item.BookPackItemOperationID = pack.BookPackItemOperationID; item.BookPackItemID = PackID; item.OperationStatusID = 7; item.ParentID = parentRepackID; item.PackSerial = serial; item.ParentBookPackItemID = parentItem.BookPackItemID; string modelCode = ""; List <BusinessLogicLayer.Entity.PPM.BookPackItemModel> itemModels = new List <BusinessLogicLayer.Entity.PPM.BookPackItemModel>(); bookStart = i == 0 ? bookLast : bookLast + 1; bookLast = bookStart + (packType.BooksPerPackage.Value - 1); foreach (BusinessLogicLayer.Entity.PPM.BookPackItemModel examModel in parentItem.ItemModels) { if (packType.ExamModelCount > 1) { BusinessLogicLayer.Entity.PPM.BookPackItemModel newModel = new BusinessLogicLayer.Entity.PPM.BookPackItemModel(); newModel.BookPackItemID = item.BookPackItemID; newModel.ExamModelID = examModel.ExamModelID; modelCode += examModel.ExamModelID + "-"; item.StartBookSerial = bookStart; item.LastBookSerial = bookLast; remaining -= packType.BooksPerPackage.Value; itemModels.Add(newModel); } else { if (isFirst) { remaining = remaining * parentItem.ItemModels.Count; isFirst = false; } itemModels = new List <BusinessLogicLayer.Entity.PPM.BookPackItemModel>(); BusinessLogicLayer.Entity.PPM.BookPackItem itemUnit = new BusinessLogicLayer.Entity.PPM.BookPackItem(); itemUnit.BookPackingOperationID = packOperation.BookPackingOperationID; itemUnit.BookPackItemOperationID = pack.BookPackItemOperationID; itemUnit.BookPackItemID = PackID; itemUnit.OperationStatusID = 7; itemUnit.ParentBookPackItemID = parentItem.BookPackItemID; itemUnit.StartBookSerial = bookStart; itemUnit.LastBookSerial = bookLast; itemUnit.PackSerial = serial; //itemUnit.PackCode = PrintingOperationID + "-" + pack.BookPackingOperationID + "-" + pack.PackagingTypeID + "-" + examModel.ExamModelID + "-" + serial; itemUnit.PackCode = RandomString(12); BusinessLogicLayer.Entity.PPM.BookPackItemModel newModel = new BusinessLogicLayer.Entity.PPM.BookPackItemModel(); newModel.BookPackItemID = item.BookPackItemID; newModel.ExamModelID = examModel.ExamModelID; modelCode += examModel.ExamModelID + "-"; itemModels.Add(newModel); itemUnit.ParentID = parentRepackID; itemUnit.ItemModels = itemModels; remaining -= packType.BooksPerPackage.Value; items.Add(itemUnit); //serial++; } } if (packType.ExamModelCount > 1) { if (!string.IsNullOrEmpty(modelCode)) { modelCode = modelCode.Remove(modelCode.Length - 1, 1); } //item.PackCode = PrintingOperationID + "-" + pack.BookPackingOperationID + "-" + pack.PackagingTypeID + "-" + modelCode + "-" + serial; item.PackCode = RandomString(12); item.ItemModels = itemModels; items.Add(item); } if (parentItem.ItemModels.Count == 0) { remaining = 0; } else { serial++; i++; } ///TODO: Add Pack Items for Sub Packs } } } }
public ActionResult PackingGridViewPartialAddNew([ModelBinder(typeof(DevExpressEditorsBinder))] Qiyas.BusinessLogicLayer.Entity.PPM.BookPackItemOperation item) { //if (ModelState.IsValid) { try { bool isValid = true; if (BookRepackPackageItemList.Count == 0) { ViewData["EditError"] = Resources.MainResource.NoRepackItemsSelected; isValid = false; var modelError = new BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic().GetByBookPackID(PackID); return(PartialView("_RepackGridViewPartial", modelError)); } if (item.PackingCalculationTypeID == 2) { if (item.PackingParentID == 0) { ViewData["EditError"] = Resources.MainResource.EnterPackingParentID; isValid = false; } } int totalPackage = TotalPackages(item); BusinessLogicLayer.Entity.PPM.BookPackItem packItem = new BusinessLogicLayer.Entity.PPM.BookPackItem(PackID); BusinessLogicLayer.Entity.PPM.BookPackingOperation package = new BusinessLogicLayer.Entity.PPM.BookPackingOperation(packItem.BookPackingOperationID.Value); BusinessLogicLayer.Entity.PPM.BookPrintingOperation printingOperation = new BusinessLogicLayer.Entity.PPM.BookPrintingOperation(PrintingOperationID); BusinessLogicLayer.Entity.PPM.PackagingType ptype = new BusinessLogicLayer.Entity.PPM.PackagingType(item.PackagingTypeID.Value); if (printingOperation != null) { BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic logic = new BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic(); int totalItems = GetTotalBooksForModel(true); int currentTotal = ptype.BooksPerPackage == 3 && ptype.ExamModelCount == 1 ? GetTotalItemsA3() : GetTotalItems(); int totalPrint = (totalPackage * ptype.BooksPerPackage.Value + currentTotal); int count = new BusinessLogicLayer.Components.PPM.ExamLogic().GetExamModelCount(printingOperation.ExamID.Value); if (count > 1) { totalItems = totalItems * count; } if (totalItems < totalPrint) { isValid = false; ViewData["EditError"] = Resources.MainResource.TotalPackGreaterThanOverallTotal; } } if (isValid) { BusinessLogicLayer.Entity.PPM.BookPackItemOperation entity = new BusinessLogicLayer.Entity.PPM.BookPackItemOperation(); entity.BookPackItemOperationID = BookPackItemOperationList.Count + 1; entity.AllocatedFrom = item.AllocatedFrom; entity.BookPackItemID = packItem.BookPackItemID; entity.PackingParentID = package.BookPackingOperationID; entity.CreatedDate = DateTime.Now; entity.ModifiedDate = DateTime.Now; entity.Name = item.Name; entity.PackingParentID = package.PackageTotal; entity.PackageTotal = totalPackage; entity.PackagingTypeID = item.PackagingTypeID; entity.PackingCalculationTypeID = item.PackingCalculationTypeID; entity.PackingValue = item.PackingValue; BookPackItemOperationList.Add(entity); } } catch (Exception e) { ViewData["EditError"] = e.Message; } } //else // ViewData["EditError"] = "Please, correct all errors."; var model = BookPackItemOperationList;//new BusinessLogicLayer.Components.PPM.BookPackItemOperationLogic().GetByBookPackID(PackID); return(PartialView("_RepackGridViewPartial", model)); }