DataChartsController.cs 40 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839
  1. using SysBaseLibs;
  2. using SysDataLibs;
  3. using SysDataLibs.TableClass;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Data;
  7. using System.Web.Mvc;
  8. using Newtonsoft.Json;
  9. namespace GSMarketSys.Controllers
  10. {
  11. public class DataChartsController : BaseController
  12. {
  13. public ActionResult ChartsData(string reportType,string reportTitle)
  14. {
  15. ViewBag.ReportType = reportType;
  16. ViewBag.ReportTitle = reportTitle?? "检测统计分析";
  17. ViewBag.IsMarketSysAccount = UserSessionInfo.IsMarketSysAccount ? "0" : "1";
  18. //ViewBag.IsSystem = UserSessionInfo.IsSystem ? "0" : "1";
  19. ViewBag.MarketID = UserSessionInfo.MarketId;
  20. ViewBag.RegionID = UserSessionInfo.UserInfo.RegionID;
  21. ViewBag.SelRegionInfo = GetData.Instance.GetRegionSelStr(Regions_info.cRegionID, Regions_info.cNames, Tn.Regions, UserSessionInfo.DBConn);
  22. ViewBag.SelMarketInfo = GetData.Instance.GetSelStr(Markets_info.cMarketID, Markets_info.cNames, Tn.Markets, Markets_info.cIsLock + "='0' " + UserSessionInfo.MarketDataSql(true), UserSessionInfo.DBConn);
  23. ViewBag.SelCheckProjectTypeInfo = GetData.Instance.GetSelStr("CheckProjectTypeID", "Name", "CheckProjectType", "IsLock=0", UserSessionInfo.DBConn);
  24. //ViewBag.SelLittleKindInfo = GetData.Instance.GetSelStr("LittleKindID", "Name", "LittleKind", "IsLock=0 ORDER by Name", UserSessionInfo.DBConn);
  25. ViewBag.SelLittleKindInfo = GetData.Instance.GetSelStr("VarietyCategoryNo", "VarietyCategoryName", "VarietyCategory", "IsLock='N' AND Depth=1 ORDER by VarietyCategoryNo", UserSessionInfo.DBConn);
  26. ViewBag.SelSampleNameInfo = GetData.Instance.GetSelStr("SpecialsID", "Name", "Specials", "IsLock=0 ORDER by Name,SortNumber", UserSessionInfo.DBConn);
  27. ViewBag.SelCorpKindInfo = GetData.Instance.GetSelStr("Names", "Names", "CorporationType", UserSessionInfo.DBConn);
  28. return View();
  29. }
  30. #region 检测数统计---------->
  31. public ActionResult ChartsYearCount()
  32. {
  33. return RedirectToAction("ChartsData", new { reportType = "YEARCOUNT", reportTitle = "检测抽样数——年统计" });
  34. }
  35. public ActionResult ChartsMonthCount()
  36. {
  37. return RedirectToAction("ChartsData", new { reportType = "MONTHCOUNT", reportTitle = "检测抽样数——月统计" });
  38. }
  39. public ActionResult ChartsCheckProjectType()
  40. {
  41. return RedirectToAction("ChartsData", new { reportType = "CHECKPROJECTTYPEID", reportTitle = "检测抽样数——检测项目统计" });
  42. }
  43. public ActionResult ChartsCheckUnit()
  44. {
  45. return RedirectToAction("ChartsData", new { reportType = "CHECKUNIT", reportTitle = "检测抽样数——检测单位统计" });
  46. }
  47. public ActionResult ChartsLittleKindName()
  48. {
  49. return RedirectToAction("ChartsData", new { reportType = "LITTLEKINDNAME", reportTitle = "检测抽样数——食品小类统计" });
  50. }
  51. public ActionResult ChartsProduceUnit()
  52. {
  53. return RedirectToAction("ChartsData", new { reportType = "PRODUCEUNIT", reportTitle = "检测抽样数——生产单位统计" });
  54. }
  55. public ActionResult ChartsSampleName()
  56. {
  57. return RedirectToAction("ChartsData", new { reportType = "SAMPLENAME", reportTitle = "检测抽样数——检测样品统计" });
  58. }
  59. #endregion
  60. #region 合格率统计---------->
  61. public ActionResult ChartsYearQualified()
  62. {
  63. return RedirectToAction("ChartsData", new { reportType = "YEARHGL", reportTitle = "年合格率统计" });
  64. }
  65. public ActionResult ChartsMonthQualified()
  66. {
  67. return RedirectToAction("ChartsData", new { reportType = "MONTHHGL", reportTitle = "月合格率统计" });
  68. }
  69. public ActionResult ChartsCheckProjectTypeQualified()
  70. {
  71. return RedirectToAction("ChartsData", new { reportType = "CHECKPROJECTTYPEHGL", reportTitle = "检测项目合格率统计" });
  72. }
  73. public ActionResult ChartsCheckUnitQualified()
  74. {
  75. return RedirectToAction("ChartsData", new { reportType = "CHECKUNITHGL", reportTitle = "检测单位合格率统计" });
  76. }
  77. public ActionResult ChartsLittleKindNameQualified()
  78. {
  79. return RedirectToAction("ChartsData", new { reportType = "LITTLEKINDNAMEHGL", reportTitle = "食品小类合格率统计" });
  80. }
  81. public ActionResult ChartsProduceUnitQualified()
  82. {
  83. return RedirectToAction("ChartsData", new { reportType = "SAMPLENAMEHGL", reportTitle = "检测样品合格率统计" });
  84. }
  85. public ActionResult ChartsSampleNameQualified()
  86. {
  87. return RedirectToAction("ChartsData", new { reportType = "PRODUCEUNITHGL", reportTitle = "生产单位合格率统计" });
  88. }
  89. #endregion
  90. #region 园区主要商品价格走势图------------>
  91. public ActionResult MajorQuoteTrendHighCharts()
  92. {
  93. ViewBag.ReportTitle = "园区主要商品价格走势图 ";
  94. ViewBag.IsMarketSysAccount = UserSessionInfo.IsMarketSysAccount ? "0" : "1";
  95. //ViewBag.IsSystem = UserSessionInfo.IsSystem ? "0" : "1";
  96. ViewBag.MarketID = UserSessionInfo.MarketId;
  97. ViewBag.RegionID = UserSessionInfo.UserInfo.RegionID;
  98. //ViewBag.SelRegionInfo = GetData.Instance.GetSelStr(Regions_info.cRegionID, Regions_info.cNames, Tn.Regions, UserSessionInfo.DBConn);
  99. ViewBag.SelMarketInfo = GetData.Instance.GetSelStr(Markets_info.cMarketID, Markets_info.cNames, Tn.Markets, Markets_info.cIsLock + "='0' " + UserSessionInfo.MarketDataSql(true), UserSessionInfo.DBConn);
  100. ViewBag.SelRegionID = GetData.Instance.GetRegionsTreeList(UserSessionInfo.DBConn);
  101. ViewBag.SelMajorGoods = GetData.Instance.GetSelStr(VarietyCategory_info.cVarietyCategoryName, VarietyCategory_info.cVarietyCategoryName, Tn.VarietyCategory, " " + VarietyCategory_info.cIsMajorCost + " = 'Y'", UserSessionInfo.DBConn);
  102. //ViewBag.SelLittleKindInfo = GetData.Instance.GetSelStr("LittleKindID", "Name", "LittleKind", "IsLock=0 ORDER by Name", UserSessionInfo.DBConn);
  103. //ViewBag.SelSampleNameInfo = GetData.Instance.GetSelStr("SpecialsID", "Name", "Specials", "IsLock=0 ORDER by Name,SortNumber", UserSessionInfo.DBConn);
  104. //ViewBag.SelCorpKindInfo = GetData.Instance.GetSelStr("Names", "Names", "CorporationType", UserSessionInfo.DBConn);
  105. return View();
  106. }
  107. public ActionResult ShowChartMajorQuoteTrendHighCharts()
  108. {
  109. string RegionID = Request["RegionID"];
  110. string MarketID = Request["MarketID"];
  111. string MajorGoods = Request["MajorGoods"];
  112. string StartTime = Request["StartTime"];
  113. string EndTime = Request["EndTime"];
  114. string ChartType = Request["ChartType"];
  115. string cmbQueryCycle = Request["cmbQueryCycle"];
  116. string IsExportImage = Request["IsExportImage"];
  117. if (IsExportImage == "Y")
  118. {
  119. return Content("{\"__totalcount\":0}");
  120. }
  121. string lcSql = "";
  122. if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
  123. {
  124. if ((StartTime != "1900-1-1") && (EndTime != "1900-1-1"))
  125. {
  126. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + ">='" + StartTime;
  127. lcSql += "' AND " + MarketMajorQuote_info.cQuoteDate + "<='" + EndTime + "'";
  128. }
  129. else if (StartTime != "1900-01-01")
  130. {
  131. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  132. }
  133. }
  134. else if (!string.IsNullOrEmpty(StartTime))
  135. {
  136. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  137. }
  138. //隶属市场
  139. if (!string.IsNullOrEmpty(MarketID))
  140. {
  141. lcSql += " AND " + MarketMajorQuote_info.cMarketID + "='" + MarketID + "'";
  142. }
  143. else
  144. {
  145. lcSql += " AND " + MarketMajorQuote_info.cMarketID + " IN ("+Markets_info.GetAllMarketIDByRegionId(RegionID, UserSessionInfo.DBConn)+" )";
  146. }
  147. string strAVGs = " AVG(" + MarketMajorQuote_info.cQuoteHigh + ") AS QUOTE_HIGH, " +
  148. " AVG(" + MarketMajorQuote_info.cQuoteLow + ") AS QUOTE_LOW, " +
  149. " AVG(" + MarketMajorQuote_info.cQuoteAverage + ") AS QUOTE_AVG ";
  150. // 周期
  151. string strDateSql = string.Empty;
  152. if (cmbQueryCycle == "1") // 日
  153. {
  154. strDateSql = " Convert(Char(10)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  155. }
  156. else if (cmbQueryCycle == "2") // 月
  157. {
  158. strDateSql = " Convert(Char(7)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  159. }
  160. else if (cmbQueryCycle == "3") // 季
  161. {
  162. strDateSql = " Convert(Char(4),year(" + MarketMajorQuote_info.cQuoteDate +
  163. ")) + '/' + Convert(Char(1),DATEPART(qq," + MarketMajorQuote_info.cQuoteDate + ")) ";
  164. }
  165. else // 年
  166. {
  167. strDateSql = " year(" + MarketMajorQuote_info.cQuoteDate + ") ";
  168. }
  169. string SearchStrHead = " SELECT " + strDateSql + " AS QUOTE_DATE, " + strAVGs + " FROM " + Tn.MarketMajorQuote + " WHERE 1=1 ";
  170. string SearchStrRear = " GROUP BY " + strDateSql;
  171. string SearchStrOrderBy = " ORDER BY " + strDateSql;
  172. // 拼装SQL查询语句
  173. lcSql = SearchStrHead + " AND " + MarketMajorQuote_info.cMajorGoodsName + " = '" + MajorGoods + "'" + " " + lcSql;
  174. lcSql += " " + SearchStrRear;
  175. // 统计按照时间排序
  176. if (SearchStrOrderBy.Length > 0)
  177. lcSql += " " + SearchStrOrderBy;
  178. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  179. string strJson = "";
  180. string strReportType = Request["ReportType"];
  181. if ((strReportType == null) || (strReportType == string.Empty))
  182. strReportType = "CHART";
  183. strReportType = strReportType.ToUpper();
  184. List<Array> listData = null;
  185. try
  186. {
  187. // 生成图片
  188. if (strReportType == "CHART")
  189. {
  190. string strChartType = ChartType;
  191. if (strChartType != null)
  192. {
  193. strChartType = strChartType.ToUpper();
  194. // 将数据库返回结果转换成按列存放的格式
  195. ChartReportUtils.PrepareData(loQuery, ref listData);
  196. // 生产Json格式的返回数据
  197. if (strChartType == "PIE")
  198. strJson = GetData.Instance.GenOutputDataForPie(loQuery.RecCount, listData);
  199. else
  200. strJson = GetData.Instance.GenOutputData(loQuery.RecCount, listData);
  201. }
  202. }
  203. }
  204. catch
  205. {
  206. strJson = string.Empty;
  207. }
  208. //strJson = "{\"__totalcount\":2,\"__categories\":[\"2011\",\"2012\"],\"__series\":[[5,3],[5,7],[9,5]]}";
  209. // 处理异常或者无数据返回
  210. if (strJson == string.Empty)
  211. strJson = "{\"__totalcount\":0}";
  212. return Content(strJson);
  213. }
  214. #endregion
  215. #region 园区主要商品价格走势图 New ------------
  216. public ActionResult HighChartsMajorQuoteTrend()
  217. {
  218. ViewBag.ReportTitle = "园区主要商品价格走势图 ";
  219. ViewBag.IsMarketSysAccount = UserSessionInfo.IsMarketSysAccount ? "0" : "1";
  220. ViewBag.MarketID = UserSessionInfo.MarketId;
  221. ViewBag.RegionID = UserSessionInfo.UserInfo.RegionID;
  222. ViewBag.SelMarketInfo = GetData.Instance.GetSelStr(Markets_info.cMarketID, Markets_info.cNames, Tn.Markets, Markets_info.cIsLock + "='0' " + UserSessionInfo.MarketDataSql(true), UserSessionInfo.DBConn);
  223. ViewBag.SelRegionID = GetData.Instance.GetRegionsTreeList(UserSessionInfo.DBConn,false);
  224. ViewBag.SelMajorGoods = GetData.Instance.GetSelStr(VarietyCategory_info.cVarietyCategoryName, VarietyCategory_info.cVarietyCategoryName, Tn.VarietyCategory, " " + VarietyCategory_info.cIsMajorCost + " = 'Y'", UserSessionInfo.DBConn);
  225. return View();
  226. }
  227. public ActionResult ShowChartMajorQuoteTrend()
  228. {
  229. string RegionID = Request["RegionID"];
  230. string MarketID = Request["MarketID"];
  231. string MajorGoods = Request["MajorGoods"];
  232. string StartTime = Request["StartTime"];
  233. string EndTime = Request["EndTime"];
  234. string cmbQueryCycle = Request["cmbQueryCycle"];
  235. string lcSql = "";
  236. if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
  237. {
  238. if ((StartTime != "1900-1-1") && (EndTime != "1900-1-1"))
  239. {
  240. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + ">='" + StartTime;
  241. lcSql += "' AND " + MarketMajorQuote_info.cQuoteDate + "<='" + EndTime + "'";
  242. }
  243. else if (StartTime != "1900-01-01")
  244. {
  245. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  246. }
  247. }
  248. else if (!string.IsNullOrEmpty(StartTime))
  249. {
  250. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  251. }
  252. //隶属市场
  253. if (!string.IsNullOrEmpty(MarketID))
  254. {
  255. lcSql += " AND " + MarketMajorQuote_info.cMarketID + "='" + MarketID + "'";
  256. }
  257. else
  258. {
  259. lcSql += " AND " + MarketMajorQuote_info.cMarketID + " IN (" + Markets_info.GetAllMarketIDByRegionId(RegionID, UserSessionInfo.DBConn) + " )";
  260. }
  261. string strAVGs = " AVG(" + MarketMajorQuote_info.cQuoteHigh + ") AS QUOTE_HIGH, " +
  262. " AVG(" + MarketMajorQuote_info.cQuoteLow + ") AS QUOTE_LOW, " +
  263. " AVG(" + MarketMajorQuote_info.cQuoteAverage + ") AS QUOTE_AVG ";
  264. // 周期
  265. string strDateSql = string.Empty;
  266. if (cmbQueryCycle == "1") // 日
  267. {
  268. strDateSql = " Convert(Char(10)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  269. }
  270. else if (cmbQueryCycle == "2") // 月
  271. {
  272. strDateSql = " Convert(Char(7)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  273. }
  274. else if (cmbQueryCycle == "3") // 季
  275. {
  276. strDateSql = " Convert(Char(4),year(" + MarketMajorQuote_info.cQuoteDate +
  277. ")) + '/' + Convert(Char(1),DATEPART(qq," + MarketMajorQuote_info.cQuoteDate + ")) ";
  278. }
  279. else // 年
  280. {
  281. strDateSql = " year(" + MarketMajorQuote_info.cQuoteDate + ") ";
  282. }
  283. string SearchStrHead = " SELECT " + strDateSql + " AS QUOTE_DATE, " + strAVGs + " FROM " + Tn.MarketMajorQuote + " WHERE 1=1 ";
  284. string SearchStrRear = " GROUP BY " + strDateSql;
  285. string SearchStrOrderBy = " ORDER BY " + strDateSql;
  286. // 拼装SQL查询语句
  287. lcSql = SearchStrHead + " AND " + MarketMajorQuote_info.cMajorGoodsName + " = '" + MajorGoods + "'" + " " + lcSql;
  288. lcSql += " " + SearchStrRear;
  289. // 统计按照时间排序
  290. if (SearchStrOrderBy.Length > 0)
  291. lcSql += " " + SearchStrOrderBy;
  292. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  293. if (loQuery.IsOpened && loQuery.RecCount > 0)
  294. {
  295. return Content(JsonConvert.SerializeObject(loQuery.CurrentTable));
  296. }
  297. return Content("{}");
  298. }
  299. #endregion
  300. #region 园区主要商品价格走势市场对比------------>
  301. public ActionResult MajorQuoteMarketCmpHighCharts()
  302. {
  303. ViewBag.ReportTitle = "园区主要商品价格走势市场对比";
  304. ViewBag.IsMarketSysAccount = UserSessionInfo.IsMarketSysAccount ? "0" : "1";
  305. string lcMarketSql = "";
  306. if (UserSessionInfo.IsMarketSysAccount)
  307. {
  308. lcMarketSql = " and " + Markets_info.cMarketID + " = '" + UserSessionInfo.MarketId + "'";
  309. }
  310. //ViewBag.IsSystem = UserSessionInfo.IsSystem ? "0" : "1";
  311. ViewBag.MarketID = UserSessionInfo.MarketId;
  312. ViewBag.RegionID = UserSessionInfo.UserInfo.RegionID;
  313. ViewBag.SelMarketInfo = GetData.Instance.GetSelStr(Markets_info.cMarketID, Markets_info.cNames, Tn.Markets, Markets_info.cIsLock + "='0' " + UserSessionInfo.MarketDataSql(true)+ lcMarketSql, UserSessionInfo.DBConn);
  314. ViewBag.SelMajorGoods = GetData.Instance.GetSelStr(VarietyCategory_info.cVarietyCategoryName, VarietyCategory_info.cVarietyCategoryName, Tn.VarietyCategory, " "+VarietyCategory_info.cIsMajorCost+" = 'Y'", UserSessionInfo.DBConn);
  315. return View();
  316. }
  317. public ActionResult ShowMajorQuoteMarketCmpHighCharts()
  318. {
  319. string MarketIDs = Request["MarketIDs"];
  320. string MajorGoods = Request["MajorGoods"];
  321. string StartTime = Request["StartTime"];
  322. string EndTime = Request["EndTime"];
  323. string ChartType = Request["ChartType"];
  324. string cmbQueryCycle = Request["cmbQueryCycle"];
  325. string lcSql = "";
  326. string lcDateSql = "";
  327. string SearchStrOrderBy = " ";
  328. string SearchStrDate = "";
  329. string IsExportImage = Request["IsExportImage"];
  330. if (IsExportImage == "Y")
  331. {
  332. return Content("{\"__totalcount\":0}");
  333. }
  334. // 周期
  335. if (cmbQueryCycle == "1") // 日
  336. {
  337. SearchStrDate = " Convert(Char(10)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  338. }
  339. else if (cmbQueryCycle == "2") // 月
  340. {
  341. SearchStrDate = " Convert(Char(7)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  342. }
  343. else if (cmbQueryCycle == "3") // 季
  344. {
  345. SearchStrDate = " Convert(Char(4),year(" + MarketMajorQuote_info.cQuoteDate +
  346. ")) + '/' + Convert(Char(1),DATEPART(qq," + MarketMajorQuote_info.cQuoteDate + ")) ";
  347. }
  348. else // 年
  349. {
  350. SearchStrDate = " year(" + MarketMajorQuote_info.cQuoteDate + ") ";
  351. }
  352. string SearchStrHead = " SELECT QUOTE_DATE, QUOTE_MARKET, QUOTE_AVG FROM ";
  353. string SearchStrGroupBy = " GROUP BY " + MarketMajorQuote_info.cMarketID + "," + SearchStrDate;
  354. SearchStrOrderBy = " ORDER BY QUOTE_DATE, QUOTE_MARKET";
  355. if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
  356. {
  357. if ((StartTime != "1900-1-1") && (EndTime != "1900-1-1"))
  358. {
  359. lcDateSql += " AND " + MarketMajorQuote_info.cQuoteDate + ">='" + StartTime;
  360. lcDateSql += "' AND " + MarketMajorQuote_info.cQuoteDate + "<='" + EndTime + "'";
  361. }
  362. else if (StartTime != "1900-01-01")
  363. {
  364. lcDateSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  365. }
  366. }
  367. else if (!string.IsNullOrEmpty(StartTime))
  368. {
  369. lcDateSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  370. }
  371. //隶属市场
  372. string lcMarketsSql = "";
  373. if (!string.IsNullOrEmpty(MarketIDs))
  374. {
  375. lcMarketsSql += " and " + Markets_info.cMarketID +" IN ('" + MarketIDs.Replace(",","','") + "' )";
  376. }
  377. string lcSqlLeft = " (SELECT " + Markets_info.cMarketID + "," + Markets_info.cNames + " AS QUOTE_MARKET FROM ";
  378. lcSqlLeft += Tn.Markets + " WHERE 1=1" + lcMarketsSql + " ) AS L ";
  379. string lcSqlRight = " (SELECT " + SearchStrDate + " AS QUOTE_DATE," + MarketMajorQuote_info.cMarketID + ", AVG(" + MarketMajorQuote_info.cQuoteAverage + ") AS QUOTE_AVG ";
  380. lcSqlRight += " FROM " + Tn.MarketMajorQuote + " WHERE " + MarketMajorQuote_info.cMajorGoodsName + "= '" + MajorGoods + "'";
  381. lcSqlRight += lcDateSql + lcMarketsSql;
  382. lcSqlRight += SearchStrGroupBy + " ) AS R ";
  383. // LEFT OUTER JOIN 是为了将无数据的市场显示在Series中.如想不显示,改为INNER JOIN
  384. string strSqlJoin = " LEFT OUTER JOIN ";
  385. //if (ChkBoxDisplayAll.Checked == false)
  386. // strSqlJoin = " INNER JOIN";
  387. lcSql = SearchStrHead + lcSqlLeft + strSqlJoin + lcSqlRight + " ON L." + Markets_info.cMarketID + "=R." + MarketMajorQuote_info.cMarketID + " ";
  388. // 统计按照时间排序
  389. if (SearchStrOrderBy.Length > 0)
  390. lcSql += " " + SearchStrOrderBy;
  391. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  392. string strJson = "";
  393. string strReportType = Request["ReportType"];
  394. if ((strReportType == null) || (strReportType == string.Empty))
  395. strReportType = "CHART";
  396. strReportType = strReportType.ToUpper();
  397. List<Array> listData = null;
  398. List<string> _listCategory = null;
  399. List<string> _listSeries = null;
  400. List<List<Array>> _listDataEx = null;
  401. try
  402. {
  403. // 生成图片
  404. if (strReportType == "CHART")
  405. {
  406. string strChartType = ChartType;
  407. if (strChartType != null)
  408. {
  409. strChartType = strChartType.ToUpper();
  410. // 将数据库返回结果转换成按列存放的格式
  411. //ChartReportUtils.PrepareData(loQuery, ref listData);
  412. ChartReportUtils.PrepareDataNonfixedCat(loQuery, ref _listSeries, ref _listDataEx);
  413. // 生产Json格式的返回数据
  414. // 生产Json格式的返回数据
  415. int nCount = 0;
  416. if (_listDataEx.Count >= 1)
  417. {
  418. strJson = GenOutputDataNonfixedCat(false, _listDataEx, _listSeries);
  419. }
  420. }
  421. }
  422. }
  423. catch
  424. {
  425. strJson = string.Empty;
  426. }
  427. //strJson = "{\"__totalcount\":2,\"__categories\":[\"2011\",\"2012\"],\"__series\":[[5,3],[5,7],[9,5]]}";
  428. // 处理异常或者无数据返回
  429. if (strJson == string.Empty)
  430. strJson = "{\"__totalcount\":0}";
  431. return Content(strJson);
  432. }
  433. // 生成返回的Json格式数据
  434. protected string GenOutputDataNonfixedCat(bool CategoryIsDatetime, List<List<Array>> _listDataEx, List<string> _listSeries)
  435. {
  436. string strRet = string.Empty;
  437. int nCount = 0;
  438. if ((_listDataEx != null) && (_listDataEx.Count >= 1))
  439. {
  440. // 数据列表,数目和Series个数一致
  441. Array arrayValue = Array.CreateInstance(typeof(string), _listSeries.Count);
  442. for (int i = 0; i < _listDataEx.Count; i++)
  443. {
  444. // 当前Series数据
  445. List<Array> ListCurSeries = _listDataEx[i];
  446. // 临时Array,大小为当前Series的容量
  447. Array ArrayTemp = Array.CreateInstance(typeof(string), ListCurSeries.Count);
  448. // 当前Series的每个元素转换为格式: {"x":"2010/1/1", "y":29.9}
  449. for (int j = 0; j < ListCurSeries.Count; j++)
  450. {
  451. if (ListCurSeries[j].GetValue(0) != "")
  452. {
  453. // 将Category和第一个数值列拼接
  454. string strItem = "\"x\":\"" + ListCurSeries[j].GetValue(0) + "\",\"y\":" + ListCurSeries[j].GetValue(2);
  455. strItem = "{" + strItem + "}";
  456. ArrayTemp.SetValue(strItem, j);
  457. }
  458. else
  459. {
  460. ArrayTemp.SetValue("", j);
  461. }
  462. }
  463. // Series的最大容量
  464. if (ListCurSeries.Count > nCount)
  465. {
  466. nCount = ListCurSeries.Count;
  467. }
  468. // 将当前Series转换为格式:[{"x":"2010/1/1", "y":29.9},{"x:"2010/1/2", "y":71.5}]
  469. string strData = ArrayToString(ArrayTemp);
  470. strData = UtilStr.GetDelimitedStr(strData);
  471. // 并加入数据列表
  472. arrayValue.SetValue(strData, i);
  473. }
  474. // 数据列表转换成string
  475. string strValues = ArrayToString(arrayValue);
  476. strValues = UtilStr.GetDelimitedStr(strValues);
  477. // 各Series的名称
  478. string strNames = ListToStringEx(_listSeries);
  479. strNames = UtilStr.GetDelimitedStr(strNames);
  480. // 返回结果
  481. strRet = "{\"__totalcount\":" + nCount + ",\"__names\":" + strNames + ",\"__series\":";
  482. strRet += strValues + "}";
  483. }
  484. return strRet;
  485. }
  486. // 生成返回的Json格式数据
  487. public string GenOutputData(int nCount,List<Array> _listData,List<string> _listCategory, List<string> _listSeries)
  488. {
  489. string strRet = string.Empty;
  490. if ((_listData != null) && (_listData.Count >= 1))
  491. {
  492. // x轴的Categories,注意各项都有双引号,用逗号相隔开
  493. string strCategories = ListToStringEx(_listCategory);
  494. strCategories = UtilStr.GetDelimitedStr(strCategories);
  495. // y轴数据列表.Array格式类似于:[[533,924,554],[100,99,98],[300,299,198]]
  496. Array arrayValue = Array.CreateInstance(typeof(string), _listSeries.Count);
  497. for (int i = 0; i < _listSeries.Count; i++)
  498. {
  499. Array arrayData = _listData[i];
  500. Array arrayTemp = Array.CreateInstance(typeof(string), _listCategory.Count);
  501. for (int j = 0; j < _listCategory.Count; j++)
  502. {
  503. Array arrayVal = (Array)(arrayData.GetValue(j));
  504. //获取对应查询语句中的第几个Val值(对于本页面的查询,就1个,编号是0)
  505. string strVal = arrayVal.GetValue(0).ToString();
  506. arrayTemp.SetValue(strVal, j);
  507. }
  508. // 当前Series的数据[533,924,554]
  509. string strData = ArrayToString(arrayTemp);
  510. strData = UtilStr.GetDelimitedStr(strData);
  511. arrayValue.SetValue(strData, i);
  512. }
  513. // y轴数据列表转换成string
  514. string strValues = ArrayToString(arrayValue);
  515. strValues = UtilStr.GetDelimitedStr(strValues);
  516. // 各Series的名称
  517. string strNames = ListToStringEx(_listSeries);
  518. strNames = UtilStr.GetDelimitedStr(strNames);
  519. // 返回结果
  520. strRet = "{\"__totalcount\":" + nCount + ",\"__categories\":" + strCategories +
  521. ",\"__names\":" + strNames + ",\"__series\":" + strValues + "}";
  522. }
  523. //strRet = "{\"__totalcount\":3,\"__categories\":[\"2012/02\",\"2012/03\",\"2012/04\"],\"__series\":[[533,924,554],[100,99,98],[300,299,198]]}";
  524. return strRet;
  525. }
  526. // 将一个Array各项用逗号隔开,拼成一个string
  527. public string ArrayToString(Array paArray)
  528. {
  529. string lcStr = "";
  530. foreach (string lcStr2 in paArray)
  531. {
  532. lcStr = lcStr + ((lcStr == "") ? "" : ",") + lcStr2;
  533. }
  534. return lcStr;
  535. }
  536. // 将一个Array各项左右加双引号,再用逗号隔开,拼成一个string
  537. public string ArrayToStringEx(Array paArray)
  538. {
  539. string lcStr = "";
  540. foreach (string lcStr2 in paArray)
  541. {
  542. lcStr = lcStr + ((lcStr == "") ? "" : ",") + "\"" + lcStr2 + "\"";
  543. }
  544. return lcStr;
  545. }
  546. // 将一个List各项左右加双引号,再用逗号隔开,拼成一个string
  547. public string ListToStringEx(List<string> paList)
  548. {
  549. string lcStr = "";
  550. foreach (string lcStr2 in paList)
  551. {
  552. lcStr = lcStr + ((lcStr == "") ? "" : ",") + "\"" + lcStr2 + "\"";
  553. }
  554. return lcStr;
  555. }
  556. #endregion
  557. #region
  558. public ActionResult MajorQuoteMultiHighCharts()
  559. {
  560. ViewBag.ReportTitle = " 园区主要商品价格走势对比 ";
  561. ViewBag.IsMarketSysAccount = UserSessionInfo.IsMarketSysAccount ? "0" : "1";
  562. string lcMarketSql = "";
  563. if (UserSessionInfo.IsMarketSysAccount)
  564. {
  565. lcMarketSql = " and " + Markets_info.cMarketID + " = '" + UserSessionInfo.MarketId + "'";
  566. }
  567. //ViewBag.IsSystem = UserSessionInfo.IsSystem ? "0" : "1";
  568. ViewBag.MarketID = UserSessionInfo.MarketId;
  569. ViewBag.RegionID = UserSessionInfo.UserInfo.RegionID;
  570. ViewBag.SelRegionID = GetData.Instance.GetRegionsTreeList(UserSessionInfo.DBConn);
  571. ViewBag.SelMarketInfo = GetData.Instance.GetSelStr(Markets_info.cMarketID, Markets_info.cNames, Tn.Markets, Markets_info.cIsLock + "='0' " + UserSessionInfo.MarketDataSql(true) + lcMarketSql, UserSessionInfo.DBConn);
  572. //ViewBag.SelMajorGoods = GetData.Instance.GetSelStr("MajorSpecialName", "MajorSpecialName", "MajorSpecials", "IsLock='N' ", UserSessionInfo.DBConn);
  573. string lcSql = " Select "+VarietyCategory_info.cVarietyCategoryName+" from "+Tn.VarietyCategory+ " where "+ VarietyCategory_info.cIsMajorCost+" = 'Y'";
  574. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  575. string MajorGoodsHtm = "";
  576. if (loQuery.IsOpened && loQuery.RecCount > 0)
  577. {
  578. loQuery.MoveFirst();
  579. for(int i = 0; i < loQuery.RecCount; i++)
  580. {
  581. if(i % 5==0&&i!=0)
  582. {
  583. MajorGoodsHtm += "<br>";
  584. }
  585. MajorGoodsHtm += "<input type='checkbox' name='chkMajor' id='chkMajor" +i+ "' value='"+loQuery.GetString("VarietyCategoryName") + "'/><label for='chkMajor" + i + "'>" +
  586. loQuery.GetString("VarietyCategoryName") + "</label>&nbsp;&nbsp;&nbsp;";
  587. loQuery.MoveNext();
  588. }
  589. }
  590. ViewBag.SelMajorGoods = MajorGoodsHtm;
  591. return View();
  592. }
  593. public ActionResult ShowMajorQuoteMultiHighCharts()
  594. {
  595. string MarketID = Request["MarketID"];
  596. string MajorGoods = Request["MajorGoods"];
  597. string StartTime = Request["StartTime"];
  598. string EndTime = Request["EndTime"];
  599. string ChartType = Request["ChartType"];
  600. string cmbQueryCycle = Request["cmbQueryCycle"];
  601. string strFixedCategory = Request["fixedCategory"];
  602. string RegionID = Request["RegionID"];
  603. string lcSql = "";
  604. //string lcDateSql = "";
  605. string SearchStrOrderBy = " ";
  606. //string SearchStrDate = "";
  607. string IsExportImage = Request["IsExportImage"];
  608. if (IsExportImage == "Y")
  609. {
  610. return Content("{\"__totalcount\":0}");
  611. }
  612. // 周期
  613. string strAVGs = " AVG(" + MarketMajorQuote_info.cQuoteAverage + ") AS QUOTE_AVG ";
  614. // 周期
  615. string strDateSql = string.Empty;
  616. if (cmbQueryCycle == "1") // 日
  617. {
  618. strDateSql = " Convert(Char(10)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  619. }
  620. else if (cmbQueryCycle == "2") // 月
  621. {
  622. strDateSql = " Convert(Char(7)," + MarketMajorQuote_info.cQuoteDate + ", 111) ";
  623. }
  624. else if (cmbQueryCycle == "3") // 季
  625. {
  626. strDateSql = " Convert(Char(4),year(" + MarketMajorQuote_info.cQuoteDate +
  627. ")) + '/' + Convert(Char(1),DATEPART(qq," + MarketMajorQuote_info.cQuoteDate + ")) ";
  628. }
  629. else // 年
  630. {
  631. strDateSql = " year(" + MarketMajorQuote_info.cQuoteDate + ") ";
  632. }
  633. // SELECT的第一个列必须是Category(本页面为日期)
  634. string SearchStrHead = " SELECT " + strDateSql + " AS QUOTE_DATE, ";
  635. // SELECT的第二个列必须是Series(本页面为商品品种)
  636. SearchStrHead += MarketMajorQuote_info.cMajorGoodsName + " AS QUOTE_NAME, ";
  637. // SELECT的第三个列开始是数值列
  638. SearchStrHead += strAVGs + " FROM " + Tn.MarketMajorQuote + " WHERE 1=1 ";
  639. // GROUP及排序
  640. string SearchStrRear = " GROUP BY " + MarketMajorQuote_info.cMajorGoodsName + "," + strDateSql;
  641. SearchStrOrderBy = " ORDER BY " + strDateSql + "," + MarketMajorQuote_info.cMajorGoodsName;
  642. if ((!string.IsNullOrEmpty(StartTime)) && (!string.IsNullOrEmpty(EndTime)))
  643. {
  644. if ((StartTime != "1900-1-1") && (EndTime != "1900-1-1"))
  645. {
  646. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + ">='" + StartTime;
  647. lcSql += "' AND " + MarketMajorQuote_info.cQuoteDate + "<='" + EndTime + "'";
  648. }
  649. else if (StartTime != "1900-01-01")
  650. {
  651. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  652. }
  653. }
  654. else if (!string.IsNullOrEmpty(StartTime))
  655. {
  656. lcSql += " AND " + MarketMajorQuote_info.cQuoteDate + "='" + StartTime + "'";
  657. }
  658. //隶属市场
  659. if (!string.IsNullOrEmpty(MarketID))
  660. {
  661. lcSql += " and " + Markets_info.cMarketID + " = '" + MarketID + "' ";
  662. }else
  663. {
  664. lcSql += " AND " + MarketMajorQuote_info.cMarketID + " IN (" + Markets_info.GetAllMarketIDByRegionId(RegionID, UserSessionInfo.DBConn) + " )";
  665. }
  666. string lcMajorGoods = "";
  667. if (!string.IsNullOrEmpty(MajorGoods))
  668. {
  669. lcMajorGoods = " AND " + MarketMajorQuote_info.cMajorGoodsName + " IN ('" + MajorGoods.Replace(",", "','") + "')";
  670. }
  671. // 拼装SQL查询语句
  672. lcSql = SearchStrHead + lcMajorGoods + " " + lcSql;
  673. lcSql += " " + SearchStrRear;
  674. // 统计按照时间排序
  675. if (SearchStrOrderBy.Length > 0)
  676. lcSql += " " + SearchStrOrderBy;
  677. rsQuery loQuery = UserSessionInfo.DBConn.OpenQuery(lcSql);
  678. // 是否固定x轴category参数
  679. bool bFixedCategory = false;
  680. //string strFixedCategory = Request["fixedCategory"];
  681. if ((strFixedCategory == null) || (strFixedCategory == string.Empty))
  682. bFixedCategory = true;
  683. else
  684. {
  685. strFixedCategory = strFixedCategory.ToUpper();
  686. if ((strFixedCategory == "1") || (strFixedCategory == "TRUE") || (strFixedCategory == "YES") || (strFixedCategory == "Y"))
  687. bFixedCategory = true;
  688. }
  689. string strJson = "";
  690. string strReportType = Request["ReportType"];
  691. if ((strReportType == null) || (strReportType == string.Empty))
  692. strReportType = "CHART";
  693. strReportType = strReportType.ToUpper();
  694. List<Array> _listData = null;
  695. List<string> _listCategory = null;
  696. List<string> _listSeries = null;
  697. List<List<Array>> _listDataEx = null;
  698. try
  699. {
  700. // 生成图片
  701. if (strReportType == "CHART")
  702. {
  703. //string strChartType = ChartType;
  704. //if (strChartType != null)
  705. //{
  706. // strChartType = strChartType.ToUpper();
  707. // // 将数据库返回结果转换成按列存放的格式
  708. // //ChartReportUtils.PrepareData(loQuery, ref listData);
  709. // ChartReportUtils.PrepareDataNonfixedCat(loQuery, ref _listSeries, ref _listDataEx);
  710. // // 生产Json格式的返回数据
  711. // // 生产Json格式的返回数据
  712. // int nCount = 0;
  713. // if (_listDataEx.Count >= 1)
  714. // {
  715. // strJson = GenOutputDataNonfixedCat(false, _listDataEx, _listSeries);
  716. // }
  717. //}
  718. if (bFixedCategory == true)
  719. {
  720. // 将数据库返回结果转换成按列存放的格式{
  721. ChartReportUtils.PrepareGridData(loQuery, ref _listCategory, ref _listSeries, ref _listData);
  722. // 生产Json格式的返回数据
  723. int nCount = 0;
  724. if (_listData.Count >= 1)
  725. {
  726. nCount = _listCategory.Count;
  727. strJson = GenOutputData(nCount, _listData, _listCategory, _listSeries);
  728. }
  729. }
  730. else
  731. {
  732. // 将数据库返回结果转换成按列存放的格式{
  733. ChartReportUtils.PrepareDataNonfixedCat(loQuery, ref _listSeries, ref _listDataEx);
  734. // 生产Json格式的返回数据
  735. if (_listDataEx.Count >= 1)
  736. {
  737. strJson = GenOutputDataNonfixedCat(false, _listDataEx, _listSeries);
  738. }
  739. }
  740. }
  741. }
  742. catch
  743. {
  744. strJson = string.Empty;
  745. }
  746. //strJson = "{\"__totalcount\":2,\"__categories\":[\"2011\",\"2012\"],\"__series\":[[5,3],[5,7],[9,5]]}";
  747. // 处理异常或者无数据返回
  748. if (strJson == string.Empty)
  749. strJson = "{\"__totalcount\":0}";
  750. return Content(strJson);
  751. }
  752. #endregion
  753. }
  754. }