In the information system that i am working with (SAP Business One), every document is represented in a SQL table.
for example:
Client order document : ORDR
Invoice document : OINV
Purchase Quotation : OPRQ
etc...
when the user clicks on one of the buttons, i need to use a exist function that checks in a part of the SQL tables, and checks if this client has documents in the system. the function returns a string message with the names of the tables that represent the documents this client has in the system.
i need to write a function that will replace the table names with the documents names.
eample:
"Client with ID:5634 has documents: OINV, ORDR"
needs to be replace with
"Client with ID:5634 has documents: Invoice, Client order"
I guess should use a string dictionary. How to do it?
thanks
Ideally you shouldn't be doing string replacement with the generated string - instead, generate it from the translated strings. So for example - without knowing what code you've actually got - you could have:
private static readonly Dictionary<string, string> TableNameTranslations
= new Dictionary<string, string>
{
{ "ORDR", "Client order document" },
{ "OINV", "Invoice document" },
{ "OPRQ", "Purchase quotation" }
};
...
public string GetClientDocumentDisplayString(int clientId)
{
var tableNames = GetTableNamesForClient(clientId);
var translatedNames = tableNames.Select(t => TableNameTranslations[t]);
return $"Client with ID:{clientId} has documents: {string.Join(",", translatedNames)}";
}
private IList<string> GetTableNamesForClient(int clientId)
{
// Whatever your code needs, returning ORDR, OINV etc
}
See more on this question at Stackoverflow