diff --git a/WebService/AppWebservice.asmx.cs b/WebService/AppWebservice.asmx.cs index 071dd5c..3517e03 100644 --- a/WebService/AppWebservice.asmx.cs +++ b/WebService/AppWebservice.asmx.cs @@ -25,6 +25,117 @@ namespace Webservice return "Hello World"; } + + /// + /// 箱码与总成码关系绑定 + /// + /// + /// + /// + /// + [WebMethod] + [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] + public void BindBoxCodeAndBarCode(string app_id, string boxCode, string barCode, 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("箱码与总成码关系绑定,入参boxCode=" + boxCode + ",barCode=" + barCode, MethodBase.GetCurrentMethod().Name); + + #region 参数判断 + //if (string.IsNullOrWhiteSpace(app_id)) + //{ + // model.ErrReason = "缺少必要传入参数 app_id"; + // Context.Response.Write(JSONTools.ScriptSerialize>(model)); + // return; + //} + //if (string.IsNullOrWhiteSpace(boxCode)) + //{ + // model.ErrReason = "缺少必要传入参数 boxCode"; + // 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(), boxCode.Trim(), barCode.Trim() }; + //bool paramIsRight = Function.signIsRight(param, sign); + //if (!paramIsRight) + //{ + // model.ErrReason = "sign参数传输错误 远程服务器拒绝了此次连接请求"; + // Context.Response.Write(JSONTools.ScriptSerialize>(model)); + // return; + //} + #endregion + + int updateNum = Function.BindBoxCodeAndBarCode(boxCode, barCode, out errorReason); + + DataTable dt = Function.GetCodeRecords(boxCode, out errorReason); + List listInfo = new List(); + + if (dt.Rows.Count < 1) + { + model.Result = "0"; + model.ResultRowsCount = "0"; + model.DataList = null; + model.ErrReason = errorReason; + } + else + { + + listInfo = Tools.DataTableToList.ConvertTo(dt); + model.ResultRowsCount = listInfo.Count.ToString(); + model.DataList = listInfo; + } + + if (updateNum == 0 && !string.IsNullOrEmpty(barCode)) + { + model.Result = "0"; + model.ErrReason = "箱码和总成码绑定失败"; + } + else + { + model.Result = "1"; + string qtyValue = "0"; + var boxCodeSplit = boxCode.Split(';'); + foreach (string part in boxCodeSplit) + { + if (part.StartsWith("QTY:")) + { + qtyValue = part.Substring(4); // 从"QTY:"后的字符开始截取 + } + } + if(listInfo.Count.ToString() == qtyValue) + { + model.ErrReason = "已满箱"; + } + } + + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + } + [WebMethod] [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] public void MD5Encrypt(string str) diff --git a/WebService/Function.cs b/WebService/Function.cs index 4a330d3..d035741 100644 --- a/WebService/Function.cs +++ b/WebService/Function.cs @@ -325,6 +325,117 @@ namespace Webservice } } + /// + /// 获取装箱记录 + /// + /// + /// + /// + public static DataTable GetCodeRecords(string boxCode, out string errorReason) + { + DataTable res = new DataTable(); + try + { + string sql = @" + select * from tb_Punch_Code_Record where BoxCode = '" + boxCode + @"' order by CreateTime desc + "; + res = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); + + errorReason = ""; + return res; + } + catch (Exception ex) + { + LogHelper.WriteLogManager(ex); + LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); + errorReason = ex.Message; + return res; + } + } + + /// + /// 箱码和总成码绑定 + /// + /// + /// + /// + /// + public static int BindBoxCodeAndBarCode(string boxCode, string barCode, out string errorReason) + { + int updateNum = 0; + string qtyValue = "0"; + try + { + errorReason = ""; + var boxCodeSplit = boxCode.Split(';'); + foreach (string part in boxCodeSplit) + { + if (part.StartsWith("QTY:")) + { + qtyValue = part.Substring(4); // 从"QTY:"后的字符开始截取 + } + } + + string sql = @" + select top 1 * from tb_Punch_Code_Record where Flag=1 and ZcBarCode = '" + barCode + @"' order by CreateTime desc + "; + DataTable dt = SqlHelper.GetDataDateTable(SqlHelper.SqlConnString, CommandType.Text, sql, null); + if (dt != null && dt.Rows.Count > 0) + { + string id = dt.Rows[0]["ID"].ToString(); + string barcode = dt.Rows[0]["barcode"].ToString(); + string zcBarCode = dt.Rows[0]["ZcBarCode"].ToString(); + string boxCodeDB = dt.Rows[0]["BoxCode"].ToString(); + if(string.IsNullOrEmpty(boxCodeDB)) + { + string updateSql = @" update [dbo].[tb_Punch_Code_Record] set BoxCode='" + boxCode + "',pkg='"+qtyValue+"' where ID='" + id + "'"; + updateNum = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, updateSql, null); + if (updateNum == 0) + { + errorReason = "箱码和总成码绑定失败"; + } + else + { + string insertSql = @" + insert into tb_Punch_Interface(PackageCode,OneBarCode) + values('" + boxCode + "','"+ barCode + @"') + "; + int insertNum = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, insertSql, null); + } + } + else + { + if(boxCode.Trim() == boxCodeDB.Trim()) + { + errorReason = "箱码已包含此总成"; + } + else + { + errorReason = "其他箱码已包含此总成"; + } + + } + + } + else + { + errorReason = "根据总成码未查到合格信息"; + } + + return updateNum; + } + catch (Exception ex) + { + LogHelper.WriteLogManager(ex); + LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); + errorReason = ex.Message; + return updateNum; + } + } + + + + public static DataTable GetMaterialInfo(string drumCode, out string errorReason) { DataTable res = new DataTable(); diff --git a/WebService/Model/MKModel .cs b/WebService/Model/MKModel .cs new file mode 100644 index 0000000..7b5b120 --- /dev/null +++ b/WebService/Model/MKModel .cs @@ -0,0 +1,43 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; + +namespace WebService.Model +{ + public class MKModel + { + /// + /// 塑件码 + /// + public string barcode { get; set; } + /// + /// 总成零件号 + /// + public string ZcBarCode { get; set; } + ///// + ///// 订单号 + ///// + //public string OrderNo { get; set; } + ///// + ///// 班次 + ///// + //public string WorkClass { get; set; } + /// + /// 合格标记 + /// + public int Flag { get; set; } + /// + /// 箱码 + /// + public string BoxCode { get; set; } + ///// + ///// 标包 + ///// + //public string PKG { get; set; } + ///// + ///// 创建时间 + ///// + //public DateTime CreateTime { get; set; } + } +} \ No newline at end of file diff --git a/WebService/WebService.csproj b/WebService/WebService.csproj index b40b104..4bc0235 100644 --- a/WebService/WebService.csproj +++ b/WebService/WebService.csproj @@ -122,6 +122,7 @@ + diff --git a/WebService/WebService.csproj.user b/WebService/WebService.csproj.user index e32f45c..1f24385 100644 --- a/WebService/WebService.csproj.user +++ b/WebService/WebService.csproj.user @@ -1,4 +1,4 @@ - + Debug|Any CPU @@ -15,7 +15,7 @@ - WMSWebService.asmx + AppWebservice.asmx SpecificPage True False