Exemplo n.º 1
0
        public void SaveToExcel(string strDirectry, Hashtable hTable, string strAcc)
        {
            _GoodsModifyStr objStru = new _GoodsModifyStr();

            if (!Directory.Exists(strDirectry))
            {
                Directory.CreateDirectory(strDirectry);
            }
            string strFileName = strAcc.ToString() + ".xls";

            strFileName = strDirectry + "\\" + strFileName;
            if (File.Exists(strFileName))
            {
                File.Delete(strFileName);
            }
            string strconn = "provider=microsoft.jet.oledb.4.0;" + "data source=" + strFileName + ";" + "extended properties=excel 8.0;";

            OleDbConnection cn        = new OleDbConnection(strconn);
            string          sqlCreate = "CREATE TABLE [sheet1] ([品牌+型号] VarChar,[价格] Number)";

            OleDbCommand cmd = new OleDbCommand(sqlCreate, cn);

            cn.Open();

            //创建TestSheet工作表

            cmd.ExecuteNonQuery();
            //添加数据
            string[] keyArray   = new string[hTable.Count];
            string[] valueArray = new string[hTable.Count];
            hTable.Keys.CopyTo(keyArray, 0);
            int i = 0;

            foreach (string skey in keyArray)
            {
                objStru       = (_GoodsModifyStr)hTable[skey];
                valueArray[i] = objStru.strNoEx;
                i++;
            }
            Array.Sort(valueArray, keyArray);
            foreach (string skey in keyArray)
            {
                objStru         = (_GoodsModifyStr)hTable[skey];
                cmd.CommandText = string.Format("INSERT INTO [sheet1] VALUES('{0}',{1})", objStru.strNoEx.Trim(), objStru.fPrice);
                cmd.ExecuteNonQuery();
            }
            cn.Close();
            cn.Dispose();
        }
Exemplo n.º 2
0
        void AnalyzeSeller(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, out int iNum)
        {
            iNum = 0;
            int match_num = 0;          //总共匹配到的数量

            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "<em>主要经营:</em>(.+?)查看联系方式");


                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "<td><a href=\"", "intro.html") + "messages_all.html";

                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
            iNum = match_num;
        }
Exemplo n.º 3
0
        private void listView_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            ListViewHitTestInfo info = listView.HitTest(e.X, e.Y);

            if (info.Item != null)
            {
                string    strAcc = info.Item.SubItems[1].Text;
                Hashtable hTable = new Hashtable();
                bool      bRet   = DataContrl.GetNeedAddData(strAcc, ref hTable);
                if (bRet)
                {
                    if (hTable.Count > 0)
                    {
                        StringBuilder   strBuilder = new StringBuilder();
                        _GoodsModifyStr objModify  = new _GoodsModifyStr();
                        int             iCount     = 0;
                        foreach (DictionaryEntry dEntry in hTable)
                        {
                            objModify = (_GoodsModifyStr)dEntry.Value;
                            string strInfo = "";
                            if (objModify.iFailFlag != 3 && objModify.iFailFlag != 2)
                            {
                                strInfo = "";
                                strBuilder.Append(string.Format("{0}  {1} {2}\r\n", objModify.strNoEx, objModify.fPrice, strInfo));
                                iCount++;
                            }
                        }
                        string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "needaddfile";
                        WriteInfo(strDirectory, strBuilder, strAcc);
                        string strFileName = strAcc + ".txt";
                        strFileName = strDirectory + "\\" + strFileName;
                        string strInfoShow = strBuilder.ToString();
                        if (strInfoShow.Length > 200)
                        {
                            strInfoShow = strInfoShow.Substring(0, 200) + ".....";
                        }
                        string strShow = string.Format("待添加信息{0}条\r\n请在 needaddfile\\{1}.txt 中查看\r\n{2}", iCount, strAcc, strInfoShow);
                        MessageBox.Show(strShow);
                    }
                }
            }
        }
Exemplo n.º 4
0
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "<input  pid=(.+?)循环结束");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                string strPrice   = "";
                //cpricestate_
                string strTemp = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串


                    goodModify.strNo = GetKeyString(matchValue, "\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("dealerPriceId_"));
                    goodModify.dealerPriceId = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("oldstatus_"));
                    goodModify.oldstatus = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp             = matchValue.Substring(matchValue.IndexOf("refprice_"));
                    goodModify.refprice = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp            = matchValue.Substring(matchValue.IndexOf("productname_"));
                    goodModify.strNoEx = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("id=\"advert_"));
                    goodModify.strAdvert = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp  = matchValue.Substring(matchValue.IndexOf("downflowprice_"));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fLowPrice);

                    strTemp  = matchValue.Substring(matchValue.IndexOf("upflowprice_"));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fHighPrice);

                    strTemp  = matchValue.Substring(matchValue.IndexOf("onchange=\"changePriceData("));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);


                    goodModify.strOtherInfo = string.Format("&cpricestate_{0}=true&priority_{0}=0", goodModify.strNo);

                    //特价
                    strTemp = GetKeyString(matchValue, string.Format("id=\"salestatus_{0}", goodModify.strNo), "特价");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&salestatus_{0}=8", goodModify.strNo);
                    }
                    //热卖
                    strTemp = GetKeyString(matchValue, string.Format("id=\"hotstatus_{0}", goodModify.strNo), "热卖");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&hotstatus_{0}=4", goodModify.strNo);
                    }
                    //新品
                    strTemp = GetKeyString(matchValue, string.Format("id=\"newstatus_{0}", goodModify.strNo), "新品");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&newstatus_{0}=2", goodModify.strNo);
                    }
                    //下架
                    strTemp = GetKeyString(matchValue, string.Format("id=\"stopstatus_{0}", goodModify.strNo), "下架");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&stopstatus_{0}=1", goodModify.strNo);
                    }
                    //行货
                    strTemp = GetKeyString(matchValue, string.Format("id=\"qualityGoodsStatus_{0}", goodModify.strNo), "行货代票");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&qualityGoodsStatus_{0}=16", goodModify.strNo);
                    }


                    /*<input   name="hotstatus_516996" id="hotstatus_516996"  type="checkbox"  value="4" onclick="thisClick(this,516996);" />热卖
                     * <input   name="newstatus_516996" id="newstatus_516996" type="checkbox" value="2" onclick="thisClick(this,516996);" />新品
                     * <input   name="stopstatus_516996" id="stopstatus_516996" onclick="stopProductPrice(this,516996);" type="checkbox" value="1" />下架
                     * <input   name="qualityGoodsStatus_516996" id="qualityGoodsStatus_516996" type="checkbox" value="16" onclick="thisClick(this,516996);" checked/>行货代票
                     */
                    /*
                     * <input type="hidden" name="dealerPriceId_542009" value="17904037" id="dealerPriceId_542009">
                     * <input type="hidden" name="oldstatus_542009" value="21" id="oldstatus_542009">
                     * <input type="hidden" name="downflowprice_542009" value="990" id="downflowprice_542009">
                     * <input type="hidden" name="upflowprice_542009" value="1755" id="upflowprice_542009">
                     * <input type="hidden" name="refprice_542009" id="refprice_542009"  value="1350.0" id="refprice_542009"/>
                     * <input type="hidden" name="cpricestate_542009" value="true" id="cpricestate_542009"/>
                     * <input type="hidden" id="catalogid_542009" value="291"/>
                     * <input type="hidden" id="brandid_542009" value="294"/>
                     * <input type="hidden" id="productname_542009" value="诺基亚5230"/>
                     */

                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable,int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "<i>商品型号:</i>(.+?)删除商品");

                int match_num = 0;		//总共匹配到的数量
                string matchValue = "";
                string strPrice = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;		//获取匹配到的字符串

                    goodModify.strNo = GetKeyString(matchValue, "\"down_limit_", "\"");
                    if (matchValue.IndexOf("自定义商品")>0)
                    {
                        //索尼爱立信 XPERIA E15i(自定义商品)
                        goodModify.fHighPrice = 100000;
                        goodModify.fLowPrice = 0;
                        goodModify.strNoEx = matchValue.Substring(0, matchValue.IndexOf("</div>"));
                    }
                    else
                    {

                        strPrice = GetKeyString(matchValue,
                            string.Format("id=\"down_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                            "\"");
                        float.TryParse(strPrice, out goodModify.fLowPrice);
                        strPrice = GetKeyString(matchValue,
                            string.Format("id=\"up_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                            "\"");
                        float.TryParse(strPrice, out goodModify.fHighPrice);

                        // +"    " + iPage.ToString();
                        goodModify.strNoEx = GetKeyString(matchValue,
                           "target=\"_blank\">",
                            "</a>");
                    }
                    strPrice = GetKeyString(matchValue,
                            string.Format("id=\"retailPrice{0}\" type=\"text\" value=\"", goodModify.strNo),
                            "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);
                    goodModify.strName = GetKeyString(matchValue,
                            string.Format("id=\"title{0}\" type=\"text\" value=\"", goodModify.strNo),
                            "\"");
                    //string strPageNum =
                    match_num++;		//匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {

            }
        }
        public int Fresh(out string strError,out int iFreshNum,out int iGoodCount, out bool bBreak,
            int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum = 0;
            iGoodCount = 0;
            strError = "";
            bBreak = false;
            try
            {
                string strBefore = "共<i class=\"num\">";
                string strAfter = "</i>";

                if (m_strGoodContent.IndexOf("出售中的商品") < 0)
                {
                    strError = "数据错误1";
                    return -1;  //数据错误,停止
                }
                string strTemp = "";// m_strGoodContent.Substring(m_strGoodContent.IndexOf("我的商品总数"));
                string strNum = "";
                if (!bIsModify)
                {
                    strNum = GetKeyString(m_strGoodContent, strBefore, strAfter);
                    bool bRet = int.TryParse(strNum, out iGoodCount);
                    if (!bRet)
                    {
                        strError = "数据错误2";
                        return -1;  //数据错误,停止
                    }
                }

                _GoodsModifyStr objModify = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("method=save");
                string strBakData = "";
                int iGoodFreshCount = 0;    //本次要刷新的商品数
                List<string> strModifyNameList = new List<string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1);
                    iFreshNum = hTableGoods.Count;
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&pid={0}&title{0}={1}&retailPrice{0}={2}&count_{0}=10", objModify.strNo, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")), objModify.fPrice));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 60)  //只拿60个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&pid={0}&title{0}={1}&retailPrice{0}={2}&count_{0}=10", objModify.strNo, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")), objModify.fPrice));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return 0;
                    }
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = strBuilder.ToString();
                string strRet = m_webPost.GetHttpPage("http://m.pconline.com.cn/member/product/products_onsell.htm",
                    "gb2312", "post", "", strData,
                    string.Format("http://m.pconline.com.cn/member/product/products_onsell.htm?&pageSize=60&pageNo={0}", iCurPage),
                    "*/*", "");
                if (strRet.IndexOf("无相关商品") > 0) //已经刷完
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (!bIsModify)
                    {
                        bBreak = true;
                    }
                    else        //修改
                    {
                        if (hWaitTable.Count < 1)
                        {
                            bBreak = true;
                        }
                    }
                }
                else if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                if (strRet.IndexOf("别人正在另一台服务器上修改您所修改的数据") > 0)
                {
                    strError = "其他人正在修改";
                    if (iNetErrorCount++ > 30)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                m_strGoodContent = strRet;
                return 0;
            }
            catch (System.Exception ex)
            {
                strError = "程序异常"+ex.Message;
                return -1;  //数据错误,停止
            }
        }
