using System; using System.Collections.Generic; using System.Data; using System.Linq; using System.Reflection; using System.Web; using System.Web.Script.Services; using System.Web.Services; using Tools; using Webservice; using WebService.Model; namespace WebService { /// /// 扫码入库附加颜色 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class StockInWebservice : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } #region 入库口附加颜色 /// /// 根据条码获取产品信息 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetProductInfoByBarcode(string app_id, string Barcode, string sign) { string errorReason = ""; JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "List"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; #region 判断参数 if (string.IsNullOrWhiteSpace(app_id)) { model.ErrReason = "缺少必要传入参数 app_id"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(Barcode)) { model.ErrReason = "缺少必要传入参数 Barcode"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(sign)) { model.ErrReason = "缺少必要传入参数 sign"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } bool access = Function.AppIDIsRight(app_id.Trim()); if (!access) { model.ErrReason = "APP接口调用标识不正确 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } string[] param = { Function.app_secret.Trim(), Barcode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion LogHelper.WriteSysLogBase("手持附加颜色【根据条码号获取产品信息】,入参Barcode:" + Barcode, MethodBase.GetCurrentMethod().Name); if (Barcode.Contains(".")) { Barcode = Function.TransToBarCodeOne(Barcode); } string stockNo = ""; //存货代码 string batchNo = ""; //批次 string partNo = ""; //零件号 Function.GetCode(Barcode, out stockNo, out batchNo, out partNo); string proInfo = FunctionAddColor.GetProdunctName(stockNo); ProInfoModel mod = new ProInfoModel(); mod.ProductInfo = proInfo; List list = new List(); list.Add(mod); if (!string.IsNullOrWhiteSpace(proInfo)) { model.Result = "1"; model.ResultType = "List"; model.ResultRowsCount = "1"; model.ErrReason = errorReason; model.DataList = list; } else { model.Result = "0"; model.ResultType = "List"; model.ResultRowsCount = "0"; model.ErrReason = "根据条码:" + Barcode + "查询不到产品信息"; model.DataList = list; } LogHelper.WriteSysLogBase("手持附加颜色【根据条码号获取产品信息】,入参Barcode:" + Barcode + ",出参 产品信息:" + proInfo, MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } /// /// 根据条码获取可选颜色信息 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetColor(string app_id, string Barcode, string sign) { string errorReason = ""; JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "List"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; #region 判断参数 if (string.IsNullOrWhiteSpace(app_id)) { model.ErrReason = "缺少必要传入参数 app_id"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(Barcode)) { model.ErrReason = "缺少必要传入参数 Barcode"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(sign)) { model.ErrReason = "缺少必要传入参数 sign"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } bool access = Function.AppIDIsRight(app_id.Trim()); if (!access) { model.ErrReason = "APP接口调用标识不正确 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } string[] param = { Function.app_secret.Trim(), Barcode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion LogHelper.WriteSysLogBase("手持附加颜色【获取颜色信息】,入参Barcode:" + Barcode, MethodBase.GetCurrentMethod().Name); DataTable dt = FunctionAddColor.GetAllColor(); List list = new List(); if (dt != null && dt.Rows.Count > 0) { for (int i = 0; i < dt.Rows.Count; i++) { ColorInfoModel mod = new ColorInfoModel(); mod.ColorInfo = dt.Rows[i][0].ToString(); list.Add(mod); } } model.Result = "1"; model.ResultType = "List"; model.ResultRowsCount = dt.Rows.Count.ToString(); model.ErrReason = errorReason; model.DataList = list; LogHelper.WriteSysLogBase("手持附加颜色【获取颜色信息】,出参:" + list.ToString(), MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } /// /// 保存 /// /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void SaveBarcodeAndColor(string app_id, string Barcode, string ColorInfo, string sign) { string errorReason = ""; JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; #region 判断参数 if (string.IsNullOrWhiteSpace(app_id)) { model.ErrReason = "缺少必要传入参数 app_id"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(Barcode)) { model.ErrReason = "缺少必要传入参数 Barcode"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(ColorInfo)) { model.ErrReason = "缺少必要传入参数 ColorInfo"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(sign)) { model.ErrReason = "缺少必要传入参数 sign"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } bool access = Function.AppIDIsRight(app_id.Trim()); if (!access) { model.ErrReason = "APP接口调用标识不正确 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } string[] param = { Function.app_secret.Trim(), Barcode.Trim(), ColorInfo.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion LogHelper.WriteSysLogBase("手持附加颜色【保存条码和颜色】,入参Barcode:" + Barcode + ",ColorInfo:" + ColorInfo, MethodBase.GetCurrentMethod().Name); if (Barcode.Contains(".")) { Barcode = Function.TransToBarCodeOne(Barcode); } string stockNo = ""; //存货代码 string batchNo = ""; //批次 string partNo = ""; //零件号 Function.GetCode(Barcode, out stockNo, out batchNo, out partNo); string proInfo = FunctionAddColor.GetProdunctName(stockNo).Trim(); string resultStr = ColorInfo + "," + proInfo; int res = 0; res = FunctionAddColor.SaveBarcodeAndColor(Barcode, resultStr, out errorReason); if (res >= 1) { model.Result = "1"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = ""; model.DataList = null; LogHelper.WriteSysLogBase("手持附加颜色【保存条码和颜色】,入参Barcode:" + Barcode + ",ColorInfo:" + ColorInfo + "已保存", MethodBase.GetCurrentMethod().Name); } else { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; } Context.Response.Write(JSONTools.ScriptSerialize>(model)); } #endregion } }