| | |
| | | */ |
| | | var TypeLot = "1, 5, 6, 7"; //批次可为空单据类型 |
| | | |
| | | int codeStrNum = 0; |
| | | try |
| | | { |
| | | if (model.Origin == "录入" || model.Origin == "导入") |
| | |
| | | && m.CreateTime.ToString("yyyyMM") == DateTime.Now.ToString("yyyyMM")).Max(m => m.BoxCodeStr); |
| | | if(string.IsNullOrWhiteSpace(maxBoxCodeStr)) |
| | | { |
| | | maxBoxCodeStr = "BK" + toDayTime.Substring(2, 4) + "0001"; |
| | | string codeEndStr = (1 + codeStrNum).ToString().PadLeft(4, '0'); |
| | | maxBoxCodeStr = "BK" + toDayTime.Substring(2, 4) + codeEndStr; |
| | | } |
| | | else |
| | | { |
| | | maxBoxCodeStr = "BK" + (int.Parse(maxBoxCodeStr.Replace("BK", "")) + 1).ToString(); |
| | | maxBoxCodeStr = "BK" + (int.Parse(maxBoxCodeStr.Replace("BK", "")) + 1 + codeStrNum).ToString(); |
| | | } |
| | | detailModel.BoxCodeStr = maxBoxCodeStr; |
| | | |
| | | codeStrNum++; |
| | | } |
| | | |
| | | // 判断是否已存在当前明细 |
| | |
| | | } |
| | | string lot1 = detailModel.Lot1; |
| | | string lot2 = detailModel.Lot2; |
| | | if (sku.IsControlled == "0")//是否请验,0:是 1:否 |
| | | //if (sku.IsControlled == "0")//是否请验,0:是 1:否 |
| | | //{ |
| | | // //需要请验物料 生产日期、有效期不能为空 |
| | | // DateTime lot12; |
| | | // DateTime lot22; |
| | | // if (!DateTime.TryParse(detailModel.Lot1, out lot12)) |
| | | // { |
| | | // throw new Exception("需要请验料生产日期转换失败"); |
| | | // } |
| | | // if (!DateTime.TryParse(detailModel.Lot2, out lot22)) |
| | | // { |
| | | // throw new Exception("需要请验料过期日期转换失败"); |
| | | // } |
| | | // lot1 = lot12.ToString("yyyy-MM-dd"); |
| | | // lot2 = lot22.ToString("yyyy-MM-dd"); |
| | | //} |
| | | if (!string.IsNullOrEmpty(lot1)) |
| | | { |
| | | //需要请验物料 生产日期、有效期不能为空 |
| | | DateTime lot12; |
| | | DateTime lot22; |
| | | if (!DateTime.TryParse(detailModel.Lot1, out lot12)) |
| | | { |
| | | throw new Exception("需要请验物料生产日期转换失败"); |
| | | } |
| | | if (!DateTime.TryParse(detailModel.Lot2, out lot22)) |
| | | { |
| | | throw new Exception("需要请验料过期日期转换失败"); |
| | | throw new Exception("生产日期转换失败,请检查格式是否正确"); |
| | | } |
| | | lot1 = lot12.ToString("yyyy-MM-dd"); |
| | | } |
| | | if (!string.IsNullOrEmpty(lot2)) |
| | | { |
| | | DateTime lot22; |
| | | if (!DateTime.TryParse(detailModel.Lot2, out lot22)) |
| | | { |
| | | throw new Exception("到期日期转换失败,请检查格式是否正确"); |
| | | } |
| | | lot2 = lot22.ToString("yyyy-MM-dd"); |
| | | } |
| | | |
| | | if (string.IsNullOrWhiteSpace(detailModel.PackagNo)) |
| | | { |
| | | detailModel.PackagNo = sku.PackagNo; |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | throw new Exception(ex.Message); |
| | | } |
| | | } |
| | |
| | | //} |
| | | |
| | | // 3. 根据受控状态验证日期 |
| | | if (material.IsControlled=="0") |
| | | //if (material.IsControlled=="0") |
| | | //{ |
| | | // // 受控状态:生产日期必填 |
| | | // if (string.IsNullOrWhiteSpace(detailModel.Lot1)) |
| | | // return $"-1:物料{detailModel.SkuNo}为需请验物料,生产日期不可为空;"; |
| | | |
| | | // // 受控状态:过期日期必填 |
| | | // if (string.IsNullOrWhiteSpace(detailModel.Lot2)) |
| | | // return $"-1:物料{detailModel.SkuNo}为需请验物料,过期日期不可为空;"; |
| | | |
| | | // // 验证日期格式有效性 |
| | | // if (!DateTime.TryParse(detailModel.Lot1, out DateTime productionDate)) |
| | | // return $"-1:物料{detailModel.SkuNo}的生产日期格式错误,请使用有效日期格式;"; |
| | | |
| | | // if (!DateTime.TryParse(detailModel.Lot2, out DateTime expiryDate)) |
| | | // return $"-1:物料{detailModel.SkuNo}的过期日期格式错误,请使用有效日期格式;"; |
| | | |
| | | // // 验证过期日期不能早于生产日期 |
| | | // if (expiryDate <= productionDate) |
| | | // return $"-1:物料{detailModel.SkuNo}的过期日期不能早于生产日期;"; |
| | | //} |
| | | |
| | | if (!string.IsNullOrEmpty(detailModel.Lot1)) |
| | | { |
| | | // 受控状态:生产日期必填 |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot1)) |
| | | return $"-1:物料{detailModel.SkuNo}为需请验物料,生产日期不可为空;"; |
| | | |
| | | // 受控状态:过期日期必填 |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot2)) |
| | | return $"-1:物料{detailModel.SkuNo}为需请验物料,过期日期不可为空;"; |
| | | |
| | | // 验证日期格式有效性 |
| | | if (!DateTime.TryParse(detailModel.Lot1, out DateTime productionDate)) |
| | | return $"-1:物料{detailModel.SkuNo}的生产日期格式错误,请使用有效日期格式;"; |
| | | |
| | | if (!DateTime.TryParse(detailModel.Lot2, out DateTime expiryDate)) |
| | | return $"-1:物料{detailModel.SkuNo}的过期日期格式错误,请使用有效日期格式;"; |
| | | |
| | | // 验证过期日期不能早于生产日期 |
| | | if (expiryDate <= productionDate) |
| | | return $"-1:物料{detailModel.SkuNo}的过期日期不能早于生产日期;"; |
| | | DateTime lot12; |
| | | if (!DateTime.TryParse(detailModel.Lot1, out lot12)) |
| | | { |
| | | throw new Exception("生产日期转换失败,请检查格式是否正确"); |
| | | } |
| | | detailModel.Lot1 = lot12.ToString("yyyy-MM-dd"); |
| | | } |
| | | if (!string.IsNullOrEmpty(detailModel.Lot2)) |
| | | { |
| | | DateTime lot22; |
| | | if (!DateTime.TryParse(detailModel.Lot2, out lot22)) |
| | | { |
| | | throw new Exception("到期日期转换失败,请检查格式是否正确"); |
| | | } |
| | | detailModel.Lot2 = lot22.ToString("yyyy-MM-dd"); |
| | | } |
| | | |
| | | // 不受控状态:日期非必填,无需验证 |
| | | |
| | | // 原有批次相关验证(保留) |
| | |
| | | |
| | | // 处理价格默认值 |
| | | detailModel.Price ??= 0; |
| | | |
| | | detailModel.BoxCodeStr = detailModel.LotNo; |
| | | // 生成箱码(自有批次逻辑) |
| | | if (detailModel.Id == 0 || detailModel.Id == null || string.IsNullOrWhiteSpace(detailModel.LotNo)) |
| | | { |
| | |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Db.Ado.RollbackTran(); |
| | | throw ex; |
| | | } |
| | | } |