Esempio n. 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string groupName = SqlDatabases.GetDatabasesGroupName(Settings);

            itemsList.GroupName = groupName;
            itemsList.QuotaName = groupName + ".Users";
        }
        private void BindUsers(int packageId)
        {
            SqlUser[] users = ES.Services.DatabaseServers.GetSqlUsers(packageId,
                                                                      SqlDatabases.GetDatabasesGroupName(Settings), false);

            dlUsers.DataSource = users;
            dlUsers.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            string groupName = SqlDatabases.GetDatabasesGroupName(Settings);

            itemsList.GroupName = groupName;
            itemsList.QuotaName = groupName + ".Databases";

            if (!IsPostBack && ES.Services.DatabaseServers.GetDatabaseBrowserConfiguration(PanelSecurity.PackageId, groupName).Enabled)
            {
                itemsList.ViewLinkText = "BrowseDatabase";
            }
        }
Esempio n. 4
0
        private void BindItem()
        {
            string policyName = (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mssql"))
                ? UserSettings.MSSQL_POLICY : UserSettings.MYSQL_POLICY;

            try
            {
                if (!IsPostBack)
                {
                    // load item if required
                    if (PanelRequest.ItemID > 0)
                    {
                        // existing item
                        try
                        {
                            item = ES.Services.DatabaseServers.GetSqlUser(PanelRequest.ItemID);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessage("SQL_GET_USER", ex);
                            return;
                        }

                        if (item != null)
                        {
                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                            usernameControl.SetPackagePolicy(item.PackageId, policyName, "UserNamePolicy");
                            passwordControl.SetPackagePolicy(item.PackageId, policyName, "UserPasswordPolicy");
                            BindDatabases(item.PackageId);
                        }
                        else
                        {
                            RedirectToBrowsePage();
                        }
                    }
                    else
                    {
                        // new item
                        ViewState["PackageId"] = PanelSecurity.PackageId;
                        usernameControl.SetPackagePolicy(PanelSecurity.PackageId, policyName, "UserNamePolicy");
                        passwordControl.SetPackagePolicy(PanelSecurity.PackageId, policyName, "UserPasswordPolicy");
                        BindDatabases(PanelSecurity.PackageId);
                    }
                }

                // load provider control
                LoadProviderControl((int)ViewState["PackageId"], SqlDatabases.GetDatabasesGroupName(Settings),
                                    providerControl, "EditUser.ascx");

                IDatabaseEditUserControl ctrl = (IDatabaseEditUserControl)providerControl.Controls[0];
                ctrl.InitControl(SqlDatabases.GetDatabasesGroupName(Settings));

                if (!IsPostBack)
                {
                    // bind item to controls
                    if (item != null)
                    {
                        // bind item to controls
                        usernameControl.Text     = item.Name;
                        usernameControl.EditMode = true;
                        passwordControl.EditMode = true;

                        foreach (string database in item.Databases)
                        {
                            foreach (ListItem li in dlDatabases.Items)
                            {
                                if (String.Compare(database, li.Value, true) == 0)
                                {
                                    li.Selected = true;
                                    break;
                                }
                            }
                        }

                        // other controls
                        ctrl.BindItem(item);
                    }
                }
            }
            catch
            {
                ShowWarningMessage("INIT_SERVICE_ITEM_FORM");
                DisableFormControls(this, btnCancel);
                return;
            }
        }
Esempio n. 5
0
        private void BindDatabases(int packageId)
        {
            try
            {
                SqlDatabase[] databases = ES.Services.DatabaseServers.GetSqlDatabases(packageId,
                                                                                      SqlDatabases.GetDatabasesGroupName(Settings), false);

                dlDatabases.DataSource = databases;
                dlDatabases.DataBind();
            }
            catch (Exception ex)
            {
                ShowErrorMessage("SQL_GET_DATABASE", ex);
                return;
            }
        }
Esempio n. 6
0
        private void SaveItem()
        {
            if (!Page.IsValid)
            {
                return;
            }

            // get form data
            SqlUser item = new SqlUser();

            item.Id        = PanelRequest.ItemID;
            item.PackageId = PanelSecurity.PackageId;
            item.Name      = usernameControl.Text;
            item.Password  = passwordControl.Password;

            List <string> databases = new List <string>();

            foreach (ListItem li in dlDatabases.Items)
            {
                if (li.Selected)
                {
                    databases.Add(li.Value);
                }
            }
            item.Databases = databases.ToArray();

            // get other props
            IDatabaseEditUserControl ctrl = (IDatabaseEditUserControl)providerControl.Controls[0];

            ctrl.SaveItem(item);

            if (PanelRequest.ItemID == 0)
            {
                // new item
                try
                {
                    int result = ES.Services.DatabaseServers.AddSqlUser(item, SqlDatabases.GetDatabasesGroupName(Settings));
                    // Show an error message if the operation has failed to complete
                    if (result < 0)
                    {
                        ShowResultMessageWithContactForm(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SQL_ADD_USER", ex);
                    return;
                }
            }
            else
            {
                // existing item
                try
                {
                    int result = ES.Services.DatabaseServers.UpdateSqlUser(item);
                    // Show an error message if the operation has failed to complete
                    if (result < 0)
                    {
                        ShowResultMessageWithContactForm(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SQL_UPDATE_USER", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
        private void BindItem()
        {
            string policyName = (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mssql"))
                ? UserSettings.MSSQL_POLICY : UserSettings.MYSQL_POLICY;

            try
            {
                if (!IsPostBack)
                {
                    // load item if required
                    if (PanelRequest.ItemID > 0)
                    {
                        // existing item
                        try
                        {
                            item = ES.Services.DatabaseServers.GetSqlDatabase(PanelRequest.ItemID);
                        }
                        catch (Exception ex)
                        {
                            ShowErrorMessage("SQL_GET_DATABASE", ex);
                            return;
                        }

                        if (item != null)
                        {
                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                            usernameControl.SetPackagePolicy(item.PackageId, policyName, "DatabaseNamePolicy");
                            BindUsers(item.PackageId);
                        }
                        else
                        {
                            RedirectToBrowsePage();
                        }
                    }
                    else
                    {
                        // new item
                        ViewState["PackageId"] = PanelSecurity.PackageId;
                        usernameControl.SetPackagePolicy(PanelSecurity.PackageId, policyName, "DatabaseNamePolicy");
                        BindUsers(PanelSecurity.PackageId);
                    }
                }

                // load provider control
                LoadProviderControl((int)ViewState["PackageId"], SqlDatabases.GetDatabasesGroupName(Settings),
                                    providerControl, "EditDatabase.ascx");

                if (!IsPostBack)
                {
                    // bind item to controls
                    if (item != null)
                    {
                        // bind item to controls
                        usernameControl.Text     = item.Name;
                        usernameControl.EditMode = true;

                        foreach (string user in item.Users)
                        {
                            ListItem li = dlUsers.Items.FindByValue(user);
                            if (li != null)
                            {
                                li.Selected = true;
                            }
                        }

                        // other controls
                        IDatabaseEditDatabaseControl ctrl = (IDatabaseEditDatabaseControl)providerControl.Controls[0];
                        ctrl.BindItem(item);
                    }
                }
            }
            catch (Exception ex)
            {
                ShowErrorMessage("INIT_SERVICE_ITEM_FORM", ex);
                DisableFormControls(this, btnCancel);
                return;
            }
        }