Exemplo n.º 7
0
        private void btnImportGoodFile_Click(object sender, EventArgs e)
        {
            int iCount = DataContrl.GetModifyCount();
            if (iCount > 0 && m_bIsStartFresh)
            {
                MessageBox.Show("正在修改中,请等待修改完后再执行此操作!");
                return;
            }
            //选择文件夹
            FolderBrowserDialog find = new FolderBrowserDialog();
            if (find.ShowDialog() != DialogResult.OK)
            {
                return;
            }

               DataContrl.ClearModifyData();
               DirectoryInfo dInfo = new DirectoryInfo(find.SelectedPath);

               foreach (FileInfo fileInfo in dInfo.GetFiles())
               {
               Hashtable hTable = new Hashtable();
               hTable.Clear();
               string strName = fileInfo.Name;
               string[] strNameArray = strName.Split('.');
               if (strNameArray.Length != 2)
               {
                   ShowLogString("文件名不合法:" + strName);
                   continue;
               }
            //                if (strNameArray[1] != "txt")    //不是文本文档
            //                {
            //                    continue;
            //                }

               if (strNameArray[1] != "xls")    //不是文本文档
               {
                   ShowLogString("文件名不合法:" + strName);
                   continue;
               }

               string strAcc = strNameArray[0];  //以账号名为商品对应的账号
               if (!DataContrl.IsInCache(strAcc))//如果此账号不存在
               {
                   ShowLogString("此账号不存在:" + strAcc);
                   continue;
               }

               //得到账号名后,判断是否已经对此账号进行过同步
               _GoodsFreshStr goodInfo = new _GoodsFreshStr();
               if (!DataContrl.GetDataCache(strAcc, ref goodInfo))
               {
                   ShowLogString("此账号不存在:" + strAcc);
                   continue;
               }
               if (goodInfo.iSynchronizeCount < 1)
               {
                   goodInfo.strSynStatus = "尚未同步,要修改价格请先同步";
                   goodInfo.strModifyStatus = "尚未同步,要修改价格请先同步";
                   ShowInfo(goodInfo);
                   ShowLogString("尚未同步,要修改价格请先同步");
                   continue;
               }
               goodInfo.iNeedAddCount = 0;
               string strContent = ReadFileLineXls(find.SelectedPath + "\\" + strName);
               string[] strArray = strContent.Split('\n');

               float fPrice = 0;
               Hashtable hTableSyn = new Hashtable();
               Hashtable hTableSynNumber = new Hashtable();
               Hashtable hTableNeedAdd = new Hashtable();
               bool bRet = DataContrl.GetSynData(strAcc, ref hTableSyn);

               if (!bRet)
               {
                   goodInfo.strModifyStatus = "获取同步商品信息失败";
                   ShowInfo(goodInfo);
                   ShowLogString("获取同步商品信息失败");
                   continue;
               }
               foreach (string strLine in strArray)
               {
                   //品牌+型号,商品价格

                   string[] strInfo = strLine.Split(',');
                   if (strInfo.Length < 2)
                   {
                       ShowLogString("导入文件内容格式错误");
                       continue;
                   }
                   string strGoodNoEx = strInfo[0].Trim();
                   strGoodNoEx = strGoodNoEx.Trim();
                   if (strGoodNoEx.Length < 1)
                   {
                       ShowLogString("导入文件内容格式错误");
                       continue;
                   }
                   string strNoList = DataContrl.GetSynNumberData(goodInfo.strAcc + strGoodNoEx).Trim();
                   if (strNoList == "")
                   {
                       float.TryParse(strInfo[1], out fPrice);
                       _GoodsModifyStr goodModify = new _GoodsModifyStr();
                       goodModify.strNo = strGoodNoEx;
                       goodModify.strNoEx = strGoodNoEx;
                       goodModify.fPrice = fPrice;
                       //加入需要添加的列表
                       if (!hTableNeedAdd.ContainsKey(strGoodNoEx))
                       {
                           hTableNeedAdd.Add(strGoodNoEx, goodModify);
                       }
                       //ShowLogString("未找到匹配的同步信息");
                       continue;
                   }
                   string[] strNolistArray = strNoList.Split(',');

                   //当等待修改的商品名称在同步列表中时,才添加
                   foreach (string strNo in strNolistArray)
                   {
                       if (strNo == "")
                       {
                           continue;
                       }
                       if (hTable.Contains(strNo))
                       {
                           continue;
                       }
                       float.TryParse(strInfo[1], out fPrice);
                       _GoodsModifyStr goodModify = new _GoodsModifyStr();
                       _GoodsModifyStr goodModifySyn = new _GoodsModifyStr();
                       if (hTableSyn.ContainsKey(strNo))
                       {
                           goodModifySyn = (_GoodsModifyStr)hTableSyn[strNo];
                           goodModify.strNo = goodModifySyn.strNo;
                           goodModify.strNoEx = goodModifySyn.strNoEx;
                           goodModify.strName = goodModifySyn.strName;
                           goodModify.fLowPrice = goodModifySyn.fLowPrice;
                           goodModify.fHighPrice = goodModifySyn.fHighPrice;

                           goodModify.fPrice = fPrice;
                           if (goodModify.fPrice < goodModify.fLowPrice)
                           {
                               goodModify.fPrice = goodModify.fLowPrice;
                           }
                           else if (goodModify.fPrice > goodModify.fHighPrice)
                           {
                               goodModify.fPrice = goodModify.fHighPrice;
                           }
                           hTable.Add(strNo, goodModify);
                       }
                       else
                       {
                           //此处还少商品名
                           goodModify.strNo = strGoodNoEx;
                           goodModify.strNoEx = strGoodNoEx;
                           goodModify.fPrice = fPrice;
                           //加入需要添加的列表
                           if (!hTableNeedAdd.ContainsKey(strNo))
                           {
                               hTableNeedAdd.Add(strNo, goodModify);
                           }
                       }
                   }
               }
               DataContrl.AddNeedAddList(strAcc, hTableNeedAdd);
               goodInfo.iNeedAddCount = hTableNeedAdd.Count;
               goodInfo.iModifyCount = hTable.Count;
               goodInfo.strModifyStatus = "等待修改";
               goodInfo.bModify = true;
               ShowInfo(goodInfo);
               DataContrl.AddModifyList(strAcc, hTable);
               ShowLogString(string.Format("{0} 添加了 {1} 条价格修改信息", strAcc, hTable.Count));
            }
        }
Exemplo n.º 8
0
        public void SaveToExcel(string strDirectry, Hashtable hTable, string strAcc)
        {
            _GoodsModifyStr objStru = new _GoodsModifyStr();
            if (!Directory.Exists(strDirectry))
            {
                Directory.CreateDirectory(strDirectry);
            }
            string strFileName = strAcc.ToString() + ".xls";
            strFileName = strDirectry + "\\" + strFileName;
            if (File.Exists(strFileName))
            {
                File.Delete(strFileName);
            }
            string strconn = "provider=microsoft.jet.oledb.4.0;" + "data source=" + strFileName + ";" + "extended properties=excel 8.0;";

            OleDbConnection cn = new OleDbConnection(strconn);
            string sqlCreate = "CREATE TABLE [sheet1] ([品牌+型号] VarChar,[价格] Number)";

            OleDbCommand cmd = new OleDbCommand(sqlCreate, cn);

            cn.Open();

            //创建TestSheet工作表

            cmd.ExecuteNonQuery();
            //添加数据
            string[] keyArray = new string[hTable.Count];
            string[] valueArray = new string[hTable.Count];
            hTable.Keys.CopyTo(keyArray, 0);
            int i = 0;
            foreach (string skey in keyArray)
            {
                objStru = (_GoodsModifyStr)hTable[skey];
                valueArray[i] = objStru.strNoEx;
                i++;
            }
            Array.Sort(valueArray, keyArray);
            foreach (string skey in keyArray)
            {
                objStru = (_GoodsModifyStr)hTable[skey];
                cmd.CommandText = string.Format("INSERT INTO [sheet1] VALUES('{0}',{1})", objStru.strNoEx.Trim(), objStru.fPrice);
                cmd.ExecuteNonQuery();
            }
            cn.Close();
            cn.Dispose();
        }
Exemplo n.º 9
0
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "<i>商品型号:</i>(.+?)删除商品");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                string strPrice   = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串


                    goodModify.strNo = GetKeyString(matchValue, "\"down_limit_", "\"");
                    if (matchValue.IndexOf("自定义商品") > 0)
                    {
                        //索尼爱立信 XPERIA E15i(自定义商品)
                        goodModify.fHighPrice = 100000;
                        goodModify.fLowPrice  = 0;
                        goodModify.strNoEx    = matchValue.Substring(0, matchValue.IndexOf("</div>"));
                    }
                    else
                    {
                        strPrice = GetKeyString(matchValue,
                                                string.Format("id=\"down_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                                                "\"");
                        float.TryParse(strPrice, out goodModify.fLowPrice);
                        strPrice = GetKeyString(matchValue,
                                                string.Format("id=\"up_limit_{0}\" type=\"hidden\" value=\"", goodModify.strNo),
                                                "\"");
                        float.TryParse(strPrice, out goodModify.fHighPrice);

                        // +"    " + iPage.ToString();
                        goodModify.strNoEx = GetKeyString(matchValue,
                                                          "target=\"_blank\">",
                                                          "</a>");
                    }
                    strPrice = GetKeyString(matchValue,
                                            string.Format("id=\"retailPrice{0}\" type=\"text\" value=\"", goodModify.strNo),
                                            "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);
                    goodModify.strName = GetKeyString(matchValue,
                                                      string.Format("id=\"title{0}\" type=\"text\" value=\"", goodModify.strNo),
                                                      "\"");
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
Exemplo n.º 10
0
        public int Fresh(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
                         int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum  = 0;
            iGoodCount = 0;
            strError   = "";
            bBreak     = false;
            try
            {
                string strBefore = ">";
                string strAfter  = "</a>";

                if (m_strGoodContent.IndexOf("我的商品总数") < 0)
                {
                    strError = "数据错误1";
                    return(-1);  //数据错误,停止
                }
                string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("我的商品总数"));
                string strNum  = GetKeyString(strTemp, strBefore, strAfter);
                bool   bRet    = int.TryParse(strNum, out iGoodCount);
                if (!bRet)
                {
                    strError = "数据错误2";
                    return(-1);  //数据错误,停止
                }
                _GoodsModifyStr objModify     = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("method=save");
                string        strBakData        = "";
                int           iGoodFreshCount   = 0;                   //本次要刷新的商品数
                List <string> strModifyNameList = new List <string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1);
                    iFreshNum = hTableGoods.Count;
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&pid={0}&title{0}={1}&retailPrice{0}={2}&count_{0}=10", objModify.strNo, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")), objModify.fPrice));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 60)  //只拿60个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&pid={0}&title{0}={1}&retailPrice{0}={2}&count_{0}=10", objModify.strNo, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")), objModify.fPrice));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return(0);
                    }
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = strBuilder.ToString();
                string strRet  = m_webPost.GetHttpPage("http://m.pconline.com.cn/member/product/products_onsell.htm",
                                                       "gb2312", "post", "", strData,
                                                       string.Format("http://m.pconline.com.cn/member/product/products_onsell.htm?&pageSize=60&pageNo={0}", iCurPage),
                                                       "*/*", "");
                if (strRet.IndexOf("无相关商品") > 0) //已经刷完
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (!bIsModify)
                    {
                        bBreak = true;
                    }
                    else        //修改
                    {
                        if (hWaitTable.Count < 1)
                        {
                            bBreak = true;
                        }
                    }
                }
                else if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                if (strRet.IndexOf("别人正在另一台服务器上修改您所修改的数据") > 0)
                {
                    strError = "其他人正在修改";
                    if (iNetErrorCount++ > 30)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                m_strGoodContent = strRet;
                return(0);
            }
            catch (System.Exception ex)
            {
                strError = "程序异常" + ex.Message;
                return(-1);  //数据错误,停止
            }
        }
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable,int iPage,out int iGoodCount)
        {
            iGoodCount = 0;
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "套红</a>(.+?)</ul>");

                int match_num = 0;		//总共匹配到的数量
                string matchValue = "";
                string strPrice = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    matchValue = match.Groups[1].Value;		//获取匹配到的字符串
                    //target="_blank">摩托罗拉 A1890</a>
                    goodModify.strNoEx = GetKeyString(matchValue, "target=\"_blank\">", "</a>");
                    goodModify.strNo = GetKeyString(matchValue, "type=\"hidden\" name=\"proid[]\" value=\"", "\"");
                    goodModify.strNo2 = GetKeyString(matchValue, "type=\"hidden\" name=\"id[]\" value=\"", "\"");
                    string strTemp = matchValue.Substring(matchValue.IndexOf("<input name=\"price[]\" type=\"text\""));

                    strPrice = GetKeyString(strTemp,
                            "value=\"",
                            "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);

                    strTemp = matchValue.Substring(matchValue.IndexOf("<input name=\"topic[]\" type=\"text\""));
                    goodModify.strName = GetKeyString(strTemp,
                           "value=\"",
                            "\"");
                    strTemp = matchValue.Substring(matchValue.IndexOf("<input name=\"url[]\" type=\"text\""));
                    goodModify.strUrl = GetKeyString(strTemp,
                           "value=\"",
                            "\"");
                    /*
                     <input type="hidden" name="proid[]" value="22413">
            <input type="hidden" name="status[21847]" id="status21847" value="">
            <input type="hidden" name="id[]" value="21847"></li>
                     */
                    //string strPageNum =
                    match_num++;		//匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                iGoodCount = match_num;
                int ii = 0;
            }
            catch (System.Exception ex)
            {

            }
        }
        public int Fresh(out string strError,out int iFreshNum,out int iGoodCount, out bool bBreak,
            int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount,string strId)
        {
            iFreshNum = 0;
            iGoodCount = 0;
            strError = "";
            bBreak = false;
            int iAnalyzeCount = 0;
            try
            {
                string strBefore = ">";
                string strAfter = "</a>";

                string strUrl = string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}&page={1}", strId, iCurPage);
                //加载
                string strRet = "";

                if (!bIsModify)
                {
                    strRet = m_webPost.GetHttpPage(strUrl,
                     "gb2312", "get", "", "",
                     string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}", strId),
                     "*/*", "");
                    if (strRet == "") //网络错误
                    {
                        strError = (strRet == "" ? "网络异常" : "数据错误");
                        if (iNetErrorCount++ > 5)
                        {
                            iNetErrorCount = 0;
                            return -1;  //出错超过3次,停止
                        }
                        return -3;
                    }
                    m_strGoodContent = strRet;
                    if (m_strGoodContent.IndexOf("<title>久腾网手机营业厅 管理后台") < 0)
                    {
                        strError = "刷新失败";
                        return -1;
                    }
                }

                _GoodsModifyStr objModify = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
               // strBuilder.Append("method=save");
                string strBakData = "";
                int iGoodFreshCount = 0;    //本次要刷新的商品数
                List<string> strModifyNameList = new List<string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1, out iAnalyzeCount);
                    iFreshNum = hTableGoods.Count;
                    if (iFreshNum < 1)  //刷新完成
                    {
                        bBreak = true;
                        return 0;
                    }
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("price%5B%5D={0}&topic%5B%5D={1}&url%5B%5D={2}&proid%5B%5D={3}&status%5B{4}%5D=&id%5B%5D={4}&",
                            objModify.fPrice, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")),
                            HttpUtility.UrlEncode(objModify.strUrl, Encoding.GetEncoding("gb2312")), objModify.strNo2, objModify.strNo, objModify.strNo));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 200)  //只拿200个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("price%5B%5D={0}&topic%5B%5D={1}&url%5B%5D={2}&proid%5B%5D={3}&status%5B{4}%5D=&id%5B%5D={4}&",
                            objModify.fPrice, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")),
                            HttpUtility.UrlEncode(objModify.strUrl, Encoding.GetEncoding("gb2312")), objModify.strNo,objModify.strNo2));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return 0;
                    }
                }

                string strLast = string.Format("act=edit&cid={0}&pr=edit&links=list2.php%3Fcid%3D1548%26tradeid%3D%26page%3D1",strId);
                strBuilder.Append(strLast);
                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                //string strData = "price%5B%5D=2111&topic%5B%5D=%D5%FD%B9%E6%B4%F3%C2%BD%D0%D0%BB%F5%A3%AC%B4%F8%B7%A2%C6%B1%A3%AC%C8%AB%B9%FA%C1%AA%B1%A3%A3%AC%CF%ED%CA%DC%B9%FA%BC%D2%C8%FD%B0%FC%A1%A3%D6%A7%B3%D6%BB%F5%B5%BD%B8%B6%BF%EE%A3%AC%C9%CF%C3%C5%D7%D4%CC%E1%A1%A3&url%5B%5D=http%3A%2F%2Fwww.c818.com%2FProductShow.asp%3FProID%3D3984&proid%5B%5D=22413&status%5B21847%5D=&id%5B%5D=21847&act=edit&cid=1548&pr=edit&links=list2.php%3Fcid%3D1548%26tradeid%3D%26page%3D1";

                string strData = strBuilder.ToString();
                strRet = m_webPost.GetHttpPage("http://shop.younet.com/c818/manage/price_man1.php",
                    "gb2312", "post", "", strData,
                    string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}", strId),
                    "*/*", "");

                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 5)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                if (strRet.IndexOf("操作成功") < 0)
                {
                    //失败,重试3次
                    if (!bIsModify)
                    {
                        strError = "刷新失败";
                    }
                    else
                    {
                        strError = "修改失败";
                    }
                    if (iNetErrorCount++ > 5)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;

                }
                //成功了
                foreach (string strName in strModifyNameList)
                {
                    hWaitTable.Remove(strName);
                }
                //修改完成
                if ( bIsModify )
                {
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                        return 0;
                    }
                }
                return 0;
            }
            catch (System.Exception ex)
            {
                strError = "程序异常"+ex.Message;
                return -1;  //数据错误,停止
            }
        }
