C#创建一个生成DEI文件的类,把实际类转成EDI文件,使用FFTIN布局规范定义了一个平面文件运输指令,需要的数据长度分别为2,1,3,1,14,35,3,35,100,255,50,250,50,45,45,12,70,70,3,1,14,100
时间: 2023-10-04 22:03:35 浏览: 149
以下是一个用C#创建生成DEI文件的类的示例:
```csharp
public class EDIFileGenerator
{
public static byte[] GenerateEDIFile(MyDataObject data)
{
// Create a new MemoryStream to hold the EDI file contents
MemoryStream stream = new MemoryStream();
// Create a new StreamWriter to write to the MemoryStream
StreamWriter writer = new StreamWriter(stream);
// Write the data to the file according to the FFTIN layout specification
writer.Write(data.Field1.PadLeft(2));
writer.Write(data.Field2.PadLeft(1));
writer.Write(data.Field3.PadLeft(3));
writer.Write(data.Field4.PadLeft(1));
writer.Write(data.Field5.PadRight(14));
writer.Write(data.Field6.PadRight(35));
writer.Write(data.Field7.PadLeft(3));
writer.Write(data.Field8.PadRight(35));
writer.Write(data.Field9.PadRight(100));
writer.Write(data.Field10.PadRight(255));
writer.Write(data.Field11.PadRight(50));
writer.Write(data.Field12.PadRight(250));
writer.Write(data.Field13.PadRight(50));
writer.Write(data.Field14.PadRight(45));
writer.Write(data.Field15.PadRight(45));
writer.Write(data.Field16.PadLeft(12));
writer.Write(data.Field17.PadRight(70));
writer.Write(data.Field18.PadRight(70));
writer.Write(data.Field19.PadLeft(3));
writer.Write(data.Field20.PadLeft(1));
writer.Write(data.Field21.PadRight(14));
writer.Write(data.Field22.PadRight(100));
// Flush the StreamWriter to write the data to the MemoryStream
writer.Flush();
// Get the byte array representation of the MemoryStream
byte[] ediFile = stream.ToArray();
// Close the StreamWriter and MemoryStream
writer.Close();
stream.Close();
// Return the byte array containing the EDI file contents
return ediFile;
}
}
```
这个示例假设你有一个名为MyDataObject的类,它包含与FFTIN布局规范定义的字段对应的属性。你可以将实际数据对象传递到GenerateEDIFile方法中,并且它将返回一个包含EDI文件内容的字节数组。要使用这个类,你需要根据你的数据对象的属性来实现它。
阅读全文