public static XLWorkbook CuttingInstruction(ProductionForCT productoinInRightFormat) { if (productoinInRightFormat != null) { var wb = new XLWorkbook(); var ws = wb.Worksheets.Add("Instruction"); ws.Cell(1, 1).Value = productoinInRightFormat.Name; ws.Cell(1, 1).AddToNamed("Titles"); var rowCount = 4; foreach (var marker in productoinInRightFormat.Markers) { ws.Cell(rowCount, 2).Value = marker.Name; ws.Cell(rowCount, 2).AddToNamed("Titles"); ws.Cell(rowCount, 5).Value = $"Lot:{marker.LotNumber}"; ws.Cell(rowCount, 5).AddToNamed("Titles"); foreach (var colMat in marker.ColorMaterials) { rowCount++; ws.Cell(rowCount, 1).Value = $"{colMat.Color} {colMat.Material}"; ws.Cell(rowCount, 2).Value = colMat.Layers; ws.Cell(rowCount, 4).Value = colMat.Packaging.ToString(); } rowCount++; rowCount++; } var titlesStyle = wb.Style; titlesStyle.Font.Bold = true; titlesStyle.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; wb.NamedRanges.NamedRange("Titles").Ranges.Style = titlesStyle; ws.Column(1).AdjustToContents(); return(wb); } return(null); }
public static ProductionForCT ProductionToFormatForExcel(Production production) { var finalProd = new ProductionForCT(); var cprer = new ItemMatColComparer(); finalProd.Date = production.Date; finalProd.Name = $"Murex {production.Date.ToShortDateString()}"; finalProd.Markers = production.CuttingInstructions.Select(ci => { return(new MarkerWithColorMaterials { Name = ci.MarkerText, LotNumber = ci.LotNumber, ColorMaterials = ci.CuttingInstructionDetails.Select(c => { //var amountPerLayer = ci.CuttingInstructionSizes.Count() > 0 ? ci.CuttingInstructionSizes.FirstOrDefault(s => s.SizeId == c.Item.SizeId).AmountPerLayer : ci.MarkerCategory.MarkerDetails.FirstOrDefault(s => s.SizeId == c.Item.SizeId).AmountPerLayer; return new ColorMaterial { Color = c.Fabric.ColorDescriptionName ?? c.Fabric.Color.Name, Material = c.Fabric.Material.Name, Layers = c.Layers, Packaging = c.Packaging }; }).ToList() }); }).ToList(); return(finalProd); }
public static ErrorsAndItems ConvertProductoinToItems(ProductionForCT production) { var tempDate = production.Name.Split()[1]; DateTime date; var isdate = DateTime.TryParseExact(tempDate, DateTimeFormats(), CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date); if (!isdate) { date = DateTime.Now; AddErrorMsg($"Sorry the date {tempDate} is in the wrong format we are going to use the current date instead"); } var repo = new ProductionRespository(Properties.Settings.Default.ManufacturingConStr); var items = new List <CuttingInstructionItem>(); foreach (var marker in production.Markers) { var markerCat = repo.GetMarkerCategory(marker.Name); if (markerCat.NotNull()) { var sizes = marker.Sizes; foreach (var s in sizes) { foreach (var colmat in marker.ColorMaterials) { var colorId = repo.GetColorId(colmat.Color); if (!NotNull(colorId)) { colorId = repo.GetColorDetailsId(colmat.Color); } if (NotNull(colorId)) { var mat = repo.GetMaterialId(colmat.Material); if (NotNull(mat)) { var item = new Item { DepartmentId = markerCat.DepartmentId, BodyStyleId = markerCat.BodyStyleId, SleeveId = markerCat.SleeveId, ColorId = (int)colorId, MaterialId = (int)mat, SizeId = s.SizeId }; var dbItem = repo.GetItem(item); if (NotNull(dbItem)) { var itemQuantity = colmat.Layers * s.AmountPerLayer; if (itemQuantity > 0) { items.Add(new CuttingInstructionItem { ItemId = dbItem.Id, Item = dbItem, Quantity = itemQuantity }); } } else { var size = repo.GetSize(item.SizeId).Name; var material = repo.GetMaterial(item.MaterialId).Name; var color = repo.GetColor(item.ColorId).Name; var department = repo.GetDepartment(item.DepartmentId).Name; var bodyStyle = repo.GetBodyStyle(item.BodyStyleId).Name; var sleeve = repo.GetSleeve(item.SleeveId).Name; AddErrorMsg("item", $"with size:{size}, Material:{material},Color:{color},Department:{department},BodyStyle:{bodyStyle}, Sleeve:{sleeve}"); } } else { AddErrorMsg("materieal", colmat.Material); } } else { AddErrorMsg("Color", colmat.Color); } } } } else { AddErrorMsg("marker", marker.Name); } } var returnItem = new ErrorsAndItems { Items = items, Errors = _erros, Date = date }; _erros = new List <string>(); return(returnItem); }
public static FinalProduction ConvertProductoinToCTs(ProductionForCT production) { _erros = new List <string>(); var repo = new ProductionRespository(Properties.Settings.Default.ManufacturingConStr); var finalProduction = new FinalProduction(); finalProduction.Date = production.Date; foreach (var marker in production.Markers) { var details = new List <CuttingItsructionDetailsWithItems>(); var markerCat = repo.GetMarkerCategory(marker.Name); if (NotNull(markerCat)) { foreach (var colmat in marker.ColorMaterials) { var colorId = repo.GetColorId(colmat.Color); if (!NotNull(colorId)) { colorId = repo.GetColorDetailsId(colmat.Color); } if (NotNull(colorId)) { colmat.ColorId = (int)colorId; var mat = repo.GetMaterialId(colmat.Material); if (NotNull(mat)) { colmat.MaterialId = (int)mat; var detail = new CuttingItsructionDetailsWithItems { ColorMaterial = colmat, Items = new List <CuttingInstructionItem>() }; var sizes = marker.Sizes; foreach (var s in sizes) { var item = new Item { DepartmentId = markerCat.DepartmentId, BodyStyleId = markerCat.BodyStyleId, SleeveId = markerCat.SleeveId, ColorId = (int)colorId, MaterialId = (int)mat, SizeId = s.SizeId }; if (item.MaterialId == 3 && item.ColorId == 34) { item.ColorId = 36; } var dbItem = repo.GetItem(item); if (NotNull(dbItem)) { var itemQuantity = colmat.Layers * s.AmountPerLayer; if (itemQuantity > 0) { detail.Items.Add(new CuttingInstructionItem { ItemId = dbItem.Id, Item = dbItem, Quantity = itemQuantity, Packaging = colmat.Packaging }); } } else { var size = repo.GetSize(item.SizeId).Name; var material = repo.GetMaterial(item.MaterialId).Name; var color = repo.GetColor(item.ColorId).Name; var department = repo.GetDepartment(item.DepartmentId).Name; var bodyStyle = repo.GetBodyStyle(item.BodyStyleId).Name; var sleeve = repo.GetSleeve(item.SleeveId).Name; AddErrorMsg("item", $"with size:{size}, Material:{material},Color:{color},Department:{department},BodyStyle:{bodyStyle}, Sleeve:{sleeve}"); } } if (detail.Items.Count > 0) { details.Add(detail); } } else { AddErrorMsg("materieal", colmat.Material); } } else { AddErrorMsg("Color", colmat.Color); } } if (details.Count > 0) { finalProduction.CuttingInstructions.Add(new CuttingInstructionWithMarker { LotNumber = marker.LotNumber, Details = details, Marker = new Finalmarker { MarkerCatId = markerCat.Id, Name = markerCat.Name, AllSizes = marker.AllSizes, Sizes = marker.Sizes, PlannedProductionId = marker.PlannedProductionId, MarkerSizeText = marker.MarkerText } }); } } else { AddErrorMsg("marker", marker.Name); } } return(finalProduction); }
public static ProductionForCT ConvertCtToProduction(DataTable cuttingInstructions) { _erros = new List <string>(); var repo = new ProductionRespository(Properties.Settings.Default.ManufacturingConStr); var production = new ProductionForCT { Name = cuttingInstructions.Columns[0].ColumnName, }; var tempDate = production.Name.Split()[1]; DateTime date; var isdate = DateTime.TryParseExact(tempDate, DateTimeFormats(), CultureInfo.InvariantCulture, DateTimeStyles.AdjustToUniversal, out date); if (!isdate) { date = DateTime.Now; AddErrorMsg($"Sorry the date {tempDate} is in the wrong format we are going to use the current date instead"); } production.Date = date; for (int x = 0; x < cuttingInstructions.Rows.Count; x++) { if (String.IsNullOrEmpty((string)cuttingInstructions.Rows[x][0])) { var allSizes = false; var temp = (string)cuttingInstructions.Rows[x][1]; temp = String.Concat(temp.Where(c => !char.IsWhiteSpace(c))).ToUpper(); if (!String.IsNullOrEmpty(temp)) { var split = temp.Split('-'); string name = split[0]; List <SizeWithLayer> sizes = new List <SizeWithLayer>(); string size = ""; if (split.Count() == 2) { var tempSize = split[1]; var sizeIs = repo.GetSize(tempSize); if (NotNull(sizeIs)) { name = split[0]; sizes.Add(new SizeWithLayer { SizeId = sizeIs.Id, Name = sizeIs.Name, AmountPerLayer = 6 }); } else { AddErrorMsg("size", tempSize); } } else if (split.Count() >= 2) { name = split[0]; var newMrker = split[1]; if (newMrker.Contains("NEWMARKER")) { sizes = NewMarkerSizeConcact(split); } else { AddErrorMsg($"Sorry [{String.Join("-", split)}] is the wrong format please change the format and try again!"); } } else { var marker = repo.GetMarkerCategory(split[0]); var sizeFromMarker = new List <SizeWithLayer>(); if (marker != null) { sizeFromMarker = repo.GetDefaltMarkerDetails(marker.Id).Select(md => { return(new SizeWithLayer { SizeId = md.SizeId, AmountPerLayer = md.AmountPerLayer, Name = md.Size.Name }); }).ToList(); allSizes = true; } else { AddErrorMsg("marker", split[0]); } sizes = sizeFromMarker; } if (true) { var marker = new MarkerWithColorMaterials { Name = name, Size = size, Sizes = sizes, AllSizes = allSizes }; production.Markers.Add(marker); for (int y = x + 1; y < cuttingInstructions.Rows.Count; y++) { x++; var temp1 = (string)cuttingInstructions.Rows[x][0]; string color; string matireal; if (!String.IsNullOrEmpty(temp1)) { var list = SplitStringOnSpace(temp1); color = list.Count > 2 ? $"{list[0]} {list[1]}" : list[0]; matireal = list[list.Count - 1]; matireal = matireal == "LYCRA" ? "NYLON" : matireal; } else { break; } var layers = (string)cuttingInstructions.Rows[x][1]; var packagingText = (string)cuttingInstructions.Rows[x][3]; var packaging = Packaging.BOX; if (packagingText != null) { if (packagingText.ToUpper() == "HANG") { packaging = Packaging.HANG; } } if (!String.IsNullOrEmpty(layers) && int.TryParse(layers, out int layersInt)) { marker.ColorMaterials.Add(new ColorMaterial { Color = color, Material = matireal, Layers = layersInt, Packaging = packaging }); } else { break; } } } } } } return(production); }