示例#1
0
        public static void WriteCSV(string filePathName, BaseItemInfo itemInfo)
        {
            try
            {
                string filePath = filePathName;

                CheckAndCreateFolder(filePath);

                if (!File.Exists(filePath))
                {
                    using (StreamWriter fileWriter = new StreamWriter(filePath, true, Encoding.Default))
                    {
                        fileWriter.WriteLine(itemInfo.GetLogHeadLine());
                        fileWriter.Flush();
                        fileWriter.Close();
                    }
                }

                WriteCSV(filePath, true, itemInfo.GetLogStrArr());
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
示例#2
0
        public static bool WriteXLS(string fileName, BaseItemInfo item)
        {
            string filePath = fileName;

            CheckAndCreateFolder(filePath);

            if (!File.Exists(filePath))
            {
                CreateXLS(filePath);
                InsertToXLS(fileName, "info", item.GetLogHeadLine().Split(','));
            }

            InsertToXLS(fileName, "info", item.GetLogStrArr());

            return(true);
        }
        private void SetBaseItemInfo(BaseItemInfo info, string[] infoStr, string[] menu)
        {
            try
            {
                string[] menuName = info.GetLogHeadLine().Split(',');

                foreach (string name in menuName)
                {
                    int index = GetMenuIndex(name, menu);

                    if (index != -1)
                    {
                        if (name == "批准文号")
                        {
                            info.ID = infoStr[index].Replace("\n", "");
                        }
                        else if (name == "通用名称")
                        {
                            info.Name = infoStr[index];
                        }
                        else if (name == "商品名称")
                        {
                            info.ItemName = infoStr[index];
                        }
                        else if (name == "出售方式(零或整)")
                        {
                            info.SellType = infoStr[index];
                        }
                        else if (name == "生产厂家" || name == "生产企业")
                        {
                            info.Created = infoStr[index];
                        }
                        else if (name == "包装规格")
                        {
                            info.Format = infoStr[index];
                        }
                        else if (name == "商城售价(最低价格)")
                        {
                            string p = infoStr[index];
                            try
                            {
                                info.ShopPrice = string.IsNullOrEmpty(p) ? 0 : Convert.ToDecimal(p);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex + p);
                            }
                        }
                        else if (name == "平台售价(最低价格)")
                        {
                            string p = infoStr[index];
                            info.PlatformPrice = string.IsNullOrEmpty(p) ? 0 : Convert.ToDecimal(p);
                        }
                        else if (name == "商城折后售价")
                        {
                            string p = infoStr[index];
                            info.ShopSelaPrice = string.IsNullOrEmpty(p) ? 0 : Convert.ToDecimal(p);
                        }
                        else if (name == "折扣")
                        {
                            string p = infoStr[index];
                            info.Sela = string.IsNullOrEmpty(p) ? 0 : Convert.ToDecimal(p);
                        }
                        else if (name == "剂型")
                        {
                            info.Type = infoStr[index];
                        }
                        else if (name == "重量(克)")
                        {
                            string p = infoStr[index];
                            try
                            {
                                info.Weight = string.IsNullOrEmpty(p) ? 0 : Convert.ToInt32(p);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine("Error:{0}, Value:{1}", ex, p);
                            }
                        }
                        else if (name == "库存")
                        {
                            info.Inventory = infoStr[index];
                        }
                        else if (name == "最近浏览")
                        {
                            info.ViewCount = infoStr[index];
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
        public void ReadBaseItemInfo(string fileName, bool isBaseItemInfo)
        {
            //DataTable data = CommonFun.ReadXLS(fileName);
            string content = CommonFun.ReadCSV(fileName);

            if (!string.IsNullOrEmpty(content))
            {
                string[] lines = content.Split('\r');

                string[] menu = null;

                foreach (string line in lines)
                {
                    try
                    {
                        if (!line.Contains('\n'))
                        {
                            menu = line.Split(',');
                        }
                        else
                        {
                            string newLine = line;

                            MatchCollection ms = CommonFun.GetValues(newLine, "\"\"\"", "\"\"\"");

                            for (int i = 0; i < ms.Count; i++)
                            {
                                if (!string.IsNullOrEmpty(ms[i].Value))
                                {
                                    newLine = newLine.Replace(ms[i].Value, string.Format("{{0}}", i));
                                }
                            }

                            string[] infoStr = newLine.Split(',');

                            for (int i = 0; i < infoStr.Length; i++)
                            {
                                for (int j = 0; j < ms.Count; j++)
                                {
                                    infoStr[i] = infoStr[i].Replace(string.Format("{{0}}", j), ms[j].Value);
                                }
                            }

                            if (infoStr.Length > 1)
                            {
                                BaseItemInfo info = isBaseItemInfo ? new BaseItemInfo() : new ItemInfo();

                                string[] menuName = info.GetLogHeadLine().Split(',');

                                SetBaseItemInfo(info, infoStr, menu);

                                if (!isBaseItemInfo)
                                {
                                    SetItemInfo(info as ItemInfo, infoStr, menu);
                                }

                                string key = info.Name + info.Format + info.Created;

                                if (!shopAllItems.ContainsKey(key))
                                {
                                    shopAllItems.Add(key, info);
                                }
                                else if (shopAllItems[key].ShopPrice > info.ShopPrice)
                                {
                                    shopAllItems[key] = info;
                                }
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex);
                    }
                }
            }
            else
            {
                Console.WriteLine("ReadBaseItemInfo error" + fileName);
            }
        }