如何使用基于屏幕的API创建银行存款

时间:2016-10-04 21:34:48

标签: acumatica

我目前需要使用基于屏幕的API自动创建银行存款。

这样做的最佳方式是什么?

1 个答案:

答案 0 :(得分:1)

这就是我设法做到的方式:

class Payment
{
    public string Module;
    public string Type;
    public string RefNbr;
    public decimal Amount;
}
class Program
{
    static void Main(string[] args)
    {
        var paymentsToDeposit = new Payment[]
        {
            new Payment { Module = "AR", Type = "Payment", RefNbr = "000483", Amount = 100 },
            new Payment { Module = "AR", Type = "Payment", RefNbr = "000484", Amount = 200 },
        };

        Screen context = new Screen();
        context.CookieContainer = new System.Net.CookieContainer();
        context.Url = "http://localhost/bankDeposits/(W(53))/Soap/CA305000.asmx";
        context.Login("admin", "admin");

        Content bankDepositSchema = context.GetSchema();

        List<Command> commands = new List<Command>();
        commands.Add(new Value { Value = "<NEW>", LinkedCommand = bankDepositSchema.DepositSummary.ReferenceNbr });
        commands.Add(new Value { Value = "102000", LinkedCommand = bankDepositSchema.DepositSummary.CashAccount });
        commands.Add(new Value { Value = "test2", LinkedCommand = bankDepositSchema.DepositSummary.DocumentRef });
        commands.Add(new Value { Value = "OK", LinkedCommand = bankDepositSchema.AddPaymentToDeposit.ServiceCommands.DialogAnswer, Commit = true });

        decimal total = 0;
        foreach(Payment pmt in paymentsToDeposit)
        {
            commands.Add(new Key { Value = "='" + pmt.Module + "'", FieldName = bankDepositSchema.AddPaymentToDeposit.DocModule.FieldName, ObjectName = bankDepositSchema.AddPaymentToDeposit.DocModule.ObjectName });
            commands.Add(new Key { Value = "='" + pmt.Type + "'", FieldName = bankDepositSchema.AddPaymentToDeposit.Type.FieldName, ObjectName = bankDepositSchema.AddPaymentToDeposit.Type.ObjectName });
            commands.Add(new Key { Value = "='" + pmt.RefNbr + "'", FieldName = bankDepositSchema.AddPaymentToDeposit.ReferenceNbr.FieldName, ObjectName = bankDepositSchema.AddPaymentToDeposit.ReferenceNbr.ObjectName });
            commands.Add(new Value { Value = "True", LinkedCommand = bankDepositSchema.AddPaymentToDeposit.Selected, Commit = true });
            total += pmt.Amount;
        }

        commands.Add(bankDepositSchema.Actions.AddPayment);
        commands.Add(new Value { Value = total.ToString(System.Globalization.CultureInfo.InvariantCulture), LinkedCommand = bankDepositSchema.DepositSummary.ControlTotal });
        commands.Add(bankDepositSchema.Actions.Save);

        context.Submit(commands.ToArray());
        context.Logout();
    }
}