Пример #1
0
        public override void ReadStockFromCSV(string fileName = null)
        {
            //todo проверить
            if (fileName == null)
            {
                fileName = FILENAME;
            }
            string[]           stockArray = File.ReadAllLines(fileName);
            List <StockRecord> stockList  = new List <StockRecord>();

            for (int i = 1; i < stockArray.Length; i++)
            {
                string[]    stockStringRecords = stockArray[i].Split(';');
                StockRecord stockRecord        = new StockRecord();
                //stockRecord.stockName = "discont";
                stockRecord.sku   = stockStringRecords[0].Trim();
                stockRecord.size  = stockStringRecords[1].Trim();
                stockRecord.upc   = stockStringRecords[2].Trim();
                stockRecord.title = stockStringRecords[4].Trim();
                if (!String.IsNullOrEmpty(stockRecord.upc))
                {
                    if (stockRecord.upc.Length == 14)
                    {
                        stockRecord.upc = stockRecord.upc.Substring(2);
                    }
                    //stockRecord.upc = stockStringRecords[4].Substring(2);
                }
                stockRecord.quantity = Int32.Parse(stockStringRecords[3].Replace("(", "").Replace(")", "")); //в файле дисконта иногда кол-во встречается в формате (1)
                stockRecord.price    = Double.Parse(stockStringRecords[5]);
                stockRecord.oldPrice = Double.Parse(stockStringRecords[6]);
                //stockRecord.price = stockRecord.price + 1500;
                stockList.Add(stockRecord);
            }
            records = stockList;
        }
Пример #2
0
        public void ParseStockOnHand(string FileName, char separator = ';')
        {
            //string[] stockArray = File.ReadAllLines(FileName,Encoding.GetEncoding(1251));
            string[]           stockArray = File.ReadAllLines(FileName);
            List <StockRecord> stockList  = new List <StockRecord>();

            int startIndex = 1;

            for (int i = 1; i < stockArray.Length; i++)
            {
                string[] stockStringRecords = stockArray[i].Split(separator);
                if (stockStringRecords[0] == "FOOTWEAR")
                {
                    startIndex = i;
                    break;
                }
            }


            for (int i = startIndex; i < stockArray.Length; i++)
            {
                string[] stockStringRecords = stockArray[i].Split(';');

                if (stockStringRecords[0].Length == 6 && !stockStringRecords[0].Contains("SX")) //если длина 6 значит это артикул и есть левые sx артикулы
                {
                    StockRecord stockRecord = new StockRecord();
                    //stockRecord.stockName = "discont";
                    stockRecord.sku  = stockStringRecords[0].Trim() + "-" + stockStringRecords[3].Trim();
                    stockRecord.size = stockStringRecords[6].Trim();
                    stockRecord.upc  = stockStringRecords[11].Trim();
                    if (!String.IsNullOrEmpty(stockRecord.upc))
                    {
                        if (stockRecord.upc.Length == 14)
                        {
                            stockRecord.upc = stockRecord.upc.Substring(2);
                        }
                        //stockRecord.upc = stockStringRecords[4].Substring(2);
                    }
                    stockRecord.title    = stockStringRecords[16].Trim();
                    stockRecord.quantity = Int32.Parse(stockStringRecords[24].Replace("(", "").Replace(")", "")); //в файле дисконта иногда кол-во встречается в формате (1)

                    //double price = 0;
                    //if (Double.TryParse(stockStringRecords[19], out price))
                    //{
                    //    stockRecord.price = price;
                    //    stockList.Add(stockRecord);
                    //}
                    if (!String.IsNullOrWhiteSpace(stockStringRecords[19]))
                    {
                        var price = stockStringRecords[19].Replace(".00", "").Replace(",", "");
                        stockRecord.price = Double.Parse(price);
                        stockList.Add(stockRecord);
                    }
                }
            }
            records = stockList;
        }
Пример #3
0
        public void ReadStandFromCSV(string FileName)
        {
            //string FileName = @"C:\Users\Администратор\YandexDisk\fullCatalogSneaker-icon\Parsing\discont\Stock On Hand Samara.csv";
            string[]           stockArray = File.ReadAllLines(FileName, Encoding.GetEncoding(1251));
            List <StockRecord> stockList  = new List <StockRecord>();

            //Находим откуда начинается обувь
            int startIndex = 1;

            for (int i = 1; i < stockArray.Length; i++)
            {
                string[] stockStringRecords = stockArray[i].Split(';');
                if (stockStringRecords[0] == "FOOTWEAR")
                {
                    startIndex = i;
                    break;
                }
            }

            for (int i = startIndex; i < stockArray.Length; i++)
            {
                string[] stockStringRecords = stockArray[i].Split(';');

                if (stockStringRecords[0].Length == 6 && !stockStringRecords[0].Contains("SX")) //если длина 6 значит это артикул
                {
                    if (!stockStringRecords[21].Contains("BW"))                                 //берем только кроссовки со стенда, не с беквола
                    {
                        StockRecord stockRecord = new StockRecord();
                        stockRecord.sku  = stockStringRecords[0].Trim() + "-" + stockStringRecords[3].Trim();
                        stockRecord.size = stockStringRecords[6].Trim();
                        stockRecord.upc  = stockStringRecords[11].Trim();
                        if (!String.IsNullOrEmpty(stockRecord.upc))
                        {
                            if (stockRecord.upc.Length == 14)
                            {
                                stockRecord.upc = stockRecord.upc.Substring(2);
                            }
                            //stockRecord.upc = stockStringRecords[4].Substring(2);
                        }
                        stockRecord.title    = stockStringRecords[16].Trim();
                        stockRecord.quantity = Int32.Parse(stockStringRecords[24].Replace("(", "").Replace(")", "")); //в файле дисконта иногда кол-во встречается в формате (1)
                        stockRecord.price    = Double.Parse(stockStringRecords[19]);
                        //stockRecord.oldPrice = Double.Parse(stockStringRecords[6]);
                        //stockRecord.price = stockRecord.price + 1500;
                        stockList.Add(stockRecord);
                    }
                    else
                    {
                        bool test = true;
                    }
                }
            }
            records = stockList;
        }