Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/281.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 动态GP:读取销售发票的行项目_C#_Asp.net_Web Services_Dynamics Gp - Fatal编程技术网

C# 动态GP:读取销售发票的行项目

C# 动态GP:读取销售发票的行项目,c#,asp.net,web-services,dynamics-gp,C#,Asp.net,Web Services,Dynamics Gp,从Microsoft Dynamics GP 2013的Web服务通过以下代码创建销售发票: private void CreateInvoice() { CompanyKey companyKey; Context context; SalesInvoice salesInvoice; SalesDocumentTypeKey salesInvoiceType; CustomerKey custom

从Microsoft Dynamics GP 2013的Web服务通过以下代码创建销售发票:

    private void CreateInvoice()
    {
        CompanyKey companyKey;
        Context context;
        SalesInvoice salesInvoice;
        SalesDocumentTypeKey salesInvoiceType;
        CustomerKey customerKey;
        BatchKey batchKey;
        SalesInvoiceLine salesInvoiceLine;
        ItemKey invoiceItem;
        Quantity invoiceCount;
        Policy salesInvoiceCreatePolicy;
        MoneyAmount unitPrice;

        DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
        context = new Context();
        companyKey = new CompanyKey();
        companyKey.Id = (-1);
        context.OrganizationKey = (OrganizationKey)companyKey;
        salesInvoice = new SalesInvoice();
        salesInvoice.Key = new SalesDocumentKey();
        salesInvoice.Key.Id = "XX555";
        salesInvoiceType = new SalesDocumentTypeKey();
        salesInvoiceType.Type = SalesDocumentType.Invoice;
        salesInvoice.DocumentTypeKey = salesInvoiceType;
        customerKey = new CustomerKey();
        customerKey.Id = "ADAMPARK0001";// "AARONFIT0001";
        salesInvoice.CustomerKey = customerKey;
        batchKey = new BatchKey();
        batchKey.Id = "SALES INVOICES";
        salesInvoice.BatchKey = batchKey;

        IList<SalesInvoiceLine> salesInvoiceLines = new List<SalesInvoiceLine>();
        string[] itemId = { "ACCS-HDS-1EAR", "32X IDE" };    //"ACCS-RST-DXBK";// "512 SDRAM";//              
        for (int i = 0; i < itemId.Count(); i++)
        {
            salesInvoiceLine = new SalesInvoiceLine();
            invoiceItem = new ItemKey();
            invoiceItem.Id = itemId[i];
            salesInvoiceLine.ItemKey = invoiceItem;
            unitPrice = new MoneyAmount();
            unitPrice.Currency = "USD";
            unitPrice.DecimalDigits = 2;
            unitPrice.Value = 1.00M;
            salesInvoiceLine.UnitPrice = unitPrice;
            invoiceCount = new Quantity();
            invoiceCount.Value = 1 + i;
            salesInvoiceLine.Quantity = invoiceCount;
            salesInvoiceLines.Add(salesInvoiceLine);
        }            
        SalesInvoiceLine[] invoiceLines = salesInvoiceLines.ToArray();
        salesInvoice.Lines = invoiceLines;
        salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);
        wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
        if (wsDynamicsGP.State != CommunicationState.Faulted)
        {
            wsDynamicsGP.Close();               
        }
    }
    private void ShowInvoice()
    {

        CompanyKey companyKey;
        Context context;
        LikeRestrictionOfstring salespersonIdRestriction;
        ListRestrictionOfNullableOfSalesTransactionState transactionStateRestriction;
        SalesInvoiceCriteria salesInvoiceCriteria;
        SalesInvoiceSummary[] salesInvoiceSummary;
        BetweenRestrictionOfNullableOfdateTime restriction;

        DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
        context = new Context();
        companyKey = new CompanyKey();
        companyKey.Id = (-1);
        context.OrganizationKey = (OrganizationKey)companyKey;
        salespersonIdRestriction = new LikeRestrictionOfstring();
        transactionStateRestriction = new ListRestrictionOfNullableOfSalesTransactionState();
        transactionStateRestriction.EqualValue = SalesTransactionState.Work;
        salesInvoiceCriteria = new SalesInvoiceCriteria();
        salesInvoiceCriteria.TransactionState = transactionStateRestriction;
        salesInvoiceCriteria.SalespersonId = salespersonIdRestriction;
        salesInvoiceSummary = wsDynamicsGP.GetSalesInvoiceList(salesInvoiceCriteria, context);

        StringBuilder summaryList = new StringBuilder();           
        foreach (SalesInvoiceSummary a in salesInvoiceSummary)
        {
           summaryList.AppendLine("<b>Invoice number:</b> " + a.Key.Id + "  <b>Invoice amount:</b> " + a.TotalAmount.Value.ToString("C"));
        }
        if (wsDynamicsGP.State != CommunicationState.Faulted)
        {
            wsDynamicsGP.Close();
        }
    }
