sapmaterialcode.ashx 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. <%@ WebHandler Language="C#" Class="bompackunit" %>
  2. using System;
  3. using System.Web;
  4. using System.Web.SessionState;
  5. using System.Collections.Generic;
  6. using System.Collections.Specialized;
  7. using System.Data;
  8. using Curtain.DataAccess;
  9. using DK.XuWei.WebMes;
  10. public class bompackunit : IHttpHandler, IReadOnlySessionState
  11. {
  12. public void ProcessRequest(HttpContext context)
  13. {
  14. context.Response.ContentType = "text/plain";
  15. if (context.Request["m"] is object)
  16. {
  17. switch (context.Request["m"].ToString().ToLower())
  18. {
  19. case "s":
  20. {
  21. context.Response.Write(search(context.Request.Form));
  22. break;
  23. }
  24. case "sync":
  25. {
  26. context.Response.Write(sync(context));
  27. break;
  28. }
  29. default:
  30. {
  31. break;
  32. }
  33. }
  34. }
  35. else
  36. {
  37. context.Response.Write(new JsonResult(JsonStatus.loginError).ToJson());
  38. }
  39. }
  40. /// <summary>
  41. /// 查询
  42. /// </summary>
  43. /// <returns>json</returns>
  44. private string search(NameValueCollection form)
  45. {
  46. using (IDataAccess conn = DataAccess.Create())
  47. {
  48. int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
  49. int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
  50. string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
  51. string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
  52. string sqlStr = @"SELECT * FROM TP_PC_SAPBOMDETAIL WHERE 1= 1";
  53. List<CDAParameter> sqlPara = new List<CDAParameter>();
  54. if (!string.IsNullOrEmpty(form["MATNR"]))
  55. {
  56. sqlStr += " AND MATNR = @MATNR@ ";
  57. sqlPara.Add(new CDAParameter("MATNR", form["MATNR"]));
  58. }
  59. int total = 0;
  60. DataTable dt = conn.SelectPages(page, rows, out total, sqlStr, sqlPara.ToArray());
  61. return new JsonResult(dt) { total = total }.ToJson();
  62. }
  63. }
  64. /// <summary>
  65. /// 同步
  66. /// </summary>
  67. /// <returns>json</returns>
  68. private string sync(HttpContext context)
  69. {
  70. string ZTYPE;
  71. string ZMSG;
  72. DataTable dtResult = SapApi.ZMMFM054(out ZTYPE, out ZMSG,"ALL", context.Request["MATNR"]);
  73. if ("E".Equals(ZTYPE) || dtResult == null || dtResult.Rows.Count == 0)
  74. {
  75. return new JsonResult(JsonStatus.otherError).ToJson();
  76. }
  77. using (IDataAccess conn = DataAccess.Create())
  78. {
  79. // 开启事务
  80. conn.BeginTransaction();
  81. string delsql = @"DELETE FROM TP_PC_SAPBOMDETAIL";
  82. List<CDAParameter> sqlPara = new List<CDAParameter>();
  83. // 删除所有
  84. int result = conn.ExecuteNonQuery(delsql);
  85. // 插入新的
  86. string sqlString = @"
  87. INSERT INTO TP_PC_SAPBOMDETAIL (
  88. MATNR
  89. ,WERKS
  90. ,MAKTX
  91. ,MATKL
  92. ,WGBEZ
  93. ,MEINS
  94. ,LABOR
  95. ,LGFSB
  96. ,MTART
  97. ,LVORM
  98. ,BSTRF
  99. ,PRDHA
  100. ,VTEXT
  101. ,BSTME
  102. ,VOLUM
  103. ,BESKZ
  104. ,SOBSL
  105. ,LGPRO
  106. ,MTPOSMARA
  107. ,GROES
  108. ,STPRS
  109. ,UMREZ
  110. ,PEINH
  111. ,XCHAR
  112. ,ZGG
  113. ,ZYS
  114. ,ZCSJ
  115. ,VRKME
  116. ,ERSDA
  117. ,MAABC
  118. ,BRGEW
  119. ,NTGEW
  120. ,VOLEH
  121. ,ZWLFL
  122. ,ZWXGG
  123. ,ZWXMZ
  124. ,ZWXJZ
  125. ,ZEWSL
  126. ,ZEWDW
  127. ,ZMEINS
  128. ,ZZXBZ
  129. ,ZWYM
  130. ,ZNMAE
  131. ,ZMYYSL
  132. ,ZCPCCBZQ
  133. ,ZCPCCBZH
  134. ,ZBY1
  135. ,ZBY2
  136. ,ZBY3
  137. ,ZBY4
  138. ,ZBY5
  139. ,ZBY6
  140. ,ACCOUNTID
  141. ,VALUEFLAG
  142. ,CREATEUSERID
  143. ,UPDATEUSERID
  144. ,ZWLJC
  145. ) values(
  146. @MATNR@
  147. ,@WERKS@
  148. ,@MAKTX@
  149. ,@MATKL@
  150. ,@WGBEZ@
  151. ,@MEINS@
  152. ,@LABOR@
  153. ,@LGFSB@
  154. ,@MTART@
  155. ,@LVORM@
  156. ,@BSTRF@
  157. ,@PRDHA@
  158. ,@VTEXT@
  159. ,@BSTME@
  160. ,@VOLUM@
  161. ,@BESKZ@
  162. ,@SOBSL@
  163. ,@LGPRO@
  164. ,@MTPOSMARA@
  165. ,@GROES@
  166. ,@STPRS@
  167. ,@UMREZ@
  168. ,@PEINH@
  169. ,@XCHAR@
  170. ,@ZGG@
  171. ,@ZYS@
  172. ,@ZCSJ@
  173. ,@VRKME@
  174. ,@ERSDA@
  175. ,@MAABC@
  176. ,@BRGEW@
  177. ,@NTGEW@
  178. ,@VOLEH@
  179. ,@ZWLFL@
  180. ,@ZWXGG@
  181. ,@ZWXMZ@
  182. ,@ZWXJZ@
  183. ,@ZEWSL@
  184. ,@ZEWDW@
  185. ,@ZMEINS@
  186. ,@ZZXBZ@
  187. ,@ZWYM@
  188. ,@ZNMAE@
  189. ,@ZMYYSL@
  190. ,@ZCPCCBZQ@
  191. ,@ZCPCCBZH@
  192. ,@ZBY1@
  193. ,@ZBY2@
  194. ,@ZBY3@
  195. ,@ZBY4@
  196. ,@ZBY5@
  197. ,@ZBY6@
  198. ,@ACCOUNTID@
  199. ,@VALUEFLAG@
  200. ,@CREATEUSERID@
  201. ,@UPDATEUSERID@
  202. ,@ZWLJC@
  203. )";
  204. decimal menge = 0;
  205. foreach (DataRow row in dtResult.Rows)
  206. {
  207. decimal.TryParse(row["BSTRF"] + "", out menge);
  208. menge = menge == 0 ? 1 : menge;
  209. result += conn.ExecuteNonQuery(sqlString,
  210. new CDAParameter("MATNR", row["MATNR"]),
  211. new CDAParameter("WERKS", "5000"),
  212. new CDAParameter("MAKTX", row["MAKTX"]),
  213. new CDAParameter("MATKL", row["MATKL"]),
  214. new CDAParameter("WGBEZ", row["WGBEZ"]),
  215. new CDAParameter("MEINS", row["MEINS"]),
  216. new CDAParameter("LABOR", row["LABOR"]),
  217. new CDAParameter("LGFSB", row["LGFSB"]),
  218. new CDAParameter("MTART", row["MTART"]),
  219. new CDAParameter("LVORM", row["LVORM"]),
  220. new CDAParameter("BSTRF", row["BSTRF"]),
  221. new CDAParameter("PRDHA", row["PRDHA"]),
  222. new CDAParameter("VTEXT", row["VTEXT"]),
  223. new CDAParameter("BSTME", row["BSTME"]),
  224. new CDAParameter("VOLUM", row["VOLUM"]),
  225. new CDAParameter("BESKZ", row["BESKZ"]),
  226. new CDAParameter("SOBSL", row["SOBSL"]),
  227. new CDAParameter("LGPRO", row["LGPRO"]),
  228. new CDAParameter("MTPOSMARA", row["MTPOS_MARA"]),
  229. new CDAParameter("GROES", row["GROES"]),
  230. new CDAParameter("STPRS", row["STPRS"]),
  231. new CDAParameter("UMREZ", row["UMREZ"]),
  232. new CDAParameter("PEINH", row["PEINH"]),
  233. new CDAParameter("XCHAR", row["XCHAR"]),
  234. new CDAParameter("ZGG", row["ZGG"]),
  235. new CDAParameter("ZYS", row["ZYS"]),
  236. new CDAParameter("ZCSJ", row["ZCSJ"]),
  237. new CDAParameter("VRKME", row["VRKME"]),
  238. new CDAParameter("ERSDA", row["ERSDA"]),
  239. new CDAParameter("MAABC", row["MAABC"]),
  240. new CDAParameter("BRGEW", row["BRGEW"]),
  241. new CDAParameter("NTGEW", row["NTGEW"]),
  242. new CDAParameter("VOLEH", row["VOLEH"]),
  243. new CDAParameter("ZWLFL", row["ZWLFL"]),
  244. new CDAParameter("ZWXGG", row["ZWXGG"]),
  245. new CDAParameter("ZWXMZ", row["ZWXMZ"]),
  246. new CDAParameter("ZWXJZ", row["ZWXJZ"]),
  247. new CDAParameter("ZEWSL", row["ZEWSL"]),
  248. new CDAParameter("ZEWDW", row["ZEWDW"]),
  249. new CDAParameter("ZMEINS", row["ZMEINS"]),
  250. new CDAParameter("ZZXBZ", row["ZZXBZ"]),
  251. new CDAParameter("ZWYM", row["ZWYM"]),
  252. new CDAParameter("ZNMAE", row["ZNMAE"]),
  253. new CDAParameter("ZMYYSL", row["ZMYYSL"]),
  254. new CDAParameter("ZCPCCBZQ", row["ZCPCC_BZQ"]),
  255. new CDAParameter("ZCPCCBZH", row["ZCPCC_BZH"]),
  256. new CDAParameter("ZBY1", row["ZBY1"]),
  257. new CDAParameter("ZBY2", row["ZBY2"]),
  258. new CDAParameter("ZBY3", row["ZBY3"]),
  259. new CDAParameter("ZBY4", row["ZBY4"]),
  260. new CDAParameter("ZBY5", row["ZBY5"]),
  261. new CDAParameter("ZBY6", row["ZBY6"]),
  262. new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
  263. new CDAParameter("VALUEFLAG", 1),
  264. new CDAParameter("CREATEUSERID", HttpContext.Current.Session["userId"]),
  265. new CDAParameter("UPDATEUSERID", HttpContext.Current.Session["userId"]),
  266. new CDAParameter("ZWLJC", row["ZWLJC"])
  267. );
  268. }
  269. if (result > 0)
  270. {
  271. conn.Commit();
  272. return new JsonResult(JsonStatus.success).ToJson();
  273. }
  274. else
  275. {
  276. conn.Rollback();
  277. return new JsonResult(JsonStatus.error).ToJson();
  278. }
  279. }
  280. }
  281. public bool IsReusable
  282. {
  283. get
  284. {
  285. return false;
  286. }
  287. }
  288. }