rpt.ashx 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  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 = dateBegin.AddDays(1);
  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. string heji = "";
  53. string sumheji = "";
  54. for (int i = 1; i <= timespan.TotalHours; i++)
  55. {
  56. int begin = ((i + dateBegin.Hour > 24 ? (i + dateBegin.Hour - 24) : (i + dateBegin.Hour)) - 1);
  57. lie += i + ",";
  58. sum += "sum(点" + i + ") \"" + begin + "点至" + (begin + 1) + "点\",";
  59. casestr += "case when createtime<@DATEBEGIN@+ INTERVAL '" + i + "' HOUR and createtime>@DATEBEGIN@ + INTERVAL '" + (i - 1) + "' HOUR then 1 else 0 end as 点" + i + ",";
  60. heji += "\"" + begin + "点至" + (begin + 1) + "点\",";
  61. sumheji += "sum(\"" + begin + "点至" + (begin + 1) + "点\") as \"" + begin + "点至" + (begin + 1) + "点\",";
  62. }
  63. lie = lie.Trim(',');
  64. sum = sum.Trim(',');
  65. casestr = casestr.Trim(',');
  66. heji = heji.Trim(',');
  67. sumheji = sumheji.Trim(',');
  68. //读取报表数据
  69. string sqlStr = @"
  70. select
  71. decode(pdg.gid, 3, '合计', 0, pdg.productionlineid, '--') 生产线,
  72. decode(pdg.gid, 0, pdg.goodstypename, '--') ""产品类别"",
  73. decode(pdg.gid, 0, pdg.goodscode, '--') ""产品编码"",
  74. decode(pdg.gid, 0, pdg.goodsspecification, '--') ""产品规格"",
  75. decode(pdg.gid, 0, pdg.GLAZETYPE, '--') ""釉料类别"",
  76. 合计,{heji}
  77. from
  78. (select grouping_id(productionlineid,goodscode) gid,
  79. productionlineid,
  80. goodstypename,
  81. goodscode,
  82. goodsspecification,
  83. GLAZETYPE,
  84. sum(合计) as 合计,{sumheji} from
  85. (select productionlineid,
  86. goodstypename ,
  87. goodscode ,
  88. goodsspecification ,
  89. GLAZETYPE ,
  90. sum(合计) 合计,
  91. {sum}
  92. from (
  93. select b.*,1 合计,
  94. {casestr}
  95. from ( select
  96. pd.productionlineid,
  97. gt2.goodstypename goodstypename2,
  98. gt.goodstypename,
  99. g.goodscode,
  100. g.goodsspecification,
  101. g.GOODSMODEL,
  102. dd.dictionaryvalue GLAZETYPE,
  103. pd.createtime
  104. from tp_pm_productiondata pd
  105. inner join tp_mst_goods g
  106. on g.goodsid = pd.goodsid
  107. inner join tp_mst_goodstype gt
  108. on gt.goodstypeid = g.goodstypeid
  109. inner join tp_mst_goodstype gt2
  110. on gt2.goodstypecode = substr(gt.goodstypecode, 0, 6)
  111. and gt2.accountid = gt.accountid
  112. inner join tp_mst_datadictionary dd
  113. on dd.dictionaryid = g.GLAZETYPEID
  114. where pd.accountid = 1
  115. and pd.productionlineid = 1
  116. and pd.createtime >= @DATEBEGIN@
  117. and pd.createtime < @DATEEND@
  118. {sqlwhere}
  119. AND((pd.procedureid = 11 AND pd.valueflag = '1' AND(pd.checkflag = '1' OR pd.checkflag IS NULL)) OR
  120. (pd.procedureid = 104 AND pd.checkflag = '1') OR (pd.procedureid NOT IN(11,104) AND pd.valueflag = '1')) and instr(',' || {procedureId} || ',', ',' || pd.procedureid || ',') > 0
  121. and pd.procedureid={procedureId}) b
  122. left join (
  123. select {lie} from dual) numlie on 1=1 ) detail
  124. GROUP BY
  125. productionlineid,
  126. goodstypename,
  127. goodstypename,
  128. goodscode,
  129. goodsspecification,
  130. GOODSMODEL,
  131. GLAZETYPE) group by grouping sets ( (productionlineid,
  132. goodstypename,
  133. goodscode,
  134. goodsspecification,
  135. GLAZETYPE),()) ) pdg
  136. ".Replace("{lie}", lie)
  137. .Replace("{sum}", sum)
  138. .Replace("{sqlwhere}", sqlwhere)
  139. .Replace("{heji}", heji)
  140. .Replace("{sumheji}", sumheji)
  141. .Replace("{procedureId}", procedureId)
  142. .Replace("{casestr}", casestr);
  143. //获取查询条件
  144. List<CDAParameter> sqlPara = new List<CDAParameter>();
  145. sqlPara.Add(new CDAParameter("DATEBEGIN", dateBegin, DataType.DateTime));
  146. sqlPara.Add(new CDAParameter("DATEEND", dateEnd, DataType.DateTime));
  147. JsonResult data = Easyui.ExecuteJsonResult(conn, sqlStr, sqlPara);
  148. context.Response.Write(data.ToJson());
  149. }
  150. }
  151. }
  152. public bool IsReusable
  153. {
  154. get
  155. {
  156. return false;
  157. }
  158. }
  159. }