我只能读一堂课

时间:2020-10-23 07:47:39

标签: c# edi.net

我正在尝试使用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,该类将包含名为UNBUNHBGMDTM等的其他类。

所以看起来像这样

enter image description here

请注意,已填充类UNB,但类UNH为NULL

我应该如何设计我的课程,以便同时填写UNBUNH。当然还有BGMDTMNAD,依此类推...

我找到了this answer,并尝试了一下,但是并不能解决我的问题。

这是我使用的代码

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; }
}

1 个答案:

答案 0 :(得分:0)

我没有EDI.net的经验,但是您共享的文件应该在行尾而不是行首具有