指定新员工的联系人和地址信息

要指定 Employee 的联系人和地址信息,你应始终在分配任何字段值之前在 ContactAddress 数据视图上调用 Select() 方法。还建议将 Select() 方法的结果分配给 ContactAddress 数据视图的 Current 属性,以保证你的代码分别修改 ContactAddress PXCache 中的当前记录。

EmployeeMaint employeeMaintGraph = PXGraph.CreateInstance<EmployeeMaint>();
EPEmployee epEmployeeRow = new EPEmployee();
epEmployeeRow.AcctCD = "EMPLOYEE1";
epEmployeeRow = employeeMaintGraph.Employee.Insert(epEmployeeRow);

Contact contactRow = employeeMaintGraph.Contact.Current = employeeMaintGraph.Contact.Select();
contactRow.FirstName = "John";
contactRow.LastName = "Green";
employeeMaintGraph.Contact.Update(contactRow);

Address addressRow = employeeMaintGraph.Address.Current = employeeMaintGraph.Address.Select();
addressRow.CountryID = "US";
addressRow = employeeMaintGraph.Address.Update(addressRow);
addressRow.State = "DC";
employeeMaintGraph.Address.Update(addressRow);

epEmployeeRow.VendorClassID = "EMPSTAND";
epEmployeeRow.DepartmentID = "FINANCE";
employeeMaintGraph.Employee.Update(epEmployeeRow);

employeeMaintGraph.Actions.PressSave();

当插入新的 Employee 时,employeeMaintGraph.Contact.Current 将始终返回主联系人记录,因为联系人记录会自动插入到缓存中,因此可通过 PXCache / Data View 的 Current 属性获得。Select() 方法的使用更加通用,因为它可以在所有可能的场景中工作,无论你是需要插入新的 Employee 还是更新现有的 Employee。