| | |
| | | |
| | | // 2. 将字符串类型的IsControlled转换为bool(根据实际取值规则调整) |
| | | // 比如:"1"表示受控,"0"表示不受控;或"True"/"False";或"是"/"否" |
| | | bool isControlled; |
| | | if (!bool.TryParse(material.IsControlled, out isControlled)) |
| | | { |
| | | // 处理非标准格式(如"1"/"0") |
| | | isControlled = material.IsControlled == "1" || |
| | | string.Equals(material.IsControlled, "是", StringComparison.OrdinalIgnoreCase); |
| | | } |
| | | //bool isControlled; |
| | | //if (!bool.TryParse(material.IsControlled, out isControlled)) |
| | | //{ |
| | | // // 处理非标准格式(如"1"/"0") |
| | | // isControlled = material.IsControlled == "1" || |
| | | // string.Equals(material.IsControlled, "是", StringComparison.OrdinalIgnoreCase); |
| | | //} |
| | | |
| | | // 3. 根据受控状态验证日期 |
| | | if (isControlled) |
| | | if (material.IsControlled=="0") |
| | | { |
| | | // 受控状态:生产日期必填 |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot1)) |
| | | return $"-1:物料{detailModel.SkuNo}为受控物料,生产日期不可为空;"; |
| | | return $"-1:物料{detailModel.SkuNo}为需请验物料,生产日期不可为空;"; |
| | | |
| | | // 受控状态:过期日期必填 |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot2)) |
| | | return $"-1:物料{detailModel.SkuNo}为受控物料,过期日期不可为空;"; |
| | | return $"-1:物料{detailModel.SkuNo}为需请验物料,过期日期不可为空;"; |
| | | |
| | | // 验证日期格式有效性 |
| | | if (!DateTime.TryParse(detailModel.Lot1, out DateTime productionDate)) |
| | |
| | | // 不受控状态:日期非必填,无需验证 |
| | | |
| | | // 原有批次相关验证(保留) |
| | | if (TypeLot.Contains(model.Type)) |
| | | { |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot1)) |
| | | throw new Exception("生产日期不可为空!"); |
| | | //if (TypeLot.Contains(model.Type)) |
| | | //{ |
| | | // if (string.IsNullOrWhiteSpace(detailModel.Lot1)) |
| | | // throw new Exception("生产日期不可为空!"); |
| | | |
| | | if (string.IsNullOrWhiteSpace(detailModel.Lot2)) |
| | | throw new Exception("过期日期不可为空!"); |
| | | } |
| | | // if (string.IsNullOrWhiteSpace(detailModel.Lot2)) |
| | | // throw new Exception("过期日期不可为空!"); |
| | | //} |
| | | |
| | | // 验证物料和批次号是否重复 |
| | | if (dbDetailModels.Any(m => m.SkuNo == detailModel.SkuNo |