我正在尝试使用 Edi.net 读取 EDI 文件
但是当我想阅读下一堂课时遇到了问题。
这是我文件的一个片段(我在这里分成单独的行,实际文件只是一个长行)
UNB+UNOA:1+0935HRB2001101+MOL4267HUBUD00+100930:1549+00000000008914
'UNH+1+LOGMES:1:0:GM
'BGM+992:Z01:ZGM
'DTM+243:1009301549:201
'NAD+MS+GM*DRIVE
'NAD+MR+MOL42670HUBUD00
'SEQ++XXXXXX
'DTM+11:1008291900:201
'DTM+191:100930:101
'TDT+20++00+:::HOEGH TRADER++00000000
'LOC+Z03+KRDAT10
'LOC+8+HUBUD00
我想要完成的是创建一个类 Heading,这个类将包含其他类,称为UNB, UNH, BGM, DTM, 等等
所以看起来像这样
请注意,类UNB已填充,但类UNH为 NULL
我应该如何设计我的课程,以便两者UNB兼而有之UNH。当然还有BGM, DTM, NAD, 等等...
我找到了这个答案并尝试了它,但它并没有解决我的问题。
这是我使用的代码
public class Interchange
{
public HeadingSection HeadingSection { get; set; }
public Quote QuoteMessage { get; set; }
}
[EdiMessage]
public class Quote
{
public List<VehicleRecord> Vehicles { get; set; }
}
[EdiElement, EdiPath("UNB/*")]
public class HeadingUNB
{
[EdiValue("X(4)", Mandatory = true, Path = "UNB/0", Description = "Syntax Identifier")]
public string SyntaxIdentifier { get; set; }
[EdiValue("9(1)", Path = "UNB/0/1", Mandatory = true)]
public int SyntaxVersion { get; set; }
[EdiValue("X(35)", Mandatory = true, Path = "UNB/1")]
public string SenderIdentificationCode { get; set; }
[EdiValue("X(35)", Path = "UNB/2/0", Mandatory = true)]
public string RecipientIdentificationCode { get; set; }
[EdiValue("9(6)", Path = "UNB/3/0", Format = "ddMMyy", Description = "Shipment Date")]
[EdiValue("9(4)", Path = "UNB/3/1", Format = "HHmm", Description = "Shipment Time")]
public DateTime Shipment_Preparation_Date { get; set; }
[EdiValue("X(14)", Path = "UNB/4/0", Mandatory = true)]
public string InterchangeControlRef { get; set; }
}
[EdiElement, EdiPath("UNH/*")]
public class HeadingUNH
{
[EdiValue("X(14)", Mandatory = true, Path = "UNH/0", Description = "Message Reference Number")]
public string MessageReferenceNumber { get; set; }
}
[EdiSegment, EdiSegmentGroup("UNB", SequenceEnd = "GIN")]
public class HeadingSection
{
public HeadingUNB UNB { get; set; }
public HeadingUNH UNH { get; set; }
}
