覆盖客户的账单到联系人和账单到地址信息

当你需要覆盖客户的 Bill-To Contact 和 Bill-To Address 信息时,第一步是为 Customer DAC 的 IsBillContSameAsMainIsBillSameAsMain 属性设置正确的值。在更新 IsBillContSameAsMainIsBillSameAsMain 属性以将当前 Same as Main 字段值提交到缓存后,不要忘记立即在 Customer 缓存上调用 Update() 方法。 **** **** ****** ****** ******

下一步是在分配任何字段值之前在 BillContactBillAddress 数据视图上调用 Select() 方法。还建议将 Select() 方法的结果分配给 BillContactBillAddress 数据视图的 Current 属性,以保证你的代码分别修改 ContactAddress PXCache 中的当前记录。

public class CustomerMaintExt : PXGraphExtension<CustomerMaint>
{
    public PXAction<Customer> UpdateBillingAddress;
    [PXButton(CommitChanges = true)]
    [PXUIField(DisplayName = "Update Bill-To Info")]
    protected void updateBillingAddress()
    {
        Customer currentCustomer = Base.BAccount.Current;

        if (currentCustomer.IsBillContSameAsMain != true)
        {
            currentCustomer.IsBillContSameAsMain = true;
            Base.BAccount.Update(currentCustomer);
        }
        else
        {
            currentCustomer.IsBillContSameAsMain = false;
            Base.BAccount.Update(currentCustomer);

            Contact billContact = Base.BillContact.Current = Base.BillContact.Select();
            billContact.FullName = "ABC Holdings Inc";
            billContact.Phone1 = "+1 (212) 532-9574";
            Base.BillContact.Update(billContact);
        }

        if (currentCustomer.IsBillSameAsMain != true)
        {
            currentCustomer.IsBillSameAsMain = true;
            Base.CurrentCustomer.Update(currentCustomer);
        }
        else
        {
            currentCustomer.IsBillSameAsMain = false;
            Base.CurrentCustomer.Update(currentCustomer);

            Address billAddress = Base.BillAddress.Current = Base.BillAddress.Select();
            billAddress.AddressLine1 = "65 Broadway";
            billAddress.AddressLine2 = "Office Suite 187";
            billAddress.City = "New York";
            billAddress.CountryID = "US";
            billAddress = Base.BillAddress.Update(billAddress);
            billAddress.State = "NY";
            billAddress.PostalCode = "10004";
            Base.BillAddress.Update(billAddress);
        }

        Base.Actions.PressSave();
    }
}