public void LoadLineItems(Guid gID, Guid gDuplicateID, IDbConnection con, IDataReader rdr, string sLOAD_MODULE, string sLOAD_MODULE_KEY)
        {
            if (!IsPostBack)
            {
                CURRENCY_ID.DataSource = SplendidCache.Currencies();
                CURRENCY_ID.DataBind();
                TAXRATE_ID.DataSource = SplendidCache.TaxRates();
                TAXRATE_ID.DataBind();
                TAXRATE_ID.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                SHIPPER_ID.DataSource = SplendidCache.Shippers();
                SHIPPER_ID.DataBind();
                SHIPPER_ID.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                try
                {
                    // 03/15/2007 Paul.  Set the default currency to the current user currency.
                    CURRENCY_ID.SelectedValue = C10n.ID.ToString();
                    EXCHANGE_RATE.Text        = C10n.CONVERSION_RATE.ToString();
                }
                catch
                {
                }
                foreach (DataControlField col in grdMain.Columns)
                {
                    if (!Sql.IsEmptyString(col.HeaderText))
                    {
                        if (col.HeaderText == ".LBL_LIST_ITEM_COST_PRICE")
                        {
                            col.Visible = m_bShowCostPrice;
                        }
                        if (col.HeaderText == ".LBL_LIST_ITEM_LIST_PRICE")
                        {
                            col.Visible = m_bShowListPrice;
                        }
                        col.HeaderText = L10n.Term(m_sMODULE + col.HeaderText);
                    }
                    CommandField cf = col as CommandField;
                    if (cf != null)
                    {
                        cf.EditText   = L10n.Term(cf.EditText);
                        cf.DeleteText = L10n.Term(cf.DeleteText);
                        cf.UpdateText = L10n.Term(cf.UpdateText);
                        cf.CancelText = L10n.Term(cf.CancelText);
                    }
                }
                if (Sql.IsEmptyString(m_sMODULE))
                {
                    throw(new Exception("EditLineItemsView: MODULE is undefined."));
                }
                //if ( Sql.IsEmptyString(m_sMODULE_KEY) )
                //	throw(new Exception("EditLineItemsView: MODULE_KEY is undefined."));

                if ((!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID)) && (con != null) && (rdr != null))
                {
                    new DynamicControl(this, "SHOW_LINE_NUMS").Checked   = Sql.ToBoolean(rdr["SHOW_LINE_NUMS"]);
                    new DynamicControl(this, "CALC_GRAND_TOTAL").Checked = Sql.ToBoolean(rdr["CALC_GRAND_TOTAL"]);
                    try
                    {
                        new DynamicControl(this, "CURRENCY_ID").SelectedValue = Sql.ToString(rdr["CURRENCY_ID"]);
                    }
                    catch
                    {
                    }
                    try
                    {
                        new DynamicControl(this, "TAXRATE_ID").SelectedValue = Sql.ToString(rdr["TAXRATE_ID"]);
                    }
                    catch
                    {
                    }
                    try
                    {
                        new DynamicControl(this, "SHIPPER_ID").SelectedValue = Sql.ToString(rdr["SHIPPER_ID"]);
                    }
                    catch
                    {
                    }
                    // 03/31/2007 Paul.  The exchange rate might be an old value.
                    float fEXCHANGE_RATE = Sql.ToFloat(rdr["EXCHANGE_RATE"]);
                    EXCHANGE_RATE.Text = fEXCHANGE_RATE.ToString();
                    if (CURRENCY_ID.Items.Count > 0)
                    {
                        // 03/31/2007 Paul.  Replace the user currency with the form currency, but use the old exchange rate.
                        Guid gCURRENCY_ID = Sql.ToGuid(CURRENCY_ID.SelectedValue);
                        SetC10n(gCURRENCY_ID, fEXCHANGE_RATE);
                    }
                    // 07/07/2007 Paul.  We should either display the previous values or convert from USD.
                    //SUBTOTAL         .Text  = C10n.ToCurrency(Sql.ToDecimal(rdr["SUBTOTAL_USDOLLAR"])).ToString("c");
                    //DISCOUNT         .Text  = C10n.ToCurrency(Sql.ToDecimal(rdr["DISCOUNT_USDOLLAR"])).ToString("0.00");
                    //SHIPPING         .Text  = C10n.ToCurrency(Sql.ToDecimal(rdr["SHIPPING_USDOLLAR"])).ToString("0.00");
                    //TAX              .Text  = C10n.ToCurrency(Sql.ToDecimal(rdr["TAX_USDOLLAR"     ])).ToString("c");
                    //TOTAL            .Text  = C10n.ToCurrency(Sql.ToDecimal(rdr["TOTAL_USDOLLAR"   ])).ToString("c");
                    // 07/07/2007 Paul.  Lets show the un-converted value as this may help us find bugs.
                    SUBTOTAL.Text = Sql.ToDecimal(rdr["SUBTOTAL"]).ToString("c");
                    DISCOUNT.Text = Sql.ToDecimal(rdr["DISCOUNT"]).ToString("0.00");
                    SHIPPING.Text = Sql.ToDecimal(rdr["SHIPPING"]).ToString("0.00");
                    TAX.Text      = Sql.ToDecimal(rdr["TAX"]).ToString("c");
                    TOTAL.Text    = Sql.ToDecimal(rdr["TOTAL"]).ToString("c");

                    // 05/26/2007 Paul.  Stored USDOLLAR values should not be converted to local currency.
                    DISCOUNT_USDOLLAR.Value = Sql.ToDecimal(rdr["DISCOUNT_USDOLLAR"]).ToString("0.00");
                    SHIPPING_USDOLLAR.Value = Sql.ToDecimal(rdr["SHIPPING_USDOLLAR"]).ToString("0.00");
                    rdr.Close();

                    string sSQL;
                    string sLINE_ITEMS_VIEW = "vw" + sLOAD_MODULE.ToUpper() + "_LINE_ITEMS";
                    sSQL = "select *                  " + ControlChars.CrLf
                           + "  from " + sLINE_ITEMS_VIEW + ControlChars.CrLf
                           + " where 1 = 1              " + ControlChars.CrLf;
                    using (IDbCommand cmd = con.CreateCommand())
                    {
                        cmd.CommandText = sSQL;
                        if (!Sql.IsEmptyGuid(gDuplicateID))
                        {
                            Sql.AppendParameter(cmd, gDuplicateID, sLOAD_MODULE_KEY, false);
                        }
                        else
                        {
                            Sql.AppendParameter(cmd, gID, sLOAD_MODULE_KEY, false);
                        }
                        cmd.CommandText += " order by POSITION asc" + ControlChars.CrLf;

                        if (bDebug)
                        {
                            RegisterClientScriptBlock(sLINE_ITEMS_VIEW, Sql.ClientScriptBlock(cmd));
                        }

                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (DbDataAdapter da = dbf.CreateDataAdapter())
                        {
                            ((IDbDataAdapter)da).SelectCommand = cmd;
                            dtLineItems = new DataTable();
                            da.Fill(dtLineItems);

                            // 04/01/2007 Paul.  If we are duplicating a quote, then we must create new IDs for the line items.
                            // Otherwise, edits to the line items will change the old quote.
                            // 04/29/2007 Paul.  If we are converting from one module to another, then the loading module will not match the current module.
                            if (!Sql.IsEmptyGuid(gDuplicateID) || m_sMODULE != sLOAD_MODULE)
                            {
                                foreach (DataRow row in dtLineItems.Rows)
                                {
                                    row["ID"] = Guid.NewGuid();
                                }
                            }
                            // 03/27/2007 Paul.  Always add blank line to allow quick editing.
                            DataRow rowNew = dtLineItems.NewRow();
                            dtLineItems.Rows.Add(rowNew);

                            ViewState["LineItems"] = dtLineItems;
                            grdMain.DataSource     = dtLineItems;
                            // 03/27/2007 Paul.  Start with last line enabled for editing.
                            grdMain.EditIndex = dtLineItems.Rows.Count - 1;
                            grdMain.DataBind();
                        }
                    }
                }
                else
                {
                    dtLineItems = new DataTable();
                    DataColumn colID                  = new DataColumn("ID", Type.GetType("System.Guid"));
                    DataColumn colLINE_GROUP_ID       = new DataColumn("LINE_GROUP_ID", Type.GetType("System.Guid"));
                    DataColumn colLINE_ITEM_TYPE      = new DataColumn("LINE_ITEM_TYPE", Type.GetType("System.String"));
                    DataColumn colPOSITION            = new DataColumn("POSITION", Type.GetType("System.Int32"));
                    DataColumn colNAME                = new DataColumn("NAME", Type.GetType("System.String"));
                    DataColumn colMFT_PART_NUM        = new DataColumn("MFT_PART_NUM", Type.GetType("System.String"));
                    DataColumn colVENDOR_PART_NUM     = new DataColumn("VENDOR_PART_NUM", Type.GetType("System.String"));
                    DataColumn colPRODUCT_TEMPLATE_ID = new DataColumn("PRODUCT_TEMPLATE_ID", Type.GetType("System.Guid"));
                    DataColumn colTAX_CLASS           = new DataColumn("TAX_CLASS", Type.GetType("System.String"));
                    DataColumn colQUANTITY            = new DataColumn("QUANTITY", Type.GetType("System.Int32"));
                    DataColumn colCOST_PRICE          = new DataColumn("COST_PRICE", Type.GetType("System.Decimal"));
                    DataColumn colCOST_USDOLLAR       = new DataColumn("COST_USDOLLAR", Type.GetType("System.Decimal"));
                    DataColumn colLIST_PRICE          = new DataColumn("LIST_PRICE", Type.GetType("System.Decimal"));
                    DataColumn colLIST_USDOLLAR       = new DataColumn("LIST_USDOLLAR", Type.GetType("System.Decimal"));
                    DataColumn colUNIT_PRICE          = new DataColumn("UNIT_PRICE", Type.GetType("System.Decimal"));
                    DataColumn colUNIT_USDOLLAR       = new DataColumn("UNIT_USDOLLAR", Type.GetType("System.Decimal"));
                    DataColumn colEXTENDED_PRICE      = new DataColumn("EXTENDED_PRICE", Type.GetType("System.Decimal"));
                    DataColumn colEXTENDED_USDOLLAR   = new DataColumn("EXTENDED_USDOLLAR", Type.GetType("System.Decimal"));
                    DataColumn colDESCRIPTION         = new DataColumn("DESCRIPTION", Type.GetType("System.String"));
                    dtLineItems.Columns.Add(colID);
                    dtLineItems.Columns.Add(colLINE_GROUP_ID);
                    dtLineItems.Columns.Add(colLINE_ITEM_TYPE);
                    dtLineItems.Columns.Add(colPOSITION);
                    dtLineItems.Columns.Add(colNAME);
                    dtLineItems.Columns.Add(colMFT_PART_NUM);
                    dtLineItems.Columns.Add(colVENDOR_PART_NUM);
                    dtLineItems.Columns.Add(colPRODUCT_TEMPLATE_ID);
                    dtLineItems.Columns.Add(colTAX_CLASS);
                    dtLineItems.Columns.Add(colQUANTITY);
                    dtLineItems.Columns.Add(colCOST_PRICE);
                    dtLineItems.Columns.Add(colCOST_USDOLLAR);
                    dtLineItems.Columns.Add(colLIST_PRICE);
                    dtLineItems.Columns.Add(colLIST_USDOLLAR);
                    dtLineItems.Columns.Add(colUNIT_PRICE);
                    dtLineItems.Columns.Add(colUNIT_USDOLLAR);
                    dtLineItems.Columns.Add(colEXTENDED_PRICE);
                    dtLineItems.Columns.Add(colEXTENDED_USDOLLAR);
                    dtLineItems.Columns.Add(colDESCRIPTION);
                    // 03/27/2007 Paul.  Always add blank line to allow quick editing.
                    DataRow rowNew = dtLineItems.NewRow();
                    dtLineItems.Rows.Add(rowNew);

                    ViewState["LineItems"] = dtLineItems;
                    grdMain.DataSource     = dtLineItems;
                    // 02/03/2007 Paul.  Start with last line enabled for editing.
                    grdMain.EditIndex = dtLineItems.Rows.Count - 1;
                    grdMain.DataBind();

                    UpdateTotals();
                }
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            // 07/11/2006 Paul.  Users must be able to view and edit their own settings.
            this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN;              //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "view") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                gID = Sql.ToGuid(Request["ID"]);
                if (bMyAccount)
                {
                    // 11/19/2005 Paul.  SugarCRM 3.5.0 allows administrator to duplicate itself.
                    btnDuplicate.Visible = Security.IS_ADMIN;
                    gID = Security.USER_ID;
                }
                ctlAccessView.USER_ID = gID;

                // 12/06/2005 Paul.  The password button is only visible if not windows authentication or Admin.
                // The reason to allow the admin to change a password is so that the admin can prepare to turn off windows authentication.
                btnChangePassword.Visible = !Security.IsWindowsAuthentication() || Security.IS_ADMIN;
                btnReset.Visible          = Security.IS_ADMIN;
                if (!Sql.IsEmptyString(txtNEW_PASSWORD.Value))
                {
                    bool bValidOldPassword = false;
                    if (!Security.IS_ADMIN)
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            // 07/17/2006 Paul.  The USER_HASH has been removed from the main vwUSERS view to prevent its use in reports.
                            sSQL = "select *                     " + ControlChars.CrLf
                                   + "  from vwUSERS_Login         " + ControlChars.CrLf
                                   + " where ID        = @ID       " + ControlChars.CrLf
                                   + "   and USER_HASH = @USER_HASH" + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@ID", gID);
                                Sql.AddParameter(cmd, "@USER_HASH", Security.HashPassword(txtOLD_PASSWORD.Value));
                                con.Open();
                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        bValidOldPassword = true;
                                    }
                                }
                            }
                        }
                        if (!bValidOldPassword)
                        {
                            lblError.Text = L10n.Term("Users.ERR_PASSWORD_INCORRECT_OLD");
                        }
                    }
                    if (bValidOldPassword || Security.IS_ADMIN)
                    {
                        if (txtNEW_PASSWORD.Value == txtCONFIRM_PASSWORD.Value)
                        {
                            SqlProcs.spUSERS_PasswordUpdate(gID, Security.HashPassword(txtNEW_PASSWORD.Value));
                            if (bMyAccount)
                            {
                                Response.Redirect("MyAccount.aspx");
                            }
                            else
                            {
                                Response.Redirect("view.aspx?ID=" + gID.ToString());
                            }
                        }
                        else
                        {
                            lblError.Text = L10n.Term("Users.ERR_REENTER_PASSWORDS");
                        }
                    }
                }
                if (!IsPostBack)
                {
                    // 05/09/2006 Paul.  We need to always initialize the separators, just in case the user is new.
                    txtGROUP_SEPARATOR.Text   = SplendidDefaults.GroupSeparator();
                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                    if (!Sql.IsEmptyGuid(gID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwUSERS_Edit" + ControlChars.CrLf
                                   + " where ID = @ID    " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                Sql.AddParameter(cmd, "@ID", gID);
                                con.Open();

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                                }

                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]) + " (" + Sql.ToString(rdr["USER_NAME"]) + ")";
                                        SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);

                                        // main
                                        txtNAME.Text      = Sql.ToString(rdr["FULL_NAME"]);
                                        txtUSER_NAME.Text = Sql.ToString(rdr["USER_NAME"]);
                                        txtSTATUS.Text    = Sql.ToString(L10n.Term(".user_status_dom.", rdr["STATUS"]));
                                        // user_settings
                                        chkIS_ADMIN.Checked              = Sql.ToBoolean(rdr["IS_ADMIN"]);
                                        chkPORTAL_ONLY.Checked           = Sql.ToBoolean(rdr["PORTAL_ONLY"]);
                                        chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]);

                                        this.AppendDetailViewFields(m_sMODULE + ".DetailView", tblMain, rdr);
                                        // 08/05/2006 Paul.  MailOptions are populated manually.
                                        this.AppendDetailViewFields(m_sMODULE + ".MailOptions", tblMailOptions, null);
                                        // 01/20/2008 Paul.  The mail options panel is manually populated.
                                        new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]);
                                        new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]);

                                        string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]);
                                        if (!Sql.IsEmptyString(sUSER_PREFERENCES))
                                        {
                                            XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES);
                                            try
                                            {
                                                // user_settings
                                                txtLANGUAGE.Text = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture"));
                                                try
                                                {
                                                    DataView vwLanguages = new DataView(SplendidCache.Languages());
                                                    vwLanguages.RowFilter = "NAME = '" + txtLANGUAGE.Text + "'";
                                                    if (vwLanguages.Count > 0)
                                                    {
                                                        txtLANGUAGE.Text = Sql.ToString(vwLanguages[0]["NATIVE_NAME"]);
                                                    }
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                txtDATEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "dateformat");
                                                txtTIMEFORMAT.Text = XmlUtil.SelectSingleNode(xml, "timeformat");
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Show Gridline is not supported at this time.
                                                //chkGRIDLINE             .Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline"             ));
                                                // mail_options
                                                new DynamicControl(this, "MAIL_FROMNAME").Text        = XmlUtil.SelectSingleNode(xml, "mail_fromname");
                                                new DynamicControl(this, "MAIL_FROMADDRESS").Text     = XmlUtil.SelectSingleNode(xml, "mail_fromaddress");
                                                new DynamicControl(this, "MAIL_SENDTYPE").Text        = XmlUtil.SelectSingleNode(xml, "mail_sendtype");
                                                new DynamicControl(this, "MAIL_SMTPSERVER").Text      = XmlUtil.SelectSingleNode(xml, "mail_smtpserver");
                                                new DynamicControl(this, "MAIL_SMTPPORT").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpport");
                                                new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req"));
                                                new DynamicControl(this, "MAIL_SMTPUSER").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpuser");
                                                // freebusy
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Calendar Publish Key is not supported at this time.
                                                //txtCALENDAR_PUBLISH_KEY .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_key" );
                                                //txtCALENDAR_PUBLISH_URL .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_url" );
                                                //txtCALENDAR_SEARCH_URL  .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_search_url"  );

                                                // 05/09/2006 Paul.  Initialize the numeric separators.
                                                txtGROUP_SEPARATOR.Text   = XmlUtil.SelectSingleNode(xml, "num_grp_sep");
                                                txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep");
                                                // 05/09/2006 Paul.  Check for empty strings as the user may have legacy data.
                                                if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text))
                                                {
                                                    txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator();
                                                }
                                                if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text))
                                                {
                                                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                                                }

                                                string   sTIMEZONE   = XmlUtil.SelectSingleNode(xml, "timezone");
                                                DataView vwTimezones = new DataView(SplendidCache.Timezones());
                                                vwTimezones.RowFilter = "ID = '" + sTIMEZONE + "'";
                                                if (vwTimezones.Count > 0)
                                                {
                                                    txtTIMEZONE.Text = Sql.ToString(vwTimezones[0]["NAME"]);
                                                }

                                                string   sCURRENCY    = XmlUtil.SelectSingleNode(xml, "currency_id");
                                                DataView vwCurrencies = new DataView(SplendidCache.Currencies());
                                                vwCurrencies.RowFilter = "ID = '" + sCURRENCY + "'";
                                                if (vwCurrencies.Count > 0)
                                                {
                                                    txtCURRENCY.Text = Sql.ToString(vwCurrencies[0]["NAME_SYMBOL"]);
                                                }
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.

                                                /*
                                                 * try
                                                 * {
                                                 *      int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time"));
                                                 *      if ( nREMINDER_TIME > 0 )
                                                 *      {
                                                 *              txtREMINDER_TIME.Text = L10n.Term(".reminder_time_options." + nREMINDER_TIME.ToString());
                                                 *              chkREMINDER.Checked = true;
                                                 *      }
                                                 * }
                                                 * catch(Exception ex)
                                                 * {
                                                 *      SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                 * }
                                                 */
                                            }
                                            catch (Exception ex)
                                            {
                                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                            }
                                        }
                                        //txtDESCRIPTION.Text = System.Text.Encoding.UTF8.GetString(Convert.FromBase64String("YToxODp7czo4OiJncmlkbGluZSI7czozOiJvZmYiO3M6ODoibWF4X3RhYnMiO3M6MjoiMTIiO3M6MTI6ImRpc3BsYXlfdGFicyI7YToxNTp7aTowO3M6NDoiSG9tZSI7aToxO3M6NzoiaUZyYW1lcyI7aToyO3M6ODoiQ2FsZW5kYXIiO2k6MztzOjEwOiJBY3Rpdml0aWVzIjtpOjQ7czo4OiJBY2NvdW50cyI7aTo1O3M6NToiTGVhZHMiO2k6NjtzOjEzOiJPcHBvcnR1bml0aWVzIjtpOjc7czo1OiJDYXNlcyI7aTo4O3M6NDoiQnVncyI7aTo5O3M6OToiRG9jdW1lbnRzIjtpOjEwO3M6NjoiRW1haWxzIjtpOjExO3M6OToiQ2FtcGFpZ25zIjtpOjEyO3M6NzoiUHJvamVjdCI7aToxMztzOjU6IkZlZWRzIjtpOjE0O3M6OToiRGFzaGJvYXJkIjt9czoxMzoicmVtaW5kZXJfdGltZSI7czozOiI5MDAiO3M6NToidGltZWYiO3M6MzoiSDppIjtzOjg6ImN1cnJlbmN5IjtzOjM6Ii05OSI7czo1OiJkYXRlZiI7czo1OiJZLW0tZCI7czo1OiJ0aW1leiI7czoxOiIwIjtzOjEzOiJtYWlsX2Zyb21uYW1lIjtzOjQ6IlBhdWwiO3M6MTY6Im1haWxfZnJvbWFkZHJlc3MiO3M6MTM6InBhdWxAcm9ueS5jb20iO3M6MTM6Im1haWxfc2VuZHR5cGUiO3M6NDoiU01UUCI7czoxNToibWFpbF9zbXRwc2VydmVyIjtzOjM6Im5zMSI7czoxMzoibWFpbF9zbXRwcG9ydCI7czoyOiIyMyI7czoxMzoibWFpbF9zbXRwdXNlciI7czo4OiJwYXVscm9ueSI7czoxMzoibWFpbF9zbXRwcGFzcyI7czo3OiJwb2NrZXQxIjtzOjE3OiJtYWlsX3NtdHBhdXRoX3JlcSI7czowOiIiO3M6MTY6Im1haWxfcG9wYXV0aF9yZXEiO3M6MDoiIjtzOjIwOiJjYWxlbmRhcl9wdWJsaXNoX2tleSI7czoxMToicHVibGlzaCBoZXkiO30="));
                                    }
                                }
                            }
                        }
                    }
                }
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                lblError.Text = ex.Message;
            }
        }
        private void Page_Load(object sender, System.EventArgs e)
        {
            Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            this.Visible = (SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            try
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
                gID = Sql.ToGuid(Request["ID"]);
                if (!IsPostBack)
                {
                    CURRENCY_ID.DataSource = SplendidCache.Currencies();
                    CURRENCY_ID.DataBind();
                    TAXRATE_ID.DataSource = SplendidCache.TaxRates();
                    TAXRATE_ID.DataBind();
                    TAXRATE_ID.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));
                    SHIPPER_ID.DataSource = SplendidCache.Shippers();
                    SHIPPER_ID.DataBind();
                    SHIPPER_ID.Items.Insert(0, new ListItem(L10n.Term(".LBL_NONE"), ""));

                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *            " + ControlChars.CrLf
                                   + "  from vwQUOTES_Edit" + ControlChars.CrLf
                                   + " where ID = @ID     " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                if (!Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Sql.AddParameter(cmd, "@ID", gDuplicateID);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AddParameter(cmd, "@ID", gID);
                                }
                                con.Open();
#if DEBUG
                                Page.RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
#endif
                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["NAME"]);
                                        Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;
                                        ViewState["BILLING_ACCOUNT_ID"]    = Sql.ToGuid(rdr["BILLING_ACCOUNT_ID"]);
                                        ViewState["SHIPPING_ACCOUNT_ID"]   = Sql.ToGuid(rdr["SHIPPING_ACCOUNT_ID"]);

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, rdr);

                                        new DynamicControl(this, "SHOW_LINE_NUMS").Checked   = Sql.ToBoolean(rdr["SHOW_LINE_NUMS"]);
                                        new DynamicControl(this, "CALC_GRAND_TOTAL").Checked = Sql.ToBoolean(rdr["CALC_GRAND_TOTAL"]);
                                        try
                                        {
                                            new DynamicControl(this, "CURRENCY_ID").SelectedValue = Sql.ToString(rdr["CURRENCY_ID"]);
                                        }
                                        catch
                                        {
                                        }
                                        try
                                        {
                                            new DynamicControl(this, "TAXRATE_ID").SelectedValue = Sql.ToString(rdr["TAXRATE_ID"]);
                                        }
                                        catch
                                        {
                                        }
                                        try
                                        {
                                            new DynamicControl(this, "SHIPPER_ID").SelectedValue = Sql.ToString(rdr["SHIPPER_ID"]);
                                        }
                                        catch
                                        {
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditDescription", tblDescription, null);
                        // 06/08/2006 Paul.  Prepopulate the Account.
                        Guid gPARENT_ID = Sql.ToGuid(Request["PARENT_ID"]);
                        if (!Sql.IsEmptyGuid(gPARENT_ID))
                        {
                            string sMODULE      = String.Empty;
                            string sPARENT_TYPE = String.Empty;
                            string sPARENT_NAME = String.Empty;
                            SqlProcs.spPARENT_Get(ref gPARENT_ID, ref sMODULE, ref sPARENT_TYPE, ref sPARENT_NAME);
                            if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Accounts")
                            {
                                UpdateAccount(gPARENT_ID, true, true);
                            }
                            if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Contacts")
                            {
                                UpdateContact(gPARENT_ID, true, true);
                            }
                            else if (!Sql.IsEmptyGuid(gPARENT_ID) && sMODULE == "Opportunities")
                            {
                                new DynamicControl(this, "OPPORTUNITY_ID").ID     = gPARENT_ID;
                                new DynamicControl(this, "OPPORTUNITY_NAME").Text = sPARENT_NAME;
                            }
                        }
                    }
                }
                else
                {
                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]);
                    Utils.SetPageTitle(Page, L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);

                    DynamicControl ctlBILLING_ACCOUNT_ID  = new DynamicControl(this, "BILLING_ACCOUNT_ID");
                    DynamicControl ctlSHIPPING_ACCOUNT_ID = new DynamicControl(this, "SHIPPING_ACCOUNT_ID");
                    if (Sql.ToGuid(ViewState["BILLING_ACCOUNT_ID"]) != ctlBILLING_ACCOUNT_ID.ID)
                    {
                        UpdateAccount(ctlBILLING_ACCOUNT_ID.ID, true, true);
                        ViewState["BILLING_ACCOUNT_ID"]  = ctlBILLING_ACCOUNT_ID.ID;
                        ViewState["SHIPPING_ACCOUNT_ID"] = ctlBILLING_ACCOUNT_ID.ID;
                    }
                    if (Sql.ToGuid(ViewState["SHIPPING_ACCOUNT_ID"]) != ctlSHIPPING_ACCOUNT_ID.ID)
                    {
                        UpdateAccount(ctlSHIPPING_ACCOUNT_ID.ID, false, true);
                        ViewState["SHIPPING_ACCOUNT_ID"] = ctlSHIPPING_ACCOUNT_ID.ID;
                    }
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex.Message);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
示例#4
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            SetPageTitle(L10n.Term(".moduleList." + m_sMODULE));
            // 06/04/2006 Paul.  Visibility is already controlled by the ASPX page, but it is probably a good idea to skip the load.
            // 07/11/2006 Paul.  Users must be able to view and edit their own settings.
            this.Visible = bMyAccount || SplendidCRM.Security.IS_ADMIN;              //(SplendidCRM.Security.GetUserAccess(m_sMODULE, "edit") >= 0);
            if (!this.Visible)
            {
                return;
            }

            reqUSER_NAME.DataBind();
            reqLAST_NAME.DataBind();
            try
            {
                // 06/09/2006 Paul.  Remove data binding in the user controls.  Binding is required, but only do so in the ASPX pages.
                //Page.DataBind();
                gID = Sql.ToGuid(Request["ID"]);
                if (bMyAccount)
                {
                    gID = Security.USER_ID;
                }
                // 07/12/2006 Paul.  Status can only be edited by an administrator.
                lstSTATUS.Enabled = false;
                // 12/06/2005 Paul.  A user can only edit his own user name if Windows Authentication is off.
                if (Security.IS_ADMIN)
                {
                    // 12/06/2005 Paul.  An administrator can always edit the user name.  This is to allow him to pre-add any NTLM users.
                    txtUSER_NAME.Enabled = true;
                    lstSTATUS.Enabled    = true;
                }
                else if (gID == Security.USER_ID)
                {
                    // 12/06/2005 Paul.  If editing yourself, then you can only edit if not NTLM.
                    // txtUSER_NAME.Enabled = !Security.IsWindowsAuthentication();
                    // 11/26/2006 Paul.  A user cannot edit their own user name. This is a job for the admin.
                    txtUSER_NAME.Enabled = false;
                }
                else
                {
                    // 12/06/2005 Paul.  If not an administrator and not editing yourself, then the name cannot be edited.
                    txtUSER_NAME.Enabled = false;
                }

                if (!IsPostBack)
                {
                    // 'date_formats' => array('Y-m-d'=>'2006-12-23', 'm-d-Y'=>'12-23-2006', 'Y/m/d'=>'2006/12/23', 'm/d/Y'=>'12/23/2006')
                    // 'time_formats' => array('H:i'=>'23:00', 'h:ia'=>'11:00pm', 'h:iA'=>'11:00PM', 'H.i'=>'23.00', 'h.ia'=>'11.00pm', 'h.iA'=>'11.00PM' )
                    lstSTATUS.DataSource = SplendidCache.List("user_status_dom");
                    lstSTATUS.DataBind();
                    // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.
                    //lstREMINDER_TIME  .DataSource = SplendidCache.List("reminder_time_dom");
                    //lstREMINDER_TIME  .DataBind();
                    lstTIMEZONE.DataSource = SplendidCache.TimezonesListbox();
                    lstTIMEZONE.DataBind();
                    lstCURRENCY.DataSource = SplendidCache.Currencies();
                    lstCURRENCY.DataBind();
                    // 05/09/2006 Paul.  We need to always initialize the separators, just in case the user is new.
                    txtGROUP_SEPARATOR.Text   = SplendidDefaults.GroupSeparator();
                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();

                    lstLANGUAGE.DataSource = SplendidCache.Languages();
                    lstLANGUAGE.DataBind();
                    lstLANGUAGE_Changed(null, null);
                    lstTHEME.DataSource = SplendidCache.Themes();
                    lstTHEME.DataBind();

                    Guid gDuplicateID = Sql.ToGuid(Request["DuplicateID"]);
                    if (!Sql.IsEmptyGuid(gID) || !Sql.IsEmptyGuid(gDuplicateID))
                    {
                        DbProviderFactory dbf = DbProviderFactories.GetFactory();
                        using (IDbConnection con = dbf.CreateConnection())
                        {
                            string sSQL;
                            sSQL = "select *           " + ControlChars.CrLf
                                   + "  from vwUSERS_Edit" + ControlChars.CrLf
                                   + " where ID = @ID    " + ControlChars.CrLf;
                            using (IDbCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandText = sSQL;
                                if (!Sql.IsEmptyGuid(gDuplicateID))
                                {
                                    Sql.AddParameter(cmd, "@ID", gDuplicateID);
                                    gID = Guid.Empty;
                                }
                                else
                                {
                                    Sql.AddParameter(cmd, "@ID", gID);
                                }
                                con.Open();

                                if (bDebug)
                                {
                                    RegisterClientScriptBlock("SQLCode", Sql.ClientScriptBlock(cmd));
                                }

                                using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                                {
                                    if (rdr.Read())
                                    {
                                        ctlModuleHeader.Title = Sql.ToString(rdr["FULL_NAME"]);
                                        SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title + " (" + Sql.ToString(rdr["USER_NAME"]) + ")");
                                        Utils.UpdateTracker(Page, m_sMODULE, gID, ctlModuleHeader.Title);
                                        ViewState["ctlModuleHeader.Title"] = ctlModuleHeader.Title;

                                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, rdr);
                                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, rdr);
                                        // 08/05/2006 Paul.  Use the dynamic grid to create the fields, but populate manually.
                                        this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null);
                                        // 01/20/2008 Paul.  The mail options panel is manually populated.
                                        new DynamicControl(this, "EMAIL1").Text = Sql.ToString(rdr["EMAIL1"]);
                                        new DynamicControl(this, "EMAIL2").Text = Sql.ToString(rdr["EMAIL2"]);

                                        // main
                                        txtUSER_NAME.Text  = Sql.ToString(rdr["USER_NAME"]);
                                        txtFIRST_NAME.Text = Sql.ToString(rdr["FIRST_NAME"]);
                                        txtLAST_NAME.Text  = Sql.ToString(rdr["LAST_NAME"]);
                                        // user_settings
                                        chkIS_ADMIN.Checked              = Sql.ToBoolean(rdr["IS_ADMIN"]);
                                        chkPORTAL_ONLY.Checked           = Sql.ToBoolean(rdr["PORTAL_ONLY"]);
                                        chkRECEIVE_NOTIFICATIONS.Checked = Sql.ToBoolean(rdr["RECEIVE_NOTIFICATIONS"]);
                                        // 12/04/2005 Paul.  Only allow the admin flag to be changed if the current user is an admin.
                                        chkIS_ADMIN.Enabled = Security.IS_ADMIN;
                                        // 12/04/2005 Paul.  Save admin flag in ViewState to prevent hacking.
                                        ViewState["IS_ADMIN"] = Sql.ToBoolean(rdr["IS_ADMIN"]);

                                        try
                                        {
                                            lstSTATUS.SelectedValue = Sql.ToString(rdr["STATUS"]);
                                        }
                                        catch (Exception ex)
                                        {
                                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                        }

                                        string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]);
                                        if (!Sql.IsEmptyString(sUSER_PREFERENCES))
                                        {
                                            XmlDocument xml = SplendidInit.InitUserPreferences(sUSER_PREFERENCES);
                                            try
                                            {
                                                ViewState["USER_PREFERENCES"] = xml.OuterXml;
                                                // user_settings
                                                chkGRIDLINE.Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "gridline"));
                                                try
                                                {
                                                    lstLANGUAGE.SelectedValue = L10N.NormalizeCulture(XmlUtil.SelectSingleNode(xml, "culture"));
                                                    lstLANGUAGE_Changed(null, null);
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstLANGUAGE.SelectedValue = XmlUtil.SelectSingleNode(xml, "theme");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstDATE_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "dateformat");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstTIME_FORMAT.SelectedValue = XmlUtil.SelectSingleNode(xml, "timeformat");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstTIMEZONE.SelectedValue = XmlUtil.SelectSingleNode(xml, "timezone");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }
                                                try
                                                {
                                                    lstCURRENCY.SelectedValue = XmlUtil.SelectSingleNode(xml, "currency_id");
                                                }
                                                catch (Exception ex)
                                                {
                                                    SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                }

                                                // mail_options
                                                new DynamicControl(this, "MAIL_FROMNAME").Text        = XmlUtil.SelectSingleNode(xml, "mail_fromname");
                                                new DynamicControl(this, "MAIL_FROMADDRESS").Text     = XmlUtil.SelectSingleNode(xml, "mail_fromaddress");
                                                new DynamicControl(this, "MAIL_SENDTYPE").Text        = XmlUtil.SelectSingleNode(xml, "mail_sendtype");
                                                new DynamicControl(this, "MAIL_SMTPSERVER").Text      = XmlUtil.SelectSingleNode(xml, "mail_smtpserver");
                                                new DynamicControl(this, "MAIL_SMTPPORT").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpport");
                                                new DynamicControl(this, "MAIL_SMTPAUTH_REQ").Checked = Sql.ToBoolean(XmlUtil.SelectSingleNode(xml, "mail_smtpauth_req"));
                                                new DynamicControl(this, "MAIL_SMTPUSER").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtpuser");
                                                new DynamicControl(this, "MAIL_SMTPPASS").Text        = XmlUtil.SelectSingleNode(xml, "mail_smtppass");

                                                ViewState["mail_smtppass"] = XmlUtil.SelectSingleNode(xml, "mail_smtppass");
                                                // 08/06/2005 Paul.  Never return password to user.
                                                TextBox txtMAIL_SMTPPASS = FindControl("MAIL_SMTPPASS") as TextBox;
                                                if (txtMAIL_SMTPPASS != null)
                                                {
                                                    if (!Sql.IsEmptyString(txtMAIL_SMTPPASS.Text))
                                                    {
                                                        txtMAIL_SMTPPASS.Text = sEMPTY_PASSWORD;
                                                    }
                                                }

                                                // 05/09/2006 Paul.  Initialize the numeric separators.
                                                txtGROUP_SEPARATOR.Text   = XmlUtil.SelectSingleNode(xml, "num_grp_sep");
                                                txtDECIMAL_SEPARATOR.Text = XmlUtil.SelectSingleNode(xml, "dec_sep");
                                                // 05/09/2006 Paul.  Check for empty strings as the user may have legacy data.
                                                if (Sql.IsEmptyString(txtGROUP_SEPARATOR.Text))
                                                {
                                                    txtGROUP_SEPARATOR.Text = SplendidDefaults.GroupSeparator();
                                                }
                                                if (Sql.IsEmptyString(txtDECIMAL_SEPARATOR.Text))
                                                {
                                                    txtDECIMAL_SEPARATOR.Text = SplendidDefaults.DecimalSeparator();
                                                }

                                                // freebusy
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Calendar Publish Key is not supported at this time.
                                                //txtCALENDAR_PUBLISH_KEY .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_key" );
                                                //txtCALENDAR_PUBLISH_URL .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_publish_url" );
                                                //txtCALENDAR_SEARCH_URL  .Text    =               XmlUtil.SelectSingleNode(xml, "calendar_search_url"  );
                                                // 08/05/2006 Paul.  Remove stub of unsupported code. Reminder is not supported at this time.

                                                /*
                                                 * try
                                                 * {
                                                 *      int nREMINDER_TIME = Sql.ToInteger(XmlUtil.SelectSingleNode(xml, "reminder_time"));
                                                 *      if ( nREMINDER_TIME > 0 )
                                                 *      {
                                                 *              lstREMINDER_TIME.SelectedValue = nREMINDER_TIME.ToString();
                                                 *              chkSHOULD_REMIND.Checked = true;
                                                 *      }
                                                 * }
                                                 * catch(Exception ex)
                                                 * {
                                                 *      SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                                                 * }
                                                 */
                                            }
                                            catch (Exception ex)
                                            {
                                                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                    else
                    {
                        this.AppendEditViewFields(m_sMODULE + ".EditView", tblMain, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditAddress", tblAddress, null);
                        this.AppendEditViewFields(m_sMODULE + ".EditMailOptions", tblMailOptions, null);

                        try
                        {
                            lstTHEME.SelectedValue = SplendidDefaults.Theme();
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                        }
                        try
                        {
                            string sDefaultLanguage = Sql.ToString(Request.ServerVariables["HTTP_ACCEPT_LANGUAGE"]);
                            if (Sql.IsEmptyString(sDefaultLanguage))
                            {
                                sDefaultLanguage = "en-US";
                            }
                            lstLANGUAGE.SelectedValue = sDefaultLanguage;
                        }
                        catch (Exception ex)
                        {
                            SplendidError.SystemWarning(new StackTrace(true).GetFrame(0), ex);
                        }
                        lstLANGUAGE_Changed(null, null);
                    }
                }
                else
                {
                    // 12/02/2005 Paul.  When validation fails, the header title does not retain its value.  Update manually.
                    ctlModuleHeader.Title = Sql.ToString(ViewState["ctlModuleHeader.Title"]);
                    SetPageTitle(L10n.Term(".moduleList." + m_sMODULE) + " - " + ctlModuleHeader.Title);
                }
            }
            catch (Exception ex)
            {
                SplendidError.SystemError(new StackTrace(true).GetFrame(0), ex);
                ctlEditButtons.ErrorText = ex.Message;
            }
        }
        public static void LoadUserPreferences(Guid gID, string sTheme, string sCulture)
        {
            HttpApplicationState Application = HttpContext.Current.Application;
            HttpSessionState     Session     = HttpContext.Current.Session;
            string sApplicationPath          = Sql.ToString(Application["rootURL"]);

            DbProviderFactory dbf = DbProviderFactories.GetFactory();

            using (IDbConnection con = dbf.CreateConnection())
            {
                string sSQL;
                sSQL = "select *           " + ControlChars.CrLf
                       + "  from vwUSERS_Edit" + ControlChars.CrLf
                       + " where ID = @ID    " + ControlChars.CrLf;
                using (IDbCommand cmd = con.CreateCommand())
                {
                    cmd.CommandText = sSQL;
                    Sql.AddParameter(cmd, "@ID", gID);
                    con.Open();
                    using (IDataReader rdr = cmd.ExecuteReader(CommandBehavior.SingleRow))
                    {
                        if (rdr.Read())
                        {
                            string sUSER_PREFERENCES = Sql.ToString(rdr["USER_PREFERENCES"]);
                            if (!Sql.IsEmptyString(sUSER_PREFERENCES))
                            {
                                XmlDocument xml = InitUserPreferences(sUSER_PREFERENCES);
                                Session["USER_PREFERENCES"] = xml.OuterXml;
                                // 11/19/2005 Paul.  Not sure why the login screen has the language, but it would seem to allow overriding the default.
                                if (Sql.IsEmptyString(sCulture))
                                {
                                    sCulture = XmlUtil.SelectSingleNode(xml, "culture").Replace("_", "-");
                                }
                                // 11/22/2005 Paul.  The theme can be overridden as well.
                                if (Sql.IsEmptyString(sTheme))
                                {
                                    sTheme = XmlUtil.SelectSingleNode(xml, "theme").Replace("_", "-");
                                }
                                Session["USER_SETTINGS/CULTURE"] = sCulture;
                                Session["USER_SETTINGS/THEME"]   = sTheme;
                                Session["themeURL"] = sApplicationPath + "Themes/" + sTheme + "/";
                                Session["USER_SETTINGS/DATEFORMAT"] = XmlUtil.SelectSingleNode(xml, "dateformat");
                                Session["USER_SETTINGS/TIMEFORMAT"] = XmlUtil.SelectSingleNode(xml, "timeformat");
                                // 01/21/2006 Paul.  It is useful to have quick access to email address.
                                Session["USER_SETTINGS/MAIL_FROMNAME"]    = XmlUtil.SelectSingleNode(xml, "mail_fromname");
                                Session["USER_SETTINGS/MAIL_FROMADDRESS"] = XmlUtil.SelectSingleNode(xml, "mail_fromaddress");
                                // 05/09/2006 Paul.  Initialize the numeric separators.
                                Session["USER_SETTINGS/GROUP_SEPARATOR"]   = XmlUtil.SelectSingleNode(xml, "num_grp_sep");
                                Session["USER_SETTINGS/DECIMAL_SEPARATOR"] = XmlUtil.SelectSingleNode(xml, "dec_sep");
                                try
                                {
                                    Session["USER_SETTINGS/TIMEZONE"] = Sql.ToGuid(XmlUtil.SelectSingleNode(xml, "timezone")).ToString();
                                }
                                catch
                                {
                                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), "Invalid USER_SETTINGS/TIMEZONE: " + XmlUtil.SelectSingleNode(xml, "timezone"));
                                }
                                try
                                {
                                    Session["USER_SETTINGS/CURRENCY"] = XmlUtil.SelectSingleNode(xml, "currency_id");
                                }
                                catch
                                {
                                    SplendidError.SystemError(new StackTrace(true).GetFrame(0), "Invalid USER_SETTINGS/CURRENCY: " + XmlUtil.SelectSingleNode(xml, "currency_id"));
                                }

                                DataView vwCurrencies = new DataView(SplendidCache.Currencies());
                                vwCurrencies.RowFilter = "ID = '" + XmlUtil.SelectSingleNode(xml, "currency_id") + "'";
                                if (vwCurrencies.Count > 0)
                                {
                                    Session["USER_SETTINGS/CURRENCY_SYMBOL"] = Sql.ToString(vwCurrencies[0]["SYMBOL"]);
                                }
                            }
                        }
                    }
                }
                // 11/21/2005 Paul.  New users may not have any settings, so we need to initialize the defaults.
                // It is best to do it here rather than wrap the variables in a function that would return the default if null.
                sCulture = Sql.ToString(Session["USER_SETTINGS/CULTURE"]);
                sTheme   = Sql.ToString(Session["USER_SETTINGS/THEME"]);
                string sDateFormat = Sql.ToString(Session["USER_SETTINGS/DATEFORMAT"]);
                string sTimeFormat = Sql.ToString(Session["USER_SETTINGS/TIMEFORMAT"]);
                string sTimeZone   = Sql.ToString(Session["USER_SETTINGS/TIMEZONE"]);
                string sCurrencyID = Sql.ToString(Session["USER_SETTINGS/CURRENCY"]);
                if (Sql.IsEmptyString(sCulture))
                {
                    Session["USER_SETTINGS/CULTURE"] = SplendidDefaults.Culture();
                }
                if (Sql.IsEmptyString(sTheme))
                {
                    sTheme = SplendidDefaults.Theme();
                    Session["USER_SETTINGS/THEME"] = sTheme;
                    Session["themeURL"]            = sApplicationPath + "Themes/" + sTheme + "/";
                }
                if (Sql.IsEmptyString(sDateFormat))
                {
                    Session["USER_SETTINGS/DATEFORMAT"] = SplendidDefaults.DateFormat();
                }
                // 11/12/2005 Paul.  "m" is not valid for .NET month formatting.  Must use MM.
                // 11/12/2005 Paul.  Require 4 digit year.  Otherwise default date in Pipeline of 12/31/2100 would get converted to 12/31/00.
                if (SplendidDefaults.IsValidDateFormat(sDateFormat))
                {
                    Session["USER_SETTINGS/DATEFORMAT"] = SplendidDefaults.DateFormat(sDateFormat);
                }
                if (Sql.IsEmptyString(sTimeFormat))
                {
                    Session["USER_SETTINGS/TIMEFORMAT"] = SplendidDefaults.TimeFormat();
                }
                if (Sql.IsEmptyString(sCurrencyID))
                {
                    Session["USER_SETTINGS/CURRENCY"] = SplendidDefaults.CurrencyID();
                }
                if (Sql.IsEmptyString(sTimeZone))
                {
                    Session["USER_SETTINGS/TIMEZONE"] = SplendidDefaults.TimeZone();
                }

                // 05/09/2006 Paul.  Use defaults when necessary.
                string sGROUP_SEPARATOR   = Sql.ToString(Session["USER_SETTINGS/GROUP_SEPARATOR"]);
                string sDECIMAL_SEPARATOR = Sql.ToString(Session["USER_SETTINGS/DECIMAL_SEPARATOR"]);
                if (Sql.IsEmptyString(sGROUP_SEPARATOR))
                {
                    Session["USER_SETTINGS/GROUP_SEPARATOR"] = SplendidDefaults.GroupSeparator();
                }
                if (Sql.IsEmptyString(sDECIMAL_SEPARATOR))
                {
                    Session["USER_SETTINGS/DECIMAL_SEPARATOR"] = SplendidDefaults.DecimalSeparator();
                }
            }
        }