rpt.ashx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  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. string GoodsTypeCode = context.Request["goodstypecode"];//产品类别
  21. //string GoodsCode = context.Request["goodsidMaster"];//产品编码
  22. string LineCode = context.Request["linecode"];//成型线号
  23. string UserCode = context.Request["usercode"];//成型工号
  24. //存坯汇总表(DataGridDetail1)中的值
  25. string GoodsID = context.Request["goodsid"];
  26. string LineID = context.Request["groutinglineid"] == "undefined" ? null : context.Request["groutinglineid"];//成型线号
  27. string UserID = context.Request["userid"] == "undefined" ? null : context.Request["userid"];
  28. //商标id
  29. string logoId = context.Request["LOGONAME"] is object ? context.Request["LOGONAME"].ToString() : "";
  30. DateTime? dateBegin;
  31. if (context.Request["chkStar"] != null)
  32. {
  33. dateBegin = Convert.ToDateTime(context.Request["datebeginMaster"]);
  34. }
  35. else
  36. {
  37. dateBegin = null;
  38. }
  39. DateTime? dateEnd;
  40. if (context.Request["chkStar"] != null)
  41. {
  42. dateEnd = Convert.ToDateTime(context.Request["dateendMaster"]);
  43. }
  44. else
  45. {
  46. dateEnd = null;
  47. }
  48. string GoodsCode = context.Request["goodsidMaster[]"];
  49. if (context.Request["goodsidMaster"] is object) GoodsCode = context.Request["goodsidMaster"].ToString();
  50. if (!String.IsNullOrWhiteSpace(GoodsCode)) {
  51. List<string> list= new List<string>(GoodsCode.Split(','));
  52. List<string> newlist = new List<string>();
  53. foreach (string item in list) {
  54. if (!String.IsNullOrWhiteSpace(item)) {
  55. newlist.Add("'"+item+"'");
  56. }
  57. }
  58. if (newlist != null && newlist.Count > 1) {
  59. GoodsCode = string.Join(",", newlist);
  60. }
  61. else
  62. {
  63. GoodsCode = "'" + GoodsCode + "'";
  64. }
  65. }
  66. //获取查询条件
  67. List<CDAParameter> sqlPara = new List<CDAParameter>();
  68. sqlPara.Add(new CDAParameter("accountid", int.Parse(context.Session["accountId"].ToString()), DataType.Int32));
  69. sqlPara.Add(new CDAParameter("DateBegin", dateBegin, DataType.DateTime));
  70. sqlPara.Add(new CDAParameter("DateEnd", dateEnd, DataType.DateTime));
  71. sqlPara.Add(new CDAParameter("GoodsTypeCode", GoodsTypeCode, DataType.VarChar));
  72. sqlPara.Add(new CDAParameter("GoodsCode", GoodsCode, DataType.VarChar));
  73. sqlPara.Add(new CDAParameter("LineCode", LineCode, DataType.VarChar));
  74. sqlPara.Add(new CDAParameter("UserCode", UserCode, DataType.VarChar));
  75. sqlPara.Add(new CDAParameter("LOGOID", logoId, DataType.VarChar));
  76. //主表
  77. if (context.Request["m"].ToString() == "master")
  78. {
  79. //读取报表数据
  80. StringBuilder sqlStr = new StringBuilder();
  81. sqlStr.Append(@"
  82. SELECT
  83. decode(grouping_id(t.goodstypecode2, t.goodsid),
  84. 3,
  85. '总计',
  86. 1,
  87. '合计[' || t.goodstypename2 || ']',
  88. t.goodstypename2) AS 产品大类
  89. ,t.goodstypename AS 产品类别
  90. ,t.goodsid AS 产品ID
  91. ,t.goodscode AS 产品编码
  92. ,SUM(t.rdcount) AS 存坯数
  93. ,t.gldcount AS 模具数
  94. ,t.rddays AS 存坯天数
  95. ,t.reserveddays AS 应存天数
  96. ,SUM(t.ProfitNum) AS 盈亏坯数
  97. --,grouping_id(t.goodstypecode2, t.goodsid) gid
  98. --,t.goodstypecode2
  99. FROM (SELECT gt2.goodstypecode goodstypecode2
  100. ,gt2.goodstypename goodstypename2
  101. ,gdrd.goodsid
  102. ,gdrd.goodscode
  103. ,gdrd.goodstypename
  104. ,gdrd.gddc rdcount -- 存坯数
  105. ,rdd.gldcount -- 模具数
  106. , CASE
  107. WHEN rdd.gldcount IS NOT NULL AND rdd.gldcount > 0 THEN
  108. round(gdrd.gddc / rdd.gldcount, 2)
  109. ELSE
  110. NULL
  111. END rddays -- 存坯天数
  112. ,gdrd.reserveddays -- 应存天数
  113. ,(gdrd.gddc - gdrd.reserveddays * rdd.gldcount) ProfitNum --盈亏坯数
  114. FROM (SELECT gdd.goodsid
  115. ,gdd.goodscode
  116. ,g.reserveddays
  117. ,substr(gt.goodstypecode, 1, 6) goodstypecode2
  118. ,gt.goodstypename
  119. ,COUNT(*) gddc
  120. FROM tp_pm_groutingdailydetail gdd
  121. INNER JOIN tp_mst_goods g
  122. ON g.goodsid = gdd.goodsid
  123. INNER JOIN tp_mst_goodstype gt
  124. ON g.goodstypeid = gt.goodstypeid
  125. left JOIN tp_pm_inproduction inp
  126. ON inp.barcode = gdd.barcode
  127. left JOIN tp_pc_procedure p
  128. ON inp.procedureid = p.procedureid
  129. WHERE gdd.accountid = @accountid@
  130. AND gdd.valueflag = '1'
  131. AND gdd.groutingflag = '1'
  132. AND gdd.barcode IS NOT NULL
  133. AND gdd.scrapflag = '0'
  134. AND gdd.deliverflag = '0'
  135. AND (gdd.beginningflag='0' or inp.barcode is not null)
  136. AND (@LineCode@ IS NULL OR
  137. instr(gdd.groutinglinecode, @LineCode@) > 0)
  138. AND (@UserCode@ IS NULL OR
  139. instr(gdd.UserCode, @UserCode@) > 0)
  140. AND (@LOGOID@ IS NULL OR
  141. instr(gdd.LOGOID, @LOGOID@) > 0) ");
  142. if (!String.IsNullOrEmpty(GoodsCode))
  143. {
  144. sqlStr.Append(@" AND gdd.GoodsCode IN ("+GoodsCode+") ");
  145. }
  146. sqlStr.Append(@"
  147. AND (@GoodsTypeCode@ IS NULL OR
  148. instr(gt.GoodstypeCode, @GoodsTypeCode@) = 1)
  149. AND (@DateBegin@ IS NULL OR
  150. gdd.groutingdate BETWEEN @DateBegin@ AND @DateEnd@)
  151. AND (P.procedurename IN('3#阴干区(入)','3#预干区(入)','3#烘干区(入)','3#烘干区(出)') or p.procedurename IS NULL)
  152. GROUP BY gt.goodstypecode,gt.goodstypename
  153. ,gdd.goodsid
  154. ,gdd.goodscode
  155. ,g.reserveddays) gdrd
  156. LEFT JOIN (SELECT gld.goodsid
  157. ,COUNT(*) gldcount
  158. FROM tp_pc_groutinglinedetail gld
  159. INNER JOIN tp_pc_groutingline gl
  160. ON gl.groutinglineid = gld.groutinglineid
  161. WHERE gld.valueflag = '1'
  162. AND gld.gmouldstatus = 1
  163. AND gl.accountid = @accountid@
  164. AND gl.valueflag = '1'
  165. AND gl.gmouldstatus = 1
  166. GROUP BY gld.goodsid
  167. ) rdd
  168. ON rdd.goodsid = gdrd.goodsid
  169. INNER JOIN tp_mst_goodstype gt2
  170. ON gt2.accountid = @accountid@
  171. AND gt2.goodstypecode = gdrd.goodstypecode2
  172. ORDER BY gt2.goodstypecode
  173. ,gdrd.goodscode
  174. ) t
  175. GROUP BY GROUPING SETS((t.goodstypecode2, t.goodstypename2,t.goodstypename, t.goodsid, t.goodscode, t.gldcount, t.rddays, t.reserveddays),(t.goodstypecode2, t.goodstypename2),())");
  176. //直接获取数据
  177. JsonResult jsonresult = Easyui.ExecuteJsonResult(conn, sqlStr.ToString(), sqlPara);
  178. context.Response.Write(jsonresult.ToJson());
  179. }
  180. //子表1
  181. if (context.Request["m"].ToString() == "detail1")
  182. {
  183. //读取报表数据
  184. string sqlStr = @"
  185. SELECT decode(grouping_id(t.goodstypecode2, t.goodsid),
  186. 3,
  187. '总计',
  188. 1,
  189. '合计[' || t.goodstypename2 || ']',
  190. t.goodstypename2) AS 产品类别
  191. ,t.goodsid AS 产品ID
  192. ,t.goodscode AS 产品编码
  193. ,t.groutinglineid AS 成型线号ID
  194. ,t.groutinglinecode AS 成型线号
  195. ,t.userid AS 工号ID
  196. ,t.usercode AS 成型工号
  197. ,t.MONITORName AS 成型班长
  198. ,SUM(t.rdcount) AS 存坯数
  199. ,t.gldcount AS 模具数
  200. ,t.rddays AS 存坯天数
  201. ,t.reserveddays AS 应存天数
  202. ,SUM(t.ProfitNum) AS 盈亏坯数
  203. --,grouping_id(t.goodstypecode2, t.goodsid) gid
  204. --,t.goodstypecode2
  205. FROM (SELECT gt2.goodstypecode goodstypecode2
  206. ,gt2.goodstypename goodstypename2
  207. ,gdrd.goodsid
  208. ,gdrd.goodscode
  209. ,gdrd.groutinglineid
  210. ,gdrd.groutinglinecode
  211. ,gdrd.userid
  212. ,gdrd.usercode
  213. ,mu.username MONITORName
  214. ,gdrd.gddc rdcount -- 存坯数
  215. ,rdd.gldcount -- 模具数
  216. , CASE
  217. WHEN rdd.gldcount IS NOT NULL AND rdd.gldcount > 0 THEN
  218. round(gdrd.gddc / rdd.gldcount, 2)
  219. ELSE
  220. NULL
  221. END rddays -- 存坯天数
  222. ,gdrd.reserveddays -- 应存天数
  223. ,(gdrd.gddc - gdrd.reserveddays * rdd.gldcount) ProfitNum --盈亏坯数
  224. FROM (SELECT gdd.goodsid
  225. ,gdd.goodscode
  226. ,gdd.groutinglineid
  227. ,gdd.groutinglinecode
  228. ,gdd.userid
  229. ,gdd.usercode
  230. ,g.reserveddays
  231. ,substr(gt.goodstypecode, 1, 6) goodstypecode2
  232. ,COUNT(*) gddc
  233. FROM tp_pm_groutingdailydetail gdd
  234. INNER JOIN tp_mst_goods g
  235. ON g.goodsid = gdd.goodsid
  236. INNER JOIN tp_mst_goodstype gt
  237. ON g.goodstypeid = gt.goodstypeid
  238. left JOIN tp_pm_inproduction inp
  239. ON inp.barcode = gdd.barcode
  240. left JOIN tp_pc_procedure p
  241. ON inp.procedureid = p.procedureid
  242. WHERE gdd.accountid = @accountid@
  243. AND gdd.valueflag = '1'
  244. AND gdd.groutingflag = '1'
  245. AND gdd.barcode IS NOT NULL
  246. AND gdd.scrapflag = '0'
  247. AND gdd.deliverflag = '0'
  248. AND (gdd.beginningflag='0' or inp.barcode is not null)
  249. AND (@LineCode@ IS NULL OR
  250. instr(gdd.groutinglinecode, @LineCode@) > 0)
  251. AND (@UserCode@ IS NULL OR
  252. instr(gdd.UserCode, @UserCode@) > 0)
  253. AND (@LOGOID@ IS NULL OR
  254. instr(gdd.LOGOID, @LOGOID@) > 0) ";
  255. if (!String.IsNullOrEmpty(GoodsCode))
  256. {
  257. sqlStr += @" AND gdd.GoodsCode IN ("+GoodsCode+") ";
  258. }
  259. sqlStr += @"
  260. AND (@GoodsTypeCode@ IS NULL OR
  261. instr(gt.GoodstypeCode, @GoodsTypeCode@) = 1)
  262. AND (@DateBegin@ IS NULL OR
  263. gdd.groutingdate BETWEEN @DateBegin@ AND @DateEnd@)
  264. AND (P.procedurename IN('3#阴干区(入)','3#预干区(入)','3#烘干区(入)','3#烘干区(出)') or p.procedurename IS NULL)
  265. GROUP BY gt.goodstypecode
  266. ,gdd.goodsid
  267. ,gdd.goodscode
  268. ,gdd.groutinglineid
  269. ,gdd.groutinglinecode
  270. ,gdd.userid
  271. ,gdd.usercode
  272. ,g.reserveddays) gdrd
  273. LEFT JOIN (SELECT gld.goodsid
  274. ,gld.groutinglineid
  275. ,gl.MONITORID
  276. ,COUNT(*) gldcount
  277. FROM tp_pc_groutinglinedetail gld
  278. INNER JOIN tp_pc_groutingline gl
  279. ON gl.groutinglineid = gld.groutinglineid
  280. WHERE gld.valueflag = '1'
  281. AND gld.gmouldstatus = 1
  282. AND gl.accountid = @accountid@
  283. AND gl.valueflag = '1'
  284. AND gl.gmouldstatus = 1
  285. GROUP BY gld.goodsid, gld.groutinglineid,gl.MONITORID) rdd
  286. ON rdd.goodsid = gdrd.goodsid
  287. AND rdd.groutinglineid = gdrd.groutinglineid
  288. LEFT JOIN tp_mst_user mu
  289. ON mu.userid = rdd.MONITORID
  290. INNER JOIN tp_mst_goodstype gt2
  291. ON gt2.accountid = @accountid@
  292. AND gt2.goodstypecode = gdrd.goodstypecode2
  293. ORDER BY gt2.goodstypecode
  294. ,gdrd.goodscode
  295. ,gdrd.groutinglinecode
  296. ,gdrd.usercode) t
  297. GROUP BY GROUPING SETS((t.goodstypecode2, t.goodstypename2, t.goodsid, t.goodscode, t.groutinglineid, t.groutinglinecode, t.userid, t.usercode,t.MONITORName, t.gldcount, t.rddays, t.reserveddays),(t.goodstypecode2, t.goodstypename2),())
  298. ";
  299. JsonResult jsonresult = Easyui.ExecuteJsonResult(conn, sqlStr.ToString(), sqlPara);
  300. context.Response.Write(jsonresult.ToJson());
  301. }
  302. //子表2
  303. if (context.Request["m"].ToString() == "detail2")
  304. {
  305. //读取报表数据
  306. string sqlStr = @"
  307. SELECT gdd.barcode AS 产品条码
  308. ,gdd.groutinglinecode AS 成型线号
  309. ,gdd.GroutingMouldCode AS 模具编号
  310. ,gdd.goodscode AS 产品编码
  311. ,gdd.usercode AS 成型工号
  312. ,gdd.groutingdate AS 注浆日期
  313. ,p.procedurename AS 当前工序
  314. ,mu.username AS 成型班长
  315. FROM tp_pm_groutingdailydetail gdd
  316. INNER JOIN tp_mst_goods g
  317. ON g.goodsid = gdd.goodsid
  318. LEFT JOIN tp_pc_groutingline gl
  319. ON gl.groutinglineid = GDD.GroutingLineID
  320. LEFT JOIN tp_mst_user mu
  321. ON mu.userid = gl.MONITORID
  322. INNER JOIN tp_mst_goodstype gt
  323. ON g.goodstypeid = gt.goodstypeid
  324. left JOIN tp_pm_inproduction inp
  325. ON inp.barcode = gdd.barcode
  326. left JOIN tp_pc_procedure p
  327. ON inp.procedureid = p.procedureid
  328. WHERE gdd.accountid = @accountid@
  329. AND gdd.valueflag = '1'
  330. AND gdd.groutingflag = '1'
  331. AND gdd.barcode IS NOT NULL
  332. AND gdd.scrapflag = '0'
  333. AND gdd.deliverflag = '0'
  334. AND (gdd.beginningflag='0' or inp.barcode is not null)
  335. AND (@LineID@ IS NULL OR gdd.groutinglineid = @LineID@)
  336. AND (@UserID@ IS NULL OR gdd.UserID = @UserID@)
  337. AND (@GoodsID@ IS NULL OR gdd.goodsid = @GoodsID@)
  338. AND (@LineCode@ IS NULL OR instr(gdd.groutinglinecode, @LineCode@) > 0)
  339. AND (@UserCode@ IS NULL OR instr(gdd.UserCode, @UserCode@) > 0)
  340. AND (@LOGOID@ IS NULL OR
  341. instr(gdd.LOGOID, @LOGOID@) > 0)
  342. ";
  343. if (!String.IsNullOrEmpty(GoodsCode))
  344. {
  345. sqlStr += @" AND gdd.GoodsCode IN ("+GoodsCode+") ";
  346. }
  347. sqlStr += @"
  348. AND (@GoodsTypeCode@ IS NULL OR
  349. instr(gt.GoodstypeCode, @GoodsTypeCode@) = 1)
  350. AND (@DateBegin@ IS NULL OR
  351. gdd.groutingdate BETWEEN @DateBegin@ AND @DateEnd@)
  352. AND (P.procedurename IN('3#阴干区(入)','3#预干区(入)','3#烘干区(入)','3#烘干区(出)') or p.procedurename IS NULL)
  353. ORDER BY gdd.barcode
  354. ";
  355. sqlPara.Add(new CDAParameter("GoodsID", GoodsID, DataType.Int32));
  356. sqlPara.Add(new CDAParameter("LineID", LineID, DataType.Int32));
  357. sqlPara.Add(new CDAParameter("UserID", UserID, DataType.Int32));
  358. JsonResult jsonresult = Easyui.ExecuteJsonResult(conn, sqlStr.ToString(), sqlPara);
  359. context.Response.Write(jsonresult.ToJson());
  360. }
  361. }
  362. }
  363. public bool IsReusable
  364. {
  365. get
  366. {
  367. return false;
  368. }
  369. }
  370. }