Ejemplo n.º 1
0
        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);    //清空旧的
        }
Ejemplo n.º 2
0
        private void buttonGetAllData_Click(object sender, EventArgs e)
        {
            buttonGetAllAgentGradeData.Enabled = false;
            textBoxAgentGradeResult.AppendText("数据导入中....");
            //连取三个月数据,先执行按天的查询,最后结束的时候查一个月的统计,把jason保存到文件,然后再for循环保存
            DateTime curMonth         = DateTime.Parse(DateTime.Today.ToString("yyyy-MM-01"));
            DateTime lastDate         = curMonth.AddMonths(-2);
            string   lastDateFilePath = "lastdate.txt";
            string   lastDateStr      = textBoxAgentLastDate.Text;

            if (!string.IsNullOrEmpty(lastDateStr))
            {
                lastDate = DateTime.Parse(lastDateStr);
            }

            string        domain     = "checking.corp.qunar.com";
            List <Cookie> cookieList = GetDomainCookies(domain, textBoxAgentGradeCookie.Text);
            int           limit      = 50;
            string        filePath   = System.AppDomain.CurrentDomain.BaseDirectory + "AgentGradeOprationJson";

            CreateFolderIfNeeded(filePath);
            DeleteAllFile(filePath);    //清空旧的
            JavaScriptSerializer jss = new JavaScriptSerializer();
            //从2个月前开始发扫
            DateTime startDate = lastDate.AddDays(-1);
            DateTime endDate   = startDate.AddMonths(1).AddDays(-1);

            for (int i = 0; i < 3; i++)
            {
                startDate = lastDate.AddMonths(i);
                if (startDate > DateTime.Today)
                {
                    break;
                }
                endDate = startDate.AddMonths(1).AddDays(-1);
                if (endDate > DateTime.Today)
                {
                    endDate = DateTime.Today;
                }
                TimeSpan ts = endDate - startDate;
                for (int j = 0; j <= ts.Days; j++)
                {
                    int      pageIndex = 1;
                    DateTime curDate   = startDate.AddDays(j);
                    //获取第一页,然后获取到totalcount,然后再翻页
                    string firstDayJson = GetDayAgentGradeOprationJson(cookieList.ToArray(), curDate, limit, pageIndex);

                    string fileName = curDate.ToString("yyyyMMdd") + "_" + pageIndex + ".txt";
                    WriteFile(firstDayJson, Path.Combine(filePath, fileName), false);
                    AgentGradeOperationRoot agentGradeOperation = jss.Deserialize(firstDayJson, typeof(AgentGradeOperationRoot)) as AgentGradeOperationRoot;
                    int totalPage = agentGradeOperation.data.totalPage;
                    for (int x = 1; x < totalPage; x++)
                    {
                        int    curPageIndex = pageIndex + x;
                        string json         = GetDayAgentGradeOprationJson(cookieList.ToArray(), curDate, limit, curPageIndex);
                        fileName = curDate.ToString("yyyyMMdd") + "_" + curPageIndex + ".txt";
                        WriteFile(json, Path.Combine(filePath, fileName), false);
                    }
                    textBoxAgentGradeResult.AppendText(fileName + ":" + totalPage + "\r\n");
                }
            }
            WriteFile(endDate.ToString("yyyy-MM-dd"), lastDateFilePath, false);
            //直接执行保存
            SaveCMSData();
            MessageBox.Show("任务执行完成.");
        }
Ejemplo n.º 3
0
 private void buttonParseJson_Click(object sender, EventArgs e)
 {
     string json = textBoxAgentGradeResult.Text;
     JavaScriptSerializer    jss = new JavaScriptSerializer();
     AgentGradeOperationRoot agentGradeOperation = jss.Deserialize(json, typeof(AgentGradeOperationRoot)) as AgentGradeOperationRoot;
 }