Beispiel #1
0
        public void GetList(string[] vendors)
        {
            HashSet <string>            UPCs = new HashSet <string>();
            HashSet <string>            ALUs = new HashSet <string>();
            Dictionary <string, string> UOMs = new Dictionary <string, string>();

            foreach (string vendor in vendors)
            {
                GetSheet(vendor).Subscribe(path =>
                {
                    assetLoader.LoadAsset <ColumnMap>(vendor).Subscribe(map =>
                    {
                        ExcelQuery query = OpenSpreadSheet(path, vendor);

                        string err = string.Empty;

                        //Get 1st sheet
                        string[] sheets = query.GetSheetNames();
                        if (sheets == null || sheets.Length > 1)
                        {
                            Debug.LogError("Sheet missing or more than one sheet! Quitting");
                            return;
                        }
                        //use first sheet in our query, whatever it is named
                        query.GetNewSheet(sheets[0]);

                        int numOfRows = query.NumOfRows();
                        int len       = query.GetLongestRowLength();

                        for (int row = 0; row < numOfRows; row++)
                        {
                            string[] cells = query.GetRow(row + 1, "(_._)", len);

                            //string upc = map.rules[upcColumn].rule.Process(cells);
                            //string alu = map.rules[aluColumn].rule.Process(cells);
                            //string uom = map.rules[uomColumn].rule.Process(cells);
                            string upc = map.rules[0].rule.Process(cells);
                            string alu = map.rules[0].rule.Process(cells);
                            string uom = map.rules[0].rule.Process(cells);


                            if (!UPCs.Contains(upc))
                            {
                                if (!ALUs.Contains(alu))
                                {
                                    UPCs.Add(upc);
                                    ALUs.Add(alu);
                                    UOMs.Add(upc, uom);
                                }
                            }
                        }
                    });
                });
            }
        }
Beispiel #2
0
        int Compare_Rows_Skip_Mismatched_UPC_If_ItemIDs_Equal(ExcelQuery query, int row1, int row2, int rowlen, int uid_index, HashSet <int> skips)
        {
            string[] vals1 = query.GetRow(row1, "(_._)", rowlen);
            string[] vals2 = query.GetRow(row2, "(_._)", rowlen);

            bool item_equal = false;

            if (vals1[uid_index] != vals2[uid_index])
            {
                item_equal = true;
            }

            if (item_equal) //if the item ids are equal, we ignore any mismatches in the UPC column because we know QB will only see one of these rows
            {
                return(CompareRows(vals1, vals2, skips));
            }
            else
            {
                return(CompareRows(vals1, vals2));
            }
        }
Beispiel #3
0
    private static string[][] ImportSheet(ExcelQuery q, ColumnMap map, int aluIndex, int upcIndex, ItemList itemList)
    {
        HashSet <string> seenALUs = new HashSet <string>();
        HashSet <string> seenUPCs = new HashSet <string>();

        InventoryItem item;

        Debug.Log("Import sheet");

        q.GetNewSheet(q.GetSheetNames()[0]);
        string err = string.Empty;

        string[] titles = q.GetTitle(0, ref err);
        if (titles == null && err != string.Empty)
        {
            Debug.LogError(string.Format("Could not read sheet titles from first sheet {0} - err msg: {1}", q.GetSheetNames()[0], err));
            return(null);
        }


        //NO--This is all wrong. Should be checking that the map matches the itemlist when it is imported
        //if (titles.Length != map.header.Count)
        //{
        //    Debug.LogError(string.Format("Map heading count does not match imported sheet"));
        //    return null;
        //}

        //int index = 0;
        //foreach (string heading in titles)
        //{
        //    if (!heading.Equals(map.header[index], StringComparison.OrdinalIgnoreCase))
        //    {
        //        Debug.LogError(string.Format("Map heading {0} does not match heading ({1})in imported sheet at index {2}", map.header[index], heading, index));
        //        return null;
        //    }

        //    index++;
        //}



        int rows = q.NumOfRows();
        int cols = map.header.Count;

        int titleRow = q.TitleRow;
        int len      = q.GetLongestRowLength();

        List <string[]> temp2 = new List <string[]>();

        string[]      inputVals;
        List <string> row = new List <string>();

        for (int x = titleRow + 1; x < rows - titleRow; x++)
        {
            inputVals = q.GetRow <string>(x, string.Empty, len);
            if (inputVals == null)
            {
                continue;
            }

            string alu = map.rules[aluIndex].rule.Process(inputVals);
            string upc = map.rules[upcIndex].rule.Process(inputVals);

            item = itemList.GetALU(alu);
            if (item != null && item.DefaultUnitIsCase)
            {
                inputVals[map.UOM.Index.GetVal()] = map.CaseVal.GetVal();
            }
            //if importOnce is set, skip any we've already seens

            if (!map.importOnce || (!seenALUs.Contains(alu)) && (!seenUPCs.Contains(upc)))
            {
                row.Clear();

                for (int y = 0; y < cols; y++)
                {
                    row.Add(map.rules[y].rule.Process(inputVals));
                }

                if (!string.IsNullOrEmpty(alu))
                {
                    seenALUs.Add(row[aluIndex]);
                }
                else
                {
                    Debug.LogError(string.Format("No ALU found for row {0}", x));
                    continue;
                }
                if (!string.IsNullOrEmpty(upc))
                {
                    seenUPCs.Add(row[upcIndex]);
                }

                temp2.Add(row.ToArray());
            }
        }

        return(temp2.ToArray());
    }
