县级监管平台

InfoController.cs 82KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007
  1. using CallCenterApi.Common;
  2. using CallCenterApi.Interface.Controllers.Base;
  3. using Newtonsoft.Json;
  4. using Newtonsoft.Json.Linq;
  5. using System;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. using System.Data;
  9. using System.Linq;
  10. using System.Web;
  11. using System.Web.Mvc;
  12. using System.Web.Script.Serialization;
  13. namespace CallCenterApi.Interface.Controllers
  14. {
  15. /// <summary>
  16. /// 大屏公示系统
  17. /// </summary>
  18. //[Authority]
  19. public class InfoController : BaseController
  20. {
  21. // GET: Info
  22. public ActionResult Index()
  23. {
  24. return View();
  25. }
  26. #region 来源渠道
  27. /// <summary>
  28. /// 获取受理区域数量
  29. /// </summary>
  30. /// <param name="branchcode"></param>
  31. /// <param name="date"></param>
  32. /// <returns></returns>
  33. public ActionResult GetAreaCount24ByDate(string branchcode, DateTime? date,string areaid)
  34. {
  35. if (date == null)
  36. {
  37. date = DateTime.Now;
  38. }
  39. int backtotal = 0;
  40. //string sqlwhere = " F_IsDelete=0 ";
  41. string sqlwhere = " F_IsDP=1 ";//大屏展示用到的
  42. if (branchcode == "sqs12345")
  43. {
  44. branchcode = "";
  45. sqlwhere += " and F_IsSQS='0";
  46. }
  47. if (!string.IsNullOrEmpty(branchcode))
  48. {
  49. sqlwhere += " and F_Code='" + branchcode + "'";
  50. }
  51. else
  52. {
  53. backtotal = 1;
  54. sqlwhere += " and F_IsSQ!=1";
  55. }
  56. int first = 1;
  57. int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  58. decimal[,] countstotal=new decimal [10,24];//用于计算累计值//固定了10个市县区
  59. decimal[] tcountstotal = new decimal[10];
  60. string[] cols=new string [10];
  61. string[] colsx = new string[1];//用于县数据相加
  62. //List<object> items;
  63. List<List<Dictionary<string, object>>> items = new List<List<Dictionary<string, object>>>();
  64. //IEnumerable<List<Dictionary<string, object>>> items;
  65. ArrayList result = new ArrayList();
  66. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  67. string controllername = RouteData.Values["controller"].ToString();
  68. string actionname = RouteData.Values["action"].ToString();
  69. foreach (var l in list)
  70. {
  71. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  72. {
  73. if (!string.IsNullOrEmpty(l.F_AreaId))
  74. {
  75. areaid = l.F_AreaId;
  76. }
  77. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  78. string strparams = "?date=" + date.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode ;
  79. //AjaxResult ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams).ToObject<AjaxResult>();
  80. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);
  81. if (!string.IsNullOrEmpty(branchcode))
  82. {
  83. return Content(ar);//查询单个时直接返回
  84. }
  85. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  86. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  87. {
  88. if (first == 1)
  89. {
  90. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["cols"].ToString(), "[\r\n\t ]", "");
  91. a = a.Replace("[", "");
  92. a = a.Replace("]", "");
  93. a = a.Replace("\"", "");
  94. cols = a.Split(',');
  95. }
  96. else
  97. {
  98. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["cols"].ToString(), "[\r\n\t ]", "");
  99. a = a.Replace("[", "");
  100. a = a.Replace("]", "");
  101. a = a.Replace("\"", "");
  102. colsx = a.Split(',');
  103. }
  104. //string x = jo0["data"].ToString();
  105. for (int i = 0; i < 10;i++)
  106. {
  107. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["counts"][i].ToString(), "[\r\n\t ]", "");
  108. y = y.Replace("[", "");
  109. y = y.Replace("]", "");
  110. string[] z = y.Split(',');
  111. for (int m = 0; m < z.Length; m++)
  112. {
  113. if (first == 1)
  114. {
  115. countstotal[i, m] = decimal.Parse(z[m]);
  116. }
  117. else if (backtotal == 1)
  118. {
  119. if (cols[i] == colsx[0])
  120. {
  121. countstotal[i, m] += decimal.Parse(z[m]);
  122. }
  123. }
  124. }
  125. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["tcounts"].ToString(), "[\r\n\t ]", "");
  126. p = p.Replace("[", "");
  127. p = p.Replace("]", "");
  128. string[] q = p.Split(',');
  129. if (backtotal == 1)
  130. {
  131. if (cols[i] == colsx[0])
  132. {
  133. tcountstotal[i] += decimal.Parse(q[0]);
  134. }
  135. }
  136. else
  137. {
  138. tcountstotal[i] += decimal.Parse(q[i]);
  139. }
  140. //item计算
  141. if (backtotal == 1)
  142. {
  143. if (cols[i] == colsx[0])
  144. {
  145. var rtlist = jo0["data"]["items"][0].ToJson().ToList<Dictionary<string, object>>();
  146. for (int r = 0; r < rtlist.Count; r++)
  147. {
  148. decimal zh = 0;
  149. if (items.Count > i)
  150. {
  151. zh = decimal.Parse(items[i][r]["Count"].ToString());
  152. }
  153. rtlist[r]["Count"] = zh + decimal.Parse(rtlist[r]["Count"].ToString());
  154. }
  155. //List<Dictionary<string, object>> li = new List<Dictionary<string, object>>();
  156. //li.AddRange(rtlist );
  157. items.Add(rtlist);
  158. }
  159. }
  160. else
  161. {
  162. var rtlist = jo0["data"]["items"][i].ToJson().ToList<Dictionary<string, object>>();
  163. items.Add(rtlist);
  164. }
  165. }
  166. first = 0;
  167. }
  168. }
  169. }
  170. var data = new
  171. {
  172. hours = hours,
  173. cols ,
  174. counts=countstotal,
  175. tcounts = tcountstotal ,
  176. items
  177. };
  178. return Success("成功", data);
  179. }
  180. /// <summary>
  181. /// 获取受理区域数量
  182. /// </summary>
  183. /// <param name="branchcode"></param>
  184. /// <param name="start"></param>
  185. /// <param name="end"></param>
  186. /// <returns></returns>
  187. public ActionResult GetAreaCountByDate(string branchcode, DateTime? start, DateTime? end, string areaid)
  188. {
  189. if (start == null && end == null)
  190. {
  191. start = DateTime.Now;
  192. end = DateTime.Now;
  193. }
  194. else
  195. {
  196. if (start == null) { start = DateTime.Now; }
  197. if (end == null) { end = DateTime.Now; }
  198. }
  199. int backtotal = 0;
  200. string sqlwhere = " F_IsDP=1 ";
  201. if (branchcode == "sqs12345")
  202. {
  203. branchcode = "";
  204. }
  205. if (!string.IsNullOrEmpty(branchcode))
  206. {
  207. sqlwhere += " and F_Code='" + branchcode + "'";
  208. }
  209. else
  210. {
  211. backtotal = 1;
  212. sqlwhere += " and F_IsSQ!=1";
  213. }
  214. #region 定义新表
  215. DataTable dtnew = new DataTable();
  216. dtnew.Columns.Add("F_AreaId");
  217. dtnew.Columns.Add("AreaName");
  218. dtnew.Columns.Add("Count");
  219. int first = 1;
  220. #endregion
  221. ArrayList result = new ArrayList();
  222. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  223. string controllername = RouteData.Values["controller"].ToString();
  224. string actionname = RouteData.Values["action"].ToString();
  225. foreach (var l in list)
  226. {
  227. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  228. {
  229. if (!string.IsNullOrEmpty(l.F_AreaId))
  230. {
  231. areaid = l.F_AreaId;
  232. }
  233. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  234. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&backtotal=" + backtotal + "&isdpjk=1" + "&signcode=" + signcode;
  235. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  236. if (!string.IsNullOrEmpty(branchcode))
  237. {
  238. return Content(ar);//查询单个时直接返回
  239. }
  240. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  241. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  242. {
  243. if (first == 1)
  244. {
  245. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  246. dtnew = dt;
  247. dtnew.Columns.Add("Item", typeof(object));
  248. for (int i = 0; i < dt.Rows.Count; i++)
  249. {
  250. dtnew.Rows[i]["Item"] = jo0["data"][i]["Item"];
  251. }
  252. first = 0;
  253. }
  254. else
  255. {
  256. for (int m = 0; m < dtnew.Rows.Count; m++)
  257. {
  258. //前部分相加
  259. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  260. for (int i = 0; i < dt1.Rows.Count; i++)
  261. {
  262. if (dtnew.Rows[m][1].ToString() == dt1.Rows[i][1].ToString())
  263. {
  264. decimal t = decimal.Parse(dtnew.Rows[i][2].ToString()) + decimal.Parse(dt1.Rows[i][2].ToString());
  265. dtnew.Rows[i][2] = t;
  266. //后半部分两个datatable相加
  267. DataTable dtitem = new DataTable();
  268. string c = jo0["data"][i]["Item"].ToString();
  269. DataTable dt = HeadToDataTable(jo0["data"][i]["Item"].ToString(), "Item");
  270. dtitem = dt;
  271. DataTable dtold = HeadToDataTable(dtnew.Rows[i]["Item"].ToString(), "Item");
  272. for (int j = 0; j < dtold.Rows.Count; j++)
  273. {
  274. dtitem.Rows[j][1] = decimal.Parse(dtold.Rows[j][1].ToString()) + decimal.Parse(dt.Rows[j][1].ToString());
  275. }
  276. dtnew.Rows[i]["Item"] = dtitem;
  277. }
  278. }
  279. }
  280. }
  281. }
  282. }
  283. }
  284. return Success("成功", dtnew);
  285. }
  286. /// <summary>
  287. /// 获取来源百分比
  288. /// </summary>
  289. /// <param name="branchcode"></param>
  290. /// <param name="start"></param>
  291. /// <param name="end"></param>
  292. /// <returns></returns>
  293. public ActionResult GetSourcePercentByDate(string branchcode, DateTime? start, DateTime? end, string areaid)
  294. {
  295. if (start == null && end == null)
  296. {
  297. start = DateTime.Now;
  298. end = DateTime.Now;
  299. }
  300. else
  301. {
  302. if (start == null) { start = DateTime.Now; }
  303. if (end == null) { end = DateTime.Now; }
  304. }
  305. string sqlwhere = " F_IsDP=1 ";
  306. if (branchcode == "sqs12345")
  307. {
  308. branchcode = "";
  309. }
  310. if (!string.IsNullOrEmpty(branchcode))
  311. {
  312. sqlwhere += " and F_Code='" + branchcode + "'";
  313. }
  314. else
  315. {
  316. sqlwhere += " and F_IsSQ!=1";
  317. }
  318. #region 定义新表
  319. DataTable dtnew = new DataTable();
  320. dtnew.Columns.Add("Id");
  321. dtnew.Columns.Add("Source");
  322. dtnew.Columns.Add("Count");
  323. dtnew.Columns.Add("Percent");
  324. int first = 1;
  325. decimal totalcount = 0;//用于计算百分比
  326. #endregion
  327. ArrayList result = new ArrayList();
  328. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  329. string controllername = RouteData.Values["controller"].ToString();
  330. string actionname = RouteData.Values["action"].ToString();
  331. foreach (var l in list)
  332. {
  333. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  334. {
  335. if (!string.IsNullOrEmpty(l.F_AreaId))
  336. {
  337. areaid = l.F_AreaId;
  338. }
  339. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  340. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&isdpjk=1" + "&signcode=" + signcode;
  341. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  342. if (!string.IsNullOrEmpty(branchcode))
  343. {
  344. return Content(ar);//查询单个时直接返回
  345. }
  346. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  347. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  348. {
  349. if (first == 1)
  350. {
  351. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  352. dtnew = dt;
  353. dtnew.Columns.Add("Item", typeof(object));
  354. for (int i = 0; i < dt.Rows.Count; i++)
  355. {
  356. dtnew.Rows[i]["Item"] = jo0["data"][i]["Item"];
  357. }
  358. first = 0;
  359. }
  360. else
  361. {
  362. //前部分相加
  363. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  364. for (int i = 0; i < dt1.Rows.Count; i++)
  365. {
  366. decimal t = decimal.Parse(dtnew.Rows[i][2].ToString()) + decimal.Parse(dt1.Rows[i][2].ToString());
  367. totalcount += t;
  368. dtnew.Rows[i][2] = t;
  369. }
  370. //后半部分两个datatable相加
  371. for (int i = 0; i < dtnew.Rows.Count; i++)
  372. {
  373. DataTable dtitem = new DataTable();
  374. string c = jo0["data"][i]["Item"].ToString();
  375. DataTable dt = HeadToDataTable(jo0["data"][i]["Item"].ToString(), "Item");
  376. dtitem = dt;
  377. DataTable dtold = HeadToDataTable(dtnew.Rows[i]["Item"].ToString(), "Item");
  378. for (int j = 0; j < dtold.Rows.Count; j++)
  379. {
  380. dtitem.Rows[j][1] = decimal.Parse(dtold.Rows[j][1].ToString()) + decimal.Parse(dt.Rows[j][1].ToString());
  381. }
  382. dtnew.Rows[i]["Item"] = dtitem;
  383. }
  384. }
  385. //var rtlist = ar.data.ToJson().ToList<Dictionary<string, object>>();
  386. //result.AddRange(rtlist);
  387. }
  388. }
  389. }
  390. //计算百分比
  391. if (totalcount > 0)
  392. {
  393. for (int m = 0; m < dtnew.Rows.Count; m++)
  394. {
  395. dtnew.Rows[m]["Percent"] = Math.Round(decimal.Parse(dtnew.Rows[m]["Count"].ToString()) / totalcount * 100, 2);
  396. }
  397. }
  398. return Success("成功", dtnew );
  399. }
  400. /// <summary>
  401. /// 获取来源数量百分比
  402. /// </summary>
  403. /// <param name="branchcode"></param>
  404. /// <param name="start"></param>
  405. /// <param name="end"></param>
  406. /// <returns></returns>
  407. public ActionResult GetSourceByDate(string branchcode, DateTime? start, DateTime? end, string areaid)
  408. {
  409. if (start == null && end == null)
  410. {
  411. start = DateTime.Now;
  412. end = DateTime.Now;
  413. }
  414. else
  415. {
  416. if (start == null) { start = DateTime.Now; }
  417. if (end == null) { end = DateTime.Now; }
  418. }
  419. string sqlwhere = " F_IsDP=1 ";
  420. if (branchcode == "sqs12345")
  421. {
  422. branchcode = "";
  423. }
  424. if (!string.IsNullOrEmpty(branchcode))
  425. {
  426. sqlwhere += " and F_Code='" + branchcode + "'";
  427. }
  428. else
  429. {
  430. sqlwhere += " and F_IsSQ!=1";
  431. }
  432. #region 定义新表
  433. DataTable dtnew = new DataTable();
  434. dtnew.Columns.Add("Id");
  435. dtnew.Columns.Add("Source");
  436. dtnew.Columns.Add("Count");
  437. //dtnew.Columns.Add("Percent");
  438. int first = 1;
  439. decimal totalcount = 0;
  440. #endregion
  441. ArrayList result = new ArrayList();
  442. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  443. string controllername = RouteData.Values["controller"].ToString();
  444. string actionname = RouteData.Values["action"].ToString();
  445. foreach (var l in list)
  446. {
  447. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  448. {
  449. if (!string.IsNullOrEmpty(l.F_AreaId))
  450. {
  451. areaid = l.F_AreaId;
  452. }
  453. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  454. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&isdpjk=1" + "&signcode=" + signcode;
  455. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  456. if (!string.IsNullOrEmpty(branchcode))
  457. {
  458. return Content(ar);//查询单个时直接返回
  459. }
  460. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  461. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  462. {
  463. if (first == 1)
  464. {
  465. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  466. dtnew = dt;
  467. //dtnew.Columns.Add("Percent", typeof(object));
  468. first = 0;
  469. }
  470. else
  471. {
  472. //前部分相加
  473. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  474. for (int i = 0; i < dt1.Rows.Count; i++)
  475. {
  476. decimal t = decimal.Parse(dtnew.Rows[i][2].ToString()) + decimal.Parse(dt1.Rows[i][2].ToString());
  477. dtnew.Rows[i][2] = t;
  478. if (dtnew.Rows[i]["Source"].ToString () == "总计")
  479. {
  480. totalcount = t;
  481. }
  482. }
  483. }
  484. }
  485. }
  486. }
  487. //计算百分比
  488. //dtnew.Columns.Add("Percent", typeof(object));
  489. if (totalcount > 0)
  490. {
  491. for (int m = 0; m < dtnew.Rows.Count; m++)
  492. {
  493. dtnew.Rows[m]["Percent"] = Math.Round(decimal.Parse(dtnew.Rows[m]["Count"].ToString()) / totalcount * 100, 2).ToString ()+"%";
  494. }
  495. }
  496. return Success("成功", dtnew);
  497. }
  498. #endregion
  499. #region 接单部门
  500. /// <summary>
  501. /// 接单情况汇总(月份)
  502. /// </summary>
  503. /// <param name="branchcode"></param>
  504. /// <returns></returns>
  505. public ActionResult GetStateCountMonthByDate(string branchcode, string areaid)
  506. {
  507. if (branchcode == "sqs12345")
  508. {
  509. branchcode = "";
  510. }
  511. string sqlwhere = " F_IsDP=1 ";
  512. if (!string.IsNullOrEmpty(branchcode))
  513. {
  514. sqlwhere += " and F_Code='" + branchcode + "'";
  515. }
  516. else
  517. {
  518. sqlwhere += " and F_IsSQ!=1";
  519. }
  520. decimal[,] countstotal = new decimal[10, 12];//用于计算累计值
  521. string[] cols = new string[10];
  522. string[] months = new string[12];
  523. ArrayList result = new ArrayList();
  524. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  525. string controllername = RouteData.Values["controller"].ToString();
  526. string actionname = RouteData.Values["action"].ToString();
  527. foreach (var l in list)
  528. {
  529. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  530. {
  531. if (!string.IsNullOrEmpty(l.F_AreaId))
  532. {
  533. areaid = l.F_AreaId;
  534. }
  535. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  536. string strparams = "?signcode=" + signcode + "&areaid=" + areaid;
  537. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  538. if (!string.IsNullOrEmpty(branchcode))
  539. {
  540. return Content(ar);//查询单个时直接返回
  541. }
  542. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  543. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  544. {
  545. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["cols"].ToString(), "[\r\n\t ]", "");
  546. a = a.Replace("[", "");
  547. a = a.Replace("]", "");
  548. a = a.Replace("\"", "");
  549. cols = a.Split(',');
  550. string b = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["months"].ToString(), "[\r\n\t ]", "");
  551. b = b.Replace("[", "");
  552. b = b.Replace("]", "");
  553. b = b.Replace("\"", "");
  554. months = b.Split(',');
  555. for (int i = 0; i < 10; i++)
  556. {
  557. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["counts"][i].ToString(), "[\r\n\t ]", "");
  558. y = y.Replace("[", "");
  559. y = y.Replace("]", "");
  560. string[] z = y.Split(',');
  561. for (int m = 0; m < z.Length; m++)
  562. {
  563. countstotal[i, m] += decimal.Parse(z[m]);
  564. }
  565. }
  566. }
  567. }
  568. }
  569. var data = new
  570. {
  571. months,
  572. cols,
  573. counts = countstotal
  574. };
  575. return Success("成功", data);
  576. }
  577. /// <summary>
  578. /// 获取承办单位数量(因为是获取部门的所以未调整)
  579. /// </summary>
  580. /// <param name="branchcode"></param>
  581. /// <param name="start"></param>
  582. /// <param name="end"></param>
  583. /// <param name="deptid"></param>
  584. /// <returns></returns>
  585. public ActionResult GetDeptCountByDateNew(string branchcode, DateTime? start, DateTime? end, string areaid, int deptid = 0)
  586. {
  587. if (branchcode == "sqs12345")
  588. {
  589. branchcode = "";
  590. }
  591. if (start == null && end == null)
  592. {
  593. start = DateTime.Now;
  594. end = DateTime.Now;
  595. }
  596. else
  597. {
  598. if (start == null) { start = DateTime.Now; }
  599. if (end == null) { end = DateTime.Now; }
  600. }
  601. string sqlwhere = " F_IsDP=1 ";
  602. if (!string.IsNullOrEmpty(branchcode))
  603. {
  604. sqlwhere += " and F_Code='" + branchcode + "'";
  605. }
  606. else
  607. {
  608. sqlwhere += " and F_IsSQ!=1";
  609. }
  610. ArrayList result = new ArrayList();
  611. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  612. string controllername = RouteData.Values["controller"].ToString();
  613. string actionname = RouteData.Values["action"].ToString();
  614. foreach (var l in list)
  615. {
  616. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  617. {
  618. if (!string.IsNullOrEmpty(l.F_AreaId))
  619. {
  620. areaid = l.F_AreaId;
  621. }
  622. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  623. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&deptid=" + deptid .ToString() + "&areaid=" + areaid + "&signcode=" + signcode;
  624. AjaxResult ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams).ToObject<AjaxResult>();
  625. if (ar.state.ToString() == ResultTypes.success.ToString())
  626. {
  627. var rtlist = ar.data.ToJson().ToList<Dictionary<string, object>>();
  628. result.AddRange(rtlist);
  629. }
  630. }
  631. }
  632. return Success("成功", result);
  633. }
  634. /// <summary>
  635. /// 单位受理处理时间分布
  636. /// </summary>
  637. /// <param name="branchcode"></param>
  638. /// <param name="date"></param>
  639. /// <returns></returns>
  640. public ActionResult GetDealCount24ByDate(string branchcode, DateTime? date, string areaid)
  641. {
  642. if (branchcode == "sqs12345")
  643. {
  644. branchcode = "";
  645. }
  646. if (date == null)
  647. {
  648. date = DateTime.Now;
  649. }
  650. string sqlwhere = " F_IsDP=1 ";
  651. if (!string.IsNullOrEmpty(branchcode))
  652. {
  653. sqlwhere += " and F_Code='" + branchcode + "'";
  654. }
  655. else
  656. {
  657. sqlwhere += " and F_IsSQ!=1";
  658. }
  659. int[] hours = Enumerable.Range(7, 12).ToArray<int>();
  660. int[] acounts = new int[12];
  661. int[] fcounts = new int[12];
  662. ArrayList result = new ArrayList();
  663. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  664. string controllername = RouteData.Values["controller"].ToString();
  665. string actionname = RouteData.Values["action"].ToString();
  666. foreach (var l in list)
  667. {
  668. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  669. {
  670. if (!string.IsNullOrEmpty(l.F_AreaId))
  671. {
  672. areaid = l.F_AreaId;
  673. }
  674. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  675. string strparams = "?date=" + date.Value.ToString("yyyy-MM-dd") + "&signcode=" + signcode + "&areaid=" + areaid;
  676. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  677. if (!string.IsNullOrEmpty(branchcode))
  678. {
  679. return Content(ar);//查询单个时直接返回
  680. }
  681. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  682. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  683. {
  684. for (int i = 0; i < 10; i++)
  685. {
  686. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["acounts"].ToString(), "[\r\n\t ]", "");
  687. p = p.Replace("[", "");
  688. p = p.Replace("]", "");
  689. string[] q = p.Split(',');
  690. acounts[i] += int.Parse(q[i]);
  691. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["fcounts"].ToString(), "[\r\n\t ]", "");
  692. a = a.Replace("[", "");
  693. a = a.Replace("]", "");
  694. string[] b = a.Split(',');
  695. fcounts[i] += int.Parse(b[i]);
  696. }
  697. }
  698. }
  699. }
  700. var data = new
  701. {
  702. hours,
  703. acounts,
  704. fcounts
  705. };
  706. return Success("成功", data);
  707. }
  708. /// <summary>
  709. /// 接单情况汇总(月份)
  710. /// </summary>
  711. /// <param name="branchcode"></param>
  712. /// <param name="month"></param>
  713. /// <param name="day"></param>
  714. /// <returns></returns>
  715. public ActionResult GetStateCountByMonth(string branchcode, string month, string day, string areaid)
  716. {
  717. if (branchcode == "sqs12345")
  718. {
  719. branchcode = "";
  720. }
  721. if (string.IsNullOrEmpty(month))
  722. {
  723. month = DateTime.Now.ToString("yyyy-MM");
  724. }
  725. if (string.IsNullOrEmpty(day))
  726. {
  727. day = "";
  728. }
  729. string sqlwhere = " F_IsDP=1 ";
  730. if (!string.IsNullOrEmpty(branchcode))
  731. {
  732. sqlwhere += " and F_Code='" + branchcode + "'";
  733. }
  734. else
  735. {
  736. sqlwhere += " and F_IsSQ!=1";
  737. }
  738. #region 定义新表
  739. DataTable dtnew = new DataTable();
  740. dtnew.Columns.Add("State");
  741. dtnew.Columns.Add("Name");
  742. dtnew.Columns.Add("Count");
  743. int first = 1;
  744. #endregion
  745. ArrayList result = new ArrayList();
  746. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  747. string controllername = RouteData.Values["controller"].ToString();
  748. string actionname = RouteData.Values["action"].ToString();
  749. foreach (var l in list)
  750. {
  751. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  752. {
  753. if (!string.IsNullOrEmpty(l.F_AreaId))
  754. {
  755. areaid = l.F_AreaId;
  756. }
  757. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  758. string strparams = "?month=" + month + "&day=" + day + "&areaid=" + areaid + "&isdpjk=1" + "&signcode=" + signcode;
  759. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  760. if (!string.IsNullOrEmpty(branchcode))
  761. {
  762. return Content(ar);//查询单个时直接返回
  763. }
  764. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  765. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  766. {
  767. if (first == 1)
  768. {
  769. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  770. dtnew = dt;
  771. first = 0;
  772. }
  773. else
  774. {
  775. //前部分相加
  776. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  777. for (int i = 0; i < dt1.Rows.Count; i++)
  778. {
  779. decimal t = decimal.Parse(dtnew.Rows[i][2].ToString()) + decimal.Parse(dt1.Rows[i][2].ToString());
  780. dtnew.Rows[i][2] = t;
  781. }
  782. }
  783. }
  784. }
  785. }
  786. return Success("成功", dtnew );
  787. }
  788. #endregion
  789. #region 投诉类型
  790. /// <summary>
  791. /// 接单情况汇总(月份)
  792. /// </summary>
  793. /// <param name="branchcode"></param>
  794. /// <param name="start"></param>
  795. /// <param name="end"></param>
  796. /// <returns></returns>
  797. public ActionResult GetTypeCountMonthByDate(string branchcode, string start, string end, string areaid)
  798. {
  799. if (branchcode == "sqs12345")
  800. {
  801. branchcode = "";
  802. }
  803. string sqlwhere = " F_IsDP=1 ";
  804. if (!string.IsNullOrEmpty(branchcode))
  805. {
  806. sqlwhere += " and F_Code='" + branchcode + "'";
  807. }
  808. else
  809. {
  810. sqlwhere += " and F_IsSQ!=1";
  811. }
  812. #region 变量定义
  813. DateTime startdate = DateTime.Now.AddMonths(-12);
  814. DateTime enddate = DateTime.Now;
  815. if (!string.IsNullOrEmpty(start))
  816. {
  817. startdate = DateTime.Parse(start + "-01");
  818. }
  819. if (!string.IsNullOrEmpty(end))
  820. {
  821. enddate = DateTime.Parse(end + "-01");
  822. }
  823. int cnt = (enddate.Year - startdate.Year) * 12 + enddate.Month - startdate.Month + 1;
  824. string[] months = new string[cnt];
  825. decimal[,] counts = new decimal[6, cnt];//用于计算累计值//固定了10个市县区
  826. string[] cols = new string[6];
  827. #endregion
  828. ArrayList result = new ArrayList();
  829. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  830. string controllername = RouteData.Values["controller"].ToString();
  831. string actionname = RouteData.Values["action"].ToString();
  832. foreach (var l in list)
  833. {
  834. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  835. {
  836. if (!string.IsNullOrEmpty(l.F_AreaId))
  837. {
  838. areaid = l.F_AreaId;
  839. }
  840. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  841. string strparams = "?start=" + start + "&end=" + end + "&areaid=" + areaid + "&signcode=" + signcode;
  842. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  843. if (!string.IsNullOrEmpty(branchcode))
  844. {
  845. return Content(ar);//查询单个时直接返回
  846. }
  847. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  848. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  849. {
  850. for (int i = 0; i < 6; i++)
  851. {
  852. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["counts"][i].ToString(), "[\r\n\t ]", "");
  853. y = y.Replace("[", "");
  854. y = y.Replace("]", "");
  855. string[] z = y.Split(',');
  856. for (int m = 0; m < z.Length; m++)
  857. {
  858. counts[i, m] += decimal.Parse(z[m]);
  859. }
  860. }
  861. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["cols"].ToString(), "[\r\n\t ]", "");
  862. a = a.Replace("[", "");
  863. a = a.Replace("]", "");
  864. a = a.Replace("\"", "");
  865. cols = a.Split(',');
  866. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["months"].ToString(), "[\r\n\t ]", "");
  867. p = p.Replace("[", "");
  868. p = p.Replace("]", "");
  869. p = p.Replace("\"", "");
  870. months = p.Split(',');
  871. }
  872. }
  873. }
  874. var data = new
  875. {
  876. months,
  877. cols,
  878. counts
  879. };
  880. return Success("成功", data);
  881. }
  882. /// <summary>
  883. /// 获取关键词数量
  884. /// </summary>
  885. /// <param name="branchcode"></param>
  886. /// <param name="start"></param>
  887. /// <param name="end"></param>
  888. /// <param name="keyid"></param>
  889. /// <returns></returns>
  890. public ActionResult GetKeyCountByDateNew(string branchcode, DateTime? start, DateTime? end, string areaid, int keyid = 0)
  891. {
  892. if (branchcode == "sqs12345")
  893. {
  894. branchcode = "";
  895. }
  896. if (start == null && end == null)
  897. {
  898. start = DateTime.Now;
  899. end = DateTime.Now;
  900. }
  901. else
  902. {
  903. if (start == null) { start = DateTime.Now; }
  904. if (end == null) { end = DateTime.Now; }
  905. }
  906. string sqlwhere = " F_IsDP=1 ";
  907. if (!string.IsNullOrEmpty(branchcode))
  908. {
  909. sqlwhere += " and F_Code='" + branchcode + "'";
  910. }
  911. else
  912. {
  913. sqlwhere += " and F_IsSQ!=1";
  914. }
  915. #region 定义新表
  916. DataTable dtnew = new DataTable();
  917. dtnew.Columns.Add("关键字");
  918. dtnew.Columns.Add("咨询");
  919. dtnew.Columns.Add("求助");
  920. dtnew.Columns.Add("投诉");
  921. dtnew.Columns.Add("建议");
  922. dtnew.Columns.Add("表扬");
  923. dtnew.Columns.Add("其他");
  924. dtnew.Columns.Add("合计");
  925. //dtnew.Columns.Add("排名");
  926. int first = 1;
  927. #endregion
  928. ArrayList result = new ArrayList();
  929. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  930. string controllername = RouteData.Values["controller"].ToString();
  931. string actionname = RouteData.Values["action"].ToString();
  932. foreach (var l in list)
  933. {
  934. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  935. {
  936. if (!string.IsNullOrEmpty(l.F_AreaId))
  937. {
  938. areaid = l.F_AreaId;
  939. }
  940. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  941. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode;
  942. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  943. if (!string.IsNullOrEmpty(branchcode))
  944. {
  945. return Content(ar);//查询单个时直接返回
  946. }
  947. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  948. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  949. {
  950. if (first == 1)
  951. {
  952. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  953. dtnew = dt;
  954. first = 0;
  955. }
  956. else
  957. {
  958. //前部分相加
  959. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  960. for (int i = 0; i < dt1.Rows.Count; i++)
  961. {
  962. for (int m = 0; m < dtnew.Rows.Count; m++)
  963. {
  964. if (dtnew.Rows[m][0].ToString() == dt1.Rows[i][0].ToString())
  965. {
  966. for (int j = 1; j < 8; j++)
  967. {
  968. decimal t = decimal.Parse(dtnew.Rows[i][j].ToString()) + decimal.Parse(dt1.Rows[i][j].ToString());
  969. dtnew.Rows[i][j] = t;
  970. }
  971. }
  972. }
  973. }
  974. }
  975. }
  976. }
  977. }
  978. //dtnew.Columns.Add("排名");
  979. dtnew.DefaultView.Sort = "合计 DESC";
  980. DataTable dtTemp = dtnew.DefaultView.ToTable();
  981. #region 增加排名
  982. if (dtTemp != null)
  983. {
  984. //DataColumn autoColumn = new DataColumn("排名", System.Type.GetType("System.Int32"));
  985. //dtTemp.Columns.Add(autoColumn);
  986. //dtTemp.Columns["排名"].SetOrdinal(0);
  987. for (int i = 0; i < dtTemp.Rows.Count; i++)
  988. {
  989. dtTemp.Rows[i]["排名"] = i + 1;
  990. }
  991. }
  992. #endregion
  993. return Success("成功", dtTemp);
  994. }
  995. /// <summary>
  996. /// 获取类型数量
  997. /// </summary>
  998. /// <param name="branchcode"></param>
  999. /// <param name="start"></param>
  1000. /// <param name="end"></param>
  1001. /// <returns></returns>
  1002. public ActionResult GetTypeCountByDate(string branchcode, DateTime? start, DateTime? end, string areaid)
  1003. {
  1004. if (branchcode == "sqs12345")
  1005. {
  1006. branchcode = "";
  1007. }
  1008. if (start == null && end == null)
  1009. {
  1010. start = DateTime.Now;
  1011. end = DateTime.Now;
  1012. }
  1013. else
  1014. {
  1015. if (start == null) { start = DateTime.Now; }
  1016. if (end == null) { end = DateTime.Now; }
  1017. }
  1018. string sqlwhere = " F_IsDP=1 ";
  1019. if (!string.IsNullOrEmpty(branchcode))
  1020. {
  1021. sqlwhere += " and F_Code='" + branchcode + "'";
  1022. }
  1023. else
  1024. {
  1025. sqlwhere += " and F_IsSQ!=1";
  1026. }
  1027. #region 定义新表
  1028. DataTable dtnew = new DataTable();
  1029. dtnew.Columns.Add("TypeName");
  1030. dtnew.Columns.Add("Count");
  1031. int first = 1;
  1032. #endregion
  1033. ArrayList result = new ArrayList();
  1034. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1035. string controllername = RouteData.Values["controller"].ToString();
  1036. string actionname = RouteData.Values["action"].ToString();
  1037. foreach (var l in list)
  1038. {
  1039. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1040. {
  1041. if (!string.IsNullOrEmpty(l.F_AreaId))
  1042. {
  1043. areaid = l.F_AreaId;
  1044. }
  1045. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1046. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode;
  1047. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1048. if (!string.IsNullOrEmpty(branchcode))
  1049. {
  1050. return Content(ar);//查询单个时直接返回
  1051. }
  1052. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1053. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1054. {
  1055. if (first == 1)
  1056. {
  1057. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  1058. dtnew = dt;
  1059. first = 0;
  1060. }
  1061. else
  1062. {
  1063. //前部分相加
  1064. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  1065. for (int i = 0; i < dt1.Rows.Count; i++)
  1066. {
  1067. decimal t = decimal.Parse(dtnew.Rows[i][1].ToString()) + decimal.Parse(dt1.Rows[i][1].ToString());
  1068. dtnew.Rows[i][1] = t;
  1069. }
  1070. }
  1071. //var rtlist = ar.data.ToJson().ToList<Dictionary<string, object>>();
  1072. //result.AddRange(rtlist);
  1073. }
  1074. }
  1075. }
  1076. return Success("成功", dtnew );
  1077. }
  1078. #endregion
  1079. #region 话务数量
  1080. /// <summary>
  1081. /// 坐席闲忙比例
  1082. /// </summary>
  1083. /// <param name="branchcode"></param>
  1084. /// <param name="start"></param>
  1085. /// <param name="end"></param>
  1086. /// <returns></returns>
  1087. public ActionResult GetUserStateCount24ByDate(string branchcode, DateTime? start, DateTime? end, string areaid)
  1088. {
  1089. if (branchcode == "sqs12345")
  1090. {
  1091. branchcode = "";
  1092. }
  1093. if (start == null && end == null)
  1094. {
  1095. start = DateTime.Now;
  1096. end = DateTime.Now;
  1097. }
  1098. else
  1099. {
  1100. if (start == null) { start = DateTime.Now; }
  1101. if (end == null) { end = DateTime.Now; }
  1102. }
  1103. string sqlwhere = " F_IsDP=1 ";
  1104. if (!string.IsNullOrEmpty(branchcode))
  1105. {
  1106. sqlwhere += " and F_Code='" + branchcode + "'";
  1107. }
  1108. else
  1109. {
  1110. sqlwhere += " and F_IsSQ!=1";
  1111. }
  1112. int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  1113. double[] kxpercents = new double[24];
  1114. double[] thpercents = new double[24];
  1115. double[] zmpercents = new double[24];
  1116. string[] kxcon = new string[24];
  1117. string[] thcon = new string[24];
  1118. string[] xxcon = new string[24];
  1119. int[] con = new int[24];
  1120. ArrayList result = new ArrayList();
  1121. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1122. string controllername = RouteData.Values["controller"].ToString();
  1123. string actionname = "GetUserStateNum24ByDate";// RouteData.Values["action"].ToString();
  1124. foreach (var l in list)
  1125. {
  1126. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1127. {
  1128. if (!string.IsNullOrEmpty(l.F_AreaId))
  1129. {
  1130. areaid = l.F_AreaId;
  1131. }
  1132. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1133. string strparams = "?start=" + start.Value.ToString("yyyy-MM-dd") + "&end=" + end.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode;
  1134. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1135. //if (!string.IsNullOrEmpty(branchcode))
  1136. //{
  1137. // return Content(ar);//查询单个时直接返回
  1138. //}
  1139. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1140. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1141. {
  1142. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["kxcon"].ToString(), "[\r\n\t ]", "");
  1143. y = y.Replace("[", "");
  1144. y = y.Replace("]", "");
  1145. y = y.Replace("\"", "");
  1146. string[] z = y.Split(',');
  1147. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["thcon"].ToString(), "[\r\n\t ]", "");
  1148. p = p.Replace("[", "");
  1149. p = p.Replace("]", "");
  1150. p = p.Replace("\"", "");
  1151. string[] q = p.Split(',');
  1152. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["xxcon"].ToString(), "[\r\n\t ]", "");
  1153. a = a.Replace("[", "");
  1154. a = a.Replace("]", "");
  1155. a = a.Replace("\"", "");
  1156. string[] b = a.Split(',');
  1157. string m = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["con"].ToString(), "[\r\n\t ]", "");
  1158. m = m.Replace("[", "");
  1159. m = m.Replace("]", "");
  1160. m = m.Replace("\"", "");
  1161. string[] n = m.Split(',');
  1162. for (int i = 0; i < hours.Length; i++)
  1163. {
  1164. if (kxcon[i] == null)
  1165. {
  1166. kxcon[i] = "0";
  1167. }
  1168. if (thcon[i] == null)
  1169. {
  1170. thcon[i] = "0";
  1171. }
  1172. if (xxcon[i] == null)
  1173. {
  1174. xxcon[i] = "0";
  1175. }
  1176. kxcon[i] = (int.Parse(kxcon[i]) +int.Parse(z[i])).ToString ();
  1177. thcon[i] = (int.Parse(thcon[i])+int.Parse(q[i])).ToString();
  1178. xxcon[i] = (int.Parse(xxcon[i]) + int.Parse(b[i])).ToString();
  1179. con[i] += int.Parse(n[i]);
  1180. }
  1181. }
  1182. }
  1183. }
  1184. for (int i = 0; i < hours.Length; i++)
  1185. {
  1186. if (con[i] == 0)
  1187. {
  1188. kxpercents[i] = 0;
  1189. thpercents[i] = 0;
  1190. zmpercents[i] = 0;
  1191. }
  1192. else
  1193. {
  1194. kxpercents[i] = Math.Round((double.Parse(kxcon[i]) * 100 / con[i]), 2);
  1195. thpercents[i] = Math.Round((double.Parse(thcon[i]) * 100 / con[i]), 2);
  1196. zmpercents[i] = Math.Round((double.Parse(xxcon[i]) * 100 / con[i]), 2);
  1197. }
  1198. }
  1199. var data = new
  1200. {
  1201. hours,
  1202. kxpercents ,
  1203. thpercents,
  1204. zmpercents
  1205. };
  1206. return Success("加载成功", data);
  1207. }
  1208. /// <summary>
  1209. /// 话务量实时数据统计
  1210. /// </summary>
  1211. /// <param name="branchcode"></param>
  1212. /// <param name="date"></param>
  1213. /// <returns></returns>
  1214. public ActionResult GetTelCount24ByDate(string branchcode, DateTime? date, string areaid)
  1215. {
  1216. if (branchcode == "sqs12345")
  1217. {
  1218. branchcode = "";
  1219. }
  1220. if (date == null)
  1221. {
  1222. date = DateTime.Now;
  1223. }
  1224. string sqlwhere = " F_IsDP=1 ";
  1225. if (!string.IsNullOrEmpty(branchcode))
  1226. {
  1227. sqlwhere += " and F_Code='" + branchcode + "'";
  1228. }
  1229. else
  1230. {
  1231. sqlwhere += " and F_IsSQ!=1";
  1232. }
  1233. int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  1234. int[] rcounts = new int[24];//来电数量
  1235. int[] ccounts = new int[24];//接通数量
  1236. int[] lcounts = new int[24];//留言数量
  1237. int[] gcounts = new int[24];//放弃数量
  1238. int[] scounts = new int[24];//骚扰数量
  1239. ArrayList result = new ArrayList();
  1240. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1241. string controllername = RouteData.Values["controller"].ToString();
  1242. string actionname = RouteData.Values["action"].ToString();
  1243. foreach (var l in list)
  1244. {
  1245. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1246. {
  1247. if (!string.IsNullOrEmpty(l.F_AreaId))
  1248. {
  1249. areaid = l.F_AreaId;
  1250. }
  1251. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1252. string strparams = "?date=" + date.Value.ToString("yyyy-MM-dd") + "&signcode=" + signcode + "&areaid=" + areaid;
  1253. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1254. if (!string.IsNullOrEmpty(branchcode))
  1255. {
  1256. return Content(ar);//查询单个时直接返回
  1257. }
  1258. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1259. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1260. {
  1261. //string x = jo0["data"].ToString();
  1262. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["rcounts"].ToString(), "[\r\n\t ]", "");
  1263. y = y.Replace("[", "");
  1264. y = y.Replace("]", "");
  1265. string[] z = y.Split(',');
  1266. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["ccounts"].ToString(), "[\r\n\t ]", "");
  1267. p = p.Replace("[", "");
  1268. p = p.Replace("]", "");
  1269. string[] q = p.Split(',');
  1270. string a = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["gcounts"].ToString(), "[\r\n\t ]", "");
  1271. a = a.Replace("[", "");
  1272. a = a.Replace("]", "");
  1273. string[] b = a.Split(',');
  1274. string m = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["scounts"].ToString(), "[\r\n\t ]", "");
  1275. m = m.Replace("[", "");
  1276. m = m.Replace("]", "");
  1277. string[] n = m.Split(',');
  1278. for (int i = 0; i < 24; i++)
  1279. {
  1280. rcounts[i] += int.Parse (z[i]);
  1281. ccounts[i] += int.Parse(q[i]);
  1282. gcounts[i] += int.Parse(b[i]);
  1283. scounts[i] += int.Parse(n[i]);
  1284. }
  1285. }
  1286. }
  1287. }
  1288. var data = new
  1289. {
  1290. hours,
  1291. rcounts ,
  1292. ccounts ,
  1293. //lcounts = lcounts,
  1294. gcounts,
  1295. scounts
  1296. };
  1297. return Success("加载成功", data);
  1298. }
  1299. /// <summary>
  1300. /// 获取通话数量
  1301. /// </summary>
  1302. /// <param name="branchcode"></param>
  1303. /// <param name="date"></param>
  1304. /// <returns></returns>
  1305. public ActionResult GetTelCountByDate(string branchcode, DateTime? date, string areaid)
  1306. {
  1307. if (branchcode == "sqs12345")
  1308. {
  1309. branchcode = "";
  1310. }
  1311. if (date == null)
  1312. {
  1313. date = DateTime.Now;
  1314. }
  1315. string sqlwhere = " F_IsDP=1 ";
  1316. if (!string.IsNullOrEmpty(branchcode))
  1317. {
  1318. sqlwhere += " and F_Code='" + branchcode + "'";
  1319. }
  1320. else
  1321. {
  1322. sqlwhere += " and F_IsSQ!=1";
  1323. }
  1324. decimal hwcon=0;
  1325. decimal lhcon = 0;
  1326. decimal jtcon = 0;
  1327. double pjthtimes = 0;
  1328. double jtl = 0;
  1329. double thtimes=0;
  1330. ArrayList result = new ArrayList();
  1331. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1332. string controllername = RouteData.Values["controller"].ToString();
  1333. string actionname = RouteData.Values["action"].ToString();
  1334. foreach (var l in list)
  1335. {
  1336. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1337. {
  1338. if (!string.IsNullOrEmpty(l.F_AreaId))
  1339. {
  1340. areaid = l.F_AreaId;
  1341. }
  1342. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1343. string strparams = "?date=" + date.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode;
  1344. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1345. if (!string.IsNullOrEmpty(branchcode))
  1346. {
  1347. return Content(ar);//查询单个时直接返回
  1348. }
  1349. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1350. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1351. {
  1352. hwcon+=decimal .Parse (jo0["data"]["hwcon"].ToString());
  1353. lhcon += decimal.Parse(jo0["data"]["lhcon"].ToString());
  1354. jtcon += decimal.Parse(jo0["data"]["jtcon"].ToString());
  1355. //pjthtimes += decimal.Parse(jo0["data"]["pjthtimes"].ToString());
  1356. thtimes += double.Parse(jo0["data"]["pjthtimes"].ToString());
  1357. //jtl += decimal.Parse(jo0["data"]["jtl"].ToString());
  1358. if (hwcon >0)
  1359. {
  1360. jtl = Math.Round((double.Parse(jtcon.ToString ()) * 100 / double.Parse(hwcon.ToString ())), 2);
  1361. }
  1362. if (jtcon >0)
  1363. {
  1364. pjthtimes = Math.Round(thtimes / double.Parse(jtcon.ToString ()));
  1365. }
  1366. }
  1367. }
  1368. }
  1369. var data = new
  1370. {
  1371. hwcon = hwcon,
  1372. lhcon = lhcon,
  1373. jtcon = jtcon,
  1374. pjthtimes = pjthtimes,
  1375. jtl = jtl
  1376. };
  1377. return Success("加载成功", data);
  1378. }
  1379. #endregion
  1380. #region 中心大数据
  1381. /// <summary>
  1382. /// 工单类型各数量
  1383. /// </summary>
  1384. /// <param name="branchcode"></param>
  1385. /// <returns></returns>
  1386. public ActionResult GetTypeCountNew(string branchcode, string areaid)
  1387. {
  1388. if (branchcode == "sqs12345")
  1389. {
  1390. branchcode = "";
  1391. }
  1392. string sqlwhere = " F_IsDP=1 ";
  1393. if (!string.IsNullOrEmpty(branchcode))
  1394. {
  1395. sqlwhere += " and F_Code='" + branchcode + "'";
  1396. }
  1397. else
  1398. {
  1399. sqlwhere += " and F_IsSQ!=1";
  1400. }
  1401. #region 定义新表
  1402. DataTable dtnew = new DataTable();
  1403. dtnew.Columns.Add("TypeName");
  1404. dtnew.Columns.Add("DayCount");
  1405. dtnew.Columns.Add("MonthCount");
  1406. dtnew.Columns.Add("TotalCount");
  1407. dtnew.Columns.Add("Percent");
  1408. int first = 1;
  1409. Int64 totalcount = 0;
  1410. #endregion
  1411. ArrayList result = new ArrayList();
  1412. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1413. string controllername = RouteData.Values["controller"].ToString();
  1414. string actionname = RouteData.Values["action"].ToString();
  1415. foreach (var l in list)
  1416. {
  1417. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1418. {
  1419. if (!string.IsNullOrEmpty(l.F_AreaId))
  1420. {
  1421. areaid = l.F_AreaId;
  1422. }
  1423. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1424. string strparams = "?signcode=" + signcode + "&areaid=" + areaid;
  1425. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1426. if (!string.IsNullOrEmpty(branchcode))
  1427. {
  1428. return Content(ar);//查询单个时直接返回
  1429. }
  1430. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1431. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1432. {
  1433. if (first == 1)
  1434. {
  1435. DataTable dt = HeadToDataTable(jo0["data"].ToString(), "Item");
  1436. dtnew = dt;
  1437. first = 0;
  1438. }
  1439. else
  1440. {
  1441. //前部分相加
  1442. DataTable dt1 = HeadToDataTable(jo0["data"].ToString(), "Item");
  1443. for (int i = 0; i < dt1.Rows.Count; i++)
  1444. {
  1445. for (int j = 1; j < 4; j++)
  1446. {
  1447. decimal t = decimal.Parse(dtnew.Rows[i][j].ToString()) + decimal.Parse(dt1.Rows[i][j].ToString());
  1448. dtnew.Rows[i][j] = t;
  1449. }
  1450. totalcount += Int64.Parse(dtnew.Rows[i]["TotalCount"].ToString());
  1451. }
  1452. }
  1453. //var rtlist = ar.data.ToJson().ToList<Dictionary<string, object>>();
  1454. //result.AddRange(rtlist);
  1455. }
  1456. }
  1457. }
  1458. #region 计算比例
  1459. if (totalcount > 0)
  1460. {
  1461. for (int j = 0; j < dtnew.Rows.Count; j++)
  1462. {
  1463. dtnew.Rows[j]["Percent"] = Math.Round(decimal.Parse(dtnew.Rows[j]["TotalCount"].ToString()) / totalcount * 100, 2);
  1464. }
  1465. }
  1466. #endregion
  1467. return Success("成功", dtnew);
  1468. }
  1469. /// <summary>
  1470. /// 接通率统计
  1471. /// </summary>
  1472. /// <param name="branchcode"></param>
  1473. /// <param name="date"></param>
  1474. /// <returns></returns>
  1475. public ActionResult GetTelRate24ByDate(string branchcode, DateTime? date, string areaid)
  1476. {
  1477. if (branchcode == "sqs12345")
  1478. {
  1479. branchcode = "";
  1480. }
  1481. if (date == null)
  1482. {
  1483. date = DateTime.Now;
  1484. }
  1485. string sqlwhere = " F_IsDP=1 ";
  1486. if (!string.IsNullOrEmpty(branchcode))
  1487. {
  1488. sqlwhere += " and F_Code='" + branchcode + "'";
  1489. }
  1490. else
  1491. {
  1492. sqlwhere += " and F_IsSQ!=1";
  1493. }
  1494. int[] hours = Enumerable.Range(0, 24).ToArray<int>();
  1495. int[] jt = new int[24];
  1496. int[] zs = new int[24];
  1497. double[] rates = new double[24];
  1498. ArrayList result = new ArrayList();
  1499. var list = new BLL.T_Branch_List().GetModelList(sqlwhere);
  1500. string controllername = RouteData.Values["controller"].ToString();
  1501. string actionname = "GetTelNum24ByDate";// RouteData.Values["action"].ToString();
  1502. foreach (var l in list)
  1503. {
  1504. if (!string.IsNullOrEmpty(l.F_Sign) && !string.IsNullOrEmpty(l.F_Url))
  1505. {
  1506. if (!string.IsNullOrEmpty(l.F_AreaId))
  1507. {
  1508. areaid = l.F_AreaId;
  1509. }
  1510. string signcode = CommonHelper.getsigncode(controllername, actionname, l.F_Sign);
  1511. string strparams = "?date=" + date.Value.ToString("yyyy-MM-dd") + "&areaid=" + areaid + "&signcode=" + signcode;
  1512. string ar = HttpMethods.HttpGet(l.F_Url + "/" + controllername + "/" + actionname + strparams);//.ToObject<AjaxResult>();
  1513. //if (!string.IsNullOrEmpty(branchcode))
  1514. //{
  1515. // return Content(ar);//查询单个时直接返回
  1516. //}
  1517. JObject jo0 = (JObject)JsonConvert.DeserializeObject(ar);
  1518. if (jo0 != null && jo0["state"].ToString() == ResultTypes.success.ToString())
  1519. {
  1520. //string x = jo0["data"].ToString();
  1521. string y = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["jt"].ToString(), "[\r\n\t ]", "");
  1522. y = y.Replace("[", "");
  1523. y = y.Replace("]", "");
  1524. string[] z = y.Split(',');
  1525. string p = System.Text.RegularExpressions.Regex.Replace(jo0["data"]["zs"].ToString(), "[\r\n\t ]", "");
  1526. p = p.Replace("[", "");
  1527. p = p.Replace("]", "");
  1528. string[] q = p.Split(',');
  1529. for (int i = 0; i < 24; i++)
  1530. {
  1531. jt[i] += int.Parse(z[i]);
  1532. zs[i] += int.Parse(q[i]);
  1533. }
  1534. }
  1535. }
  1536. }
  1537. for (int j = 0; j < 24; j++)
  1538. {
  1539. rates[j] = zs[j] > 0 ? Math.Round(((double)jt[j] * 100 / zs[j]), 2) : 0;
  1540. }
  1541. var data = new
  1542. {
  1543. hours ,
  1544. rates
  1545. };
  1546. return Success("成功", data);
  1547. }
  1548. #endregion
  1549. #region 数据处理
  1550. /// <summary>
  1551. /// Json 字符串 转换为 DataTable数据集合
  1552. /// </summary>
  1553. /// <param name="json"></param>
  1554. /// <returns></returns>
  1555. public static DataTable ToDataTable(string json,string dicstr)//Item
  1556. {
  1557. DataTable dataTable = new DataTable(); //实例化
  1558. DataTable result;
  1559. try
  1560. {
  1561. JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
  1562. javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
  1563. ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
  1564. if (arrayList.Count > 0)
  1565. {
  1566. foreach (Dictionary<string, object> dictionary in arrayList)
  1567. {
  1568. if (dictionary.Keys.Count<string>() == 0)
  1569. {
  1570. result = dataTable;
  1571. return result;
  1572. }
  1573. //Columns
  1574. if (dataTable.Columns.Count == 0)
  1575. {
  1576. foreach (string current in dictionary.Keys)
  1577. {
  1578. if (current != dicstr)
  1579. dataTable.Columns.Add(current, dictionary[current].GetType());
  1580. else
  1581. {
  1582. ArrayList list = dictionary[current] as ArrayList;
  1583. foreach (Dictionary<string, object> dic in list)
  1584. {
  1585. foreach (string key in dic.Keys)
  1586. {
  1587. dataTable.Columns.Add(key, dic[key].GetType());
  1588. }
  1589. break;
  1590. }
  1591. }
  1592. }
  1593. }
  1594. //Rows
  1595. //string root = "";
  1596. List<string> cname = new List<string>();
  1597. foreach (string current in dictionary.Keys)
  1598. {
  1599. if (current != dicstr)
  1600. {
  1601. //root = current;
  1602. //dataRow[root] = dictionary[root];
  1603. cname.Add(current);
  1604. }
  1605. else
  1606. {
  1607. ArrayList list = dictionary[current] as ArrayList;
  1608. foreach (Dictionary<string, object> dic in list)
  1609. {
  1610. DataRow dataRow = dataTable.NewRow();
  1611. foreach (var li in cname )
  1612. {
  1613. if (dictionary[li] == null)
  1614. {
  1615. dataRow[li] = -1;
  1616. }
  1617. else
  1618. {
  1619. dataRow[li] = dictionary[li];
  1620. }
  1621. }
  1622. //dataRow[root] = dictionary[root];
  1623. foreach (string key in dic.Keys)
  1624. {
  1625. dataRow[key] = dic[key];
  1626. }
  1627. dataTable.Rows.Add(dataRow);
  1628. }
  1629. }
  1630. }
  1631. }
  1632. }
  1633. }
  1634. catch
  1635. {
  1636. }
  1637. result = dataTable;
  1638. return result;
  1639. }
  1640. public static DataTable HeadToDataTable(string json, string dicstr)//Item
  1641. {
  1642. DataTable dataTable = new DataTable(); //实例化
  1643. DataTable result;
  1644. try
  1645. {
  1646. JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
  1647. javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
  1648. ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
  1649. if (arrayList.Count > 0)
  1650. {
  1651. foreach (Dictionary<string, object> dictionary in arrayList)
  1652. {
  1653. if (dictionary.Keys.Count<string>() == 0)
  1654. {
  1655. result = dataTable;
  1656. return result;
  1657. }
  1658. //Columns
  1659. if (dataTable.Columns.Count == 0)
  1660. {
  1661. foreach (string current in dictionary.Keys)
  1662. {
  1663. if (current != dicstr)
  1664. dataTable.Columns.Add(current, dictionary[current].GetType());
  1665. //else
  1666. //{
  1667. // ArrayList list = dictionary[current] as ArrayList;
  1668. // foreach (Dictionary<string, object> dic in list)
  1669. // {
  1670. // foreach (string key in dic.Keys)
  1671. // {
  1672. // dataTable.Columns.Add(key, dic[key].GetType());
  1673. // }
  1674. // break;
  1675. // }
  1676. //}
  1677. }
  1678. }
  1679. //Rows
  1680. //string root = "";
  1681. List<string> cname = new List<string>();
  1682. DataRow dataRow = dataTable.NewRow();
  1683. foreach (string current in dictionary.Keys)
  1684. {
  1685. if (current != dicstr)
  1686. {
  1687. //root = current;
  1688. //dataRow[root] = dictionary[root];
  1689. cname.Add(current);
  1690. }
  1691. foreach (var li in cname)
  1692. {
  1693. if (dictionary[li] == null)
  1694. {
  1695. dataRow[li] = -1;
  1696. }
  1697. else
  1698. {
  1699. dataRow[li] = dictionary[li];
  1700. }
  1701. }
  1702. //dataRow[root] = dictionary[root];
  1703. //else
  1704. //{
  1705. // ArrayList list = dictionary[current] as ArrayList;
  1706. // foreach (Dictionary<string, object> dic in list)
  1707. // {
  1708. // DataRow dataRow = dataTable.NewRow();
  1709. // foreach (var li in cname)
  1710. // {
  1711. // dataRow[li] = dictionary[li];
  1712. // }
  1713. // //dataRow[root] = dictionary[root];
  1714. // foreach (string key in dic.Keys)
  1715. // {
  1716. // dataRow[key] = dic[key];
  1717. // }
  1718. // dataTable.Rows.Add(dataRow);
  1719. // }
  1720. //}
  1721. }
  1722. dataTable.Rows.Add(dataRow);
  1723. }
  1724. }
  1725. }
  1726. catch
  1727. {
  1728. }
  1729. result = dataTable;
  1730. return result;
  1731. }
  1732. public static DataTable ItemToDataTable(string json, string dicstr)//Item
  1733. {
  1734. DataTable dataTable = new DataTable(); //实例化
  1735. DataTable result;
  1736. try
  1737. {
  1738. JavaScriptSerializer javaScriptSerializer = new JavaScriptSerializer();
  1739. javaScriptSerializer.MaxJsonLength = Int32.MaxValue; //取得最大数值
  1740. ArrayList arrayList = javaScriptSerializer.Deserialize<ArrayList>(json);
  1741. if (arrayList.Count > 0)
  1742. {
  1743. foreach (Dictionary<string, object> dictionary in arrayList)
  1744. {
  1745. if (dictionary.Keys.Count<string>() == 0)
  1746. {
  1747. result = dataTable;
  1748. return result;
  1749. }
  1750. //Columns
  1751. if (dataTable.Columns.Count == 0)
  1752. {
  1753. foreach (string current in dictionary.Keys)
  1754. {
  1755. if (current != dicstr)
  1756. { }//dataTable.Columns.Add(current, dictionary[current].GetType());
  1757. else
  1758. {
  1759. ArrayList list = dictionary[current] as ArrayList;
  1760. foreach (Dictionary<string, object> dic in list)
  1761. {
  1762. foreach (string key in dic.Keys)
  1763. {
  1764. dataTable.Columns.Add(key, dic[key].GetType());
  1765. }
  1766. break;
  1767. }
  1768. }
  1769. }
  1770. }
  1771. //Rows
  1772. //string root = "";
  1773. List<string> cname = new List<string>();
  1774. foreach (string current in dictionary.Keys)
  1775. {
  1776. if (current != dicstr)
  1777. {
  1778. //root = current;
  1779. //dataRow[root] = dictionary[root];
  1780. //cname.Add(current);
  1781. }
  1782. else
  1783. {
  1784. ArrayList list = dictionary[current] as ArrayList;
  1785. foreach (Dictionary<string, object> dic in list)
  1786. {
  1787. DataRow dataRow = dataTable.NewRow();
  1788. //foreach (var li in cname)
  1789. //{
  1790. //dataRow[li] = dictionary[li];
  1791. //}
  1792. //dataRow[root] = dictionary[root];
  1793. foreach (string key in dic.Keys)
  1794. {
  1795. dataRow[key] = dic[key];
  1796. }
  1797. dataTable.Rows.Add(dataRow);
  1798. }
  1799. }
  1800. }
  1801. }
  1802. }
  1803. }
  1804. catch
  1805. {
  1806. }
  1807. result = dataTable;
  1808. return result;
  1809. }
  1810. #endregion
  1811. }
  1812. }