コード例 #1
0
        }       //	loadDefault

        /// <summary>
        /// Validate Login.
        /// Creates session and calls ModelValidationEngine
        /// </summary>
        /// <param name="org">log-in org</param>
        /// <returns>error message</returns>
        public String ValidateLogin(KeyNamePair org)
        {
            String info         = m_user + ",R:" + m_role.ToString() + ",O=" + m_org.ToString();
            int    AD_Client_ID = m_ctx.GetAD_Client_ID();
            int    AD_Org_ID    = org.GetKey();
            int    AD_Role_ID   = m_ctx.GetAD_Role_ID();
            int    AD_User_ID   = m_ctx.GetAD_User_ID();
            //
            MSession session = MSession.Get(m_ctx, true);

            if (AD_Client_ID != session.GetAD_Client_ID())
            {
                session.SetAD_Client_ID(AD_Client_ID);
            }
            if (AD_Org_ID != session.GetAD_Org_ID())
            {
                session.SetAD_Org_ID(AD_Org_ID);
            }
            if (AD_Role_ID != session.GetAD_Role_ID())
            {
                session.SetAD_Role_ID(AD_Role_ID);
            }
            //
            String error = ModelValidationEngine.Get().LoginComplete(AD_Client_ID, AD_Org_ID, AD_Role_ID, AD_User_ID);

            if (error != null && error.Length > 0)
            {
                session.SetDescription(error);
                session.Save();
                return(error);
            }
            //	Log
            session.Save();
            return(null);
        }       //	validateLogin
コード例 #2
0
        }       //	copyGL

        /// <summary>
        /// Copy Default
        /// </summary>
        /// <param name="targetAS">target</param>
        private void CopyDefault(MAcctSchema targetAS)
        {
            MAcctSchemaDefault source = MAcctSchemaDefault.Get(GetCtx(), _SourceAcctSchema_ID);
            MAcctSchemaDefault target = new MAcctSchemaDefault(GetCtx(), 0, Get_Trx());

            target.SetC_AcctSchema_ID(_TargetAcctSchema_ID);
            target.SetC_AcctSchema_ID(_TargetAcctSchema_ID);
            //ArrayList<KeyNamePair> list = source.getAcctInfo();
            List <KeyNamePair> list = source.GetAcctInfo();

            for (int i = 0; i < list.Count; i++)
            {
                //KeyNamePair pp = list.get(i);
                KeyNamePair pp = list[i];
                int         sourceC_ValidCombination_ID = pp.GetKey();
                String      columnName    = pp.GetName();
                MAccount    sourceAccount = MAccount.Get(GetCtx(), sourceC_ValidCombination_ID);
                MAccount    targetAccount = CreateAccount(targetAS, sourceAccount);
                target.SetValue(columnName, Utility.Util.GetValueOfInt(targetAccount.GetC_ValidCombination_ID()));
            }
            if (!target.Save())
            {
                throw new Exception("Could not Save Default");
            }
        }       //	copyDefault
コード例 #3
0
        }       //	getAD_User_ID

        public int GetAD_Role_ID()
        {
            if (m_role != null)
            {
                return(m_role.GetKey());
            }
            return(-1);
        }       //	getAD_Role_ID
コード例 #4
0
 /// <summary>
 /// Get User
 /// </summary>
 /// <returns>user id</returns>
 public int GetAD_User_ID()
 {
     if (m_user != null)
     {
         return(m_user.GetKey());
     }
     return(-1);
 }       //	getAD_User_ID
コード例 #5
0
        }       //	getOrgAddSummary

        /// <summary>
        ///  Load Warehouses
        /// </summary>
        /// <param name="org"></param>
        /// <returns></returns>
        public KeyNamePair[] GetWarehouses(KeyNamePair org)
        {
            ;
            if (org == null)
            {
                throw new Exception("Org missing");
            }
            m_org = org;
            if (m_store != null)
            {
                return new KeyNamePair[] { new KeyNamePair(m_store.GetM_Warehouse_ID(), m_store.GetName() + " Warehouse") }
            }
            ;

            //	s_log.info("loadWarehouses - Org: " + org.toStringX());

            List <KeyNamePair> list = new List <KeyNamePair>();

            KeyNamePair[] retValue = null;
            String        sql      = "SELECT M_Warehouse_ID, Name FROM M_Warehouse "
                                     + "WHERE AD_Org_ID=@p1 AND IsActive='Y' "
                                     + "ORDER BY Name";
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];

                param[0] = new SqlParameter("@p1", org.GetKey());
                dr       = DataBase.DB.ExecuteReader(sql, param);
                if (!dr.Read())
                {
                    dr.Close();
                    return(null);
                }

                //  load Warehouses
                do
                {
                    int         AD_Warehouse_ID = Utility.Util.GetValueOfInt(dr[0].ToString());
                    String      Name            = dr[1].ToString();
                    KeyNamePair p = new KeyNamePair(AD_Warehouse_ID, Name);
                    list.Add(p);
                }while (dr.Read());

                dr.Close();
                //
                retValue = new KeyNamePair[list.Count];
                retValue = list.ToArray();
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
                retValue = null;
            }

            return(retValue);
        }   //  getWarehouses
