文件助手仅返回一行数据

时间:2018-10-17 16:01:58

标签: c# filehelpers

我正在使用FileHelpers从csv加载到类中,但是由于某种原因,它只能拉回一条记录。

public void LoadPumpData(string Filename)
{
        var engine = new FileHelperEngine(typeof(FuelPumpData));
        //read the CSV file into your object Arrary
        var productSales = (FuelPumpData[])engine.ReadFile(Filename);


        if (productSales.Any())
        {
            //process your records as per your requirements
            foreach (var sales in productSales)
            {
                string carCodeNumber = GetCustomerCodeByVechicleTag(sales.VechicleTagNo);
                CreateInvoice(carCodeNumber, double.Parse(sales.FuelQty), double.Parse(sales.FuelValue));

            }
        }

 }

这是我的课程

[DelimitedRecord(",")]
[IgnoreEmptyLines()]
[IgnoreFirst()]

public class FuelPumpData
{
    [FieldQuoted(QuoteMode.OptionalForRead)]

    public int Date { get; set; }
    [FieldQuoted(QuoteMode.OptionalForRead)]

    public int Time { get; set; }
    public string SystemGroup1 { get; set; }
    public string SystemGroup3 { get; set; }
    public string VechicleTagNo { get; set; }
    public string SystemGroup2 { get; set; }
    public string SystemGroup4 { get; set; }
    public string FuelQty { get; set; }
    public string FuelValue { get; set; }
    public string FuelType { get; set; }
}

我认为读取字段并将其传递给类的数组将允许读取所有行,但只返回第一行?。

编辑2 创建发票例程

 public void CreateInvoice(string customerCode, double fuelQty, double price)
 {
        try
        {
            SAPbobsCOM.Documents oInvoice = company.GetBusinessObject(BoObjectTypes.oInvoices);

            oInvoice.DocDate = DateTime.Now;
            oInvoice.CardCode = customerCode;

            oInvoice.Lines.ItemDescription="David Test";
            oInvoice.Lines.ItemCode = "DSL";
            oInvoice.Lines.Quantity = fuelQty;
            oInvoice.Lines.LineTotal = price;
            oInvoice.Lines.Add();



            int addInvoice = oInvoice.Add();

            if (addInvoice < 0 )
            {
                Console.Write("Error:" + company.GetLastErrorDescription());

            }
        }catch(Exception ex)
        {


        }

    }

创建发票例程在树液业务中创建一个不会覆盖产品销售的产品。

编辑3 显示我的调试

enter image description here

CSV记录以显示到数据行

"011018","0020","D SAYERS","SYSTEM DEFAULT",   5680,"20101","06009",35.64  ,               52.14,"DSL"
"011018","0438","SYSTEM DEFAULT","DECLAN MCDERMOTT",   5839,"SYSTEM DEFAULT","14502",36.52  ,               53.43,"DSL"

1 个答案:

答案 0 :(得分:0)

对于其他任何人,我的问题是我首先忽略了这一点,以为我会在不在时获取文件中的标头信息。

[DelimitedRecord(",")]
[IgnoreEmptyLines()]
[IgnoreFirst()]

我先删除了IgnoreFirst,然后使用正确的信息正确检测了文件。