Exemplo n.º 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);
                                }
                            }
                        }
                    });
                });
            }
        }
Exemplo n.º 2
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());
    }