コード例 #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="client"></param>
        /// <returns></returns>
        public KeyNamePair[] GetOrgs(KeyNamePair client)
        {
            if (client == null)
            {
                throw new ArgumentException("Client missing");
            }
            //	Web Store Login
            if (m_store != null)
            {
                return new KeyNamePair[] { new KeyNamePair(m_store.GetAD_Org_ID(), m_store.GetName() + " Org") }
            }
            ;

            if (m_ctx.GetContext("#AD_Role_ID").Length == 0)    //	could be number 0
            {
                throw new Exception("Missing Context #AD_Role_ID");
            }

            int AD_Role_ID = m_ctx.GetAD_Role_ID();
            int AD_User_ID = m_ctx.GetAD_User_ID();
            //	s_log.fine("Client: " + client.toStringX() + ", AD_Role_ID=" + AD_Role_ID);

            //	get Client details for role
            List <KeyNamePair> list = new List <KeyNamePair>();

            KeyNamePair[] retValue = null;
            //
            String sql = "SELECT o.AD_Org_ID,o.Name,o.IsSummary "       //	1..3
                         + "FROM AD_Role r, AD_Client c"
                         + " INNER JOIN AD_Org o ON (c.AD_Client_ID=o.AD_Client_ID OR o.AD_Org_ID=0) "
                         + "WHERE r.AD_Role_ID='" + AD_Role_ID + "'"       //	#1
                         + " AND c.AD_Client_ID='" + client.GetKey() + "'" //	#2
                         + " AND o.IsActive='Y' AND o.IsSummary='N'"
                         + " AND (r.IsAccessAllOrgs='Y' "
                         + "OR (r.IsUseUserOrgAccess='N' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_Role_OrgAccess ra "
                         + "WHERE ra.AD_Role_ID=r.AD_Role_ID AND ra.IsActive='Y')) "
                         + "OR (r.IsUseUserOrgAccess='Y' AND o.AD_Org_ID IN (SELECT AD_Org_ID FROM AD_User_OrgAccess ua "
                         + "WHERE ua.AD_User_ID='" + AD_User_ID + "' AND ua.IsActive='Y'))"             //	#3
                         + ") "
                         + "ORDER BY o.Name";
            //
            MRole       role = null;
            IDataReader dr   = null;

            try
            {
                dr = DataBase.DB.ExecuteReader(sql);
                //  load Orgs
                while (dr.Read())
                {
                    int    AD_Org_ID = Utility.Util.GetValueOfInt(dr[0].ToString());
                    String Name      = dr[1].ToString();
                    bool   summary   = "Y".Equals(dr[2].ToString());
                    if (summary)
                    {
                        if (role == null)
                        {
                            role = MRole.Get(m_ctx, AD_Role_ID, AD_User_ID, false);
                        }
                        GetOrgsAddSummary(list, AD_Org_ID, Name, role);
                    }
                    else
                    {
                        KeyNamePair p = new KeyNamePair(AD_Org_ID, Name);
                        if (!list.Contains(p))
                        {
                            list.Add(p);
                        }
                    }
                }
                dr.Close();

                //
                retValue = new KeyNamePair[list.Count];
                retValue = list.ToArray();
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
                retValue = null;
            }

            //	No Orgs
            if (retValue == null || retValue.Length == 0)
            {
                return(null);
            }

            //  Client Info
            m_ctx.SetContext("#AD_Client_ID", client.GetKey());
            m_ctx.SetContext("#AD_Client_Name", client.GetName());
            Ini.SetProperty(Ini.P_CLIENT, client.GetName());
            return(retValue);
        }   //  getOrgs
