public void SaveCMSData() { //读取文件夹下面的所有文件 JavaScriptSerializer jss = new JavaScriptSerializer(); string filePath = System.AppDomain.CurrentDomain.BaseDirectory + "AgentGradeOprationJson"; if (CreateFolderIfNeeded(filePath)) { string[] fileNames = GetAllFileName(filePath); Dictionary <string, int> perDayTicketDict = new Dictionary <string, int>(); List <AgentDetailOperationDatum> agentDetailList = new List <AgentDetailOperationDatum>(); DateTime startDate = DateTime.Parse(textBoxAgentLastDate.Text); startDate = startDate.AddDays(-1); //一次性读完整理完 foreach (string fileName in fileNames) { string json = ReadTxtFile(Path.Combine(filePath, fileName), false); AgentGradeOperationRoot root = jss.Deserialize(json, typeof(AgentGradeOperationRoot)) as AgentGradeOperationRoot; if (root != null && root.data != null && root.data.data != null && root.data.data.Length > 0) { agentDetailList.AddRange(root.data.data); foreach (AgentDetailOperationDatum item in root.data.data) { DateTime curDate = DateTime.Parse(item.statDate); if (curDate == startDate) { continue; } string perDayKey = item.agentDomain.Trim() + curDate.ToString("yyyyMMdd"); if (!perDayTicketDict.ContainsKey(perDayKey)) { perDayTicketDict.Add(perDayKey, item.totalTicketNum); } } } } if (agentDetailList.Count > 0) { //需要分批存储 List <AgentGradeOperation> agoList = GetAgentGradeOperations(agentDetailList, perDayTicketDict); CrmWebService.ApiWebServiceSoapClient ws = new ApiWebServiceSoapClient(); for (int i = 0; i < agoList.Count; i += 1000) { int len = 1000; if (i + len > agoList.Count) { len = agoList.Count - i; } string md5str = GetMd5Str(DateTime.Now.ToString("yyyyMMddHHmm00") + md5hashstr); ws.InsertAgentGradeOprations(agoList.GetRange(i, len).ToArray(), md5str); textBoxAgentGradeResult.AppendText(agoList.Count + ":" + i.ToString() + "\r\n"); } textBoxAgentGradeResult.AppendText("保存成功:" + agoList.Count); } } DeleteAllFile(filePath); //清空旧的 }
private void buttonGetAllPageCmsReponse_Click(object sender, EventArgs e) { //计算页数,然后从第一页开始翻页 int totalCount = int.Parse(textBoxCmsTotalcount.Text); int pageCount = totalCount / 30; pageCount++; List <CompanyCmsData> pagecmsList = new List <CompanyCmsData>(); for (int i = 1; i <= pageCount; i++) { string html = GetCmsPageHtml(i, totalCount); int temp = 0; List <CompanyCmsData> ccdList = GenerateCCDList(html, out temp); pagecmsList.AddRange(ccdList); } string compactStr = ""; for (int i = 0; i < pagecmsList.Count; i++) { compactStr += pagecmsList[i].CmsId.Value.ToString() + "^" + pagecmsList[i].CompanyName + "^" + pagecmsList[i].TTSStatusDesp + "^" + pagecmsList[i].SalesName + "\r\n"; } WriteFile(compactStr, "cms.txt", false); CrmWebService.ApiWebServiceSoapClient ws = new ApiWebServiceSoapClient(); //然后每个获取详情 List <CompanyCmsData> result = new List <CompanyCmsData>(); //每一个公司进去抓取更加详细的信息 for (int i = 0; i < pagecmsList.Count; i++) { //获取详细的html string detailhtml = GetCmsDetailHtml(pagecmsList[i].CmsId.Value); //把html转成对象 CompanyCmsData dItem = GenerateCCD(detailhtml); if (dItem == null || string.IsNullOrEmpty(dItem.RealAddress)) { textBoxCmsResult.AppendText(pagecmsList[i].CmsId.Value.ToString() + ":失败\r\n"); } else { //重新赋值对象 dItem.CmsId = pagecmsList[i].CmsId; dItem.CompanyName = pagecmsList[i].CompanyName; dItem.TTSStatusDesp = pagecmsList[i].TTSStatusDesp; dItem.SalesName = pagecmsList[i].SalesName; result.Add(dItem); textBoxCmsResult.AppendText(pagecmsList[i].CmsId.Value.ToString() + ":成功\r\n"); } if (result.Count > 100) { string md5str = GetMd5Str(DateTime.Now.ToString("yyyyMMddHHmm00") + md5hashstr); ws.InsertCompanyCms(result.ToArray(), md5str); textBoxCmsResult.AppendText("100"); result = new List <CompanyCmsData>(); } } if (result.Count > 0) { string md5str = GetMd5Str(DateTime.Now.ToString("yyyyMMddHHmm00") + md5hashstr); ws.InsertCompanyCms(result.ToArray(), md5str); textBoxCmsResult.AppendText("100"); result = new List <CompanyCmsData>(); } }