Ejemplo n.º 1
0
        //private OrgAccess[] _orgAccess = null;
        public static Role GetRole(MRole role)
        {
            Role r = new Role();

            r.IsAccessAllOrgs     = role.IsAccessAllOrgs();
            r.IsAdministrator     = role.IsAdministrator();
            r.AD_Client_ID        = role.GetAD_Client_ID();
            r.AD_User_ID          = role.GetAD_User_ID();
            r.UserLevel           = role.GetUserLevel();
            r.IsCanExport         = role.IsCanExport();
            r.IsCanReport         = role.IsCanReport();
            r.IsUseBPRestrictions = role.IsUseBPRestrictions();
            r.IsPersonalAccess    = role.IsPersonalAccess();
            r.Name             = role.GetName();
            r.IsShowPreference = role.IsShowPreference();
            r.PreferenceType   = role.GetPreferenceType();

            r.IsDisplayClient        = role.IsDisplayClient();
            r.IsDisplayOrg           = role.IsDisplayOrg();
            r.IsPersonalLock         = role.IsPersonalLock();
            r.IsOverwritePriceLimit  = role.IsOverwritePriceLimit();
            r.IsOverrideReturnPolicy = role.IsOverrideReturnPolicy();

            r.tableAccessLevel = role.GetTableAccessLevel();
            r.tableName        = role.GetTableNames();
            r.orgAccess        = role.GetOrgAccess();
            r.windowAccess     = role.GetWindowAccess();
            r.formAccess       = role.GetFormAccess();
            r.processAccess    = role.GetProcessAccess();

            r.tableAccess           = TableAccess.Get(role.GetTableAccess());
            r.columnAccess          = ColumnAccess.Get(role.GetColumnAccess());
            r.recordAccess          = RecordAccess.Get(role.GetRecordAccess());
            r.recordDependentAccess = RecordAccess.Get(role.GetRecordDependentAccess());

            r.MaxQueryRecords = role.GetMaxQueryRecords();
            r.IsShowAcct      = role.IsShowAcct();
            r.IsDisableMenu   = role.IsDisableMenu();
            r.HomePage        = role.GetHomePage_ID();

            /* Prepare Pre Setting of Table*/

            r.tableData = TableData.Get();


            return(r);
        }
