コード例 #1
0
ファイル: Form1.cs プロジェクト: coderli7/WinForm
        /// <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);
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: coderli7/WinForm
        private string GetErrorinfo(string startDate, String endDate, string cityid = "-1")
        {
            string errorInfo = "";

            try
            {
                startDate = HttpUtility.UrlEncode(startDate, Encoding.GetEncoding("utf-8"));
                endDate   = HttpUtility.UrlEncode(endDate, Encoding.GetEncoding("utf-8"));
                string getErrorUrl = string.Format("http://cqa.91bihu.com/ErrorType/Index?cityid={2}&sourec={3}&topagentid=&sta_data={0}&end_data={1}", startDate, endDate, cityid, Config.companyId);
                string errorHtml   = HttpHelper.SimpleGetOrPostUrlData(getErrorUrl, "", "GET");
                HtmlAgilityPack.HtmlDocument hd = new HtmlAgilityPack.HtmlDocument();
                hd.LoadHtml(errorHtml);
                HtmlNode node = hd.GetElementbyId("data");
                if (node != null)
                {
                    string jsonResult = node.InnerHtml.Trim().Replace("&quot;", "\"");
                    jsonResult = "{\"Result\":" + jsonResult.Trim().Trim(new char[] { '{', '}' }) + "}";
                    GetPriceTimeRoot jsonResultRoot = JavaScriptConvert.DeserializeObject <GetPriceTimeRoot>(jsonResult);
                    double           Amount         = jsonResultRoot.Result.Sum(c => Convert.ToDouble(c.value));
                    StringBuilder    errorSb        = new StringBuilder();
                    foreach (var item in jsonResultRoot.Result.OrderByDescending(c => Convert.ToDouble(c.value)))
                    {
                        double curCoun      = item.value;
                        string percent      = Math.Round((curCoun / Amount) * 100, 2) + "%";
                        string curErrorInfo = string.Format("{0}\t\t{1}个,占比 ({2})", item.name, item.value, percent);
                        errorSb.AppendLine(curErrorInfo);
                    }
                    errorInfo = errorSb.ToString();
                }
            }
            catch (Exception ex)
            {
                this.richTextBox1.AppendText(string.Format("执行函数GetErrorinfo发生异常:{0}", ex.Message));
            }
            return(errorInfo);
        }