diff --git a/WebService/AppWebservice.asmx.cs b/WebService/AppWebservice.asmx.cs index 9487064..bf7b04b 100644 --- a/WebService/AppWebservice.asmx.cs +++ b/WebService/AppWebservice.asmx.cs @@ -65,9 +65,17 @@ namespace Webservice Context.Response.Write(JSONTools.ScriptSerialize>(model)); return; } - //箱码格式验证 + //小米箱码格式验证 + //var boxCodeList = boxCode.Split(';'); + //if (!boxCode.Contains("PN") || !boxCode.Contains("PKG") || !boxCode.Contains("QTY") || boxCodeList.Length != 7 || boxCodeList[0].Length != 16 || boxCodeList[1].Length != 12 || boxCodeList[5].Length != 16) + //{ + // model.ErrReason = "箱码标签格式不对"; + // Context.Response.Write(JSONTools.ScriptSerialize>(model)); + // return; + //} + //Wms箱码格式验证 var boxCodeList = boxCode.Split(';'); - if (!boxCode.Contains("PN") || !boxCode.Contains("PKG") || !boxCode.Contains("QTY") || boxCodeList.Length != 7 || boxCodeList[0].Length != 16 || boxCodeList[1].Length != 12 || boxCodeList[5].Length != 16) + if (!boxCode.Contains(".0") || !boxCode.Contains("/") || boxCodeList.Length != 7 || boxCodeList[5].Length != 10) { model.ErrReason = "箱码标签格式不对"; Context.Response.Write(JSONTools.ScriptSerialize>(model)); @@ -141,8 +149,9 @@ namespace Webservice return; } - //箱码和总成码零件验证 - string boxPartNo = boxCodeList[0].Substring(3,10); + //箱码和总成码零件号验证 分Wms箱码和小米箱码 + //string boxPartNo = boxCodeList[0].Substring(3,10); + string boxPartNo = boxCodeList[0].Substring(0, 10); string barCodePartNo = barCodeList[0].Substring(0, 10); if(boxPartNo != barCodePartNo) { @@ -192,24 +201,233 @@ namespace Webservice 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) - { + //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) + //{ - } + //} } } Context.Response.Write(JSONTools.ScriptSerialize>(model)); } + /// + /// WMS箱码与小米箱码绑定 + /// + /// + /// + /// + /// + [WebMethod] + [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] + public void ChangeBoxCode(string app_id, string boxCode, string changeBoxCode, 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("WMS箱码与小米箱码绑定,入参boxCode=" + boxCode + ",changeBoxCode=" + changeBoxCode, MethodBase.GetCurrentMethod().Name); + Context.Response.ContentType = "application/json; charset=utf-8"; + + //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(changeBoxCode)) + { + model.ErrReason = "缺少必要传入参数 changeBoxCode"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + + var boxCodeList = boxCode.Split(';'); + var changeBoxCodeList = changeBoxCode.Split(';'); + + //小米箱码格式验证 + if (!changeBoxCode.Contains("PN") || !changeBoxCode.Contains("PKG") || !changeBoxCode.Contains("QTY") || changeBoxCodeList.Length != 7 || changeBoxCodeList[0].Length != 16 || changeBoxCodeList[1].Length != 12 || changeBoxCodeList[5].Length != 16) + { + model.ErrReason = "小米箱码标签格式不对"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + //Wms箱码格式验证 + if (!boxCode.Contains(".0") || !boxCode.Contains("/") || boxCodeList.Length != 7 || boxCodeList[5].Length != 10) + { + model.ErrReason = "Wms箱码标签格式不对"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + string boxPartNo = boxCodeList[0].Substring(0, 10); + string changeBoxPartNo = changeBoxCodeList[0].Substring(3,10); + //Wms箱码和小米箱码零件号验证 + if (boxPartNo != changeBoxPartNo) + { + model.Result = "0"; + model.ErrReason = "Wms箱码和小米箱码零件号不符"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + List listInfo = new List(); + string errorReasonBoxData = ""; + DataTable dtBoxNum = Function.GetCodeRecords(boxCode, out errorReasonBoxData); + string qtyValue = boxCodeList[1]; + + if (dtBoxNum != null && dtBoxNum.Rows.Count == 0) + { + model.ErrReason = "Wms箱单装箱数量为0,无法绑定"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + if (dtBoxNum != null && dtBoxNum.Rows.Count.ToString() != qtyValue) + { + model.ErrReason = "Wms箱单不满箱无法绑定"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + + + if (!string.IsNullOrEmpty(errorReasonBoxData)) + { + model.ErrReason = errorReasonBoxData; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + listInfo = Tools.DataTableToList.ConvertTo(dtBoxNum); + if(listInfo.Count > 1) + { + if (!string.IsNullOrEmpty(listInfo[0].ChangeBoxCode)) + { + model.ErrReason = "Wms箱码和小米箱码已绑定"; + model.ResultRowsCount = listInfo.Count.ToString(); + model.DataList = listInfo; + model.Result = "0"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + } + + int updateNum = Function.BindBoxCodeAndChangeBoxCode(boxCode, changeBoxCode, out errorReason); + + if (!string.IsNullOrEmpty(errorReason)) + { + model.Result = "0"; + model.ErrReason = errorReason; + } + else + { + dtBoxNum = Function.GetCodeRecords(boxCode, out errorReasonBoxData); + listInfo.Clear(); + listInfo = Tools.DataTableToList.ConvertTo(dtBoxNum); + model.ResultRowsCount = listInfo.Count.ToString(); + model.DataList = listInfo; + model.Result = "1"; + model.ErrReason = ""; + } + + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + } + + /// + /// 获取小米箱码绑定数据 + /// + /// + /// + /// + [WebMethod] + [ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)] + public void GetMiBoxCodeData(string app_id, string boxCode, 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("WMS箱码与小米箱码绑定,入参boxCode=" + boxCode , MethodBase.GetCurrentMethod().Name); + Context.Response.ContentType = "application/json; charset=utf-8"; + + //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; + } + + var boxCodeList = boxCode.Split(';'); + + //小米箱码格式验证 + if (!boxCode.Contains("PN") || !boxCode.Contains("PKG") || !boxCode.Contains("QTY") || boxCodeList.Length != 7 || boxCodeList[0].Length != 16 || boxCodeList[1].Length != 12 || boxCodeList[5].Length != 16) + { + model.ErrReason = "小米箱码标签格式不对"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + + List listInfo = new List(); + string errorReasonBoxData = ""; + DataTable dtBoxNum = Function.GetMiCodeRecords(boxCode, out errorReasonBoxData); + + if (!string.IsNullOrEmpty(errorReasonBoxData)) + { + model.ErrReason = errorReasonBoxData; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + listInfo = Tools.DataTableToList.ConvertTo(dtBoxNum); + if (listInfo == null) + { + model.ErrReason = "小米箱码未绑定"; + model.Result = "0"; + Context.Response.Write(JSONTools.ScriptSerialize>(model)); + return; + } + + model.ResultRowsCount = listInfo.Count.ToString(); + model.DataList = listInfo; + model.Result = "1"; + 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 57a33c5..3f7b2bc 100644 --- a/WebService/Function.cs +++ b/WebService/Function.cs @@ -353,13 +353,42 @@ namespace Webservice } } - /// - /// 箱码和总成码绑定 - /// - /// - /// - /// - /// + /// + /// 获取小米箱码装箱记录 + /// + /// + /// + /// + public static DataTable GetMiCodeRecords(string boxCode, out string errorReason) + { + DataTable res = new DataTable(); + try + { + string sql = @" + select * from tb_Punch_Code_Record where ChangeBoxCode = '" + 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; @@ -368,13 +397,14 @@ namespace Webservice { errorReason = ""; var boxCodeSplit = boxCode.Split(';'); - foreach (string part in boxCodeSplit) - { - if (part.StartsWith("QTY:")) - { - qtyValue = part.Substring(4); // 从"QTY:"后的字符开始截取 - } - } + qtyValue = boxCodeSplit[1]; + //foreach (string part in boxCodeSplit) + //{ + // if (part.StartsWith("QTY:")) + // { + // qtyValue = part.Substring(4); // 从"QTY:"后的字符开始截取 + // } + //} DataTable dtBoxNum = GetCodeRecords(boxCode, out errorReason); if(dtBoxNum != null && dtBoxNum.Rows.Count.ToString() == qtyValue) @@ -397,7 +427,7 @@ namespace Webservice 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 + "'"; + string updateSql = @" update [dbo].[tb_Punch_Code_Record] set BoxCode='" + boxCode + "',BoxCodeUpdateTime='" + DateTime.Now + "',pkg='" + qtyValue+"' where ID='" + id + "'"; updateNum = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, updateSql, null); if (updateNum == 0) { @@ -442,6 +472,39 @@ namespace Webservice } } + /// + /// WMS箱码与小米箱码绑定 + /// + /// + /// + /// + /// + public static int BindBoxCodeAndChangeBoxCode(string boxCode, string changeBoxCode, out string errorReason) + { + int updateNum = 0; + + try + { + errorReason = ""; + + string updateSql = @" update [dbo].[tb_Punch_Code_Record] set ChangeBoxCode='" + changeBoxCode + "',ChangeTime='" + DateTime.Now + "' where BoxCode='" + boxCode + "'"; + updateNum = SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnString, CommandType.Text, updateSql, null); + if (updateNum == 0) + { + errorReason = "WMS箱码与小米箱码绑定失败"; + } + + return updateNum; + } + catch (Exception ex) + { + LogHelper.WriteLogManager(ex); + LogHelper.WriteErrLogBase(ex.ToString(), MethodBase.GetCurrentMethod().Name); + errorReason = ex.Message; + return updateNum; + } + } + diff --git a/WebService/Model/MKModel .cs b/WebService/Model/MKModel .cs index 7b5b120..0e07cbb 100644 --- a/WebService/Model/MKModel .cs +++ b/WebService/Model/MKModel .cs @@ -28,7 +28,7 @@ namespace WebService.Model /// public int Flag { get; set; } /// - /// 箱码 + /// Wms箱码 /// public string BoxCode { get; set; } ///// @@ -39,5 +39,10 @@ namespace WebService.Model ///// 创建时间 ///// //public DateTime CreateTime { get; set; } + + /// + /// 小米箱码 + /// + public string ChangeBoxCode { get; set; } } } \ No newline at end of file