Exemplo n.º 13
0
        private bool Fresh(ref _GoodsFreshStr goodInfo, GoodsFresh objFresh,bool bSynFlag)
        {
            //http://m.pconline.com.cn/member/product/products_onsell.htm?&pageSize=60&pageNo=1
            goodInfo.strModifyStatus = "";
            goodInfo.bModify = false;
            string strError = "";

            bool bRet = false;

            int iCurPage = 0;
            int iRet = -1;
            int iFreshCount;
            int iGoodCount;
            bool bBreak = false;

            if (bSynFlag)
            {
                goodInfo.strFreshStatus = "正在同步...";
            }
            else
            {
                goodInfo.strFreshStatus = "正在刷新...";
            }
            ShowInfo(goodInfo);

            Hashtable hWaitTable = new Hashtable();
            Hashtable hFailTable = new Hashtable(); //修改失败的价格列表
            Hashtable hSynTable = new Hashtable(); //同步列表
            Hashtable hSynDuplicateTable = new Hashtable(); //同步列表
            int iNetErrorCount = 0;
            string strContent = "";// "为了方便在太平洋商城的店主们  批量  更新商品信息,      \r\n我们特别为店主们量身定做了一款批量刷新、    \r\n同步商品信息,       \r\n批量修改商品价格信息的软件.        \r\n 以达到商家的商品一直排前, 提高客户关注度.            \r\n在商品价格需要修改时, 只需要导入一个Excel 文件,  即可实现批量修改价格.       让商家从繁复的操作中解脱出来, 从战略的角度考虑商品销售.        \r\n另可定制各种商城的同类刷新修改软件:             \r\n如: 中关村在线,  pcpop,  天极等商城.";
            //strContent = strContent + "          \r\n 详情请联系QQ: 1194410385 请注明[太平洋刷新] ";

            strContent = m_strMsgSend;
            //strContent = "test info111";
            goodInfo.iFreshNumCount = 0;
            while (m_bFresh && !bBreak)
            {
                if (bSynFlag)
                {
                    iRet = objFresh.SynchronizeSeller(out strError, out iFreshCount, out iGoodCount, out bBreak, iCurPage + 1, ref iNetErrorCount, ref hSynTable, ref hSynDuplicateTable,goodInfo.strAcc);
                }
                else{
                    bBreak = true;
                    goodInfo.strFreshStatus = "正在获取验证码...";
                    ShowInfo(goodInfo);
                    //获取验证码
                    string strDirect = System.AppDomain.CurrentDomain.BaseDirectory + "pic";
                    if (!Directory.Exists(strDirect))
                    {
                        Directory.CreateDirectory(strDirect);
                    }
                    m_strCheckCode = "SDFKD";
                    string strName = goodInfo.strAcc;
                    strName = strName.Replace(":", "");
                    strName = strName.Replace(".", "");
                    strName = strName.Replace("\\", "");
                    strName = strName.Replace("/", "");
                    string strFile = string.Format("{0}\\{1}.bmp", strDirect, strName);
                    string strMemo = "";
                    string strTarget = "";
                    if (m_strCheckCode == "")
                    {
                        bRet = objFresh.GetImage(goodInfo.strAcc, strFile, out strError, out strMemo, out strTarget);
                        if (!bRet)
                        {
                            goodInfo.strFreshStatus = "获取验证码失败";
                            ShowInfo(goodInfo);
                            return false;
                        }
                        lock (m_hLockTable)
                        {
                            GetCodeHandler _myInvoke = new GetCodeHandler(GetCode);
                            m_strCheckCode = (string)this.Invoke(_myInvoke, new object[] { strFile });
                            if (m_strCheckCode.Length < 1)
                            {
                                goodInfo.strFreshStatus = "验证码错误";
                                ShowInfo(goodInfo);
                                return false;
                            }
                        }
                    }

                    iRet = objFresh.AddNotie(goodInfo.strAcc, strContent, m_strCheckCode, strMemo, strTarget,out strError);
                    iGoodCount = 0;
                    iFreshCount = 0;
                }

                //成功
                if (iRet == 0)
                {
                    goodInfo.iFreshNumCount += iGoodCount;
                    if (bSynFlag)
                    {
                        goodInfo.iFreshSucNumCount = hSynTable.Count;
                        goodInfo.iSynchronizeCount = hSynTable.Count;
                    }
                    else
                        goodInfo.iFreshSucNumCount += iFreshCount;

                    if (bSynFlag)
                    {
                        goodInfo.strFreshStatus = string.Format("正在同步:{0}", goodInfo.iFreshSucNumCount);
                    }
                    else
                    {
                        goodInfo.strFreshStatus = "发送成功";
                    }
                    if (bBreak)
                    {
                        if (bSynFlag)
                        {
                          //  goodInfo.strFreshStatus = "同步完成";
                            goodInfo.strFreshStatus = string.Format("同步完成:{0},需要重启", goodInfo.iFreshSucNumCount);
                        }
                        else
                        {
                            goodInfo.strFreshStatus = "发广告成功";
                            //将发送成功的URL地址写入新的配置文件
                            IniUtility.FilePath = System.AppDomain.CurrentDomain.BaseDirectory + "\\setEx.ini";
                            IniUtility.WriteIniKey("setex", goodInfo.strAcc, "1");
                            goodInfo.iSynchronizeCount = 1;
                        }
                    }
                }
                else if (iRet == -1)
                {
                    goodInfo.strFreshStatus = strError;
                    goodInfo.strSynStatus = strError;
                    goodInfo.strModifyStatus = strError;
                    bRet = false;
                    ShowLogString(string.Format("{0} {1}", iCurPage, strError));
                    break;
                }
                else
                {
                    goodInfo.strFreshStatus = strError;
                    ShowLogString(string.Format("{0} {1}",iCurPage,strError));
                }
                ShowInfo(goodInfo);
                if (iRet != -3)
                {
                    iCurPage++;
                }
                if (bBreak)
                {
                    if (bSynFlag)
                    {
                        //保存到文件
                        StringBuilder strBuilder = new StringBuilder();
                        _GoodsModifyStr objStru = new _GoodsModifyStr();

                        string[] keyArray = new string[hSynTable.Count];
                        string[] valueArray = new string[hSynTable.Count];
                        hSynTable.Keys.CopyTo(keyArray, 0);
                        int i=0;
                        foreach (string skey in keyArray)
                        {
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            valueArray[i] = objStru.strNoEx;
                            i++;
                        }
                        Array.Sort(valueArray, keyArray);
                        foreach (string skey in keyArray)
                        {
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            strBuilder.Append(string.Format("{0},{1},{2},{3},{4},{5},\r\n", objStru.strNo, objStru.strNoEx, objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice, objStru.strName));
                        }
                        string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "synfile";
                        string strDirectoryXls = System.AppDomain.CurrentDomain.BaseDirectory + "xlsfile";

                        WriteInfo(strDirectory, strBuilder, goodInfo.strAcc);
                        SaveToExcel(strDirectoryXls, hSynTable, goodInfo.strAcc);

                        if (hSynDuplicateTable.Count > 0)
                        {
                            StringBuilder strBuilderEx = new StringBuilder();

                            string[] keyArrayDup = new string[hSynDuplicateTable.Count];
                            string[] valueArrayDup = new string[hSynDuplicateTable.Count];
                            hSynTable.Keys.CopyTo(keyArrayDup, 0);
                            int ii = 0;
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];
                                valueArrayDup[ii] = objStru.strNoEx;
                                ii++;
                            }
                            Array.Sort(valueArrayDup, keyArrayDup);
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];
                                strBuilder.Append(string.Format("{0},{1},{2},{3},{4},{5},\r\n", objStru.strNo, objStru.strNoEx, objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice, objStru.strName));
                            }

                            WriteInfo(strDirectory, strBuilderEx, goodInfo.strAcc + "_duplicate");
                            SaveToExcel(strDirectoryXls, hSynDuplicateTable, goodInfo.strAcc + "_duplicate");
                        }
                    }
                    break;
                }
                Thread.Sleep(500);
            }
            return true;
        }
