示例#1
0
        private static int CalculateQuantityForX(InputItem item)
        {
            double size = item.SummedUpSize;                                // size in meter

            StringParserService.ParseType(item.Type, out int a, out int b); // a, b in millimeter
            double bInMeter = b / 1000.0;

            return((int)Math.Ceiling(size / bInMeter));
        }
示例#2
0
        private static int CalculateQuantityForB(InputItem item)
        {
            double size       = item.SummedUpSize;                                    // size in meter
            double unitLength = StringParserService.ParseUnitLength(item.UnitLength); // unitLength in meter

            StringParserService.ParseType(item.Type, out int a, out int b);           // a, b in millimeter
            double aInMeter = a / 1000.0, bInMeter = b / 1000.0;

            return((int)Math.Ceiling(size / aInMeter / Math.Floor(bInMeter / unitLength)));
        }
示例#3
0
        public static int CalculateBuckleItemQuantity(List <SummedItem> items)
        {
            int res = 0;

            foreach (SummedItem item in items)
            {
                if (item.BorX == "b")
                {
                    StringParserService.ParseType(item.Type, out int a, out int b);
                    res += (int)Math.Ceiling(1.0 * b * item.Quantity / 600);
                }
            }
            return(res);
        }
示例#4
0
        /// <summary>
        /// Use PriceCollector to collect price for SummedItems with same ProductName and width of Type,
        /// then populate collected prices back to SummedItems
        /// </summary>
        public static List <PriceCollector> SummedItemsToPriceCollectors(List <SummedItem> summedItems)
        {
            List <PriceCollector> priceCollectors = new List <PriceCollector>();
            HashSet <string>      collectorIDs    = new HashSet <string>();

            foreach (SummedItem summedItem in summedItems)
            {
                StringParserService.ParseType(summedItem.Type, out int widthOfType, out int lengthOfType);
                string id = summedItem.ProductName + "_" + widthOfType;
                if (!collectorIDs.Contains(id))
                {
                    PriceCollector collector = new PriceCollector(summedItem.ProductName, widthOfType.ToString());
                    priceCollectors.Add(collector);
                    collectorIDs.Add(id);
                }
            }

            return(priceCollectors);
        }
示例#5
0
        public static void PopulateSummedItemsPriceFromPriceCollectors(List <PriceCollector> priceCollectors, ref List <SummedItem> summedItems)
        {
            Dictionary <string, string[]> pricesDict = new Dictionary <string, string[]>();

            foreach (PriceCollector priceCollector in priceCollectors)
            {
                pricesDict.Add(priceCollector.ID, new string[] { priceCollector.BuyPrice, priceCollector.SellPrice });
            }

            foreach (SummedItem summedItem in summedItems)
            {
                StringParserService.ParseType(summedItem.Type, out int widthOfType, out int lengthOfType);
                string itemID = summedItem.ProductName + "_" + widthOfType;

                if (!pricesDict.ContainsKey(itemID))
                {
                    throw new Exception("PriceCollectors does not cover all SummedItems");
                }

                summedItem.BuyPrice  = pricesDict[itemID][0];
                summedItem.SellPrice = pricesDict[itemID][1];
            }
        }
示例#6
0
        /// <summary>
        /// Read the saved InputCheckingSheet, put each record on sheet into a InputItem
        /// </summary>
        /// <param name="filepath"></param>
        /// <returns></returns>
        public static List <InputItem> ReadInputCheckingSheetToInputItemList(string filepath)
        {
            List <InputItem> inputItems = new List <InputItem>();

            using (SpreadsheetDocument spreadsheetDocument = SpreadsheetDocument.Open(filepath, false))
            {
                WorkbookPart  workbookPart  = spreadsheetDocument.WorkbookPart;
                WorksheetPart worksheetPart = workbookPart.WorksheetParts.First();
                SheetData     sheetData     = worksheetPart.Worksheet.Elements <SheetData>().First();

                foreach (Row r in sheetData.Elements <Row>())
                {
                    if (r.RowIndex == 1u)
                    {
                        continue;                   // skip first row
                    }
                    var       cells     = r.Elements <Cell>().ToList();
                    InputItem inputItem = new InputItem();

                    inputItem.ProductName    = cells[1].CellValue.Text;
                    inputItem.BorX           = cells[2].CellValue.Text;
                    inputItem.Type           = cells[3].CellValue.Text;
                    inputItem.Size           = cells[4].CellValue.Text;
                    inputItem.Position       = cells[5].CellValue.Text;
                    inputItem.Room           = cells[6].CellValue.Text;
                    inputItem.UnitLength     = cells[7].CellValue.Text != string.Empty ? cells[7].CellValue.Text : null;
                    inputItem.ApplyDirection = cells[8].CellValue.Text != string.Empty ? cells[8].CellValue.Text : null;
                    inputItem.SummedUpSize   = StringParserService.StringToDouble(cells[9].CellValue.Text);
                    inputItem.Quantity       = StringParserService.StringToInt(cells[10].CellValue.Text);

                    inputItems.Add(inputItem);
                }
            }

            return(inputItems);
        }
示例#7
0
        public static List <SummedItem> MergeInputItem(List <InputItem> inputItemList)
        {
            List <SummedItem> summedItemList = new List <SummedItem>();
            Dictionary <string, List <InputItem> > itemDict = new Dictionary <string, List <InputItem> >();

            // Get dict of "s-802 300*3600 x" -> List<InputItem> that has same product name and type
            foreach (InputItem item in inputItemList)
            {
                string inputItemKey = item.ProductName + " " + item.Type + " " + item.BorX;
                if (itemDict.ContainsKey(inputItemKey))
                {
                    itemDict[inputItemKey].Add(item);
                }
                else
                {
                    List <InputItem> similarInputItemList = new List <InputItem>();
                    similarInputItemList.Add(item);
                    itemDict.Add(inputItemKey, similarInputItemList);
                }
            }

            // Loop through dictionary, for each key value pair, merge the List<InputItem> into one SummedItem
            foreach (KeyValuePair <string, List <InputItem> > entry in itemDict)
            {
                SummedItem    summedItem = new SummedItem(entry.Value[0].ProductName, entry.Value[0].Type, entry.Value[0].BorX);
                int           quantity   = 0;
                StringBuilder memosb     = new StringBuilder();

                // Sum up quantity and memo (Southeast bedroom top 19 + kitchen top 16 ...)
                foreach (InputItem item in entry.Value)
                {
                    quantity += item.Quantity;
                    memosb.Append(item.Room + item.Position + item.Quantity + "+");
                }
                memosb.Remove(memosb.Length - 1, 1);

                summedItem.Quantity = quantity;
                summedItem.Memo     = memosb.ToString();

                // Calculate TotalArea (for b) or TotalLength (for x)
                StringParserService.ParseType(summedItem.Type, out int a, out int b);
                switch (summedItem.BorX)
                {
                case "b":
                    CalculateTotalAreaForB(a, b, summedItem.Quantity, out double totalArea);
                    summedItem.TotalAreaOrLength = totalArea;
                    break;

                case "x":
                    CalculateTotalLengthForX(a, b, summedItem.Quantity, out double totalLength);
                    summedItem.TotalAreaOrLength = totalLength;
                    break;

                default:
                    throw new Exception("B or X not assigned to summedItem");
                }

                summedItemList.Add(summedItem);
            }

            return(summedItemList);
        }