private void CreateInvoice()
{
CompanyKey CompanyKey;
语境;
销售发票销售发票;
SalesDocumentType键salesInvoiceType;
CustomerKey CustomerKey;
BatchKey BatchKey;
销售发票行销售发票行;
项目关键发票项目;
数量发票计数;
策略salesInvoiceCreatePolicy;
金额单价;
DynamicsGPClient wsDynamicsGP=新的DynamicsGPClient();
上下文=新上下文();
companyKey=新companyKey();
companyKey.Id=(-1);
context.OrganizationKey=(OrganizationKey)companyKey;
salesInvoice=新的salesInvoice();
salesInvoice.Key=新的SalesDocumentKey();
salesInvoice.Key.Id=“XX555”;
salesInvoiceType=新的SalesDocumentTypeKey();
salesInvoiceType.Type=SalesDocumentType.Invoice;
salesInvoice.DocumentTypeKey=salesInvoiceType;
customerKey=新customerKey();
customerKey.Id=“ADAMPARK0001”/“aaronfit001”;
salesInvoice.CustomerKey=CustomerKey;
batchKey=新的batchKey();
batchKey.Id=“销售发票”;
salesInvoice.BatchKey=BatchKey;
IList salesInvoiceLines=新列表();
字符串[]itemId={“ACCS-HDS-1EAR”,“32X IDE”};//“ACCS-RST-DXBK”;//“512 SDRAM”;//
对于(int i=0;i

按以下代码读取销售发票:

    private void CreateInvoice()
    {
        CompanyKey companyKey;
        Context context;
        SalesInvoice salesInvoice;
        SalesDocumentTypeKey salesInvoiceType;
        CustomerKey customerKey;
        BatchKey batchKey;
        SalesInvoiceLine salesInvoiceLine;
        ItemKey invoiceItem;
        Quantity invoiceCount;
        Policy salesInvoiceCreatePolicy;
        MoneyAmount unitPrice;

        DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
        context = new Context();
        companyKey = new CompanyKey();
        companyKey.Id = (-1);
        context.OrganizationKey = (OrganizationKey)companyKey;
        salesInvoice = new SalesInvoice();
        salesInvoice.Key = new SalesDocumentKey();
        salesInvoice.Key.Id = "XX555";
        salesInvoiceType = new SalesDocumentTypeKey();
        salesInvoiceType.Type = SalesDocumentType.Invoice;
        salesInvoice.DocumentTypeKey = salesInvoiceType;
        customerKey = new CustomerKey();
        customerKey.Id = "ADAMPARK0001";// "AARONFIT0001";
        salesInvoice.CustomerKey = customerKey;
        batchKey = new BatchKey();
        batchKey.Id = "SALES INVOICES";
        salesInvoice.BatchKey = batchKey;

        IList<SalesInvoiceLine> salesInvoiceLines = new List<SalesInvoiceLine>();
        string[] itemId = { "ACCS-HDS-1EAR", "32X IDE" };    //"ACCS-RST-DXBK";// "512 SDRAM";//              
        for (int i = 0; i < itemId.Count(); i++)
        {
            salesInvoiceLine = new SalesInvoiceLine();
            invoiceItem = new ItemKey();
            invoiceItem.Id = itemId[i];
            salesInvoiceLine.ItemKey = invoiceItem;
            unitPrice = new MoneyAmount();
            unitPrice.Currency = "USD";
            unitPrice.DecimalDigits = 2;
            unitPrice.Value = 1.00M;
            salesInvoiceLine.UnitPrice = unitPrice;
            invoiceCount = new Quantity();
            invoiceCount.Value = 1 + i;
            salesInvoiceLine.Quantity = invoiceCount;
            salesInvoiceLines.Add(salesInvoiceLine);
        }            
        SalesInvoiceLine[] invoiceLines = salesInvoiceLines.ToArray();
        salesInvoice.Lines = invoiceLines;
        salesInvoiceCreatePolicy = wsDynamicsGP.GetPolicyByOperation("CreateSalesInvoice", context);
        wsDynamicsGP.CreateSalesInvoice(salesInvoice, context, salesInvoiceCreatePolicy);
        if (wsDynamicsGP.State != CommunicationState.Faulted)
        {
            wsDynamicsGP.Close();               
        }
    }
    private void ShowInvoice()
    {

        CompanyKey companyKey;
        Context context;
        LikeRestrictionOfstring salespersonIdRestriction;
        ListRestrictionOfNullableOfSalesTransactionState transactionStateRestriction;
        SalesInvoiceCriteria salesInvoiceCriteria;
        SalesInvoiceSummary[] salesInvoiceSummary;
        BetweenRestrictionOfNullableOfdateTime restriction;

        DynamicsGPClient wsDynamicsGP = new DynamicsGPClient();
        context = new Context();
        companyKey = new CompanyKey();
        companyKey.Id = (-1);
        context.OrganizationKey = (OrganizationKey)companyKey;
        salespersonIdRestriction = new LikeRestrictionOfstring();
        transactionStateRestriction = new ListRestrictionOfNullableOfSalesTransactionState();
        transactionStateRestriction.EqualValue = SalesTransactionState.Work;
        salesInvoiceCriteria = new SalesInvoiceCriteria();
        salesInvoiceCriteria.TransactionState = transactionStateRestriction;
        salesInvoiceCriteria.SalespersonId = salespersonIdRestriction;
        salesInvoiceSummary = wsDynamicsGP.GetSalesInvoiceList(salesInvoiceCriteria, context);

        StringBuilder summaryList = new StringBuilder();           
        foreach (SalesInvoiceSummary a in salesInvoiceSummary)
        {
           summaryList.AppendLine("<b>Invoice number:</b> " + a.Key.Id + "  <b>Invoice amount:</b> " + a.TotalAmount.Value.ToString("C"));
        }
        if (wsDynamicsGP.State != CommunicationState.Faulted)
        {
            wsDynamicsGP.Close();
        }
    }
private void ShowInvoice()
{
CompanyKey CompanyKey;
语境;
比如对字符串销售人员的限制;
ListRestrictionOfNullableOfSalesTransactionState交易状态限制;
SalesInvoiceCriteria SalesInvoiceCriteria;
SalesInvoiceSummary[]SalesInvoiceSummary;
时间限制的不完全限制之间的关系;
DynamicsGPClient wsDynamicsGP=新的DynamicsGPClient();
上下文=新上下文();
companyKey=新companyKey();
companyKey.Id=(-1);
context.OrganizationKey=(OrganizationKey)companyKey;
salespersonIdRestriction=新的类似RestrictionofString();
transactionStateRestriction=新的ListRestrictionofSalesTransactionState();
transactionStateRestriction.EqualValue=SalesTransactionState.Work;
salesInvoiceCriteria=新的salesInvoiceCriteria();
salesInvoiceCriteria.TransactionState=transactionStateRestriction;
salesInvoiceCriteria.SalesorSonid=SalesorSonidRestriction;
salesInvoiceSummary=wsDynamicsGP.GetSalesInvoiceList(salesInvoiceCriteria,上下文);
StringBuilder summaryList=新建StringBuilder();
foreach(SalesInvoiceSummary中的SalesInvoiceSummary a)
{
summaryList.AppendLine(“发票编号:+a.Key.Id+”发票金额:+a.TotalAmount.Value.ToString(“C”);
}
if(wsDynamicsGP.State!=CommunicationState.Faulted)
{
wsDynamicsGP.Close();
}
}


问题是:如何获取特定发票的行项目?

您需要获取包含关联行项目的实际对象。您可以通过传入发票的订单号(SOPNUMBER)来完成此操作

扩展第二个示例:

foreach (SalesInvoiceSummary a in salesInvoiceSummary)
{
    summaryList.AppendLine("<b>Invoice number:</b> " + a.Key.Id + "  <b>Invoice amount:</b> " + a.TotalAmount.Value.ToString("C"));

    SalesInvoice invoice = wsDynamicsGP.GetSalesInvoiceByKey(a.Key.Id, context);
    SalesInvoiceLine[] lineItems = invoice.Lines;
}
foreach(SalesInvoiceSummary中的SalesInvoiceSummary a)
{
summaryList.AppendLine(“发票编号:+a.Key.Id+”发票金额:+a.TotalAmount.Value.ToString(“C”);
SalesInvoice invoice=wsDynamicsGP.getSalesInvoiceKey(a.Key.Id,上下文);
SalesInvoiceLine[]lineItems=发票行;
}
但是,不需要先调用
GetSalesInvoiceList()
——如果知道订单号,可以直接调用
GetSalesInvoiceKey()