Exemplo n.º 14
0
        private bool Fresh(ref _GoodsFreshStr goodInfo, GoodsFresh objFresh,bool bSynFlag)
        {
            //http://m.pconline.com.cn/member/product/products_onsell.htm?&pageSize=60&pageNo=1
            goodInfo.strModifyStatus = "";
            goodInfo.bModify = false;
            string strError = "";
            if (bSynFlag)
            {
                goodInfo.strSynStatus = "登录中...";
            }
            else{
                goodInfo.strFreshStatus = "登录中...";
            }
            ShowInfo(goodInfo);
            bool bRet = false;

            bRet = objFresh.PaoPaoLogin(goodInfo.strAcc, goodInfo.strPwd, "", out strError,false);
            if (!bRet)
            {
                //strError = "登录失败";
                if (bSynFlag)
                {
                    goodInfo.strSynStatus = strError;
                }
                else
                {
                    goodInfo.strFreshStatus = strError;
                }
                ShowLogString(strError);
                ShowInfo(goodInfo);
                return false;
            }
            goodInfo.strMid = strError;
            int iCurPage = 1;
            int iRet = -1;
            int iFreshCount;
            int iGoodCount;
            bool bBreak = false;

            if (bSynFlag)
            {
                goodInfo.strSynStatus = "正在同步...";
            }
            else
            {
                goodInfo.strFreshStatus = "正在刷新...";
            }
            ShowInfo(goodInfo);
            Hashtable hWaitTable = new Hashtable();
            Hashtable hFailTable = new Hashtable(); //修改失败的价格列表
            Hashtable hSynTable = new Hashtable(); //同步列表
            Hashtable hSynDuplicateTable = new Hashtable(); //同步列表
            int iNetErrorCount = 0;
            while (m_bFresh && !bBreak)
            {
                if (bSynFlag)
                {
                    iRet = objFresh.Synchronize(out strError, out iFreshCount, out iGoodCount, out bBreak, iCurPage + 1, ref iNetErrorCount, ref hSynTable, ref hSynDuplicateTable,goodInfo.strMid);
                }
                else{
                    iRet = objFresh.Fresh(out strError, out iFreshCount, out iGoodCount, out bBreak, iCurPage + 1, false, ref hWaitTable, ref hFailTable, ref iNetErrorCount);
                }
                
                //成功
                if (iRet == 0)
                {
                    goodInfo.iFreshNumCount = iGoodCount;
                    if (bSynFlag)
                    {
                        goodInfo.iFreshSucNumCount = hSynTable.Count;
                        goodInfo.iSynchronizeCount = hSynTable.Count;
                    }
                    else
                        goodInfo.iFreshSucNumCount += iFreshCount;

                    if (bSynFlag)
                    {
                        goodInfo.strSynStatus = "正在同步";
                    }
                    else
                    {
                        goodInfo.strFreshStatus = "正在刷新";
                    }
                    if (bBreak)
                    {
                        if (bSynFlag)
                        {
                            goodInfo.strSynStatus = "同步完成";
                        }
                        else
                        {
                            goodInfo.strFreshStatus = "刷新完成";
                        }
                    }
                }
                else if (iRet == -1)
                {
                    goodInfo.strFreshStatus = strError;
                    goodInfo.strSynStatus = strError;
                    goodInfo.strModifyStatus = strError;
                    bRet = false;
                    ShowLogString(string.Format("{0} {1}", iCurPage, strError));
                    break;
                }
                else
                {                    
                    goodInfo.strFreshStatus = strError;
                    ShowLogString(string.Format("{0} {1}",iCurPage,strError));
                }
                ShowInfo(goodInfo);
                if (iRet != -3)
                {
                    iCurPage++;
                }                
                if (bBreak)
                {
                    if (bSynFlag)
                    {
                        //保存到文件
                        StringBuilder strBuilder = new StringBuilder();
                        _GoodsModifyStr objStru = new _GoodsModifyStr();

                        string[] keyArray = new string[hSynTable.Count];
                        string[] valueArray = new string[hSynTable.Count];
                        hSynTable.Keys.CopyTo(keyArray, 0);
                        int i=0;
                        foreach (string skey in keyArray)
                        {
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            valueArray[i] = objStru.strNoEx;
                            i++;
                        }
                        Array.Sort(valueArray, keyArray);
                        foreach (string skey in keyArray)
                        {
                            /*
                               public string strTicket;
        public string strPay;
        public string strSequence;
        public string strTrueprice;
        public string strMid;
        public string strOtherInfo;  //表示特价等的字符串
        public string dealerPriceId;
        public string oldstatus;
        public string refprice;
        public string productname;
        public string strAdvert;
                             */
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            strBuilder.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},\r\n", objStru.strNo, objStru.strNoEx.Trim(),
                                objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice,
                                objStru.dealerPriceId,
                                objStru.oldstatus,
                                objStru.refprice,
                                objStru.strOtherInfo,
                                objStru.strAdvert                               
                                ));
                        }
                        string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "synfile";
                        string strDirectoryXls = System.AppDomain.CurrentDomain.BaseDirectory + "xlsfile";

                        WriteInfo(strDirectory, strBuilder, goodInfo.strAcc);
                        SaveToExcel(strDirectoryXls, hSynTable, goodInfo.strAcc);

                        if (hSynDuplicateTable.Count > 0)
                        {
                            StringBuilder strBuilderEx = new StringBuilder();

                            string[] keyArrayDup = new string[hSynDuplicateTable.Count];
                            string[] valueArrayDup = new string[hSynDuplicateTable.Count];
                            hSynDuplicateTable.Keys.CopyTo(keyArrayDup, 0);
                            int ii = 0;
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];
                                valueArrayDup[ii] = objStru.strNoEx;
                                ii++;
                            }
                            Array.Sort(valueArrayDup, keyArrayDup);
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];

                                strBuilderEx.Append(string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},\r\n", objStru.strNo, objStru.strNoEx.Trim(),
                                objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice,
                                objStru.dealerPriceId,
                                objStru.oldstatus,
                                objStru.refprice,
                                objStru.strOtherInfo,
                                objStru.strAdvert
                                ));
                            }
                            
                            WriteInfo(strDirectory, strBuilderEx, goodInfo.strAcc + "_duplicate");
                            SaveToExcel(strDirectoryXls, hSynDuplicateTable, goodInfo.strAcc + "_duplicate");
                        }                        
                    }
                    break;
                }
                Thread.Sleep(500);
            }            
            return true;
        }
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable,int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "<input  pid=(.+?)循环结束");
                
                int match_num = 0;		//总共匹配到的数量
                string matchValue = "";
                string strPrice = "";
                //cpricestate_
                string strTemp = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;		//获取匹配到的字符串


                    goodModify.strNo = GetKeyString(matchValue, "\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("dealerPriceId_"));
                    goodModify.dealerPriceId = GetKeyString(strTemp, "value=\"", "\"");
                    
                    strTemp = matchValue.Substring(matchValue.IndexOf("oldstatus_"));
                    goodModify.oldstatus = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("refprice_"));
                    goodModify.refprice = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("productname_"));
                    goodModify.strNoEx = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("id=\"advert_"));
                    goodModify.strAdvert = GetKeyString(strTemp, "value=\"", "\"");

                    strTemp = matchValue.Substring(matchValue.IndexOf("downflowprice_"));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fLowPrice);

                    strTemp = matchValue.Substring(matchValue.IndexOf("upflowprice_"));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fHighPrice);

                    strTemp = matchValue.Substring(matchValue.IndexOf("onchange=\"changePriceData("));
                    strPrice = GetKeyString(strTemp, "value=\"", "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);
                    
                    
                    goodModify.strOtherInfo = string.Format("&cpricestate_{0}=true&priority_{0}=0",goodModify.strNo);
                    
                    //特价
                    strTemp = GetKeyString(matchValue, string.Format("id=\"salestatus_{0}", goodModify.strNo), "特价");
                    if (strTemp.ToLower().IndexOf("checked")>0)
                    {
                        goodModify.strOtherInfo += string.Format("&salestatus_{0}=8", goodModify.strNo);
                    }
                    //热卖
                    strTemp = GetKeyString(matchValue, string.Format("id=\"hotstatus_{0}", goodModify.strNo), "热卖");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&hotstatus_{0}=4", goodModify.strNo);
                    }
                    //新品
                    strTemp = GetKeyString(matchValue, string.Format("id=\"newstatus_{0}", goodModify.strNo), "新品");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&newstatus_{0}=2", goodModify.strNo);
                    }
                    //下架
                    strTemp = GetKeyString(matchValue, string.Format("id=\"stopstatus_{0}", goodModify.strNo), "下架");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&stopstatus_{0}=1", goodModify.strNo);
                    }
                    //行货
                    strTemp = GetKeyString(matchValue, string.Format("id=\"qualityGoodsStatus_{0}", goodModify.strNo), "行货代票");
                    if (strTemp.ToLower().IndexOf("checked") > 0)
                    {
                        goodModify.strOtherInfo += string.Format("&qualityGoodsStatus_{0}=16", goodModify.strNo);
                    }

                    
                    /*<input   name="hotstatus_516996" id="hotstatus_516996"  type="checkbox"  value="4" onclick="thisClick(this,516996);" />热卖
                     * <input   name="newstatus_516996" id="newstatus_516996" type="checkbox" value="2" onclick="thisClick(this,516996);" />新品
                     * <input   name="stopstatus_516996" id="stopstatus_516996" onclick="stopProductPrice(this,516996);" type="checkbox" value="1" />下架
                     * <input   name="qualityGoodsStatus_516996" id="qualityGoodsStatus_516996" type="checkbox" value="16" onclick="thisClick(this,516996);" checked/>行货代票
                    */
                    /*
                    <input type="hidden" name="dealerPriceId_542009" value="17904037" id="dealerPriceId_542009">
                    <input type="hidden" name="oldstatus_542009" value="21" id="oldstatus_542009">
                    <input type="hidden" name="downflowprice_542009" value="990" id="downflowprice_542009">
                    <input type="hidden" name="upflowprice_542009" value="1755" id="upflowprice_542009">
                    <input type="hidden" name="refprice_542009" id="refprice_542009"  value="1350.0" id="refprice_542009"/>
                    <input type="hidden" name="cpricestate_542009" value="true" id="cpricestate_542009"/>
                    <input type="hidden" id="catalogid_542009" value="291"/>
                    <input type="hidden" id="brandid_542009" value="294"/>
                    <input type="hidden" id="productname_542009" value="诺基亚5230"/>  
                     */

                    //string strPageNum = 
                    match_num++;		//匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            	
            }            
        }
Exemplo n.º 16
0
        public int FreshPaoPao(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
                               int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum  = 0;
            iGoodCount = 0;
            strError   = "";
            bBreak     = false;
            bool bRet = false;

            try
            {
                string strBefore = "共";
                string strAfter  = "条记录";
                if (m_strGoodContent.IndexOf("退出登录") < 0)
                {
                    strError = "数据错误";
                    return(-1);  //数据错误,停止
                }
                string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("全选/反选"));
                string strNum  = GetKeyString(strTemp, strBefore, strAfter).Trim();
                bRet = int.TryParse(strNum, out iGoodCount);
                if (!bRet)
                {
                    strError = "数据错误";
                    return(-1);  //数据错误,停止
                }

                _GoodsModifyStr objModify     = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("[");
                string        strBakData        = "";
                int           iGoodFreshCount   = 0;                   //本次要刷新的商品数
                List <string> strModifyNameList = new List <string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;

                //HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312"))
                //拿前20个,直至拿完
                iCurPage = 101;
                foreach (DictionaryEntry dEntry in hWaitTable)
                {
                    if (strModifyNameList.Count == 20)  //只拿20个
                    {
                        break;
                    }
                    objModify = (_GoodsModifyStr)dEntry.Value;
                    string strInfo = "{\"index\":"
                                     + (strModifyNameList.Count + 1).ToString()
                                     + ",\"productId\":\""
                                     + objModify.strNo.ToString()
                                     + "\",\"price\":"
                                     + objModify.fPrice.ToString()
                                     + ",\"link\":\"\",\"remark\":\"\"}";
                    strBuilder.Append(strInfo);
                    strModifyNameList.Add((string)dEntry.Key);
                    if (strModifyNameList.Count != 20 && strModifyNameList.Count < hWaitTable.Count)  //只拿20个
                    {
                        strBuilder.Append(",");
                    }
                }
                strBuilder.Append("]");
                iFreshNum = strModifyNameList.Count;
                if (iFreshNum < 1)
                {
                    bBreak = true;
                    return(0);
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = "action=savePriceList&jsonData=" + HttpUtility.UrlEncode(strBuilder.ToString(), Encoding.GetEncoding("gb2312"));
                string strRet  = m_webPost.GetHttpPage("http://my.shop.pcpop.com/Handler/Price/Price.ashx",
                                                       "gb2312", "post", "", strData,
                                                       string.Format("http://my.shop.pcpop.com/Price/PriceList.aspx"),
                                                       "*/*", "");
                if (strRet.IndexOf("{res") >= 0) //刷新成功
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                    }
                }
                else if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                //m_strGoodContent = strRet;
                return(0);
            }
            catch (System.Exception ex)
            {
                strError = "程序异常";
                return(-1);  //数据错误,停止
            }
        }
