| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303 |
- <%@ WebHandler Language="C#" Class="bompackunit" %>
- using System;
- using System.Web;
- using System.Web.SessionState;
- using System.Collections.Generic;
- using System.Collections.Specialized;
- using System.Data;
- using Curtain.DataAccess;
- using DK.XuWei.WebMes;
- public class bompackunit : IHttpHandler, IReadOnlySessionState
- {
- public void ProcessRequest(HttpContext context)
- {
- context.Response.ContentType = "text/plain";
- if (context.Request["m"] is object)
- {
- switch (context.Request["m"].ToString().ToLower())
- {
- case "s":
- {
- context.Response.Write(search(context.Request.Form));
- break;
- }
- case "sync":
- {
- context.Response.Write(sync(context));
- break;
- }
- default:
- {
- break;
- }
- }
- }
- else
- {
- context.Response.Write(new JsonResult(JsonStatus.loginError).ToJson());
- }
- }
- /// <summary>
- /// 查询
- /// </summary>
- /// <returns>json</returns>
- private string search(NameValueCollection form)
- {
- using (IDataAccess conn = DataAccess.Create())
- {
- int page = HttpContext.Current.Request["page"] is object ? Convert.ToInt32(HttpContext.Current.Request["page"]) : 1;
- int rows = HttpContext.Current.Request["rows"] is object ? Convert.ToInt32(HttpContext.Current.Request["rows"]) : 10;
- string sort = HttpContext.Current.Request["sort"] is object ? HttpContext.Current.Request["sort"] : "";
- string order = HttpContext.Current.Request["order"] is object ? HttpContext.Current.Request["order"] : "";
- string sqlStr = @"SELECT * FROM TP_PC_SAPBOMDETAIL WHERE 1= 1";
- List<CDAParameter> sqlPara = new List<CDAParameter>();
- if (!string.IsNullOrEmpty(form["MATNR"]))
- {
- sqlStr += " AND MATNR = @MATNR@ ";
- sqlPara.Add(new CDAParameter("MATNR", form["MATNR"]));
- }
- int total = 0;
- DataTable dt = conn.SelectPages(page, rows, out total, sqlStr, sqlPara.ToArray());
- return new JsonResult(dt) { total = total }.ToJson();
- }
- }
- /// <summary>
- /// 同步
- /// </summary>
- /// <returns>json</returns>
- private string sync(HttpContext context)
- {
- string ZTYPE;
- string ZMSG;
- DataTable dtResult = SapApi.ZMMFM054(out ZTYPE, out ZMSG,"ALL", context.Request["MATNR"]);
- if ("E".Equals(ZTYPE) || dtResult == null || dtResult.Rows.Count == 0)
- {
- return new JsonResult(JsonStatus.otherError).ToJson();
- }
- using (IDataAccess conn = DataAccess.Create())
- {
- // 开启事务
- conn.BeginTransaction();
- string delsql = @"DELETE FROM TP_PC_SAPBOMDETAIL";
- List<CDAParameter> sqlPara = new List<CDAParameter>();
- // 删除所有
- int result = conn.ExecuteNonQuery(delsql);
- // 插入新的
- string sqlString = @"
- INSERT INTO TP_PC_SAPBOMDETAIL (
- MATNR
- ,WERKS
- ,MAKTX
- ,MATKL
- ,WGBEZ
- ,MEINS
- ,LABOR
- ,LGFSB
- ,MTART
- ,LVORM
- ,BSTRF
- ,PRDHA
- ,VTEXT
- ,BSTME
- ,VOLUM
- ,BESKZ
- ,SOBSL
- ,LGPRO
- ,MTPOSMARA
- ,GROES
- ,STPRS
- ,UMREZ
- ,PEINH
- ,XCHAR
- ,ZGG
- ,ZYS
- ,ZCSJ
- ,VRKME
- ,ERSDA
- ,MAABC
- ,BRGEW
- ,NTGEW
- ,VOLEH
- ,ZWLFL
- ,ZWXGG
- ,ZWXMZ
- ,ZWXJZ
- ,ZEWSL
- ,ZEWDW
- ,ZMEINS
- ,ZZXBZ
- ,ZWYM
- ,ZNMAE
- ,ZMYYSL
- ,ZCPCCBZQ
- ,ZCPCCBZH
- ,ZBY1
- ,ZBY2
- ,ZBY3
- ,ZBY4
- ,ZBY5
- ,ZBY6
- ,ACCOUNTID
- ,VALUEFLAG
- ,CREATEUSERID
- ,UPDATEUSERID
- ,ZWLJC
- ) values(
- @MATNR@
- ,@WERKS@
- ,@MAKTX@
- ,@MATKL@
- ,@WGBEZ@
- ,@MEINS@
- ,@LABOR@
- ,@LGFSB@
- ,@MTART@
- ,@LVORM@
- ,@BSTRF@
- ,@PRDHA@
- ,@VTEXT@
- ,@BSTME@
- ,@VOLUM@
- ,@BESKZ@
- ,@SOBSL@
- ,@LGPRO@
- ,@MTPOSMARA@
- ,@GROES@
- ,@STPRS@
- ,@UMREZ@
- ,@PEINH@
- ,@XCHAR@
- ,@ZGG@
- ,@ZYS@
- ,@ZCSJ@
- ,@VRKME@
- ,@ERSDA@
- ,@MAABC@
- ,@BRGEW@
- ,@NTGEW@
- ,@VOLEH@
- ,@ZWLFL@
- ,@ZWXGG@
- ,@ZWXMZ@
- ,@ZWXJZ@
- ,@ZEWSL@
- ,@ZEWDW@
- ,@ZMEINS@
- ,@ZZXBZ@
- ,@ZWYM@
- ,@ZNMAE@
- ,@ZMYYSL@
- ,@ZCPCCBZQ@
- ,@ZCPCCBZH@
- ,@ZBY1@
- ,@ZBY2@
- ,@ZBY3@
- ,@ZBY4@
- ,@ZBY5@
- ,@ZBY6@
- ,@ACCOUNTID@
- ,@VALUEFLAG@
- ,@CREATEUSERID@
- ,@UPDATEUSERID@
- ,@ZWLJC@
- )";
- decimal menge = 0;
- foreach (DataRow row in dtResult.Rows)
- {
- decimal.TryParse(row["BSTRF"] + "", out menge);
- menge = menge == 0 ? 1 : menge;
- result += conn.ExecuteNonQuery(sqlString,
- new CDAParameter("MATNR", row["MATNR"]),
- new CDAParameter("WERKS", "5000"),
- new CDAParameter("MAKTX", row["MAKTX"]),
- new CDAParameter("MATKL", row["MATKL"]),
- new CDAParameter("WGBEZ", row["WGBEZ"]),
- new CDAParameter("MEINS", row["MEINS"]),
- new CDAParameter("LABOR", row["LABOR"]),
- new CDAParameter("LGFSB", row["LGFSB"]),
- new CDAParameter("MTART", row["MTART"]),
- new CDAParameter("LVORM", row["LVORM"]),
- new CDAParameter("BSTRF", row["BSTRF"]),
- new CDAParameter("PRDHA", row["PRDHA"]),
- new CDAParameter("VTEXT", row["VTEXT"]),
- new CDAParameter("BSTME", row["BSTME"]),
- new CDAParameter("VOLUM", row["VOLUM"]),
- new CDAParameter("BESKZ", row["BESKZ"]),
- new CDAParameter("SOBSL", row["SOBSL"]),
- new CDAParameter("LGPRO", row["LGPRO"]),
- new CDAParameter("MTPOSMARA", row["MTPOS_MARA"]),
- new CDAParameter("GROES", row["GROES"]),
- new CDAParameter("STPRS", row["STPRS"]),
- new CDAParameter("UMREZ", row["UMREZ"]),
- new CDAParameter("PEINH", row["PEINH"]),
- new CDAParameter("XCHAR", row["XCHAR"]),
- new CDAParameter("ZGG", row["ZGG"]),
- new CDAParameter("ZYS", row["ZYS"]),
- new CDAParameter("ZCSJ", row["ZCSJ"]),
- new CDAParameter("VRKME", row["VRKME"]),
- new CDAParameter("ERSDA", row["ERSDA"]),
- new CDAParameter("MAABC", row["MAABC"]),
- new CDAParameter("BRGEW", row["BRGEW"]),
- new CDAParameter("NTGEW", row["NTGEW"]),
- new CDAParameter("VOLEH", row["VOLEH"]),
- new CDAParameter("ZWLFL", row["ZWLFL"]),
- new CDAParameter("ZWXGG", row["ZWXGG"]),
- new CDAParameter("ZWXMZ", row["ZWXMZ"]),
- new CDAParameter("ZWXJZ", row["ZWXJZ"]),
- new CDAParameter("ZEWSL", row["ZEWSL"]),
- new CDAParameter("ZEWDW", row["ZEWDW"]),
- new CDAParameter("ZMEINS", row["ZMEINS"]),
- new CDAParameter("ZZXBZ", row["ZZXBZ"]),
- new CDAParameter("ZWYM", row["ZWYM"]),
- new CDAParameter("ZNMAE", row["ZNMAE"]),
- new CDAParameter("ZMYYSL", row["ZMYYSL"]),
- new CDAParameter("ZCPCCBZQ", row["ZCPCC_BZQ"]),
- new CDAParameter("ZCPCCBZH", row["ZCPCC_BZH"]),
- new CDAParameter("ZBY1", row["ZBY1"]),
- new CDAParameter("ZBY2", row["ZBY2"]),
- new CDAParameter("ZBY3", row["ZBY3"]),
- new CDAParameter("ZBY4", row["ZBY4"]),
- new CDAParameter("ZBY5", row["ZBY5"]),
- new CDAParameter("ZBY6", row["ZBY6"]),
- new CDAParameter("ACCOUNTID", HttpContext.Current.Session["accountId"]),
- new CDAParameter("VALUEFLAG", 1),
- new CDAParameter("CREATEUSERID", HttpContext.Current.Session["userId"]),
- new CDAParameter("UPDATEUSERID", HttpContext.Current.Session["userId"]),
- new CDAParameter("ZWLJC", row["ZWLJC"])
- );
- }
- if (result > 0)
- {
- conn.Commit();
- return new JsonResult(JsonStatus.success).ToJson();
- }
- else
- {
- conn.Rollback();
- return new JsonResult(JsonStatus.error).ToJson();
- }
- }
- }
- public bool IsReusable
- {
- get
- {
- return false;
- }
- }
- }
|