/// <summary> /// 耗时统计 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void button3_Click(object sender, EventArgs e) { string startDate = HttpUtility.UrlEncode(GetDateStr(this.dateTimePicker1, "0"), Encoding.GetEncoding("utf-8")); string endDate = HttpUtility.UrlEncode(GetDateStr(this.dateTimePicker2, "1"), Encoding.GetEncoding("utf-8")); Dictionary <int, string> cityDic = EnumToDictionary <CityEnum>(); List <Dictionary <string, string> > cityDataList = new List <Dictionary <string, string> >(); foreach (var item in cityDic) { Dictionary <string, string> curCityDataDic = new Dictionary <string, string>(); curCityDataDic.Add("CityId", item.Key.ToString()); curCityDataDic.Add("CityName", item.Value); curCityDataDic.Add("ZeroToTwenty", ""); curCityDataDic.Add("TwentyToFourty", ""); curCityDataDic.Add("FourtyToSixty", ""); curCityDataDic.Add("SixtyToBigger", ""); #region 获取耗时Json string url1 = string.Format("http://cqa.91bihu.com/consumingcount/Getcount?cityid={2}&sourec={3}&topagentid=&sta_data={0}&end_data={1}", startDate, endDate, item.Key.ToString(), Config.companyId); string result = HttpHelper.SimpleGetOrPostUrlData(url1, "", "GET"); string resultData = "{\"Result\":" + result.Trim().Trim(new char[] { '{', '}' }) + "}"; GetPriceTimeRoot getPriceTimeRoot = JavaScriptConvert.DeserializeObject <GetPriceTimeRoot>(resultData); #endregion double amount = getPriceTimeRoot.Result.Sum(c => Convert.ToDouble(c.value)); double ZeroToTwenty = Math.Round(getPriceTimeRoot.Result.Where(c => c.name.Contains("0—20")).Sum(d => Convert.ToDouble(d.value)) / amount, 4) * 100; ZeroToTwenty = ZeroToTwenty.ToString() == "非数字" ? 0 : ZeroToTwenty; double TwentyToFourty = Math.Round(getPriceTimeRoot.Result.Where(c => c.name.Contains("20—40")).Sum(d => Convert.ToDouble(d.value)) / amount, 4) * 100; TwentyToFourty = TwentyToFourty.ToString() == "非数字" ? 0 : TwentyToFourty; double FourtyToSixty = Math.Round(getPriceTimeRoot.Result.Where(c => c.name.Contains("40—60")).Sum(d => Convert.ToDouble(d.value)) / amount, 4) * 100; FourtyToSixty = FourtyToSixty.ToString() == "非数字" ? 0 : FourtyToSixty; double SixtyToBigger = Math.Round(100 - (ZeroToTwenty + TwentyToFourty + FourtyToSixty), 2); curCityDataDic["ZeroToTwenty"] = ZeroToTwenty.ToString() + "%"; curCityDataDic["TwentyToFourty"] = TwentyToFourty.ToString() + "%"; curCityDataDic["FourtyToSixty"] = FourtyToSixty.ToString() + "%"; curCityDataDic["SixtyToBigger"] = SixtyToBigger.ToString() + "%"; cityDataList.Add(curCityDataDic); } ExcelHandler.GenTimeExcel(cityDataList); }
/// <summary> /// 成功率统计 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btn1_Click(object sender, EventArgs e) { string startDate = GetDateStr(this.dateTimePicker1, "0"); string endDate = GetDateStr(this.dateTimePicker2, "1"); Dictionary <int, string> cityDic = EnumToDictionary <CityEnum>(); List <Dictionary <string, string> > cityDataList = new List <Dictionary <string, string> >(); foreach (var item in cityDic) { Dictionary <string, string> curCityDataDic = new Dictionary <string, string>(); curCityDataDic.Add("CityId", item.Key.ToString()); curCityDataDic.Add("CityName", item.Value); Dictionary <string, string> retDic = GetSucessedPercent(startDate, endDate, item.Key.ToString()); #region 获取失败原因分布 string curCityErrorInfo = GetErrorinfo(startDate, endDate, item.Key.ToString()); curCityDataDic.Add("ErrorInfo", curCityErrorInfo); #endregion string curSuccessedPercent = retDic["SuccessPercent"]; string Amount = retDic["Amount"]; curCityDataDic.Add("CityPercent", curSuccessedPercent + "%" + string.Format("({0})", Amount)); cityDataList.Add(curCityDataDic); } ExcelHandler.GenScussedExcel(cityDataList); }