Exemplo n.º 17
0
        public int FreshPaoPao(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
                               int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount, string strMid, string strAcc)
        {
            iFreshNum  = 0;
            iGoodCount = 0;
            strError   = "";
            bBreak     = false;
            bool bRet = false;


            string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "modifyfail";

            try
            {
                string strBefore = "共<span>";
                string strAfter  = "</span>";
                if (m_strGoodContent.IndexOf(string.Format("http://dealer.zol.com.cn/d_{0}/", strMid)) < 0)
                {
                    strError = "数据错误";
                    return(-1);  //数据错误,停止
                }
                string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("<strong>产品搜索 : </strong>"));
                string strNum  = GetKeyString(strTemp, strBefore, strAfter).Trim();
                bRet = int.TryParse(strNum, out iGoodCount);
                if (!bRet)
                {
                    strError = "数据错误";
                    return(-1);  //数据错误,停止
                }

                _GoodsModifyStr objModify     = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("");
                string        strBakData        = "";
                int           iGoodFreshCount   = 0;                   //本次要刷新的商品数
                List <string> strModifyNameList = new List <string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;

                //HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312"))
                //拿前20个,直至拿完
                iCurPage = 101;
                string strPostUrl = "";
                foreach (DictionaryEntry dEntry in hWaitTable)
                {
                    if (strModifyNameList.Count == 1)  //只拿1个
                    {
                        break;
                    }
                    objModify = (_GoodsModifyStr)dEntry.Value;
                    strModifyNameList.Add((string)dEntry.Key);
                    strPostUrl = string.Format("http://mydealer.zol.com.cn/admin/ajax/ajax_response.php?type=2&mid={0}&pro_id={1}&price={2}&old_price=undefined&sequence={3}&ispay={4}&have_ticket={5}&istrueprice={6}",
                                               objModify.strMid,
                                               objModify.strNo,
                                               objModify.fPrice,
                                               objModify.strSequence,
                                               objModify.strPay,
                                               objModify.strTicket,
                                               objModify.strTrueprice);
                }
                // strBuilder.Append("]");
                iFreshNum = strModifyNameList.Count;
                if (iFreshNum < 1)
                {
                    bBreak = true;
                    return(0);
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = "";
                string strRet  = m_webPost.GetHttpPage(strPostUrl,
                                                       "gb2312", "post", "", strData,
                                                       string.Format("http://mydealer.zol.com.cn/admin/index.php?action=price"),
                                                       "*/*", "");

                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                            StringBuilder strBuilderEx = new StringBuilder();
                            strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                            WriteInfo(strDirectory, strBuilderEx, strAcc);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }

                if (strRet.Length > 10 || strRet == "1" || strRet == "4")
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                    }
                    return(0);
                }
                //!
                else if (strRet == "5")
                {
                    strError = "同一款产品每天报价不能超过两次!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return(-2);
                }
                else if (strRet == "3")
                {
                    strError = "两次报价金额相同!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return(-2);
                }
                else if (strRet == "6")
                {
                    strError = "价格不在报价区间!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return(-2);
                }
                else
                {
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    return(0);
                }
                return(0);
            }
            catch (System.Exception ex)
            {
                strError = "程序异常";
                return(-1);  //数据错误,停止
            }
        }
Exemplo n.º 18
0
        public int Fresh(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
                         int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount, string strId)
        {
            iFreshNum  = 0;
            iGoodCount = 0;
            strError   = "";
            bBreak     = false;
            int iAnalyzeCount = 0;

            try
            {
                string strBefore = ">";
                string strAfter  = "</a>";

                string strUrl = string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}&page={1}", strId, iCurPage);
                //加载
                string strRet = "";

                if (!bIsModify)
                {
                    strRet = m_webPost.GetHttpPage(strUrl,
                                                   "gb2312", "get", "", "",
                                                   string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}", strId),
                                                   "*/*", "");
                    if (strRet == "") //网络错误
                    {
                        strError = (strRet == "" ? "网络异常" : "数据错误");
                        if (iNetErrorCount++ > 5)
                        {
                            iNetErrorCount = 0;
                            return(-1);  //出错超过3次,停止
                        }
                        return(-3);
                    }
                    m_strGoodContent = strRet;
                    if (m_strGoodContent.IndexOf("<title>久腾网手机营业厅 管理后台") < 0)
                    {
                        strError = "刷新失败";
                        return(-1);
                    }
                }

                _GoodsModifyStr objModify     = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                // strBuilder.Append("method=save");
                string        strBakData        = "";
                int           iGoodFreshCount   = 0;                   //本次要刷新的商品数
                List <string> strModifyNameList = new List <string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1, out iAnalyzeCount);
                    iFreshNum = hTableGoods.Count;
                    if (iFreshNum < 1)  //刷新完成
                    {
                        bBreak = true;
                        return(0);
                    }
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("price%5B%5D={0}&topic%5B%5D={1}&url%5B%5D={2}&proid%5B%5D={3}&status%5B{4}%5D=&id%5B%5D={4}&",
                                                        objModify.fPrice, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")),
                                                        HttpUtility.UrlEncode(objModify.strUrl, Encoding.GetEncoding("gb2312")), objModify.strNo2, objModify.strNo, objModify.strNo));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 200)  //只拿200个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("price%5B%5D={0}&topic%5B%5D={1}&url%5B%5D={2}&proid%5B%5D={3}&status%5B{4}%5D=&id%5B%5D={4}&",
                                                        objModify.fPrice, HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312")),
                                                        HttpUtility.UrlEncode(objModify.strUrl, Encoding.GetEncoding("gb2312")), objModify.strNo, objModify.strNo2));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return(0);
                    }
                }

                string strLast = string.Format("act=edit&cid={0}&pr=edit&links=list2.php%3Fcid%3D1548%26tradeid%3D%26page%3D1", strId);
                strBuilder.Append(strLast);
                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                //string strData = "price%5B%5D=2111&topic%5B%5D=%D5%FD%B9%E6%B4%F3%C2%BD%D0%D0%BB%F5%A3%AC%B4%F8%B7%A2%C6%B1%A3%AC%C8%AB%B9%FA%C1%AA%B1%A3%A3%AC%CF%ED%CA%DC%B9%FA%BC%D2%C8%FD%B0%FC%A1%A3%D6%A7%B3%D6%BB%F5%B5%BD%B8%B6%BF%EE%A3%AC%C9%CF%C3%C5%D7%D4%CC%E1%A1%A3&url%5B%5D=http%3A%2F%2Fwww.c818.com%2FProductShow.asp%3FProID%3D3984&proid%5B%5D=22413&status%5B21847%5D=&id%5B%5D=21847&act=edit&cid=1548&pr=edit&links=list2.php%3Fcid%3D1548%26tradeid%3D%26page%3D1";

                string strData = strBuilder.ToString();
                strRet = m_webPost.GetHttpPage("http://shop.younet.com/c818/manage/price_man1.php",
                                               "gb2312", "post", "", strData,
                                               string.Format("http://shop.younet.com/c818/manage/list2.php?cid={0}", strId),
                                               "*/*", "");

                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 5)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                if (strRet.IndexOf("操作成功") < 0)
                {
                    //失败,重试3次
                    if (!bIsModify)
                    {
                        strError = "刷新失败";
                    }
                    else
                    {
                        strError = "修改失败";
                    }
                    if (iNetErrorCount++ > 5)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                //成功了
                foreach (string strName in strModifyNameList)
                {
                    hWaitTable.Remove(strName);
                }
                //修改完成
                if (bIsModify)
                {
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                        return(0);
                    }
                }
                return(0);
            }
            catch (System.Exception ex)
            {
                strError = "程序异常" + ex.Message;
                return(-1);  //数据错误,停止
            }
        }
Exemplo n.º 19
0
        void AnalyzeGoodsPaoPao(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage, string strMid)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "><input type=\"checkbox\" name=\"product_id(.+?)报价时间:");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "value=\"", "\"");

                    string strTempPrice = matchValue.Substring(matchValue.IndexOf(string.Format("name=\"price{0}\" id=\"price{0}\" type=\"text\"", goodModify.strNo)));
                    //362"
                    string strPrice = GetKeyString(strTempPrice,
                                                   "value=\"",
                                                   "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);

                    //name="have_ticket80865" id="have_ticket80865" checked  value='1'  />带票
                    string strTempEx = matchValue.Substring(matchValue.IndexOf(string.Format("name=\"have_ticket{0}\" id=", goodModify.strNo)));

                    goodModify.strTicket = GetKeyString(strTempEx,
                                                        "value='",
                                                        "'");
                    goodModify.strPay = GetKeyString(matchValue,
                                                     string.Format("id=\"ispay_{0}\" checked value=\"", goodModify.strNo),
                                                     "\"");
                    goodModify.strSequence = GetKeyString(matchValue,
                                                          string.Format("id=\"sequence{0}\" class=\"txt\" type=\"text\" value=\"", goodModify.strNo),
                                                          "\"");

                    goodModify.strTrueprice = GetKeyString(matchValue,
                                                           string.Format("id=\"istrueprice{0}\" checked value=\"", goodModify.strNo),
                                                           "\"");

                    goodModify.strMid  = strMid;
                    goodModify.strNoEx = GetKeyString(matchValue,
                                                      "javascript:cfg_module_pic('",
                                                      "'");
                    goodModify.strName = goodModify.strNoEx;

                    string   strTemp  = GetKeyString(matchValue, "javascript:merchant_price_set(", ")");
                    string[] strArray = strTemp.Split(',');
                    if (strArray.Length > 6)
                    {
                        float.TryParse(strArray[4], out goodModify.fLowPrice);
                        float.TryParse(strArray[5], out goodModify.fHighPrice);
                    }
                    else
                    {
                        goodModify.fLowPrice  = 0;
                        goodModify.fHighPrice = 0;
                    }

                    //获取最高和最低价格
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
Exemplo n.º 20
0
        void AnalyzeGoodsPaoPao(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "产品描述</a></div>(.+?)报价时间");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "productInfoChanged('", "'");
                    string strPrice = GetKeyString(matchValue,
                                                   string.Format("class=\"currentPrice\" value=\""),
                                                   "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);


                    goodModify.strNoEx = GetKeyString(matchValue,
                                                      string.Format("id=\"txtProductName{0}\" value=\"", goodModify.strNo),
                                                      "\"");// +"    " + iPage.ToString();
                    goodModify.strName = goodModify.strNoEx;


                    //获取最高和最低价格
                    string strData = string.Format("action=getLimitPrice&productId={0}", goodModify.strNo);
                    try
                    {
                        string strRet = m_webPost.GetHttpPage("http://my.shop.pcpop.com/Handler/Price/Price.ashx",
                                                              "gb2312", "post", "", strData,
                                                              "",
                                                              "*/*", "");
                        //{type:"2",res:"620 - 930 "}
                        if (strRet.IndexOf("res:\"") < 0)
                        {
                            goodModify.fLowPrice = goodModify.fHighPrice = goodModify.fPrice;
                        }
                        else
                        {
                            strRet   = strRet.Substring(strRet.IndexOf("res:\""));
                            strPrice = GetKeyString(strRet,
                                                    "res:\"",
                                                    " -");
                            float.TryParse(strPrice, out goodModify.fLowPrice);
                            strPrice = GetKeyString(strRet,
                                                    " - ",
                                                    " ");
                            float.TryParse(strPrice, out goodModify.fHighPrice);
                        }
                    }
                    catch (System.Exception ex)
                    {
                    }
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
Exemplo n.º 21
0
 private void listView_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     ListViewHitTestInfo info = listView.HitTest(e.X, e.Y);
     if (info.Item != null)
     {
         string strAcc = info.Item.SubItems[1].Text;
         Hashtable hTable = new Hashtable();
         bool bRet = DataContrl.GetNeedAddData(strAcc, ref hTable);
         if (bRet)
         {
             if (hTable.Count > 0)
             {
                 StringBuilder strBuilder = new StringBuilder();
                 _GoodsModifyStr objModify = new _GoodsModifyStr();
                 int iCount = 0;
                 foreach (DictionaryEntry dEntry in hTable)
                 {
                     objModify = (_GoodsModifyStr)dEntry.Value;
                     string strInfo = "";
                     if (objModify.iFailFlag != 3 && objModify.iFailFlag != 2)
                     {
                         strInfo = "";
                         strBuilder.Append(string.Format("{0}  {1} {2}\r\n", objModify.strNoEx, objModify.fPrice, strInfo));
                         iCount++;
                     }
                 }
                 string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "needaddfile";
                 WriteInfo(strDirectory, strBuilder, strAcc);
                 string strFileName = strAcc + ".txt";
                 strFileName = strDirectory + "\\" + strFileName;
                 string strInfoShow = strBuilder.ToString();
                 if (strInfoShow.Length > 200)
                 {
                    strInfoShow = strInfoShow.Substring(0, 200) + ".....";
                 }
                 string strShow = string.Format("待添加信息{0}条\r\n请在 needaddfile\\{1}.txt 中查看\r\n{2}", iCount,strAcc, strInfoShow);
                 MessageBox.Show(strShow);
             }
         }
     }
 }
