Hi all,
I have the following code where I list all the companies that have the same base currency as the current company.
public List<CompanySelection> GetTheCompaniesSameBase() { List<CompanySelection> companies = new List<CompanySelection>(); string ACTIVECONNECTIONDATA = "Sage.ObjectStore.ConnectionData.ActiveConnectionData"; Sage.ObjectStore.ConnectionData currentCompany = (Sage.ObjectStore.ConnectionData)Sage.Common.Contexts.SessionContext.Context.GetData(ACTIVECONNECTIONDATA); Sage.ObjectStore.ConnectionData connectionData = null; try { Sage.Accounting.Application app = new Sage.Accounting.Application(); Sage.Accounting.Company activeCompany = app.ActiveCompany; foreach (Sage.Accounting.Company c in app.Companies) { connectionData = new Sage.ObjectStore.ConnectionData(Sage.ObjectStore.DatabaseType.Sql, c.ConnectString); Sage.Common.Contexts.SessionContext.Context.SetData(ACTIVECONNECTIONDATA, connectionData); FlushPrimaryKeys(connectionData); if (!c.Name.Trim().Equals(activeCompany.Name.Trim())) { // Get the base currency of other company Sage.Accounting.SystemManager.FinancialCurrency otherCompanyBaseCurrency = (Sage.Accounting.SystemManager.FinancialCurrency)Sage.Accounting.SystemManager.FinancialCurrencyFactory.Factory.GetBaseCurrency(); if (baseCurrency.CurrencyISOCode.Code == otherCompanyBaseCurrency.CurrencyISOCode.Code) { CompanySelection company = new CompanySelection(); company.Name = c.Name; company.BaseCurrency = otherCompanyBaseCurrency.CurrencyISOCode; companies.Add(company); } } } } catch (Exception ex) { MessageBox.Show(ex.Message); Logger.WriteLog(ex.ToString()); Sage.Common.Contexts.SessionContext.Context.SetData(ACTIVECONNECTIONDATA, currentCompany); FlushPrimaryKeys(currentCompany); return null; } finally { Sage.Common.Contexts.SessionContext.Context.SetData(ACTIVECONNECTIONDATA, currentCompany); FlushPrimaryKeys(currentCompany); } return companies; }
How can I check if the specific company can be access by the current user? I have try the Sage.Accounting.Company.Users but this list is deprecated and cannot be used
Thank you