using System.Collections.Generic; using System.Data; using System.Reflection; using System.Web.Script.Services; using System.Web.Services; using Tools; using WebService.Model; namespace Webservice { /// /// 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 = "1"; 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; LogHelper.WriteSysLogBase("根据塑料粒子查询加料信息,入参particleCode=" + particleCode, MethodBase.GetCurrentMethod().Name); #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 = ""; //批次 string partNo = ""; //零件号 Function.GetCode(particleCode, out stockNo, out batchNo, out partNo); #endregion if (!string.IsNullOrWhiteSpace(stockNo) || !string.IsNullOrWhiteSpace(partNo)) { DataTable dt = Function.GetInfoByParticles(stockNo, partNo, out errorReason); List listInfo = new List(); if (dt.Rows.Count < 1) { model.Result = "0"; errorReason = "根据零件号:" + partNo + "查询不到塑料粒子信息"; } else { model.Result = "1"; InfoModel info = new InfoModel(); info.Code = dt.Rows[0]["StockNo"].ToString(); ; info.Name = dt.Rows[0]["ProductName"].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; LogHelper.WriteSysLogBase("APP根据塑料粒子查询加料信息,入参particleCode=" + particleCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); 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; LogHelper.WriteSysLogBase("料筒与塑料粒子关系绑定,入参particleCode=" + particleCode + "drumCode=" + drumCode, MethodBase.GetCurrentMethod().Name); #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 #region 20200927注销:查询当前料筒是否已经绑定塑料粒子和注塑机,如果有绑定则提示解绑;如果没绑定注塑机,绑定了塑料粒子,则解绑之前的塑料粒子 //bool isBind = Function.QueryIsBind(particleCode, drumCode, out errorReason); //if (isBind) //{ // model.ErrReason = errorReason; // Context.Response.Write(JSONTools.ScriptSerialize>(model)); // return; //} #endregion #region 解绑之前的塑料粒子 Function.UnBindParticleAndDrum(drumCode, out errorReason); #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; LogHelper.WriteSysLogBase("APP料筒与塑料粒子关系绑定,入参particleCode=" + particleCode + "drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); 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; LogHelper.WriteSysLogBase("根据注塑机条码查询计划信息,入参machineCode=" + machineCode, MethodBase.GetCurrentMethod().Name); #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; LogHelper.WriteSysLogBase("APP根据注塑机条码查询计划信息,入参machineCode=" + machineCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); 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; LogHelper.WriteSysLogBase("根据料筒条码查询加料信息,入参drumCode=" + drumCode, MethodBase.GetCurrentMethod().Name); #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); if (dt != null && dt.Rows.Count > 0) { string cylinderBarCode = dt.Rows[0][0].ToString(); string stockNo = ""; //存货代码 string batchNo = ""; //批次 string partNo = ""; //零件号 Function.GetCode(cylinderBarCode, out stockNo, out batchNo, out partNo); if (!string.IsNullOrWhiteSpace(stockNo) || !string.IsNullOrWhiteSpace(partNo)) { DataTable dt_info = Function.GetInfoByParticles(stockNo, partNo, out errorReason); List listInfo = new List(); if (dt.Rows.Count < 1) { model.Result = "0"; } else { model.Result = "1"; MaterialInfoModel info = new MaterialInfoModel(); if (dt_info != null && dt_info.Rows.Count > 0) { info.Code = dt_info.Rows[0]["PartNo"].ToString(); info.Name = dt_info.Rows[0]["ProductName"].ToString(); } info.Batch = batchNo; listInfo.Add(info); } model.ErrReason = errorReason; model.ResultRowsCount = dt.Rows.Count.ToString(); model.DataList = listInfo; LogHelper.WriteSysLogBase("APP根据料筒条码查询加料信息,入参drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } else { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = "未获取到加料信息"; model.DataList = null; LogHelper.WriteSysLogBase("APP根据料筒条码查询加料信息,入参drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } } else { model.Result = "0"; model.ResultType = "Result"; model.ResultRowsCount = "0"; model.ErrReason = "未获取到条码信息"; model.DataList = null; LogHelper.WriteSysLogBase("APP根据料筒条码查询加料信息,入参drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); 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; LogHelper.WriteSysLogBase("注塑机与料筒关系绑定,入参machineCode=" + machineCode + "drumCode=" + drumCode, MethodBase.GetCurrentMethod().Name); #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; LogHelper.WriteSysLogBase("APP注塑机与料筒关系绑定,入参machineCode=" + machineCode + "drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); 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; LogHelper.WriteSysLogBase("注塑机与料筒关系绑定,入参drumCode=" + drumCode, MethodBase.GetCurrentMethod().Name); #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); bool res = Function.UnBindParticleAndDrum(drumCode, out errorReason); if (res == false) { model.Result = "0"; } else { model.Result = "1"; } model.ErrReason = errorReason; model.ResultRowsCount = res.ToString(); model.DataList = null; LogHelper.WriteSysLogBase("APP注塑机与料筒关系绑定,入参drumCode=" + drumCode + ",出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void UnBindStationAndCylinder(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(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; } #endregion LogHelper.WriteSysLogBase("注塑机与料筒关系解绑,入参machineCode=" + machineCode + ",drumCode=" + drumCode, MethodBase.GetCurrentMethod().Name); bool res = Function.UnBindStationAndCylinder(machineCode, drumCode, out errorReason); if (res == false) { model.Result = "0"; } else { model.Result = "1"; } LogHelper.WriteSysLogBase("注塑机与料筒关系解绑,入参machineCode=" + machineCode + ",drumCode=" + drumCode + "。出参:" + JSONTools.ScriptSerialize>(model), MethodBase.GetCurrentMethod().Name); Context.Response.Write(JSONTools.ScriptSerialize>(model)); } } }