Exemplo n.º 22
0
        void AnalyzeGoods(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage, out int iGoodCount)
        {
            iGoodCount = 0;
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                strContent = strContent.Replace("\t", "");
                Match match = Regex.Match(strContent, "套红</a>(.+?)</ul>");

                int    match_num  = 0;          //总共匹配到的数量
                string matchValue = "";
                string strPrice   = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    matchValue = match.Groups[1].Value;         //获取匹配到的字符串
                    //target="_blank">摩托罗拉 A1890</a>
                    goodModify.strNoEx = GetKeyString(matchValue, "target=\"_blank\">", "</a>");
                    goodModify.strNo   = GetKeyString(matchValue, "type=\"hidden\" name=\"proid[]\" value=\"", "\"");
                    goodModify.strNo2  = GetKeyString(matchValue, "type=\"hidden\" name=\"id[]\" value=\"", "\"");
                    string strTemp = matchValue.Substring(matchValue.IndexOf("<input name=\"price[]\" type=\"text\""));

                    strPrice = GetKeyString(strTemp,
                                            "value=\"",
                                            "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);

                    strTemp            = matchValue.Substring(matchValue.IndexOf("<input name=\"topic[]\" type=\"text\""));
                    goodModify.strName = GetKeyString(strTemp,
                                                      "value=\"",
                                                      "\"");
                    strTemp           = matchValue.Substring(matchValue.IndexOf("<input name=\"url[]\" type=\"text\""));
                    goodModify.strUrl = GetKeyString(strTemp,
                                                     "value=\"",
                                                     "\"");

                    /*
                     * <input type="hidden" name="proid[]" value="22413">
                     * <input type="hidden" name="status[21847]" id="status21847" value="">
                     * <input type="hidden" name="id[]" value="21847"></li>
                     */
                    //string strPageNum =
                    match_num++;                //匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                iGoodCount = match_num;
                int ii = 0;
            }
            catch (System.Exception ex)
            {
            }
        }
Exemplo n.º 23
0
        private void btnImportAcc_Click(object sender, EventArgs e)
        {
            string strPath = "";
            OpenFileDialog find = new OpenFileDialog();
            find.Filter = "TXT文件(*.txt)|*.txt";

            if (find.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            strPath = find.FileName;
            string strContent = ReadFileLine(strPath);
            string[] strArray = strContent.Split('\n');
            foreach (string strLine in strArray)
            {
                //解析帐号密码
                string[] strInfo = strLine.Split(',');
                if (strInfo.Length < 2)
                {
                    continue;
                }
                if (DataContrl.IsInCache(strInfo[0]))
                {
                    continue;
                }
                if (strInfo[0].Length < 1 || strInfo[1].Length < 1)
                {
                    continue;
                }
                _GoodsFreshStr GoodInfo = new _GoodsFreshStr();
                GoodInfo.strAcc = strInfo[0];
                GoodInfo.strPwd = strInfo[1];
                GoodInfo.webPost = new ClassHttpPost();
                GoodInfo.iFreshCount = 0;
                GoodInfo.iFreshSucCount = 0;
                GoodInfo.iFreshFailCount = 0;
                ShowLogString(string.Format("正在加载 {0} 的商品同步信息", GoodInfo.strAcc));
                //此处需要添加已经同步好的文本文档,以便添加修改文件时对比,得出需要添加的商品
                string strSynPath = System.AppDomain.CurrentDomain.BaseDirectory + "synfile\\" + GoodInfo.strAcc + ".txt";
                if (!File.Exists(strSynPath))
                {
                    GoodInfo.iSynchronizeCount = 0;
                    GoodInfo.strSynStatus = "未找到同步信息文件";
                    ShowLogString(GoodInfo.strSynStatus);
                }
                else
                {
                    //加载同步信息
                    string strInfoEx = ReadFileLine(strSynPath);
                    string[] strArrayEx = strInfoEx.Split('\n');
                    Hashtable hSynTable = new Hashtable();
                    Hashtable hNoList = new Hashtable();
                    foreach (string strGoodInfo in strArrayEx)
                    {
                        string[] strSynInfo = strGoodInfo.Split(',');
                        if (strSynInfo.Length < 7)
                        {
                            continue;
                        }
                        _GoodsModifyStr goodModify = new _GoodsModifyStr();
                        goodModify.strNo = strSynInfo[0];
                        goodModify.strNoEx = strSynInfo[1];
                        goodModify.strName = "";
                        float.TryParse(strSynInfo[2], out goodModify.fPrice);
                        float.TryParse(strSynInfo[3], out goodModify.fLowPrice);
                        float.TryParse(strSynInfo[4], out goodModify.fHighPrice);
                        if (strSynInfo.Length > 7)
                        {
                            for (int i = 5; i < strSynInfo.Length - 2;i++ )
                            {
                                goodModify.strName += strSynInfo[i];
                            }
                        }
                        else{
                            goodModify.strName = strSynInfo[5];
                        }
                        if (hNoList.ContainsKey(goodModify.strNoEx))
                        {
                            hNoList[goodModify.strNoEx] = (string)hNoList[goodModify.strNoEx] + "," + goodModify.strNo;
                        }
                        else{
                            hNoList[goodModify.strNoEx] = goodModify.strNo;
                        }
                        hSynTable.Add(goodModify.strNo, goodModify);
                    }

                    foreach (DictionaryEntry dEntry in hNoList)
                    {
                        DataContrl.AddSynNumberList(GoodInfo.strAcc + (string)dEntry.Key, (string)dEntry.Value);
                    }
                    GoodInfo.iSynchronizeCount = hSynTable.Count;
                    DataContrl.AddSynList(GoodInfo.strAcc, hSynTable);
                    ShowLogString(string.Format("导入同步信息 {0} 条", hSynTable.Count));
                }

                DataContrl.AddDataCache(GoodInfo);
                AddViewItem(GoodInfo.strAcc, GoodInfo.strPwd);
                GoodInfo.bModify = true;
                //导入上次一键刷新的时间
                GoodInfo.strQuickFreshTimeLeft = "未知";
                GoodInfo.strLastFreshQuickTime = IniUtility.GetIniKeyValue("set", GoodInfo.strAcc+"_lastFreshTime", "");
                if (GoodInfo.strLastFreshQuickTime=="")
                {
                    GoodInfo.strLastFreshQuickTime = "未刷新过";
                }
                if (GoodInfo.iSynchronizeCount < 1)
                {
                    GoodInfo.strSynStatus = "尚未同步";
                }
                ShowInfo(GoodInfo);
            }
        }
        public int FreshPaoPao(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
           int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount,string strMid,string strAcc)
        {
            iFreshNum = 0;
            iGoodCount = 0;
            strError = "";
            bBreak = false;
            bool bRet = false;


            string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "modifyfail";
            
            try
            {   
                string strBefore = "共<span>";
                string strAfter = "</span>";
                if (m_strGoodContent.IndexOf(string.Format("http://dealer.zol.com.cn/d_{0}/",strMid)) < 0)
                {
                    strError = "数据错误";
                    return -1;  //数据错误,停止
                }
                string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("<strong>产品搜索 : </strong>"));
                string strNum = GetKeyString(strTemp, strBefore, strAfter).Trim();
                bRet = int.TryParse(strNum, out iGoodCount);
                if (!bRet)
                {
                    strError = "数据错误";
                    return -1;  //数据错误,停止
                }

                _GoodsModifyStr objModify = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("");
                string strBakData = "";
                int iGoodFreshCount = 0;    //本次要刷新的商品数
                List<string> strModifyNameList = new List<string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;

                //HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312"))
                //拿前20个,直至拿完
                iCurPage = 101;
                string strPostUrl = "";
                foreach (DictionaryEntry dEntry in hWaitTable)
                {
                    if (strModifyNameList.Count == 1)  //只拿1个
                    {
                        break;
                    }
                    objModify = (_GoodsModifyStr)dEntry.Value;
                    strModifyNameList.Add((string)dEntry.Key);
                    strPostUrl = string.Format("http://mydealer.zol.com.cn/admin/ajax/ajax_response.php?type=2&mid={0}&pro_id={1}&price={2}&old_price=undefined&sequence={3}&ispay={4}&have_ticket={5}&istrueprice={6}",
                        objModify.strMid,
                        objModify.strNo,
                        objModify.fPrice,
                        objModify.strSequence,
                        objModify.strPay,
                        objModify.strTicket,
                        objModify.strTrueprice);
                }
               // strBuilder.Append("]");
                iFreshNum = strModifyNameList.Count;
                if (iFreshNum < 1)
                {
                    bBreak = true;
                    return 0;
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = "";
                string strRet = m_webPost.GetHttpPage(strPostUrl,
                    "gb2312", "post", "", strData,
                    string.Format("http://mydealer.zol.com.cn/admin/index.php?action=price"),
                    "*/*", "");

                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                            StringBuilder strBuilderEx = new StringBuilder();
                            strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                            WriteInfo(strDirectory, strBuilderEx, strAcc);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                
                if (strRet.Length > 10 || strRet == "1" || strRet == "4")
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                    }
                    return 0;
                }
                //!
                else if (strRet == "5")
                {
                    strError = "同一款产品每天报价不能超过两次!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return -2;
                }
                else if (strRet == "3")
                {
                    strError = "两次报价金额相同!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return -2;
                }
                else if (strRet == "6")
                {
                    strError = "价格不在报价区间!";
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    StringBuilder strBuilderEx = new StringBuilder();
                    strBuilderEx.Append(string.Format("{0} --- {1} --- {2}", objModify.strNoEx, objModify.fPrice, strError));
                    WriteInfo(strDirectory, strBuilderEx, strAcc);
                    return -2;
                }
                else
                {
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    return 0;
                }
                return 0;
            }
            catch (System.Exception ex)
            {
                strError = "程序异常";
                return -1;  //数据错误,停止
            }

        }
