Esempio n. 1
0
        /// <summary>
        /// 读取导入列表文件
        /// </summary>
        /// <param name="path"></param>
        private void Read(string path)
        {
            StreamReader sr = new StreamReader(path, Encoding.Default);

            InportThreads.WareLength = sr.ReadToEnd().Split('\n').Length;
            if (sr.EndOfStream)
            {
                //重置文件指针至文件头
                sr.BaseStream.Seek(0, SeekOrigin.Begin);
            }
            String             line;
            List <ProductInfo> wareList = new List <ProductInfo>();

            while ((line = sr.ReadLine()) != null)
            {
                _myProduct = WareService.GetInstance().GetWareInfo(line);
                if (_myProduct != null)
                {
                    wareList.Add(_myProduct);
                }
                InportThreads.WareStep++;
            }

            foreach (var item in wareList)
            {
                DBHelper.GetInstance().WareInsert(item);
                InportThreads.WareStep++;
            }

            InportThreads.WareEnd = true;
        }
Esempio n. 2
0
 /// <summary>
 /// 获取商品评价数据流程1
 /// </summary>
 private void GetBadMsgThread()
 {
     InitMsgProcess();
     ShowMsgProcess("获取商品评价数据");
     WareService.GetInstance().GetEvaluateMsg(_myProduct.ProductID, true);
     ShowMsgProcess("评价数据入库");
     RefreshMsgGrid();
 }
Esempio n. 3
0
        /// <summary>
        /// 导入商品
        /// </summary>
        /// <param name="webSites">商品地址数据</param>
        private void ImportWares(List <WebSiteModel> webSites)
        {
            try
            {
                //确定采集模式为批量采集
                SysParams.GatherModel = GatherType.Batch;
                _step = 0;
                ShowImportMessage("导入商品线程开始");
                List <ProductInfo> wareList = new List <ProductInfo>();
                ShowImportMessage("等待导入商品总数:" + webSites.Count.ToString());
                foreach (var item in webSites)
                {
                    string pid = Regex.Match(item.url, "\\d{1,14}").Value;
                    //如果商品编号已存在,则不导入
                    if (!string.IsNullOrEmpty(pid) && !DBHelper.GetInstance().WareIsExists(pid))
                    {
                        ImportThreads.WareID = pid;
                        ShowImportMessage("获取商品数据" + item.url);
                        _myProduct = WareService.GetInstance().GetWareInfo(item.url);
                        if (_myProduct != null)
                        {
                            wareList.Add(_myProduct);
                        }
                    }
                    else
                    {
                        ShowImportMessage("商品" + item.url + "已存在");
                    }
                    ShowImportStep(_step);
                    _step++;
                }
                ShowImportMessage("已获取商品总数:" + wareList.Count.ToString());

                foreach (var item in wareList)
                {
                    ShowImportMessage("导入商品数据" + item.ProductName);
                    DBHelper.GetInstance().WareInsert(item);
                    DBHelper.GetInstance().WarePriceInsert(item.ProductID, item.ProductPrice);
                    ShowImportStep(_step);
                    _step++;
                }
                while (_step <= webSites.Count * 2)
                {
                    _step++;
                    ShowImportStep(_step);
                }
                ShowImportMessage("导入商品线程结束");
                EndImportProcess(true);
            }
            catch (Exception ex)
            {
                EndImportProcess(false);
                ShowImportMessage("导入商品线程异常" + ex.Message);
                Debug.WriteLine(ex.Message);
            }
        }
Esempio n. 4
0
        private void GetSearchResultThread()
        {
            if (string.IsNullOrEmpty(txtSearchCondition.Text))
            {
                return;
            }
            List <WebSiteModel> sites = WareService.GetInstance().GetSearchList(txtSearchCondition.Text);

            InvokeControls(sites);
        }
Esempio n. 5
0
 /// <summary>
 /// 获取分类下所有商品详细数据
 /// </summary>
 /// <param name="html"></param>
 public void ParseWareTypeData(string html, string myType)
 {
     try
     {
         //string re = "<(link|script)(.*?type)[^>]+?(/)?>(?(3)|\\s*</\\1>)"; 提取页面link和Script
         //string regStr = @"var pay_after = \[(\d{1,16}\,){58}(\d{1,16})\];";
         //var slaveWareList ={(.*)};
         //var pay_after = \[(.*)\];
         string regStr  = @"var pay_after =\s*\[(\d{1,16}\,)+(\d{1,16})\];";
         string rtnData = Regex.Match(html, regStr).Value;
         ShowGetMessage("解析页面商品...");
         if (!string.IsNullOrEmpty(rtnData))
         {
             string   tt       = rtnData.Replace("var pay_after = [", "").Replace("];", "");
             string[] wareList = tt.Split(',');
             if (wareList != null && wareList.Length > 0)
             {
                 ShowGetMessage(string.Format("当前页面共计{0}个商品", wareList.Length));
                 foreach (var item in wareList)
                 {
                     iStep++;
                     if (!DBHelper.GetInstance().WareIsExists(item))
                     {
                         ShowGetMessage(string.Format("获取商品[{0}]信息", item));
                         ProductInfo tmpWare = WareService.GetInstance().GetWareInfoByID(item);
                         if (tmpWare != null)
                         {
                             tmpWare.ProductType = myType;
                             ShowGetMessage(string.Format("商品[{0}]{1}信息入库...", item, tmpWare.ProductName));
                             DBHelper.GetInstance().WareInsert(tmpWare);
                             DBHelper.GetInstance().WarePriceInsert(tmpWare.ProductID, tmpWare.ProductPrice);
                             ShowGetMessage(string.Format("商品[{0}]{1}信息入库完成。", item, tmpWare.ProductName));
                         }
                     }
                     ShowGetStep(iStep);
                 }
             }
         }
     }
     catch (Exception ex)
     {
         ShowGetMessage(string.Format("商品处理异常:{0}", ex.Message));
         OtCom.XLogErr(ex.Message);
     }
 }