Beispiel #4
0
        void ColumnCheck(ExcelQuery query, string heading)
        {
            string err = string.Empty;

            //use first sheet in our query, whatever it is named
            query.GetNewSheet(query.GetSheetNames()[0]);

            //Get titles
            string[] titles = query.GetTitle(0, ref err);
            if (titles == null)
            {
                Debug.Log("No titles found! Quitting");
                return;
            }
            int len = titles.Length;

            int uid_col = SheetUtils.FindMatchIndexesInStringArr(titles, UID_ColumnNames.ToArray())[0];

            if (uid_col < 0)
            {
                Debug.LogError(string.Format("couldn't find UID column"));
                return;
            }
            else
            {
                Debug.Log(string.Format("Found uid_column at {0} which is header {1}", uid_col, query.GetHeaderColumnName(uid_col)));
            }


            for (int col = 0; col < len; col++)
            {
                if (titles[col].Equals(heading, StringComparison.OrdinalIgnoreCase))
                {
                    Dictionary <long, int> column = new Dictionary <long, int>();


                    //add all values for that column to dictionary with row as value

                    long[] vals = query.GetColumn <long>(col, -1);
                    for (int row = 0; row < vals.Length; row++)
                    {
                        long val = vals[row];
                        if (val == -1)
                        {
                            continue;            //skip our null sentinel
                        }
                        if (column.ContainsKey(val))
                        {
                            string[] duplicate = query.GetRow(row + 1, "(_._)", len);
                            string[] original  = query.GetRow(column[val] + 1, "(_._)", len);

                            int result = CompareRows(duplicate, original);

                            if (result < 3 && original[uid_col] != duplicate[uid_col])
                            {
                                LogResult(string.Format("Problem! found almost duplicate upc and row (misses:{0}) with non-identical itemids: row {1} (item:{3}) and row {2} (item:{4})", result, column[val] + 1, row + 1, original[uid_col], duplicate[uid_col]));
                                continue;
                            }

                            if (result > 2 && original[uid_col] == duplicate[uid_col])
                            {
                                LogResult(string.Format("Problem! found duplicate upc with non-duplicate rows (misses:{0}) but with identical itemids: row {1} (item:{3}) and row {2} (item:{4})", result, column[val] + 1, row + 1, original[uid_col], duplicate[uid_col]));
                                continue;
                            }

                            if (result < 3 && result > 0)
                            {
                                LogResult(string.Format("found almost duplicate upc/itemid (misses:{0}) we expect item:{1} at row:{2} will not be added because item:{3} exists at row:{4}", result, duplicate[uid_col], row + 1, original[uid_col], column[val] + 1));
                                continue;
                            }

                            if (result < 1)
                            {
                                LogResult(string.Format("found duplicate upc/itemid (misses:{0}) we expect item:{1} at row:{2} will not be added because item:{3} exists at row:{4}", result, duplicate[uid_col], row + 1, original[uid_col], column[val] + 1));
                                continue;
                            }

                            if (result > 2)
                            {
                                LogResult(string.Format("found non-duplicate items with the same UPC: {0} misses between row {1} (item:{3}) and row {2} (item:{4})", result, column[val] + 1, row + 1, original[uid_col], duplicate[uid_col]));
                                continue;
                            }

                            LogResult(string.Format("somehow managed to miss a case: found  {0} misses between row {1} (item:{3}) and row {2} (item:{4})", result, column[val] + 1, row + 1, original[uid_col], duplicate[uid_col]));
                        }
                        else
                        {
                            column.Add(val, row);
                        }
                    }
                }
            }

            return;
        }