コード例 #7
0
        }       //	getRoles

        /// <summary>
        /// Load Clients.
        /// <para>
        /// Sets Role info in context and loads its clients
        /// </para>
        /// </summary>
        /// <param name="role"> role information</param>
        /// <returns>list of valid client KeyNodePairs or null if in error</returns>
        public KeyNamePair[] GetClients(KeyNamePair role)
        {
            if (role == null)
            {
                throw new Exception("Role missing");
            }
            m_role = role;
            //	Web Store Login
            if (m_store != null)
            {
                return new KeyNamePair[] { new KeyNamePair(m_store.GetAD_Client_ID(), m_store.GetName() + " Tenant") }
            }
            ;

            //	Set User for Role
            int AD_Role_ID = role.GetKey();

            for (int i = 0; i < m_roles.Count; i++)
            {
                if (AD_Role_ID == m_roles[i].GetKey())
                {
                    int AD_User_ID = m_users[i];
                    m_ctx.SetAD_User_ID(AD_User_ID);
                    if (MUser.IsSalesRep(AD_User_ID))
                    {
                        m_ctx.SetContext("#SalesRep_ID", AD_User_ID);
                    }
                    m_user = new KeyNamePair(AD_User_ID, m_user.GetName());
                    break;
                }
            }

            List <KeyNamePair> list = new List <KeyNamePair>();

            KeyNamePair[] retValue = null;
            String        sql      = "SELECT DISTINCT r.UserLevel, r.ConnectionProfile, " //	1..2
                                     + " c.AD_Client_ID,c.Name "                          //	3..4
                                     + "FROM AD_Role r"
                                     + " INNER JOIN AD_Client c ON (r.AD_Client_ID=c.AD_Client_ID) "
                                     + "WHERE r.AD_Role_ID=@roleid" //	#1
                                     + " AND r.IsActive='Y' AND c.IsActive='Y'";

            //	get Role details
            IDataReader dr = null;

            try
            {
                SqlParameter[] param = new SqlParameter[1];
                param[0] = new SqlParameter("@roleid", role.GetKey());

                dr = DataBase.DB.ExecuteReader(sql, param);
                if (!dr.Read())
                {
                    dr.Close();
                    return(null);
                }

                //  Role Info
                m_ctx.SetAD_Role_ID(role.GetKey());
                m_ctx.SetContext("#AD_Role_Name", role.GetName());
                Ini.SetProperty(Ini.P_ROLE, role.GetName());
                //	User Level
                m_ctx.SetContext("#User_Level", dr[0].ToString());      //	Format 'SCO'

                //  load Clients
                do
                {
                    int         AD_Client_ID = Utility.Util.GetValueOfInt(dr[2].ToString());
                    String      Name         = dr[3].ToString();
                    KeyNamePair p            = new KeyNamePair(AD_Client_ID, Name);
                    list.Add(p);
                }while (dr.Read());
                dr.Close();
                //
                retValue = new KeyNamePair[list.Count];
                retValue = list.ToArray();
            }
            catch
            {
                if (dr != null)
                {
                    dr.Close();
                }
                retValue = null;
            }
            return(retValue);
        }
コード例 #8
0
        }       //	getAD_Role_ID

        /// <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(KeyNamePair org,
                                      KeyNamePair warehouse, DateTime timestamp, String printerName)
        {
            m_org = org;

            if (m_ctx == null || org == null)
            {
                throw new ArgumentException("Required parameter missing");
            }
            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");
            }


            //  Org Info - assumes that it is valid
            m_ctx.SetAD_Org_ID(org.GetKey());
            m_ctx.SetContext("#AD_Org_Name", org.GetName());
            Ini.SetProperty(Ini.P_ORG, org.GetName());

            //  Warehouse Info
            if (warehouse != null)
            {
                m_ctx.SetContext("#M_Warehouse_ID", warehouse.GetKey());
                Ini.SetProperty(Ini.P_WAREHOUSE, warehouse.GetName());
            }

            //	Date (default today)
            long today = CommonFunctions.CurrentTimeMillis();

            if (timestamp != null)
            {
                today = CommonFunctions.CurrentTimeMillis(timestamp);
            }
            m_ctx.SetContext("#Date", today.ToString());

            //	Load User/Role Info
            MUser           user       = MUser.Get(m_ctx, GetAD_User_ID());
            MUserPreference preference = user.GetPreference();
            MRole           role       = MRole.GetDefault(m_ctx, true);

            //	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
コード例 #9
0
ファイル: AReport.cs プロジェクト: vuongthai91/ERP-CMR-DMS
        /// <summary>
        /// Launch Report
        /// </summary>
        /// <param name="pp">KeyNamePair values</param>
        private void LaunchReport(KeyNamePair pp)
        {
            MPrintFormat pf = MPrintFormat.Get(Env.GetContext(), pp.GetKey(), true);

            LaunchReport(pf);
        }       //	launchReport