diff --git a/WebService/AppWebservice.asmx.cs b/WebService/AppWebservice.asmx.cs index 5408ca4..bf7b04b 100644 --- a/WebService/AppWebservice.asmx.cs +++ b/WebService/AppWebservice.asmx.cs @@ -219,6 +219,215 @@ namespace Webservice 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 50b2f01..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; @@ -443,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