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

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

            dlUsers.DataSource = users;
            dlUsers.DataBind();
        }
Esempio n. 3
0
        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 SaveItem()
        {
            if (!Page.IsValid)
            {
                return;
            }

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

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

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

            foreach (ListItem li in dlUsers.Items)
            {
                if (li.Selected)
                {
                    users.Add(li.Value);
                }
            }
            item.Users = users.ToArray();

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

            ctrl.SaveItem(item);

            if (PanelRequest.ItemID == 0)
            {
                // new item
                try
                {
                    int result = ES.Services.DatabaseServers.AddSqlDatabase(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_DATABASE", ex);
                    return;
                }
            }
            else
            {
                // existing item
                try
                {
                    int result = ES.Services.DatabaseServers.UpdateSqlDatabase(item);
                    // Show an error message if the operation has failed to complete
                    if (result < 0)
                    {
                        ShowResultMessageWithContactForm(result);
                        return;
                    }
                }
                catch (Exception ex)
                {
                    ShowErrorMessage("SQL_UPDATE_DATABASE", ex);
                    return;
                }
            }

            // return
            RedirectSpaceHomePage();
        }
Esempio n. 5
0
        private void BindItem()
        {
            var policyName = "";

            if (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mssql"))
            {
                policyName = "MsSqlPolicy";
            }
            else if (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mysql"))
            {
                policyName = "MySqlPolicy";
            }
            else
            {
                policyName = "MariaDBPolicy";
            }

            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)
                        {
                            if (!string.IsNullOrEmpty(item.ExternalServerName))
                            {
                                lblDBExternalServer.Visible = litDBExternalServer.Visible = true;
                                litDBExternalServer.Text    = item.ExternalServerName;
                            }

                            if (!string.IsNullOrEmpty(item.InternalServerName))
                            {
                                lblDBInternalServer.Visible = litDBInternalServer.Visible = true;
                                litDBInternalServer.Text    = item.InternalServerName;
                            }

                            // save package info
                            ViewState["PackageId"] = item.PackageId;
                            usernameControl.SetPackagePolicy(item.PackageId, policyName, "DatabaseNamePolicy");
                            BindUsers(item.PackageId);
                        }
                        else
                        {
                            RedirectToBrowsePage();
                        }
                    }
                    else
                    {
                        lblDBExternalServer.Visible = lblDBInternalServer.Visible = false;
                        litDBExternalServer.Visible = litDBInternalServer.Visible = false;

                        // 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;
            }
        }
Esempio n. 6
0
        private void BindItem()
        {
            var policyName = "";

            if (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mssql"))
            {
                policyName = "MsSqlPolicy";
            }
            else if (SqlDatabases.GetDatabasesGroupName(Settings).ToLower().StartsWith("mysql"))
            {
                policyName = "MySqlPolicy";
            }
            else
            {
                policyName = "MariaDBPolicy";
            }

            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. 7
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;
            }
        }