Ejemplo n.º 2
0
        }   //  getWarehouses

        /* HTML5 */

        /// <summary>
        /// Load Preferences into Context for selected client.
        /// <para>
        /// Sets Org info in context and loads relevant field from
        /// - AD_Client/Info,
        /// - C_AcctSchema,
        /// - C_AcctSchema_Elements
        /// - AD_Preference
        /// </para>
        /// Assumes that the context is set for #AD_Client_ID, ##AD_User_ID, #AD_Role_ID
        /// </summary>
        /// <param name="org">org information</param>
        /// <param name="warehouse">optional warehouse information</param>
        /// <param name="timestamp">optional date</param>
        /// <param name="printerName">optional printer info</param>
        /// <returns>AD_Message of error (NoValidAcctInfo) or ""</returns>
        public String LoadPreferences(string date, String printerName)
        {
            if (m_ctx.GetContext("#AD_Client_ID").Length == 0)
            {
                throw new Exception("Missing Context #AD_Client_ID");
            }
            if (m_ctx.GetContext("##AD_User_ID").Length == 0)
            {
                throw new Exception("Missing Context ##AD_User_ID");
            }
            if (m_ctx.GetContext("#AD_Role_ID").Length == 0)
            {
                throw new Exception("Missing Context #AD_Role_ID");
            }

            string dateS = m_ctx.GetContext("#Date");

            DateTime dt    = DateTime.Now;
            long     today = CommonFunctions.CurrentTimeMillis();

            if (DateTime.TryParse(dateS, out dt))
            {
                today = CommonFunctions.CurrentTimeMillis(dt);
            }

            m_ctx.SetContext("#Date", today.ToString());

            //	Load User/Role Infos
            MUser user = MUser.Get(m_ctx, m_ctx.GetAD_User_ID());

            MUserPreference preference = user.GetPreference();
            MRole           role       = MRole.GetDefault(m_ctx);

            //	Optional Printer
            if (printerName == null)
            {
                printerName = "";
            }
            if (printerName.Length == 0 && preference.GetPrinterName() != null)
            {
                printerName = preference.GetPrinterName();
            }
            m_ctx.SetPrinterName(printerName);
            if (preference.GetPrinterName() == null && printerName.Length > 0)
            {
                preference.SetPrinterName(printerName);
            }

            //	Other
            m_ctx.SetAutoCommit(preference.IsAutoCommit());
            m_ctx.SetAutoNew(Ini.IsPropertyBool(Ini.P_A_NEW));
            if (role.IsShowAcct())
            {
                m_ctx.SetContext("#ShowAcct", preference.IsShowAcct());
            }
            else
            {
                m_ctx.SetContext("#ShowAcct", "N");
            }
            m_ctx.SetContext("#ShowTrl", preference.IsShowTrl());
            m_ctx.SetContext("#ShowAdvanced", preference.IsShowAdvanced());

            String retValue     = "";
            int    AD_Client_ID = m_ctx.GetAD_Client_ID();
            //	int AD_Org_ID =  org.getKey();
            //	int AD_User_ID =  Env.getAD_User_ID (m_ctx);
            int AD_Role_ID = m_ctx.GetAD_Role_ID();

            //	Other Settings
            m_ctx.SetContext("#YYYY", "Y");

            //	AccountSchema Info (first)
            String sql = "SELECT a.C_AcctSchema_ID, a.C_Currency_ID, a.HasAlias, c.ISO_Code, c.StdPrecision "
                         + "FROM C_AcctSchema a"
                         + " INNER JOIN AD_ClientInfo ci ON (a.C_AcctSchema_ID=ci.C_AcctSchema1_ID)"
                         + " INNER JOIN C_Currency c ON (a.C_Currency_ID=c.C_Currency_ID) "
                         + "WHERE ci.AD_Client_ID='" + AD_Client_ID + "'";
            IDataReader dr = null;

            try
            {
                int C_AcctSchema_ID = 0;
                dr = DataBase.DB.ExecuteReader(sql);

                if (!dr.Read())
                {
                    //  No Warning for System
                    if (AD_Role_ID != 0)
                    {
                        retValue = "NoValidAcctInfo";
                    }
                }
                else
                {
                    //	Accounting Info
                    C_AcctSchema_ID = Utility.Util.GetValueOfInt(dr[0].ToString());
                    m_ctx.SetContext("$C_AcctSchema_ID", C_AcctSchema_ID);
                    m_ctx.SetContext("$C_Currency_ID", Utility.Util.GetValueOfInt(dr[1].ToString()));
                    m_ctx.SetContext("$HasAlias", dr[2].ToString());
                    m_ctx.SetContext("$CurrencyISO", dr[3].ToString());
                    m_ctx.SetStdPrecision(Utility.Util.GetValueOfInt(dr[4].ToString()));
                }
                dr.Close();

                //	Accounting Elements
                sql = "SELECT ElementType "
                      + "FROM C_AcctSchema_Element "
                      + "WHERE C_AcctSchema_ID='" + C_AcctSchema_ID + "'"
                      + " AND IsActive='Y'";

                dr = DataBase.DB.ExecuteReader(sql);
                while (dr.Read())
                {
                    m_ctx.SetContext("$Element_" + dr["ElementType"].ToString(), "Y");
                }
                dr.Close();


                //	This reads all relevant window neutral defaults
                //	overwriting superseeded ones.  Window specific is read in Maintain
                sql = "SELECT Attribute, Value, AD_Window_ID "
                      + "FROM AD_Preference "
                      + "WHERE AD_Client_ID IN (0, @#AD_Client_ID@)"
                      + " AND AD_Org_ID IN (0, @#AD_Org_ID@)"
                      + " AND (AD_User_ID IS NULL OR AD_User_ID=0 OR AD_User_ID=@##AD_User_ID@)"
                      + " AND IsActive='Y' "
                      + "ORDER BY Attribute, AD_Client_ID, AD_User_ID DESC, AD_Org_ID";
                //	the last one overwrites - System - Client - User - Org - Window
                sql = Utility.Env.ParseContext(m_ctx, 0, sql, false);
                if (sql.Length == 0)
                {
                }
                else
                {
                    dr = DataBase.DB.ExecuteReader(sql);
                    while (dr.Read())
                    {
                        string AD_Window_ID = dr[2].ToString();
                        String at           = "";
                        if (string.IsNullOrEmpty(AD_Window_ID))
                        {
                            at = "P|" + dr[0].ToString();
                        }
                        else
                        {
                            at = "P" + AD_Window_ID + "|" + dr[0].ToString();
                        }
                        String va = dr[1].ToString();
                        m_ctx.SetContext(at, va);
                    }
                    dr.Close();
                }

                //	Default Values
                sql = "SELECT t.TableName, c.ColumnName "
                      + "FROM AD_Column c "
                      + " INNER JOIN AD_Table t ON (c.AD_Table_ID=t.AD_Table_ID) "
                      + "WHERE c.IsKey='Y' AND t.IsActive='Y'"
                      + " AND EXISTS (SELECT * FROM AD_Column cc "
                      + " WHERE ColumnName = 'IsDefault' AND t.AD_Table_ID=cc.AD_Table_ID AND cc.IsActive='Y')";

                dr = DataBase.DB.ExecuteReader(sql);
                while (dr.Read())
                {
                    LoadDefault(dr[0].ToString(), dr[1].ToString());
                }
                dr.Close();
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
            }

            //Ini.SaveProperties(Ini.IsClient());
            //	Country
            m_ctx.SetContext("#C_Country_ID", MCountry.GetDefault(m_ctx).GetC_Country_ID());

            m_ctx.SetShowClientOrg(Ini.IsShowClientOrg() ? "Y" : "N");
            m_ctx.SetShowMiniGrid(Ini.GetProperty(Ini.P_Show_Mini_Grid));
            return(retValue);
        }       //	loadPreferences