rpt.ashx 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <%@ WebHandler Language="C#" Class="rpt" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. using System.Data;
  6. using System.Text;
  7. using System.Collections;
  8. using System.Collections.Generic;
  9. using Newtonsoft.Json;
  10. using Newtonsoft.Json.Linq;
  11. using Curtain.DataAccess;
  12. using DK.XuWei.WebMes;
  13. public class rpt : IHttpHandler, IReadOnlySessionState
  14. {
  15. public void ProcessRequest(HttpContext context)
  16. {
  17. context.Response.ContentType = "text/plain";
  18. using (IDataAccess conn = DataAccess.Create())
  19. {
  20. DateTime dateBegin;
  21. DateTime dateEnd;
  22. string procedureId = context.Request["procedureidMaster[]"] is object ? context.Request["procedureidMaster[]"].ToString() : "0";
  23. if (procedureId == "0" && context.Request["procedureidMaster"] is object) procedureId = context.Request["procedureidMaster"].ToString();
  24. if (procedureId == "") procedureId = "0";
  25. string goodstypeCode = context.Request["goodstypecodeMaster"] is object ? context.Request["goodstypecodeMaster"].ToString() : "";
  26. string goodsidMaster = context.Request["goodsidMaster[]"] is object ? context.Request["goodsidMaster[]"] : "0";
  27. if (goodsidMaster == "0" && context.Request["goodsidMaster"] is object) goodsidMaster = context.Request["goodsidMaster"].ToString();
  28. if (goodsidMaster == "") goodsidMaster = "0";
  29. //主表
  30. if (context.Request["m"].ToString() == "0")
  31. {
  32. dateBegin = Convert.ToDateTime(context.Request["datebeginMaster"]);
  33. dateEnd = Convert.ToDateTime(context.Request["dateendMaster"]);
  34. string sqlwhere = "";
  35. if (!string.IsNullOrEmpty(goodstypeCode) && goodstypeCode != "0")
  36. {
  37. sqlwhere += " and gt.goodstypeCode=" + goodstypeCode;
  38. }
  39. if (!string.IsNullOrEmpty(goodsidMaster) && goodsidMaster != "0")
  40. {
  41. sqlwhere += " and g.GOODSID in(" + goodsidMaster + ")";
  42. }
  43. var timespan = dateEnd - dateBegin;
  44. if (timespan.TotalHours > 48 || timespan.TotalHours <= 0 || procedureId == "0")
  45. {
  46. //context.Response.Write(new JsonResult(JsonStatus.loginError) { message = "必须选择数据来源和生产工序!" }.ToJson());
  47. return;
  48. }
  49. string lie = "";
  50. string sum = "";
  51. string casestr = "";
  52. for (int i = 1; i <= timespan.TotalHours; i++)
  53. {
  54. lie += i + ",";
  55. sum += "sum(点" + i + ") \"" + ((i + dateBegin.Hour > 24 ? (i + dateBegin.Hour - 24) : (i + dateBegin.Hour)) - 1) + "点至" + (i + dateBegin.Hour > 24 ? (i + dateBegin.Hour - 24) : (i + dateBegin.Hour)) + "点\",";
  56. casestr += "case when createtime<@DATEBEGIN@+ INTERVAL '" + i + "' HOUR and createtime>@DATEBEGIN@ + INTERVAL '" + (i - 1) + "' HOUR then 1 else 0 end as 点" + i + ",";
  57. }
  58. lie = lie.Trim(',');
  59. sum = sum.Trim(',');
  60. casestr = casestr.Trim(',');
  61. //读取报表数据
  62. string sqlStr = @"
  63. select productionlineid 生产线,
  64. goodstypename 产品类别,
  65. goodscode 产品编码,
  66. goodsspecification 产品介绍,
  67. GOODSMODEL 产品型号,
  68. GLAZETYPE 产品规格,
  69. sum(合计) 合计,
  70. {sum}
  71. from (
  72. select b.*,1 合计,
  73. {casestr}
  74. from ( select
  75. pd.productionlineid,
  76. gt2.goodstypename goodstypename2,
  77. gt.goodstypename,
  78. g.goodscode,
  79. g.goodsspecification,
  80. g.GOODSMODEL,
  81. dd.dictionaryvalue GLAZETYPE,
  82. pd.createtime
  83. from tp_pm_productiondata pd
  84. inner join tp_mst_goods g
  85. on g.goodsid = pd.goodsid
  86. inner join tp_mst_goodstype gt
  87. on gt.goodstypeid = g.goodstypeid
  88. inner join tp_mst_goodstype gt2
  89. on gt2.goodstypecode = substr(gt.goodstypecode, 0, 6)
  90. and gt2.accountid = gt.accountid
  91. inner join tp_mst_datadictionary dd
  92. on dd.dictionaryid = g.GLAZETYPEID
  93. where pd.accountid = 1
  94. and pd.productionlineid = 1
  95. and pd.createtime >= @DATEBEGIN@
  96. and pd.createtime < @DATEEND@
  97. {sqlwhere}
  98. AND((pd.procedureid = 11 AND pd.valueflag = '1' AND(pd.checkflag = '1' OR pd.checkflag IS NULL)) OR
  99. (pd.procedureid = 104 AND pd.checkflag = '1') OR (pd.procedureid NOT IN(11,104) AND pd.valueflag = '1')) and instr(',' || {procedureId} || ',', ',' || pd.procedureid || ',') > 0
  100. and pd.procedureid={procedureId}
  101. AND exists (Select 1 from TP_MST_UserPurview up where up.PurviewType= 7 and up.UserID = 1828 and (up.PurviewID = -1 or up.PurviewID= pd.ProductionLineId))) b
  102. left join (
  103. select {lie} from dual) numlie on 1=1 ) detail
  104. group by
  105. productionlineid,
  106. goodstypename,
  107. goodstypename,
  108. goodscode,
  109. goodsspecification,
  110. GOODSMODEL,
  111. GLAZETYPE
  112. ".Replace("{lie}", lie)
  113. .Replace("{sum}", sum)
  114. .Replace("{sqlwhere}", sqlwhere)
  115. .Replace("{procedureId}", procedureId)
  116. .Replace("{casestr}", casestr);
  117. //获取查询条件
  118. List<CDAParameter> sqlPara = new List<CDAParameter>();
  119. sqlPara.Add(new CDAParameter("DATEBEGIN", dateBegin, DataType.DateTime));
  120. sqlPara.Add(new CDAParameter("DATEEND", dateEnd, DataType.DateTime));
  121. JsonResult data = Easyui.ExecuteJsonResult(conn, sqlStr, sqlPara);
  122. context.Response.Write(data.ToJson());
  123. }
  124. }
  125. }
  126. public bool IsReusable
  127. {
  128. get
  129. {
  130. return false;
  131. }
  132. }
  133. }