public void InitSchedulerManager()
 {
     if (tSchedulerManager == null)
     {
         tSchedulerManager = new Timer(SchedulerUtils.OnTimer, this, new TimeSpan(0, 1, 0), new TimeSpan(0, 5, 0));
         SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "The Scheduler Manager timer has been activated.");
     }
     else
     {
         tSchedulerManager.Change(new TimeSpan(0, 1, 0), new TimeSpan(0, 5, 0));
         SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "The Scheduler Manager timer has been updated.");
     }
 }
Beispiel #2
0
        private void OnDataBinding(object sender, EventArgs e)
        {
            Literal      lbl          = (Literal)sender;
            DataGridItem objContainer = (DataGridItem)lbl.NamingContainer;
            DataRowView  row          = objContainer.DataItem as DataRowView;

            if (row != null)
            {
                // 04/30/2006 Paul.  Use the Context to store pointers to the localization objects.
                // This is so that we don't need to require that the page inherits from SplendidPage.
                L10N L10n = HttpContext.Current.Items["L10n"] as L10N;
                if (L10n == null)
                {
                    // 04/26/2006 Paul.  We want to have the AccessView on the SystemCheck page.
                    L10n = new L10N(Sql.ToString(HttpContext.Current.Session["USER_SETTINGS/CULTURE"]));
                }
                if (L10n != null)
                {
                    if (row[sDATA_FIELD] != DBNull.Value)
                    {
                        string sList = sLIST_NAME;
                        // 01/18/2007 Paul.  If AssignedUser list, then use the cached value to find the value.
                        if (sLIST_NAME == "AssignedUser")
                        {
                            lbl.Text = SplendidCache.AssignedUser(Sql.ToGuid(row[sDATA_FIELD]));
                        }
                        // 12/05/2005 Paul.  The activity status needs to be dynamically converted to the correct list.
                        else if (sLIST_NAME == "activity_status")
                        {
                            string sACTIVITY_TYPE = String.Empty;
                            try
                            {
                                sACTIVITY_TYPE = Sql.ToString(row["ACTIVITY_TYPE"]);
                                switch (sACTIVITY_TYPE)
                                {
                                case "Tasks":  sList = "task_status_dom";  break;

                                case "Meetings":  sList = "meeting_status_dom";  break;

                                case "Calls":
                                    // 07/15/2006 Paul.  Call status is translated externally.
                                    lbl.Text = Sql.ToString(row[sDATA_FIELD]);
                                    return;

                                //sList = "call_status_dom"   ;  break;
                                case "Notes":
                                    // 07/15/2006 Paul.  Note Status is not normally as it does not have a status.
                                    lbl.Text = L10n.Term(".activity_dom.Note");
                                    return;

                                // 06/15/2006 Paul.  This list name for email_status does not follow the standard.
                                case "Emails":  sList = "dom_email_status";  break;

                                // 04/21/2006 Paul.  If the activity does not have a status (such as a Note), then use activity_dom.
                                default:  sList = "activity_dom";  break;
                                }
                            }
                            catch (Exception ex)
                            {
                                SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                            }
                            lbl.Text = Sql.ToString(L10n.Term("." + sList + ".", row[sDATA_FIELD]));
                        }
                        else
                        {
                            lbl.Text = Sql.ToString(L10n.Term("." + sList + ".", row[sDATA_FIELD]));
                        }
                    }
                }
                else
                {
                    lbl.Text = Sql.ToString(row[sDATA_FIELD]);
                }
            }
            else
            {
                lbl.Text = sDATA_FIELD;
            }
        }
        public static bool LoginUser(string sUSER_NAME, string sPASSWORD, string sTHEME, string sLANGUAGE, string sUSER_DOMAIN, bool bIS_ADMIN)
        {
            HttpApplicationState Application = HttpContext.Current.Application;
            HttpSessionState     Session     = HttpContext.Current.Session;

            bool bValidUser       = false;
            DbProviderFactory dbf = DbProviderFactories.GetFactory();

            using (IDbConnection con = dbf.CreateConnection())
            {
                con.Open();
                string sSQL;
                // 03/22/2006 Paul.  The user name should be case-insignificant.  The password is case-significant.
                // 03/22/2006 Paul.  DB2 does not like lower(USER_NAME) = lower(@USER_NAME).  It returns the following error.
                // ERROR [42610] [IBM][DB2/NT] SQL0418N A statement contains a use of a parameter marker that is not valid. SQLSTATE=42610
                // 05/23/2006 Paul.  Use vwUSERS_Login so that USER_HASH can be removed from vwUSERS to prevent its use in reports.
                sSQL = "select ID                           " + ControlChars.CrLf
                       + "     , USER_NAME                    " + ControlChars.CrLf
                       + "     , FULL_NAME                    " + ControlChars.CrLf
                       + "     , IS_ADMIN                     " + ControlChars.CrLf
                       + "     , STATUS                       " + ControlChars.CrLf
                       + "     , PORTAL_ONLY                  " + ControlChars.CrLf
                       + "  from vwUSERS_Login                " + ControlChars.CrLf
                       + " where lower(USER_NAME) = @USER_NAME" + ControlChars.CrLf;
                using (IDbCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = sSQL;

/*
 #if DEBUG
 *                                      if ( sUSER_NAME == "paulrony" && Sql.ToString(Application["SplendidProvider"]) == "MySql.Data" )
 *                                              sUSER_NAME = "admin";
 #endif
 */
                    // 03/22/2006 Paul.  Convert the name to lowercase here.
                    Sql.AddParameter(cmd, "@USER_NAME", sUSER_NAME.ToLower());
                    // 11/19/2005 Paul.  sUSER_DOMAIN is used to determine if NTLM is enabled.
                    if (Sql.IsEmptyString(sUSER_DOMAIN))
                    {
                        if (!Sql.IsEmptyString(sPASSWORD))
                        {
                            string sUSER_HASH = Security.HashPassword(sPASSWORD);
                            cmd.CommandText += "   and USER_HASH = @USER_HASH" + ControlChars.CrLf;
                            Sql.AddParameter(cmd, "@USER_HASH", sUSER_HASH);
                        }
                        else
                        {
                            // 11/19/2005 Paul.  Handle the special case of the password stored as NULL or empty string.
                            cmd.CommandText += "   and (USER_HASH = '' or USER_HASH is null)" + ControlChars.CrLf;
                        }
                    }
                    using (IDataReader rdr = cmd.ExecuteReader())
                    {
                        string sApplicationPath = Sql.ToString(Application["rootURL"]);
                        if (rdr.Read())
                        {
                            // 11/19/2005 Paul.  Clear all session values.
                            Session.Clear();
                            Security.USER_ID     = Sql.ToGuid(rdr["ID"]);
                            Security.USER_NAME   = Sql.ToString(rdr["USER_NAME"]);
                            Security.FULL_NAME   = Sql.ToString(rdr["FULL_NAME"]);
                            Security.IS_ADMIN    = Sql.ToBoolean(rdr["IS_ADMIN"]);
                            Security.PORTAL_ONLY = Sql.ToBoolean(rdr["PORTAL_ONLY"]);

                            Guid gUSER_ID = Sql.ToGuid(rdr["ID"]);
                            // 08/08/2006 Paul.  Don't supply the Language as it prevents the user value from being used.
                            // This bug is a hold-over from the time we removed the Lauguage combo from the login screen.
                            LoadUserPreferences(gUSER_ID, sTHEME, String.Empty);
                            LoadUserACL(gUSER_ID);
                            bValidUser = true;
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "User login.");
                        }
                        else if (Security.IsWindowsAuthentication())
                        {
                            // 11/04/2005.  If user does not exist, then create it, but only if NTLM is used.
                            Guid gUSER_ID = Guid.Empty;
                            SqlProcs.spUSERS_InsertNTLM(ref gUSER_ID, sUSER_DOMAIN, sUSER_NAME, bIS_ADMIN);

                            // 11/19/2005 Paul.  Clear all session values.
                            Session.Clear();
                            Security.USER_ID     = gUSER_ID;
                            Security.USER_NAME   = sUSER_NAME;
                            Security.IS_ADMIN    = bIS_ADMIN;
                            Security.PORTAL_ONLY = false;
                            // 11/21/2005 Paul.  Load the preferences to initialize cuture, date, time and currency preferences.
                            LoadUserPreferences(gUSER_ID, String.Empty, String.Empty);
                            LoadUserACL(gUSER_ID);
                            bValidUser = true;
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "User login.");
                        }
                        else
                        {
                            // 11/22/2005 Paul.  Initialize preferences even if login fails so that the theme gets set to the default value.
                            LoadUserPreferences(Guid.Empty, String.Empty, String.Empty);
                        }
                    }
                }
            }
            return(bValidUser);            // throw(new Exception("Users.ERR_INVALID_PASSWORD"));
        }
