dev
dengyu 2 months ago
parent 420cf517e8
commit a769849a17

@ -24,14 +24,15 @@ public class CM_CheckCntrnoRes
{
public List<string> RightCntrnoList { get; set; } = new List<string>();
public List<string> WrongCntrnoList { get; set; } = new List<string>();
public void AddCntrno(string CNTRNO, bool isRight) {
public List<string> TrueCntrnoList { get; set; } = new List<string>();
public void AddCntrno(string CNTRNO, bool isRight,string trueCntrno) {
if (isRight)
{
RightCntrnoList.Add(CNTRNO);
}
else {
WrongCntrnoList.Add(CNTRNO);
TrueCntrnoList.Add(trueCntrno);
}
}
}

@ -168,9 +168,10 @@ public class CM_BaseInfoService : ICM_BaseInfoService
if (cntrnoList != null) {
foreach (var cntrno in cntrnoList) {
var istrue = ValidateContainerNumber(cntrno);
var trueCntrno = "";
var istrue = ValidateContainerNumber(cntrno,out trueCntrno);
result.AddCntrno(cntrno, istrue);
result.AddCntrno(cntrno, istrue, trueCntrno);
}
}
@ -210,14 +211,17 @@ public class CM_BaseInfoService : ICM_BaseInfoService
return result;
}
public static bool ValidateContainerNumber(string containerNumber)
public static bool ValidateContainerNumber(string containerNumber,out string trueCntrno)
{
// 集装箱号的校验规则
// - 由4位字母ISO代码+ 6位数字 + 1位校验码组成
// - 校验码的计算方式是将字母转换为数字,然后按照一定的公式计算得出
trueCntrno = "";
if (containerNumber.Length != 11)
{
trueCntrno = " ";
return false;
}
@ -225,19 +229,31 @@ public class CM_BaseInfoService : ICM_BaseInfoService
string numbers = containerNumber.Substring(4, 6);
string checkDigit = containerNumber.Substring(10, 1);
var result = true;
// 检查字母部分是否都是大写字母
if (!letters.All(char.IsUpper))
{
result= false;
}
//letters = letters.ToUpper();
if (!letters.All(char.IsLetter) )
{
trueCntrno = " ";
return false;
}
// 检查数字部分是否都是数字字符
if (!numbers.All(char.IsDigit))
{
trueCntrno = " ";
return false;
//result = false;
}
// 计算校验码
letters = letters.ToUpper();
int[] letterValues = letters.Select(c => numtostr(c)).ToArray();
int[] numberValues = numbers.Select(c => c - '0').ToArray();
@ -259,10 +275,14 @@ public class CM_BaseInfoService : ICM_BaseInfoService
// 检查校验码是否匹配
if (calculatedCheckDigit != int.Parse(checkDigit))
{
return false;
result=false;
}
if (result == false) {
trueCntrno= letters + numbers + calculatedCheckDigit.ToString();
}
return true;
return result;
}

@ -909,22 +909,61 @@ public class CM_State_Change_TemplatImportService : CMServiceBase, ICM_State_Cha
newchange.Id = 0;
newchange.Pid = req.Id;
Type type = newchange.GetType();
var XXDM = "";
var XXHM = "";
var Vessel = "";
var Voyno = "";
foreach (var in )
{
if (string.IsNullOrWhiteSpace(.Value))
continue;
var field = type.GetProperty(.Value);
if (field != null && dt.Columns.Contains(.Name))
{
var _value = row[.Name];
field.SetValue(newchange, _value);
}
else
if (field == null && .Value == "XXDM")
{
XXDM = row[.Name].ToString();
}
else
if (field == null && .Value == "XXHM")
{
XXHM = row[.Name].ToString();
}
else
if (field == null && .Value == "Vessel")
{
Vessel = row[.Name].ToString();
}
else
if (field == null && .Value == "Voyno")
{
Voyno = row[.Name].ToString();
}
else
{
continue;
//throw new ArgumentException("Field not found", fieldName);
}
}
if (XXDM != "" && XXHM != "") {
newchange.Ctnall= XXDM + XXHM;
}
if (Vessel != "" && Voyno != "")
{
newchange.VesselVoyno = Vessel +" : "+ Voyno;
}
changelist.Add(newchange);
}
@ -1187,6 +1226,11 @@ public class CM_State_Change_TemplatImportService : CMServiceBase, ICM_State_Cha
var _pid = reqtype.GetProperty("Pid");
_pid.SetValue(newchange, req.Id);
var XXDM = "";
var XXHM = "";
var Vessel = "";
var Voyno = "";
foreach (var in )
{
//if (string.IsNullOrWhiteSpace(字段.Value))
@ -1228,12 +1272,48 @@ public class CM_State_Change_TemplatImportService : CMServiceBase, ICM_State_Cha
}
else
if (field == null && .FieldTitle == "XXDM")
{
XXDM = row[.ColumnTitle].ToString();
}
else
if (field == null && .FieldTitle == "XXHM")
{
XXHM = row[.ColumnTitle].ToString();
}
else
if (field == null && .FieldTitle == "Vessel")
{
Vessel = row[.ColumnTitle].ToString();
}
else
if (field == null && .FieldTitle == "Voyno")
{
Voyno = row[.ColumnTitle].ToString();
}
else
{
continue;
//throw new ArgumentException("Field not found", fieldName);
}
}
if (XXDM != "" && XXHM != "")
{
var field = reqtype.GetProperty("Ctnall");
if(field!=null)
field.SetValue(newchange, XXDM+ XXHM);
}
if (Vessel != "" && Voyno != "")
{
var field = reqtype.GetProperty("VesselVoyno");
if (field != null)
field.SetValue(newchange, Vessel +" : "+ Voyno);
}
changelist.Add(newchange);
}

Loading…
Cancel
Save