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; }
private void button1_Click(object sender, EventArgs e) { // _GoodsFreshStr objInfoEx = new _GoodsFreshStr(); //objInfoEx.strAcc = "aaa"; TestStr1 bulder = new TestStr1(); bulder.strAcc = "AAA"; Hashtable tblHash = new Hashtable(); bulder.strAcc = "AAABBB"; _GoodsFreshStr objInfoExEx = new _GoodsFreshStr(); string strDirectoryXls = System.AppDomain.CurrentDomain.BaseDirectory + "xlsfile"; SaveToExcel(strDirectoryXls, null, "aaaaa"); return; GoodsFresh objFreshEx = new GoodsFresh(); ClassHttpPost webPost = new ClassHttpPost(); objFreshEx.SetWebPost(webPost); string strDirect = System.AppDomain.CurrentDomain.BaseDirectory + "pic"; if (!Directory.Exists(strDirect)) { Directory.CreateDirectory(strDirect); } return; //string str = System.Web.HttpUtility.UrlEncode("你好", Encoding.GetEncoding("gb2312")); string str = string.Format("{0} {1}", 519.0, 535.01); MessageBox.Show(str); return; TimerFunction(); return; string strAcc = "heilongjiangjt"; _GoodsFreshStr objInfo = new _GoodsFreshStr(); DataContrl.GetDataCache(strAcc, ref objInfo); MessageBox.Show(objInfo.iFreshCount.ToString()); objInfo.iFreshCount = 2; //DataContrl.InitFreshTime(); DataContrl.GetDataCache(strAcc, ref objInfo); MessageBox.Show(objInfo.iFreshCount.ToString()); return; IsSetIllegal(); return; _GoodsFreshStr goodInfo = new _GoodsFreshStr(); bool bRet = DataContrl.GetDataCache("heilongjiangjt", ref goodInfo); if (!bRet) { return; } GoodsFresh objFresh = new GoodsFresh(); objFresh.SetWebPost(goodInfo.webPost); bRet = objFresh.Login(goodInfo.strAcc, goodInfo.strPwd,true); string strError = ""; objFresh.FreshQuick(out strError,out strError); }
private bool FreshQuick(ref _GoodsFreshStr goodInfo, GoodsFresh objFresh) { string strError = ""; if (string.IsNullOrEmpty(goodInfo.strLastFreshQuickTime)) { goodInfo.strLastFreshQuickTime = "未知"; } //得到还有的次数显示 goodInfo.strQuickFreshTimeLeft = "未知"; goodInfo.strFreshStatus = "正在登录..."; ShowInfo(goodInfo); bool bRet = objFresh.Login(goodInfo.strAcc, goodInfo.strPwd,true); if (!bRet) { strError = "登录失败"; goodInfo.strFreshStatus = strError; return false; } goodInfo.strFreshStatus = "正在刷新..."; ShowInfo(goodInfo); string strLeft = ""; int iRet = objFresh.FreshQuick(out strError, out strLeft); if (iRet != 0) { goodInfo.strFreshStatus = strError; if (strError == "您今天的刷新次数已用完" || strError == "没有一键刷新权限") { goodInfo.strQuickFreshTimeLeft = "0"; } ShowInfo(goodInfo); return false; } //写入配置文件 goodInfo.strLastFreshQuickTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); //得到还有的次数显示 goodInfo.strQuickFreshTimeLeft = strLeft; ShowInfo(goodInfo); IniUtility.WriteIniKey("set", goodInfo.strAcc + "_lastFreshTime", goodInfo.strLastFreshQuickTime); return true; }
private bool Modify(ref _GoodsFreshStr goodInfo, GoodsFresh objFresh) { goodInfo.strFreshStatus = ""; goodInfo.bModify = true; string strError = ""; Hashtable hWaitTable = new Hashtable(); Hashtable hFailTable = new Hashtable(); //修改失败的价格列表 bool bRet = DataContrl.GetModifyData(goodInfo.strAcc, ref hWaitTable); //得到等待刷新的商品列表 if (!bRet) { goodInfo.strModifyStatus = "无价格刷新列表"; ShowInfo(goodInfo); ShowLogString(strError); return true; } int iTotalCount = hWaitTable.Count; goodInfo.iModifyCount = iTotalCount; goodInfo.strModifyStatus = "登录中..."; ShowInfo(goodInfo); #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); ShowLogString(strError); 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 = "登录失败"; goodInfo.strModifyStatus = strError; ShowInfo(goodInfo); ShowLogString(strError); return false; } goodInfo.strModifyStatus = "修改中..."; ShowInfo(goodInfo); int iCurPage = 1; int iRet = -1; int iModifyCount = 0; int iGoodCount = 0; bool bBreak = false; int iNetErrorCount = 0; while (m_bFresh && !bBreak) { #if __PAOPAO //FreshPaoPao iRet = objFresh.FreshPaoPao(out strError, out iModifyCount, out iGoodCount, out bBreak, iCurPage + 1, true, ref hWaitTable, ref hFailTable, ref iNetErrorCount); #else iRet = objFresh.Fresh(out strError, out iModifyCount, out iGoodCount, out bBreak, iCurPage + 1, true, ref hWaitTable, ref hFailTable, ref iNetErrorCount); #endif goodInfo.strModifyStatus = strError; //成功 if (iRet == 0) { goodInfo.iModifyCount = iTotalCount; goodInfo.iModifySucCount += iModifyCount; goodInfo.strModifyStatus = "修改中..."; if (bBreak) { goodInfo.strModifyStatus = "修改完成"; } } else if (iRet == -3)//网络错误 { goodInfo.strModifyStatus = strError; ShowLogString(string.Format("{0} {1}", iCurPage, strError)); } else if (iRet == -1)//数据错误,直接退出 { ShowLogString("发生数据错误,退出"); ShowLogString(string.Format("{0} {1}", iCurPage, strError)); } else { goodInfo.strModifyStatus = strError; ShowLogString(string.Format("{0} {1}", iCurPage, strError)); } ShowInfo(goodInfo); if ( iRet != -3 ) { iCurPage++; } if (bBreak) { bRet = true; break; } if (iRet == -1) { bRet = false; break; } Thread.Sleep(500); } //DataContrl.AddNeedAddList(goodInfo.strAcc, hFailTable); return bRet; }
private void button1_Click(object sender, EventArgs e) { // _GoodsFreshStr objInfoEx = new _GoodsFreshStr(); //objInfoEx.strAcc = "aaa"; TestStr1 bulder = new TestStr1(); bulder.strAcc = "AAA"; Hashtable tblHash = new Hashtable(); bulder.strAcc = "AAABBB"; _GoodsFreshStr objInfoExEx = new _GoodsFreshStr(); string strDirectoryXls = System.AppDomain.CurrentDomain.BaseDirectory + "xlsfile"; SaveToExcel(strDirectoryXls, null, "aaaaa"); return; GoodsFresh objFreshEx = new GoodsFresh(); ClassHttpPost webPost = new ClassHttpPost(); objFreshEx.SetWebPost(webPost); string strDirect = System.AppDomain.CurrentDomain.BaseDirectory + "pic"; if (!Directory.Exists(strDirect)) { Directory.CreateDirectory(strDirect); } return; //string str = System.Web.HttpUtility.UrlEncode("你好", Encoding.GetEncoding("gb2312")); string str = string.Format("{0} {1}", 519.0, 535.01); MessageBox.Show(str); return; TimerFunction(); return; string strAcc = "heilongjiangjt"; _GoodsFreshStr objInfo = new _GoodsFreshStr(); DataContrl.GetDataCache(strAcc, ref objInfo); MessageBox.Show(objInfo.iFreshCount.ToString()); objInfo.iFreshCount = 2; //DataContrl.InitFreshTime(); DataContrl.GetDataCache(strAcc, ref objInfo); MessageBox.Show(objInfo.iFreshCount.ToString()); return; IsSetIllegal(); return; _GoodsFreshStr goodInfo = new _GoodsFreshStr(); bool bRet = DataContrl.GetDataCache("heilongjiangjt", ref goodInfo); if (!bRet) { return; } GoodsFresh objFresh = new GoodsFresh(); objFresh.SetWebPost(goodInfo.webPost); bRet = objFresh.Login(goodInfo.strAcc, goodInfo.strPwd, true); string strError = ""; objFresh.FreshQuick(out strError, out strError); }