I created about 50 different methods that update different tables. The code in them is exactly the same, except the table names and field names are different.
I know this is really a C# question, but I am not very good with C#. I’ve looked at the Acumatica repository to try to see how to do it, but I am pretty darn ignorant about how to do it.
Below you will see the code that is hard coded with the table and fields. It is the code after the //all this stuff is hard coded comment.
I want to create a generic method I can call that would accept the table name and field name as parameters.
Here is a signature for what I *think* is what I need to have. At a minimum, I got something to compile.
How do I replace the hard coded table names and field names? Is this an easy thing to do?
My application works fine with 50 different methods (each having the table name and field name hard coded), but this would make my app more “professional”.
public static List<T> TableUpdate<T, TField>(MergeViews graph, int bAccountFrom, int bAccountTo)
where TField : class, IBqlField
where T : class, IBqlTable
{
//all this stuff is hard coded
APInvoice exists = SelectFrom<APInvoice>.Where<APInvoice.suppliedByVendorID.IsEqual<@P.AsInt>>.View.Select(graph, bAccountFrom);
if (exists != null)
{
if (!PXDatabase.Update<APInvoice>(
new PXDataFieldAssign(typeof(APInvoice.suppliedByVendorID).Name,
PXDbType.Int, bAccountTo),
new PXDataFieldRestrict(typeof(APInvoice.suppliedByVendorID).Name,
PXDbType.Int, bAccountFrom)))
{
throw new PXException(ICSMessages.UpdateFailed, "APInvoice-suppliedByVendorID",
typeof(APInvoice).Name);
}
}
return null;
}
Thanks in advance for any insights you can offer.
Best answer by davidnavasardyan09
View original