Ejemplo n.º 1
0
    /// <summary>
    /// Takes the user's input in the textboxes and adds a new site using those parameters.
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Contains the event data of the event that triggered the method.</param>
    protected void AddButton_Click(object sender, EventArgs e)
    {
        MessageUserControl.TryRun(() =>
        {
            MessageUserControl.Visible = true;

            // Get the user's inputs from the textboxes.
            string siteName    = AddSiteNameTextBox.Text;
            string description = AddDescriptionTextBox.Text;
            string passcode    = AddPasscodeTextBox.Text;

            // Special character validation.
            Utility utility = new Utility();
            utility.checkValidString(siteName);
            utility.checkValidString(description);
            utility.checkValidString(passcode);

            // Adds the new site to the database.
            SiteController sysmgr = new SiteController();
            sysmgr.Site_Add(siteName, description, passcode);

            // Clears the textboxes when a site is successfully added.
            AddSiteNameTextBox.Text    = "";
            AddDescriptionTextBox.Text = "";
            AddPasscodeTextBox.Text    = "";

            // Resets the default datasource and rebinds all active site lists.
            ActiveSiteListView.DataSourceID = ActiveSiteListODS.ID;
            AddSiteListView.DataBind();
            ActiveSiteListView.DataBind();
        }, "Success", "New site has been added.");
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Handles all the events caused by clicking any button in the ActiveSiteListView.
    /// </summary>
    /// <param name="sender">Contains a reference to the control/object that raised the event.</param>
    /// <param name="e">Contains the event data of the event that triggered the method.</param>
    protected void SiteListView_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        MessageUserControl.Visible = false;
        int siteId = 1;

        // If the cancel button is pressed the CommandArgument will be null so we do not want to try to convert it to string.
        // Otherwise we want to get the siteId of the row the user clicked the button on.
        if (!e.CommandName.Equals("Cancel"))
        {
            siteId = int.Parse(e.CommandArgument.ToString());
        }
        // If the user presses the "Update" button we grab the values they input into the textboxes and then run Site_Update using them as the parameters.
        // Afterwords we must set EditIndex to -1 to deactivate edit mode on the updated field.
        if (e.CommandName.Equals("Change"))
        {
            // Grabs the index of the current item in the listview.
            int i = e.Item.DisplayIndex;

            // Gets the values the user has input into the textboxs and assigns them to a string variable.
            TextBox siteNameBox    = ActiveSiteListView.Items[i].FindControl("SiteNameTextBox") as TextBox;
            string  siteName       = siteNameBox.Text;
            TextBox descriptionBox = ActiveSiteListView.Items[i].FindControl("DescriptionTextBox") as TextBox;
            string  description    = descriptionBox.Text;
            TextBox passcodeBox    = ActiveSiteListView.Items[i].FindControl("PasscodeTextBox") as TextBox;
            string  passcode       = passcodeBox.Text;

            MessageUserControl.TryRun(() =>
            {
                MessageUserControl.Visible = true;

                // Validation for special characters.
                Utility utility = new Utility();
                utility.checkValidString(siteName);
                utility.checkValidString(description);
                utility.checkValidString(passcode);

                // Updates the selected site, turns off the edit mode and rebinds all active site listviews.
                SiteController sysmgr = new SiteController();
                sysmgr.Site_Update(siteId, siteName, description, passcode);
                ActiveSiteListView.DataSourceID = ActiveSiteListODS.ID;
                ActiveSiteListView.EditIndex    = -1;
                ActiveSiteListView.DataBind();
                AddSiteListView.DataBind();

                // Clears the search field and re-enables all the controls that are disabled during edit mode.
                ActiveSearchBox.Text       = "";
                ActiveSearchButton.Enabled = true;
                ActiveClearButton.Enabled  = true;
                DataPager pager            = ActiveSiteListView.FindControl("ActiveDataPager") as DataPager;
                pager.Visible = true;
            }, "Success", "Site has been updated");
        }
        // If the user presses deactivate we simply take the siteId from above and deactivate the site it is attributed to.
        else if (e.CommandName.Equals("Deactivate"))
        {
            MessageUserControl.TryRun(() =>
            {
                MessageUserControl.Visible = true;

                // Deactivates the current site.
                SiteController sysmgr = new SiteController();
                sysmgr.Site_Deactivate(siteId);
            }, "Success", "Site has been deactivated");

            // Rebinds all listviews and resets the ODS' to their defaults rather than the search ODS.
            ActiveSiteListView.DataSourceID      = ActiveSiteListODS.ID;
            DeactivatedSiteListView.DataSourceID = DeactivatedSiteListODS.ID;
            ActiveSiteListView.DataBind();
            AddSiteListView.DataBind();
            DeactivatedSiteListView.DataBind();
        }
    }