Exemplo n.º 25
0
        private bool Fresh(ref _GoodsFreshStr goodInfo, GoodsFresh objFresh,bool bSynFlag)
        {
            //http://m.pconline.com.cn/member/product/products_onsell.htm?&pageSize=60&pageNo=1
            goodInfo.strModifyStatus = "";
            goodInfo.bModify = false;
            string strError = "";
            if (bSynFlag)
            {
                goodInfo.strSynStatus = "登录中...";
            }
            else{
                goodInfo.strFreshStatus = "登录中...";
            }
            ShowInfo(goodInfo);
            bool bRet = false;
            #if __PAOPAO
            string strDirect = System.AppDomain.CurrentDomain.BaseDirectory + "pic";
            if (!Directory.Exists(strDirect))
            {
                Directory.CreateDirectory(strDirect);
            }
            string strFile = string.Format("{0}\\{1}.bmp", strDirect, goodInfo.strAcc);
            bRet = objFresh.GetImage(strFile, out strError);
            string strCheckCode = "";
            if (bRet)
            {
                lock(m_hLockTable)
                {
                    GetCodeHandler _myInvoke = new GetCodeHandler(GetCode);
                    strCheckCode = (string)this.Invoke(_myInvoke, new object[] { strFile });
                    if (strCheckCode.Length != 4)
                    {
                        goodInfo.strFreshStatus = "验证码错误";
                        ShowInfo(goodInfo);
                        return false;
                    }
                }
            }
            else
            {
                goodInfo.strFreshStatus = strError;
                ShowInfo(goodInfo);
                return false;
            }
            bRet = objFresh.PaoPaoLogin(goodInfo.strAcc, goodInfo.strPwd, strCheckCode, out strError);
            #else
            bRet = objFresh.Login(goodInfo.strAcc, goodInfo.strPwd, false);
            #endif

            if (!bRet)
            {
                //strError = "登录失败";
                if (bSynFlag)
                {
                    goodInfo.strSynStatus = strError;
                }
                else
                {
                    goodInfo.strFreshStatus = strError;
                }
                ShowLogString(strError);
                ShowInfo(goodInfo);
                return false;
            }
            int iCurPage = 1;
            int iRet = -1;
            int iFreshCount;
            int iGoodCount;
            bool bBreak = false;

            if (bSynFlag)
            {
                goodInfo.strSynStatus = "正在同步...";
            }
            else
            {
                goodInfo.strFreshStatus = "正在刷新...";
            }
            ShowInfo(goodInfo);
            Hashtable hWaitTable = new Hashtable();
            Hashtable hFailTable = new Hashtable(); //修改失败的价格列表
            Hashtable hSynTable = new Hashtable(); //同步列表
            Hashtable hSynDuplicateTable = new Hashtable(); //同步列表
            int iNetErrorCount = 0;
            while (m_bFresh && !bBreak)
            {
                if (bSynFlag)
                {
                    iRet = objFresh.Synchronize(out strError, out iFreshCount, out iGoodCount, out bBreak, iCurPage + 1, ref iNetErrorCount, ref hSynTable, ref hSynDuplicateTable);
                }
                else{
                    iRet = objFresh.Fresh(out strError, out iFreshCount, out iGoodCount, out bBreak, iCurPage + 1, false, ref hWaitTable, ref hFailTable, ref iNetErrorCount);
                }

                //成功
                if (iRet == 0)
                {
                    goodInfo.iFreshNumCount = iGoodCount;
                    if (bSynFlag)
                    {
                        goodInfo.iFreshSucNumCount = hSynTable.Count;
                        goodInfo.iSynchronizeCount = hSynTable.Count;
                    }
                    else
                        goodInfo.iFreshSucNumCount += iFreshCount;

                    if (bSynFlag)
                    {
                        goodInfo.strSynStatus = "正在同步";
                    }
                    else
                    {
                        goodInfo.strFreshStatus = "正在刷新";
                    }
                    if (bBreak)
                    {
                        if (bSynFlag)
                        {
                            goodInfo.strSynStatus = "同步完成";
                        }
                        else
                        {
                            goodInfo.strFreshStatus = "刷新完成";
                        }
                    }
                }
                else if (iRet == -1)
                {
                    goodInfo.strFreshStatus = strError;
                    goodInfo.strSynStatus = strError;
                    goodInfo.strModifyStatus = strError;
                    bRet = false;
                    ShowLogString(string.Format("{0} {1}", iCurPage, strError));
                    break;
                }
                else
                {
                    goodInfo.strFreshStatus = strError;
                    ShowLogString(string.Format("{0} {1}",iCurPage,strError));
                }
                ShowInfo(goodInfo);
                if (iRet != -3)
                {
                    iCurPage++;
                }
                if (bBreak)
                {
                    if (bSynFlag)
                    {
                        //保存到文件
                        StringBuilder strBuilder = new StringBuilder();
                        _GoodsModifyStr objStru = new _GoodsModifyStr();

                        string[] keyArray = new string[hSynTable.Count];
                        string[] valueArray = new string[hSynTable.Count];
                        hSynTable.Keys.CopyTo(keyArray, 0);
                        int i=0;
                        foreach (string skey in keyArray)
                        {
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            valueArray[i] = objStru.strNoEx;
                            i++;
                        }
                        Array.Sort(valueArray, keyArray);
                        foreach (string skey in keyArray)
                        {
                            objStru = (_GoodsModifyStr)hSynTable[skey];
                            strBuilder.Append(string.Format("{0},{1},{2},{3},{4},{5},\r\n", objStru.strNo, objStru.strNoEx.Trim(), objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice, objStru.strName));
                        }
                        string strDirectory = System.AppDomain.CurrentDomain.BaseDirectory + "synfile";
                        string strDirectoryXls = System.AppDomain.CurrentDomain.BaseDirectory + "xlsfile";

                        WriteInfo(strDirectory, strBuilder, goodInfo.strAcc);
                        SaveToExcel(strDirectoryXls, hSynTable, goodInfo.strAcc);

                        if (hSynDuplicateTable.Count > 0)
                        {
                            StringBuilder strBuilderEx = new StringBuilder();

                            string[] keyArrayDup = new string[hSynDuplicateTable.Count];
                            string[] valueArrayDup = new string[hSynDuplicateTable.Count];
                            hSynTable.Keys.CopyTo(keyArrayDup, 0);
                            int ii = 0;
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];
                                valueArrayDup[ii] = objStru.strNoEx;
                                ii++;
                            }
                            Array.Sort(valueArrayDup, keyArrayDup);
                            foreach (string skey in keyArrayDup)
                            {
                                objStru = (_GoodsModifyStr)hSynDuplicateTable[skey];
                                strBuilder.Append(string.Format("{0},{1},{2},{3},{4},{5},\r\n", objStru.strNo, objStru.strNoEx.Trim(), objStru.fPrice, objStru.fLowPrice, objStru.fHighPrice, objStru.strName));
                            }

                            WriteInfo(strDirectory, strBuilderEx, goodInfo.strAcc + "_duplicate");
                            SaveToExcel(strDirectoryXls, hSynDuplicateTable, goodInfo.strAcc + "_duplicate");
                        }
                    }
                    break;
                }
                Thread.Sleep(500);
            }
            return true;
        }
        public int Fresh(out string strError,out int iFreshNum,out int iGoodCount, out bool bBreak,
            int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum = 0;
            iGoodCount = 0;
            strError = "";
            bBreak = false;
            try
            {
                
                _GoodsModifyStr objModify = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                if (!bIsModify)
                {
                    string strBefore = "找到相符的产品";
                    string strAfter = "个";

                    if (m_strGoodContent.IndexOf("找到相符的产品") < 0)
                    {
                        strError = "数据错误1";
                        return -1;  //数据错误,停止
                    }
                    // string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("我的商品总数"));
                    string strNum = GetKeyString(m_strGoodContent, strBefore, strAfter);
                    bool bRet = int.TryParse(strNum, out iGoodCount);
                    if (!bRet)
                    {
                        strError = "数据错误2";
                        return -1;  //数据错误,停止
                    }

                    string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("<span id=\"numpage_t\">"));
                    string strNumLeft = GetKeyString(strTemp, ">", "/").Trim();
                    string strNumRight = GetKeyString(strTemp, "/", "<a").Trim();
                    if (strNumLeft == strNumRight) //已经同步完
                    {
                        bBreak = true;
                    }
                }
                

                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append(string.Format("clickIndex=0&clickPage=2&searchProductPrice.type=2&searchProductPrice.status=1&searchProductPrice.pageNo={0}&searchProductPrice.brandId=0&searchProductPrice.sort=0&searchProductPrice.fatherId=0&searchProductPrice.relatetype=0&searchProductPrice.productStatus=-1&searchProductPrice.productName=&productstatus=-1",iCurPage));
                string strBakData = "";
                int iGoodFreshCount = 0;    //本次要刷新的商品数
                List<string> strModifyNameList = new List<string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1);
                    iFreshNum = hTableGoods.Count;
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&productid={0}&price_{0}={7}&advert_{0}={1}&dealerPriceId_{0}={2}&oldstatus_{0}={3}&downflowprice_{0}={4}&upflowprice_{0}={5}&refprice_{0}={6}{8}", 
                        objModify.strNo,
                        HttpUtility.UrlEncode(objModify.strAdvert, Encoding.GetEncoding("gb2312")),
                        objModify.dealerPriceId,
                        objModify.oldstatus,
                        objModify.fLowPrice,
                        objModify.fHighPrice,
                        objModify.refprice,
                        objModify.fPrice,
                        objModify.strOtherInfo));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 30) //只拿60个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&productid={0}&price_{0}={7}&advert_{0}={1}&dealerPriceId_{0}={2}&oldstatus_{0}={3}&downflowprice_{0}={4}&upflowprice_{0}={5}&refprice_{0}={6}{8}", 
                        objModify.strNo,
                        HttpUtility.UrlEncode(objModify.strAdvert, Encoding.GetEncoding("gb2312")),
                        objModify.dealerPriceId,
                        objModify.oldstatus,
                        objModify.fLowPrice,
                        objModify.fHighPrice,
                        objModify.refprice,
                        objModify.fPrice,
                        objModify.strOtherInfo));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return 0;
                    }
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strReffer = string.Format("http://manage.jxs.yesky.com/price/searchprice.do");
                //string strReffer = string.Format("http://manage.jxs.yesky.com/price/searchprice.do?searchProductPrice.type=2&searchProductPrice.status=1&searchProductPrice.pageNo={0}&searchProductPrice.sort=0&clickPage=2&clickIndex=0&searchProductPrice.brandId=0&searchProductPrice.fatherId=0&searchProductPrice.relatetype=0&returnMessage=aaa", iCurPage);
                string strData = strBuilder.ToString();
                string strRet = m_webPost.GetHttpPage("http://manage.jxs.yesky.com/price/saveproductprice.do",
                    "gb2312", "post", "", strData,
                    strReffer,
                    "*/*", "");
