Dynamics NAV Webservice在第二个循环上失败

时间:2014-12-11 16:34:46

标签: c# web-services nav microsoft-dynamics navision

我创建了一个C#程序来读取管道(" |")分隔文件并创建采购发票和行。基本上,如果"报告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;
    }

1 个答案:

答案 0 :(得分:0)

我意识到,如果它不是“Billable”,我没有为joblinetype分配值,因此web服务无法解析空字符串

Job_Line_Type = (PurchLines.Job_Line_Type) (Enum.Parse(typeof (PurchLines.Job_Line_Type), joblinetype)),
相关问题