Dynamics NAV Web服务在第二个循环上失败

问题描述 投票:0回答:1

我创建了一个C#程序来读取以竖线(“ |”)分隔的文件并创建购买发票和行。本质上,我让它遍历每一行,如果未使用“ Report ID”,则会创建一个标题,然后,如果该标题已创建,则该行将跳过标题创建,并应添加下一行。但是,当我达到该行的对象分配时,它将出现以下错误:

“未处理ArgumentException”“必须指定用于解析字符串的有效信息。”

PIheader函数工作正常,因此这里未包括在内。请告知是否需要更多信息/代码。

//Parse selected SAE File
SAEline[] sae = ParseSAE.Parse(file);

//Begin Analyzing Data
int saesize = sae.Length;
int i = 0;
List<string> cashIDs = new List<string>();
string paymentterms = "";
string invno = "";
string company = "";
string[] getcompany = new string[2];
string reportid = sae[i].ReportID;
int lineno = 0;
while(i < 10) //limit the loop for testing
//while (i < saesize)
{
    if (sae[i].ReportEntryPaymentCodeCode != "CBCP")
    {
        if (!cashIDs.Contains(reportid))
        {
            cashIDs.Add(reportid);
            getcompany = WebServices.GetCompany(sae[i].EmployeeID.ToUpper());
            paymentterms = sae[i].ReportEntryPaymentCodeCode;
            invno = WebServices.PIheader(getcompany[0], getcompany[1], 0, sae[i]);
            lineno = 0;
        }
        lineno = lineno + 10000;
        company = getcompany[0];
        lineno = WebServices.PIlines(invno, lineno, company, sae[i]);
    }
    i++;
}

WebService.cs包含:

//Web Service Client
        PurchLines.PurchLines_PortClient piClient =
            new PurchLines_PortClient((System.ServiceModel.Channels.Binding)basicHttpBindingNTLM,
                new EndpointAddress("URL" + company + "/Page/PurchLines"));

        //Conditional variables
        string joblinetype = "";
        string qty = "";


        if  (sae.ReportEntryCustom1 == "Billable")
        {
            joblinetype = "3";
        }

        if (sae.BusinessDistance == "")
        {
            if (sae.ReportCustom2 == "")
            {
                qty = "1";
            }
            else
            {
                qty = sae.ReportCustom2;
            }
        }
        else
        {
            qty = sae.BusinessDistance;
        }

        string unitcost = (Convert.ToDecimal(sae.ReportEntryApprovedAmount)/Convert.ToDecimal(qty)).ToString();

        //Line Creation
        PurchLines.PurchLines line = new PurchLines.PurchLines()
        {
            No = sae.JournalAccountCode,
            Line_No = Convert.ToInt16(lineno),
            Line_NoSpecified = true,
            Job_Line_TypeSpecified = true,
            Job_Line_Type = (PurchLines.Job_Line_Type) (Enum.Parse(typeof (PurchLines.Job_Line_Type), joblinetype)),
            QuantitySpecified = true,
            Quantity = Convert.ToDecimal(qty),
            TypeSpecified = true,
            Type = (PurchLines.Type) (Enum.Parse(typeof (PurchLines.Type), "1")),
            Direct_Unit_CostSpecified = true,
            Direct_Unit_Cost = Convert.ToDecimal(unitcost),
            Job_Unit_PriceSpecified = true,
            Job_Unit_Price = Convert.ToDecimal(unitcost),
            Job_No = sae.ReportEntryCustom5,
            Job_Task_No = sae.ReportEntryCustom6,
            Document_TypeSpecified = true,
            Document_Type = (PurchLines.Document_Type)(Enum.Parse(typeof(PurchLines.Document_Type),"2")),
            Document_No = invno
        };

        piClient.Create(ref line);
        PurchLines.Create_Result result = new PurchLines.Create_Result(line);
        int lin = result.PurchLines.Line_No;
        return lin;
    }
c# web-services microsoft-dynamics navision dynamics-nav
1个回答
0
投票

我意识到我没有为joblinetype分配一个值,因为它不是“可结算的”,因此Web服务无法解析空白字符串

Job_Line_Type = (PurchLines.Job_Line_Type) (Enum.Parse(typeof (PurchLines.Job_Line_Type), joblinetype)),
© www.soinside.com 2019 - 2024. All rights reserved.