//                 if (strRet.IndexOf("无相关商品") > 0) //已经刷完
//                 {
//                     //清除相关的待修改商品
//                     foreach (string strName in strModifyNameList)
//                     {
//                         hWaitTable.Remove(strName);
//                     }
//                     if (!bIsModify)
//                     {
//                         bBreak = true;
//                     }
//                     else        //修改
//                     {
//                         if (hWaitTable.Count < 1)
//                         {
//                             bBreak = true;
//                         }
//                     }
//                 }
                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                if (strRet.IndexOf("别人正在另一台服务器上修改您所修改的数据") > 0)
                {
                    strError = "其他人正在修改";
                    if (iNetErrorCount++ > 30)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                //成功
                foreach (string strName in strModifyNameList)
                {
                    objModify.iFailFlag = 3;
                    hFailTable.Add(strName, hWaitTable[strName]);
                    hWaitTable.Remove(strName);
                }
                m_strGoodContent = strRet;
                return 0;
            }
            catch (System.Exception ex)
            {
                strError = "程序异常"+ex.Message;
                return -1;  //数据错误,停止
            }
            
        }
        public int FreshPaoPao(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
            int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum = 0;
            iGoodCount = 0;
            strError = "";
            bBreak = false;
            bool bRet = false;
            try
            {
                string strBefore = "共";
                string strAfter = "条记录";
                if (m_strGoodContent.IndexOf("退出登录") < 0)
                {
                    strError = "数据错误";
                    return -1;  //数据错误,停止
                }
                string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("全选/反选"));
                string strNum = GetKeyString(strTemp, strBefore, strAfter).Trim();
                bRet = int.TryParse(strNum, out iGoodCount);
                if (!bRet)
                {
                    strError = "数据错误";
                    return -1;  //数据错误,停止
                }

                _GoodsModifyStr objModify = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append("[");
                string strBakData = "";
                int iGoodFreshCount = 0;    //本次要刷新的商品数
                List<string> strModifyNameList = new List<string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;

                //HttpUtility.UrlEncode(objModify.strName, Encoding.GetEncoding("gb2312"))
                //拿前20个,直至拿完
                iCurPage = 101;
                foreach (DictionaryEntry dEntry in hWaitTable)
                {
                    if (strModifyNameList.Count == 20)  //只拿20个
                    {
                        break;
                    }
                    objModify = (_GoodsModifyStr)dEntry.Value;
                    string strInfo = "{\"index\":"
                        +(strModifyNameList.Count+1).ToString()
                        +",\"productId\":\""
                        +objModify.strNo.ToString()
                        + "\",\"price\":"
                        +objModify.fPrice.ToString()
                        +",\"link\":\"\",\"remark\":\"\"}";
                        strBuilder.Append(strInfo);
                    strModifyNameList.Add((string)dEntry.Key);
                    if (strModifyNameList.Count != 20 && strModifyNameList.Count < hWaitTable.Count)  //只拿20个
                    {
                        strBuilder.Append(",");
                    }
                }
                strBuilder.Append("]");
                iFreshNum = strModifyNameList.Count;
                if (iFreshNum < 1)
                {
                    bBreak = true;
                    return 0;
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strData = "action=savePriceList&jsonData=" + HttpUtility.UrlEncode(strBuilder.ToString(), Encoding.GetEncoding("gb2312"));
                string strRet = m_webPost.GetHttpPage("http://my.shop.pcpop.com/Handler/Price/Price.ashx",
                    "gb2312", "post", "", strData,
                    string.Format("http://my.shop.pcpop.com/Price/PriceList.aspx"),
                    "*/*", "");
                if (strRet.IndexOf("{res") >= 0) //刷新成功
                {
                    //清除相关的待修改商品
                    foreach (string strName in strModifyNameList)
                    {
                        hWaitTable.Remove(strName);
                    }
                    if (hWaitTable.Count < 1)
                    {
                        bBreak = true;
                    }
                }
                else if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return -1;  //出错超过3次,停止
                    }
                    return -3;
                }
                //m_strGoodContent = strRet;
                return 0;
            }
            catch (System.Exception ex)
            {
                strError = "程序异常";
                return -1;  //数据错误,停止
            }
        }
        void AnalyzeGoodsPaoPao(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage,string strMid)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "><input type=\"checkbox\" name=\"product_id(.+?)报价时间:");
                
                int match_num = 0;		//总共匹配到的数量
                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;		//获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "value=\"", "\"");

                    string strTempPrice = matchValue.Substring(matchValue.IndexOf(string.Format("name=\"price{0}\" id=\"price{0}\" type=\"text\"", goodModify.strNo)));
                    //362"
                    string strPrice = GetKeyString(strTempPrice,
                        "value=\"",
                        "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);
                    
                    //name="have_ticket80865" id="have_ticket80865" checked  value='1'  />带票
                    string strTempEx = matchValue.Substring(matchValue.IndexOf(string.Format("name=\"have_ticket{0}\" id=", goodModify.strNo)));

                    goodModify.strTicket = GetKeyString(strTempEx,
                        "value='",
                        "'");
                    goodModify.strPay = GetKeyString(matchValue,
                        string.Format("id=\"ispay_{0}\" checked value=\"",goodModify.strNo),
                        "\"");
                    goodModify.strSequence = GetKeyString(matchValue,
                        string.Format("id=\"sequence{0}\" class=\"txt\" type=\"text\" value=\"",goodModify.strNo),
                        "\"");
                    
                    goodModify.strTrueprice = GetKeyString(matchValue,
                        string.Format("id=\"istrueprice{0}\" checked value=\"",goodModify.strNo),
                        "\"");

                    goodModify.strMid = strMid;
                    goodModify.strNoEx = GetKeyString(matchValue,
                        "javascript:cfg_module_pic('",
                        "'");
                    goodModify.strName = goodModify.strNoEx;

                    string strTemp = GetKeyString(matchValue, "javascript:merchant_price_set(", ")");
                    string[] strArray = strTemp.Split(',');
                    if (strArray.Length > 6)
                    {
                        float.TryParse(strArray[4], out goodModify.fLowPrice);
                        float.TryParse(strArray[5], out goodModify.fHighPrice);
                    }
                    else
                    {
                        goodModify.fLowPrice = 0;
                        goodModify.fHighPrice = 0;
                    }

                    //获取最高和最低价格
                                        //string strPageNum = 
                    match_num++;		//匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {

            }
        }
        void AnalyzeGoodsPaoPao(string strContent, ref Hashtable goodFreshList, ref Hashtable hSynDuplicateTable, int iPage)
        {
            try
            {
                strContent = strContent.Replace("\r", "");
                strContent = strContent.Replace("\n", "");
                strContent = strContent.Replace("\r\n", "");
                Match match = Regex.Match(strContent, "产品描述</a></div>(.+?)报价时间");

                int match_num = 0;		//总共匹配到的数量
                string matchValue = "";
                while (match.Success)
                {
                    _GoodsModifyStr goodModify = new _GoodsModifyStr();
                    //id="down_limit_6981520" type="hidden" value="774.0" /><input id="up_limit_6981520" type="hidden" value="1677.0" />
                    matchValue = match.Groups[1].Value;		//获取匹配到的字符串
                    //"><textarea id="txtRemark384380
                    goodModify.strNo = GetKeyString(matchValue, "productInfoChanged('", "'");
                    string strPrice = GetKeyString(matchValue,
                        string.Format("class=\"currentPrice\" value=\""),
                        "\"");
                    float.TryParse(strPrice, out goodModify.fPrice);

                    goodModify.strNoEx = GetKeyString(matchValue,
                        string.Format("id=\"txtProductName{0}\" value=\"", goodModify.strNo),
                        "\"");// +"    " + iPage.ToString();
                    goodModify.strName = goodModify.strNoEx;

                    //获取最高和最低价格
                    string strData = string.Format("action=getLimitPrice&productId={0}", goodModify.strNo);
                    try
                    {
                       string strRet = m_webPost.GetHttpPage("http://my.shop.pcpop.com/Handler/Price/Price.ashx",
                                        "gb2312", "post", "", strData,
                                        "",
                                        "*/*", "");
                       //{type:"2",res:"620 - 930 "}
                        if (strRet.IndexOf("res:\"") < 0)
                        {
                            goodModify.fLowPrice = goodModify.fHighPrice = goodModify.fPrice;
                        }
                        else{
                            strRet = strRet.Substring(strRet.IndexOf("res:\""));
                            strPrice = GetKeyString(strRet,
                        "res:\"",
                        " -");
                            float.TryParse(strPrice, out goodModify.fLowPrice);
                            strPrice = GetKeyString(strRet,
                                " - ",
                                " ");
                            float.TryParse(strPrice, out goodModify.fHighPrice);
                        }
                    }
                    catch (System.Exception ex)
                    {

                    }
                    //string strPageNum =
                    match_num++;		//匹配数增加
                    if (!goodFreshList.ContainsKey(goodModify.strNo))
                    {
                        goodFreshList.Add(goodModify.strNo, goodModify);
                    }
                    else
                    {
                        if (hSynDuplicateTable != null && !hSynDuplicateTable.ContainsKey(goodModify.strNo))
                        {
                            hSynDuplicateTable.Add(goodModify.strNo, goodModify);
                        }
                    }
                    match = match.NextMatch();
                }
                int ii = 0;
            }
            catch (System.Exception ex)
            {

            }
        }
Exemplo n.º 30
0
        public int Fresh(out string strError, out int iFreshNum, out int iGoodCount, out bool bBreak,
                         int iCurPage, bool bIsModify, ref Hashtable hWaitTable, ref Hashtable hFailTable, ref int iNetErrorCount)
        {
            iFreshNum  = 0;
            iGoodCount = 0;
            strError   = "";
            bBreak     = false;
            try
            {
                _GoodsModifyStr objModify     = new _GoodsModifyStr();
                _GoodsModifyStr objModifyWait = new _GoodsModifyStr();
                //通过解析得到当前的商品数据
                //m_strGoodContent
                if (!bIsModify)
                {
                    string strBefore = "找到相符的产品";
                    string strAfter  = "个";

                    if (m_strGoodContent.IndexOf("找到相符的产品") < 0)
                    {
                        strError = "数据错误1";
                        return(-1);  //数据错误,停止
                    }
                    // string strTemp = m_strGoodContent.Substring(m_strGoodContent.IndexOf("我的商品总数"));
                    string strNum = GetKeyString(m_strGoodContent, strBefore, strAfter);
                    bool   bRet   = int.TryParse(strNum, out iGoodCount);
                    if (!bRet)
                    {
                        strError = "数据错误2";
                        return(-1);  //数据错误,停止
                    }

                    string strTemp     = m_strGoodContent.Substring(m_strGoodContent.IndexOf("<span id=\"numpage_t\">"));
                    string strNumLeft  = GetKeyString(strTemp, ">", "/").Trim();
                    string strNumRight = GetKeyString(strTemp, "/", "<a").Trim();
                    if (strNumLeft == strNumRight) //已经同步完
                    {
                        bBreak = true;
                    }
                }


                Hashtable hTableGoods = new Hashtable();

                StringBuilder strBuilder = new StringBuilder();
                strBuilder.Append(string.Format("clickIndex=0&clickPage=2&searchProductPrice.type=2&searchProductPrice.status=1&searchProductPrice.pageNo={0}&searchProductPrice.brandId=0&searchProductPrice.sort=0&searchProductPrice.fatherId=0&searchProductPrice.relatetype=0&searchProductPrice.productStatus=-1&searchProductPrice.productName=&productstatus=-1", iCurPage));
                string        strBakData        = "";
                int           iGoodFreshCount   = 0;                   //本次要刷新的商品数
                List <string> strModifyNameList = new List <string>(); //本次刷新的商品名称列表

                Hashtable hTableSynDuplicate = null;
                if (bIsModify == false)   //刷新
                {
                    AnalyzeGoods(m_strGoodContent, ref hTableGoods, ref hTableSynDuplicate, 1);
                    iFreshNum = hTableGoods.Count;
                    foreach (DictionaryEntry dEntry in hTableGoods)
                    {
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&productid={0}&price_{0}={7}&advert_{0}={1}&dealerPriceId_{0}={2}&oldstatus_{0}={3}&downflowprice_{0}={4}&upflowprice_{0}={5}&refprice_{0}={6}{8}",
                                                        objModify.strNo,
                                                        HttpUtility.UrlEncode(objModify.strAdvert, Encoding.GetEncoding("gb2312")),
                                                        objModify.dealerPriceId,
                                                        objModify.oldstatus,
                                                        objModify.fLowPrice,
                                                        objModify.fHighPrice,
                                                        objModify.refprice,
                                                        objModify.fPrice,
                                                        objModify.strOtherInfo));
                        iGoodFreshCount++;
                    }
                }
                else    //修改
                {
                    //拿前60个,直至拿完
                    iCurPage = 101;
                    foreach (DictionaryEntry dEntry in hWaitTable)
                    {
                        if (strModifyNameList.Count == 30) //只拿60个
                        {
                            break;
                        }
                        objModify = (_GoodsModifyStr)dEntry.Value;
                        strBuilder.Append(string.Format("&productid={0}&price_{0}={7}&advert_{0}={1}&dealerPriceId_{0}={2}&oldstatus_{0}={3}&downflowprice_{0}={4}&upflowprice_{0}={5}&refprice_{0}={6}{8}",
                                                        objModify.strNo,
                                                        HttpUtility.UrlEncode(objModify.strAdvert, Encoding.GetEncoding("gb2312")),
                                                        objModify.dealerPriceId,
                                                        objModify.oldstatus,
                                                        objModify.fLowPrice,
                                                        objModify.fHighPrice,
                                                        objModify.refprice,
                                                        objModify.fPrice,
                                                        objModify.strOtherInfo));
                        strModifyNameList.Add((string)dEntry.Key);
                    }
                    iFreshNum = strModifyNameList.Count;
                    if (iFreshNum < 1)
                    {
                        bBreak = true;
                        return(0);
                    }
                }

                /************************************************************************/
                /*                                                                      */
                /************************************************************************/
                string strReffer = string.Format("http://manage.jxs.yesky.com/price/searchprice.do");
                //string strReffer = string.Format("http://manage.jxs.yesky.com/price/searchprice.do?searchProductPrice.type=2&searchProductPrice.status=1&searchProductPrice.pageNo={0}&searchProductPrice.sort=0&clickPage=2&clickIndex=0&searchProductPrice.brandId=0&searchProductPrice.fatherId=0&searchProductPrice.relatetype=0&returnMessage=aaa", iCurPage);
                string strData = strBuilder.ToString();
                string strRet  = m_webPost.GetHttpPage("http://manage.jxs.yesky.com/price/saveproductprice.do",
                                                       "gb2312", "post", "", strData,
                                                       strReffer,
                                                       "*/*", "");
//                 if (strRet.IndexOf("无相关商品") > 0) //已经刷完
//                 {
//                     //清除相关的待修改商品
//                     foreach (string strName in strModifyNameList)
//                     {
//                         hWaitTable.Remove(strName);
//                     }
//                     if (!bIsModify)
//                     {
//                         bBreak = true;
//                     }
//                     else        //修改
//                     {
//                         if (hWaitTable.Count < 1)
//                         {
//                             bBreak = true;
//                         }
//                     }
//                 }
                if (strRet == "") //网络错误
                {
                    strError = (strRet == "" ? "网络异常" : "数据错误");
                    if (iNetErrorCount++ > 3)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                if (strRet.IndexOf("别人正在另一台服务器上修改您所修改的数据") > 0)
                {
                    strError = "其他人正在修改";
                    if (iNetErrorCount++ > 30)
                    {
                        iNetErrorCount = 0;
                        //添加修改失败的商品名
                        foreach (string strName in strModifyNameList)
                        {
                            objModify.iFailFlag = 3;
                            hFailTable.Add(strName, hWaitTable[strName]);
                            hWaitTable.Remove(strName);
                        }
                        return(-1);  //出错超过3次,停止
                    }
                    return(-3);
                }
                //成功
                foreach (string strName in strModifyNameList)
                {
                    objModify.iFailFlag = 3;
                    hFailTable.Add(strName, hWaitTable[strName]);
                    hWaitTable.Remove(strName);
                }
                m_strGoodContent = strRet;
                return(0);
            }
            catch (System.Exception ex)
            {
                strError = "程序异常" + ex.Message;
                return(-1);  //数据错误,停止
            }
        }