Beispiel #4
0
        public static void Import(XmlDocument xml, ArrayList arrTables, bool bTruncate)
        {
            HttpResponse Response = HttpContext.Current.Response;
            // 12/16/2005 Paul.  First create a hash table to convert tab name to a uppercase table name.
            Hashtable   hashTables = new Hashtable();
            XmlNodeList nlTables   = xml.DocumentElement.ChildNodes;

            foreach (XmlNode node in nlTables)
            {
                if (!hashTables.ContainsKey(node.Name.ToUpper()))
                {
                    hashTables.Add(node.Name.ToUpper(), node.Name);
                }
            }

            ArrayList lstReservedTables = new ArrayList();

            lstReservedTables.Add("CONFIG");
            lstReservedTables.Add("DETAILVIEWS");
            lstReservedTables.Add("DETAILVIEWS_FIELDS");
            lstReservedTables.Add("DETAILVIEWS_RELATIONSHIPS");
            lstReservedTables.Add("EDITVIEWS");
            lstReservedTables.Add("EDITVIEWS_FIELDS");
            lstReservedTables.Add("GRIDVIEWS");
            lstReservedTables.Add("GRIDVIEWS_COLUMNS");
            lstReservedTables.Add("LANGUAGES");
            lstReservedTables.Add("MODULES");
            lstReservedTables.Add("SHORTCUTS");
            lstReservedTables.Add("TERMINOLOGY");
            lstReservedTables.Add("TIMEZONES");

            StringBuilder     sbErrors = new StringBuilder();
            DbProviderFactory dbf      = DbProviderFactories.GetFactory();

            if (arrTables == null)
            {
                arrTables = new ArrayList();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = "select * from vwSqlTableDependencies order by 2, 1";
                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            using (DataTable dt = new DataTable())
                            {
                                da.Fill(dt);
                                for (int i = 0; i < dt.Rows.Count; i++)
                                {
                                    DataRow row = dt.Rows[i];
                                    arrTables.Add(row["name"].ToString());
                                }
                            }
                        }
                        if (bTruncate)
                        {
                            cmd.CommandText = "select * from vwSqlTableDependencies order by 2 desc, 1 desc";
                            using (DbDataAdapter da = dbf.CreateDataAdapter())
                            {
                                ((IDbDataAdapter)da).SelectCommand = cmd;
                                using (DataTable dt = new DataTable())
                                {
                                    da.Fill(dt);
                                    for (int i = 0; i < dt.Rows.Count && Response.IsClientConnected; i++)
                                    {
                                        DataRow row         = dt.Rows[i];
                                        string  sTABLE_NAME = row["name"].ToString().ToUpper();
                                        // 12/18/2005 Paul.  Some tables are reserved and should not be truncated or imported.
                                        if (lstReservedTables.Contains(sTABLE_NAME))
                                        {
                                            continue;
                                        }
                                        // 12/18/2005 Paul.  Only truncate tables that are being imported.
                                        if (hashTables.ContainsKey(sTABLE_NAME))
                                        {
                                            try
                                            {
                                                if (sTABLE_NAME == "USERS")
                                                {
                                                    // 12/17/2005 Paul.  Don't delete the existing user, otherwise it will cause a login problem in the future.
                                                    cmd.CommandText = "delete from USERS where ID != @ID";
                                                    Sql.AddParameter(cmd, "@ID", Security.USER_ID);
                                                }
                                                else
                                                {
                                                    cmd.CommandText = "delete from " + sTABLE_NAME;
                                                }
                                                cmd.ExecuteNonQuery();
                                                Response.Write(" ");                                                 // Write a singe byte to keep the connection open.
                                            }
                                            catch (Exception ex)
                                            {
                                                LogError(ref sbErrors, Sql.ExpandParameters(cmd), ex.Message);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < arrTables.Count && Response.IsClientConnected; i++)
            {
                string sTABLE_NAME = arrTables[i].ToString().ToUpper();
                // 12/18/2005 Paul.  Some tables are reserved and should not be truncated or imported.
                if (lstReservedTables.Contains(sTABLE_NAME))
                {
                    continue;
                }
                if (hashTables.ContainsKey(sTABLE_NAME))
                {
                    string sXML_TABLE_NAME = hashTables[sTABLE_NAME].ToString();

                    XmlNodeList nlRows = xml.DocumentElement.SelectNodes(sXML_TABLE_NAME);
                    if (nlRows.Count > 0)
                    {
                        SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Import Database Table: " + sTABLE_NAME);
                        // 12/17/2005 Paul.  Use a new connection for each table import so that connection state will be reset.
                        // My main concern is that the identity_insert gets reset.
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            try
                            {
                                if (Sql.IsSQLServer(con))
                                {
                                    // 12/17/2005 Paul.  In SQL Server, turn on identity_insert.
                                    string sIDENTITY_NAME = String.Empty;
                                    switch (sIDENTITY_NAME)
                                    {
                                    case "BUGS": sIDENTITY_NAME = "BUGS";  break;

                                    case "CASES": sIDENTITY_NAME = "CASES";  break;

                                    case "CAMPAIGNS": sIDENTITY_NAME = "CAMPAIGNS";  break;

                                    case "PROSPECTS": sIDENTITY_NAME = "PROSPECTS";  break;
                                    }
                                    if (!Sql.IsEmptyString(sIDENTITY_NAME))
                                    {
                                        IDbCommand cmdIdentity = con.CreateCommand();
                                        cmdIdentity.CommandText = "set identity_insert " + sIDENTITY_NAME + " on";
                                        cmdIdentity.ExecuteNonQuery();
                                    }
                                }
                                else if (Sql.IsOracle(con))
                                {
                                    // 12/17/2005 Paul.  In Oracle, disable sequence triggers.
                                    string sTRIGGER_NAME = String.Empty;
                                    switch (sTABLE_NAME)
                                    {
                                    case "BUGS": sTRIGGER_NAME = "TR_S_BUGS_BUG_NUMBER";  break;

                                    case "CASES": sTRIGGER_NAME = "TR_S_CASES_CASE_NUMBER";  break;

                                    case "CAMPAIGNS": sTRIGGER_NAME = "TR_S_CAMPAIGNS_TRACKER_KEY";  break;

                                    case "PROSPECTS": sTRIGGER_NAME = "TR_S_PROSPECTS_TRACKER_KEY";  break;
                                    }
                                    if (!Sql.IsEmptyString(sTRIGGER_NAME))
                                    {
                                        IDbCommand cmdTrigger = con.CreateCommand();
                                        cmdTrigger.CommandText = "alter trigger " + sTRIGGER_NAME + " disable";
                                        cmdTrigger.ExecuteNonQuery();
                                    }
                                }

                                int        nTableErrors = 0;
                                IDbCommand cmdImport    = Sql.CreateInsertParameters(con, sTABLE_NAME);
                                foreach (XmlNode node in nlRows)
                                {
                                    if (!Response.IsClientConnected)
                                    {
                                        break;
                                    }
                                    foreach (IDataParameter par in cmdImport.Parameters)
                                    {
                                        par.Value = DBNull.Value;
                                    }
                                    for (int j = 0; j < node.ChildNodes.Count; j++)
                                    {
                                        // 12/18/2005 Paul.  A short-sighted programmer at SugarCRM created GUIDs with invalid characters.
                                        // We need to convert them to valid GUIDs.
                                        string sText = node.ChildNodes[j].InnerText;
                                        // 08/20/2006 Paul.  Dynamically attempt to fix invalid GUIDs. It really only works for the ones defined below.
                                        string sName = node.ChildNodes[j].Name.ToUpper();
                                        if (sName == "ID" || sName.EndsWith("_ID"))
                                        {
                                            if (sText.Length < 36)
                                            {
                                                sText = "00000000-0000-0000-0000-000000000000".Substring(0, 36 - sText.Length) + sText;
                                            }
                                        }
                                        switch (sText)
                                        {
                                        case "00000000-0000-0000-0000-000000jim_id":  sText = "00000000-0000-0000-0001-000000000000";  break;

                                        case "00000000-0000-0000-0000-000000max_id":  sText = "00000000-0000-0000-0002-000000000000";  break;

                                        case "00000000-0000-0000-0000-00000will_id":  sText = "00000000-0000-0000-0003-000000000000";  break;

                                        case "00000000-0000-0000-0000-0000chris_id":  sText = "00000000-0000-0000-0004-000000000000";  break;

                                        case "00000000-0000-0000-0000-0000sally_id":  sText = "00000000-0000-0000-0005-000000000000";  break;

                                        case "00000000-0000-0000-0000-0000sarah_id":  sText = "00000000-0000-0000-0006-000000000000";  break;
                                        }
                                        Sql.SetParameter(cmdImport, node.ChildNodes[j].Name, sText);
                                    }
                                    // 12/18/2005 Paul.  ID can never be NULL.  SugarCRM does not use an ID in the CONFIG or USERS_FEEDS table.
                                    IDbDataParameter parID = Sql.FindParameter(cmdImport, "@ID");
                                    if (parID != null)
                                    {
                                        // 12/18/2005 Paul. GUIDs from SugarCRM may not be 36 characters.
                                        string sID = Sql.ToString(parID.Value);
                                        if (parID.Value != DBNull.Value)
                                        {
                                            if (sID.Length < 36)
                                            {
                                                // 07/31/2006 Paul.  Stop using VisualBasic library to increase compatibility with Mono.
                                                parID.Value = "00000000-0000-0000-0000-000000000000".Substring(0, 36 - sID.Length) + sID;
                                            }
                                        }
                                        if (Sql.IsEmptyGuid(parID.Value))
                                        {
                                            if (parID.DbType == DbType.Guid)
                                            {
                                                parID.Value = Guid.NewGuid();
                                            }
                                            else
                                            {
                                                parID.Value = Guid.NewGuid().ToString();
                                            }
                                        }
                                    }
                                    // 12/18/2005 Paul.  DATE_ENTERED can never be NULL.  SugarCRM does not use DATE_ENTERED in a number of tables.
                                    IDbDataParameter parDATE_ENTERED = Sql.FindParameter(cmdImport, "@DATE_ENTERED");
                                    if (parDATE_ENTERED != null)
                                    {
                                        if (parDATE_ENTERED.Value == DBNull.Value)
                                        {
                                            parDATE_ENTERED.Value = DateTime.Now;
                                        }
                                    }
                                    // 12/18/2005 Paul.  DATE_MODIFIED can never be NULL.  SugarCRM does not use DATE_MODIFIED in a number of tables.
                                    IDbDataParameter parDATE_MODIFIED = Sql.FindParameter(cmdImport, "@DATE_MODIFIED");
                                    if (parDATE_MODIFIED != null)
                                    {
                                        if (parDATE_MODIFIED.Value == DBNull.Value)
                                        {
                                            parDATE_MODIFIED.Value = DateTime.Now;
                                        }
                                    }
                                    try
                                    {
                                        cmdImport.ExecuteNonQuery();
                                        Response.Write(" ");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogError(ref sbErrors, Sql.ExpandParameters(cmdImport), ex.Message);
                                        // 12/17/2005 Paul.  If there is an error, stop importing from this table.
                                        // 12/18/2005 Paul.  I'd like to see the first 100 errors.
                                        nTableErrors++;
                                        if (nTableErrors > 100)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                LogError(ref sbErrors, sTABLE_NAME, ex.Message);
                            }
                            finally
                            {
                                try
                                {
                                    if (Sql.IsSQLServer(con))
                                    {
                                        // 12/17/2005 Paul.  In SQL Server, turn off identity_insert.
                                        string sIDENTITY_NAME = String.Empty;
                                        switch (sIDENTITY_NAME)
                                        {
                                        case "BUGS": sIDENTITY_NAME = "BUGS";  break;

                                        case "CASES": sIDENTITY_NAME = "CASES";  break;

                                        case "CAMPAIGNS": sIDENTITY_NAME = "CAMPAIGNS";  break;

                                        case "PROSPECTS": sIDENTITY_NAME = "PROSPECTS";  break;
                                        }
                                        if (!Sql.IsEmptyString(sIDENTITY_NAME))
                                        {
                                            IDbCommand cmdIdentity = con.CreateCommand();
                                            cmdIdentity.CommandText = "set identity_insert " + sIDENTITY_NAME + " off";
                                            cmdIdentity.ExecuteNonQuery();
                                        }
                                    }
                                    else if (Sql.IsOracle(con))
                                    {
                                        // 12/17/2005 Paul.  In Oracle, enable sequence triggers.
                                        string sTRIGGER_NAME = String.Empty;
                                        switch (sTABLE_NAME)
                                        {
                                        case "BUGS": sTRIGGER_NAME = "TR_S_BUGS_BUG_NUMBER";  break;

                                        case "CASES": sTRIGGER_NAME = "TR_S_CASES_CASE_NUMBER";  break;

                                        case "CAMPAIGNS": sTRIGGER_NAME = "TR_S_CAMPAIGNS_TRACKER_KEY";  break;

                                        case "PROSPECTS": sTRIGGER_NAME = "TR_S_PROSPECTS_TRACKER_KEY";  break;
                                        }
                                        if (!Sql.IsEmptyString(sTRIGGER_NAME))
                                        {
                                            IDbCommand cmdTrigger = con.CreateCommand();
                                            cmdTrigger.CommandText = "alter trigger " + sTRIGGER_NAME + " enable";
                                            cmdTrigger.ExecuteNonQuery();
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    LogError(ref sbErrors, sTABLE_NAME, ex.Message);
                                }
                            }
                        }
                        Response.Write(" ");                         // Write a singe byte to keep the connection open.
                    }
                }
            }
            // 12/18/2005 Paul.  Reserved tables will still be imported, but we use the associated spXXX_Update procedure.
            for (int i = 0; i < arrTables.Count && Response.IsClientConnected; i++)
            {
                string sTABLE_NAME = arrTables[i].ToString().ToUpper();
                if (hashTables.ContainsKey(sTABLE_NAME) && lstReservedTables.Contains(sTABLE_NAME))
                {
                    string sXML_TABLE_NAME = hashTables[sTABLE_NAME].ToString();

                    XmlNodeList nlRows = xml.DocumentElement.SelectNodes(sXML_TABLE_NAME);
                    if (nlRows.Count > 0)
                    {
                        SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Import Database Table: " + sTABLE_NAME);
                        // 12/17/2005 Paul.  Use a new connection for each table import so that connection state will be reset.
                        // My main concern is that the identity_insert gets reset.
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            con.Open();
                            try
                            {
                                int        nTableErrors = 0;
                                IDbCommand cmdImport    = SqlProcs.Factory(con, "sp" + sTABLE_NAME + "_Update");
                                foreach (XmlNode node in nlRows)
                                {
                                    if (!Response.IsClientConnected)
                                    {
                                        break;
                                    }
                                    foreach (IDataParameter par in cmdImport.Parameters)
                                    {
                                        par.Value = DBNull.Value;
                                    }
                                    for (int j = 0; j < node.ChildNodes.Count; j++)
                                    {
                                        string sText = node.ChildNodes[j].InnerText;
                                        Sql.SetParameter(cmdImport, node.ChildNodes[j].Name, sText);
                                    }
                                    // 12/18/2005 Paul.  ID can never be NULL.  SugarCRM does not use an ID in the CONFIG or USERS_FEEDS table.
                                    IDbDataParameter parID = Sql.FindParameter(cmdImport, "@ID");
                                    if (parID != null)
                                    {
                                        // 12/18/2005 Paul. GUIDs from SugarCRM may not be 36 characters.
                                        string sID = Sql.ToString(parID.Value);
                                        if (parID.Value != DBNull.Value)
                                        {
                                            if (sID.Length < 36)
                                            {
                                                // 07/31/2006 Paul.  Stop using VisualBasic library to increase compatibility with Mono.
                                                parID.Value = "00000000-0000-0000-0000-000000000000".Substring(0, 36 - sID.Length) + sID;
                                            }
                                        }
                                    }
                                    try
                                    {
                                        cmdImport.ExecuteNonQuery();
                                        Response.Write(" ");
                                    }
                                    catch (Exception ex)
                                    {
                                        LogError(ref sbErrors, Sql.ExpandParameters(cmdImport), ex.Message);
                                        // 12/17/2005 Paul.  If there is an error, stop importing from this table.
                                        // 12/18/2005 Paul.  I'd like to see the first 100 errors.
                                        nTableErrors++;
                                        if (nTableErrors > 100)
                                        {
                                            break;
                                        }
                                    }
                                }
                            }
                            catch (Exception ex)
                            {
                                LogError(ref sbErrors, sTABLE_NAME, ex.Message);
                            }
                        }
                        Response.Write(" ");                         // Write a singe byte to keep the connection open.
                    }
                }
            }
            if (sbErrors.Length > 0)
            {
                throw(new Exception(sbErrors.ToString()));
            }
        }
        public static void InitApp()
        {
            try
            {
                HttpApplicationState Application = HttpContext.Current.Application;
                if (Application.Count == 0)
                {
                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Application start.");
                }
                else
                {
                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), "Application restart.");
                }

                // 11/14/2005 Paul.  Force the reload of the provider and connection strings.
                // Application.Remove("SplendidProvider");
                // 11/28/2005 Paul.  Use Clear() to clear all application variables.
                DataTable dtSystemErrors = Application["SystemErrors"] as DataTable;
                Application.Clear();
                // 11/28/2005 Paul.  Save and restore the system errors table.
                Application["SystemErrors"] = dtSystemErrors;
                InitAppURLs();

                // 11/28/2005 Paul.  Clear all cache variables as well.
                foreach (DictionaryEntry oKey in HttpContext.Current.Cache)
                {
                    string sKey = oKey.Key.ToString();
                    HttpContext.Current.Cache.Remove(sKey);
                }
                // 06/03/2006 Paul.  Clear the cached data that is stored in the Session object.
                if (HttpContext.Current.Session != null)
                {
                    Hashtable hashSessionKeys = new Hashtable();
                    foreach (string sKey in HttpContext.Current.Session.Keys)
                    {
                        hashSessionKeys.Add(sKey, null);
                    }
                    // 06/03/2006 Paul.  We can't remove a key when it is used in the enumerator.
                    foreach (string sKey in hashSessionKeys.Keys)
                    {
                        if (sKey.StartsWith("vwSHORTCUTS_Menu_ByUser") || sKey.StartsWith("vwMODULES_TabMenu_ByUser"))
                        {
                            HttpContext.Current.Session.Remove(sKey);
                        }
                    }
                }

                DbProviderFactory dbf = DbProviderFactories.GetFactory();
                using (IDbConnection con = dbf.CreateConnection())
                {
                    // 07/28/2006 Paul.  Test the database connection and allow an early exit if failed.
                    con.Open();
                }

                // 01/12/2006 Paul.  Separate out the terminology so that it can be called when importing a language pack.
                InitTerminology();

                using (IDbConnection con = dbf.CreateConnection())
                {
                    con.Open();
                    string sSQL;
                    sSQL = "select NAME    " + ControlChars.CrLf
                           + "     , VALUE   " + ControlChars.CrLf
                           + "  from vwCONFIG" + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                Application["CONFIG." + Sql.ToString(rdr["NAME"])] = Sql.ToString(rdr["VALUE"]);
                            }
                        }
                    }
                    sSQL = "select *          " + ControlChars.CrLf
                           + "  from vwTIMEZONES" + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                TimeZone oTimeZone = new TimeZone
                                                         (Sql.ToGuid(rdr["ID"])
                                                         , Sql.ToString(rdr["NAME"])
                                                         , Sql.ToString(rdr["STANDARD_NAME"])
                                                         , Sql.ToString(rdr["STANDARD_ABBREVIATION"])
                                                         , Sql.ToString(rdr["DAYLIGHT_NAME"])
                                                         , Sql.ToString(rdr["DAYLIGHT_ABBREVIATION"])
                                                         , Sql.ToInteger(rdr["BIAS"])
                                                         , Sql.ToInteger(rdr["STANDARD_BIAS"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_BIAS"])
                                                         , Sql.ToInteger(rdr["STANDARD_YEAR"])
                                                         , Sql.ToInteger(rdr["STANDARD_MONTH"])
                                                         , Sql.ToInteger(rdr["STANDARD_WEEK"])
                                                         , Sql.ToInteger(rdr["STANDARD_DAYOFWEEK"])
                                                         , Sql.ToInteger(rdr["STANDARD_HOUR"])
                                                         , Sql.ToInteger(rdr["STANDARD_MINUTE"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_YEAR"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_MONTH"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_WEEK"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_DAYOFWEEK"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_HOUR"])
                                                         , Sql.ToInteger(rdr["DAYLIGHT_MINUTE"])
                                                         , Sql.ToBoolean(Application["CONFIG.GMT_Storage"])
                                                         );
                                Application["TIMEZONE." + oTimeZone.ID.ToString()] = oTimeZone;
                            }
                        }
                    }
                    sSQL = "select *           " + ControlChars.CrLf
                           + "  from vwCURRENCIES" + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        using (IDataReader rdr = cmd.ExecuteReader())
                        {
                            while (rdr.Read())
                            {
                                Currency C10n = new Currency
                                                    (Sql.ToGuid(rdr["ID"])
                                                    , Sql.ToString(rdr["NAME"])
                                                    , Sql.ToString(rdr["SYMBOL"])
                                                    , Sql.ToFloat(rdr["CONVERSION_RATE"])
                                                    );
                                Application["CURRENCY." + C10n.ID.ToString()] = C10n;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                //HttpContext.Current.Response.Write(ex.Message);
            }
        }