using AppWebservice.Model; using System.Collections.Generic; using System.Data; using System.Web.Script.Services; using System.Web.Services; using Tools; namespace AppWebservice { /// /// AppWebservice 的摘要说明 /// [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 AppWebservice : System.Web.Services.WebService { [WebMethod] public string HelloWorld() { return "Hello World"; } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void MD5Encrypt(string str) { string errorReason = ""; JsonModel model = new JsonModel(); model.Result = "0"; model.ResultType = "List"; model.ResultRowsCount = "0"; model.ErrReason = errorReason; model.DataList = null; List res = new List(); if (!string.IsNullOrWhiteSpace(str)) { DataTable dt = new DataTable(); dt.Columns.Add("result"); DataRow dr = dt.NewRow(); dr[0] = Function.MD5Encryption(str); dt.Rows.Add(dr); res = Tools.DataTableToList.ConvertTo(dt); model.Result = "0"; model.ResultRowsCount = "1"; model.DataList = res; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } else { model.ErrReason = "缺少必要的传入参数 服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } } /// /// 根据塑料粒子条码查询加料信息 /// lx 20190527 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetInfoByParticles(string app_id, string particleCode, 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(particleCode)) { model.ErrReason = "缺少必要传入参数 particleCode"; 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(), particleCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion #region 解析塑料粒子条码 //解析塑料粒子条码,长度为20的为一维码,否则为二维码 //二维码样例Z-340.180411.000001;5000;S35001;20180411;P1710401.[#Line#];180411; //第一个分号之前的数据,即Z-340.180411.000001; Z-340为零件号,180411为批次号,000001为流水号 //一维码前十位为零件号,tb_Product PartNo,11~16位为批次 string stockNo = ""; //存货代码 string batchNo = ""; //批次 Function.GetCode(particleCode, out stockNo, out batchNo); #endregion if (!string.IsNullOrWhiteSpace(stockNo)) { DataTable dt = Function.GetInfoByParticles(stockNo, out errorReason); List listInfo = new List(); if (dt.Rows.Count < 1) { model.Result = "0"; } else { model.Result = "1"; InfoModel info = new InfoModel(); info.Code = stockNo; info.Name = dt.Rows[0]["PartName"].ToString(); info.Type = dt.Rows[0]["PartNo"].ToString(); info.CarType = "塑料粒子"; info.Color = dt.Rows[0]["ColorName"].ToString(); info.Batch = batchNo; info.Stock = ""; listInfo.Add(info); } model.ErrReason = errorReason; model.ResultRowsCount = dt.Rows.Count.ToString(); model.DataList = listInfo; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } else { model.Result = "0"; model.ErrReason = "塑料粒子条码错误,无法解析"; model.ResultRowsCount = "0"; model.DataList = null; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } } /// /// 料筒与塑料粒子关系绑定 /// lx 20190527 /// /// /// 塑料粒子 /// /// 料筒 /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void BindparticleCodeAndDrum(string app_id, string particleCode, string drumCode, 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(particleCode)) { model.ErrReason = "缺少必要传入参数 particleCode"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(drumCode)) { model.ErrReason = "缺少必要传入参数 drumCode"; 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(), particleCode.Trim(), drumCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion int res = Function.BindparticleCodeAndDrum(particleCode, drumCode, out errorReason); if (res < 1) { model.Result = "0"; } else { model.Result = "1"; } model.ErrReason = errorReason; model.ResultRowsCount = res.ToString(); model.DataList = null; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } /// /// 根据注塑机条码查询计划信息 /// lx 20190527 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetPlan(string app_id, string machineCode, 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(machineCode)) { model.ErrReason = "缺少必要传入参数 machineCode"; 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(), machineCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion DataTable dt = Function.GetPlan(machineCode, out errorReason); List listInfo = new List(); if (dt.Rows.Count < 1) { model.Result = "0"; } else { model.Result = "1"; listInfo = Tools.DataTableToList.ConvertTo(dt); } model.ErrReason = errorReason; model.ResultRowsCount = dt.Rows.Count.ToString(); model.DataList = listInfo; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } /// /// 根据料筒条码查询加料信息 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void GetMaterialInfo(string app_id, string drumCode, 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(drumCode)) { model.ErrReason = "缺少必要传入参数 drumCode"; 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(), drumCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion DataTable dt = Function.GetMaterialInfo(drumCode, out errorReason); string cylinderBarCode = dt.Rows[0][0].ToString(); string stockNo = ""; //存货代码 string batchNo = ""; //批次 Function.GetCode(cylinderBarCode, out stockNo, out batchNo); if (!string.IsNullOrWhiteSpace(stockNo)) { DataTable dt_info = Function.GetInfoByParticles(stockNo, out errorReason); List listInfo = new List(); if (dt.Rows.Count < 1) { model.Result = "0"; } else { model.Result = "1"; MaterialInfoModel info = new MaterialInfoModel(); info.Code = cylinderBarCode; info.Name = dt_info.Rows[0]["PartName"].ToString(); info.Batch = batchNo; listInfo.Add(info); } model.ErrReason = errorReason; model.ResultRowsCount = dt.Rows.Count.ToString(); model.DataList = listInfo; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } else { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = "未获取到加料信息"; model.DataList = null; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } } /// /// 注塑机与料筒关系绑定 /// lx 20190527 /// /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void BindMachineAndDrum(string app_id, string machineCode, string drumCode, 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(machineCode)) { model.ErrReason = "缺少必要传入参数 machineCode"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } if (string.IsNullOrWhiteSpace(drumCode)) { model.ErrReason = "缺少必要传入参数 drumCode"; 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(), machineCode.Trim(), drumCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion int res = Function.BindMachineAndDrum(machineCode, drumCode, out errorReason); if (res < 1) { model.Result = "0"; } else { model.Result = "1"; } model.ErrReason = errorReason; model.ResultRowsCount = res.ToString(); model.DataList = null; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } /// /// 料筒清空关系解绑 /// lx 20190527 /// /// /// /// [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void ClearDrum(string app_id, string drumCode, 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(drumCode)) { model.ErrReason = "缺少必要传入参数 drumCode"; 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(), drumCode.Trim() }; bool paramIsRight = Function.signIsRight(param, sign); if (!paramIsRight) { model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } #endregion int res = Function.ClearDrum(drumCode, out errorReason); if (res < 1) { model.Result = "0"; } else { model.Result = "1"; } model.ErrReason = errorReason; model.ResultRowsCount = res.ToString(); model.DataList = null; Context.Response.Write(JSONTools.ScriptSerialize>(model)); } } }