Esempio n. 1
0
        //*******************************************************
        //
        // The Page_Load event handler on this User Control is used to
        // obtain a DataReader of contact information from the Contacts
        // table, and then databind the results to a DataGrid
        // server control.  It uses the ASPNET.StarterKit.Portal.ContactsDB()
        // data component to encapsulate all data functionality.
        //
        //*******************************************************

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Obtain contact information from Contacts table
            // and bind to the DataGrid Control
            ASPNET.StarterKit.Portal.ContactsDB contacts = new ASPNET.StarterKit.Portal.ContactsDB();

            myDataGrid.DataSource = contacts.GetContacts(ModuleId);
            myDataGrid.DataBind();
        }
Esempio n. 2
0
        //****************************************************************
        //
        // The Page_Load event on this Page is used to obtain the ModuleId
        // and ItemId of the contact to edit.
        //
        // It then uses the ASPNET.StarterKit.Portal.ContactsDB() data component
        // to populate the page's edit controls with the contact details.
        //
        //****************************************************************

        private void Page_Load(object sender, System.EventArgs e)
        {
            // Determine ModuleId of Contacts Portal Module
            moduleId = Int32.Parse(Request.Params["Mid"]);

            // Verify that the current user has access to edit this module
            if (PortalSecurity.HasEditPermissions(moduleId) == false)
            {
                Response.Redirect("~/Admin/EditAccessDenied.aspx");
            }

            // Determine ItemId of Contacts to Update
            if (Request.Params["ItemId"] != null)
            {
                itemId = Int32.Parse(Request.Params["ItemId"]);
            }

            // If the page is being requested the first time, determine if an
            // contact itemId value is specified, and if so populate page
            // contents with the contact details

            if (Page.IsPostBack == false)
            {
                if (itemId != 0)
                {
                    // Obtain a single row of contact information
                    ASPNET.StarterKit.Portal.ContactsDB contacts = new ASPNET.StarterKit.Portal.ContactsDB();
                    SqlDataReader dr = contacts.GetSingleContact(itemId);

                    // Read first row from database
                    dr.Read();

                    // Security check.  verify that itemid is within the module.
                    int dbModuleID = Convert.ToInt32(dr["ModuleID"]);
                    if (dbModuleID != moduleId)
                    {
                        dr.Close();
                        Response.Redirect("~/Admin/EditAccessDenied.aspx");
                    }

                    NameField.Text     = (String)dr["Name"];
                    RoleField.Text     = (String)dr["Role"];
                    EmailField.Text    = (String)dr["Email"];
                    Contact1Field.Text = (String)dr["Contact1"];
                    Contact2Field.Text = (String)dr["Contact2"];
                    CreatedBy.Text     = (String)dr["CreatedByUser"];
                    CreatedDate.Text   = ((DateTime)dr["CreatedDate"]).ToShortDateString();

                    // Close datareader
                    dr.Close();
                }

                // Store URL Referrer to return to portal
                ViewState["UrlReferrer"] = Request.UrlReferrer.ToString();
            }
        }
Esempio n. 3
0
        //****************************************************************
        //
        // The DeleteBtn_Click event handler on this Page is used to delete an
        // a contact.  It  uses the ASPNET.StarterKit.Portal.ContactsDB()
        // data component to encapsulate all data functionality.
        //
        //****************************************************************

        private void DeleteBtn_Click(Object sender, EventArgs e)
        {
            // Only attempt to delete the item if it is an existing item
            // (new items will have "ItemId" of 0)

            if (itemId != 0)
            {
                ASPNET.StarterKit.Portal.ContactsDB contacts = new ASPNET.StarterKit.Portal.ContactsDB();
                contacts.DeleteContact(itemId);
            }

            // Redirect back to the portal home page
            Response.Redirect((String)ViewState["UrlReferrer"]);
        }
Esempio n. 4
0
        //****************************************************************
        //
        // The UpdateBtn_Click event handler on this Page is used to either
        // create or update a contact.  It  uses the ASPNET.StarterKit.Portal.ContactsDB()
        // data component to encapsulate all data functionality.
        //
        //****************************************************************

        private void UpdateBtn_Click(Object sender, EventArgs e)
        {
            // Only Update if Entered data is Valid
            if (Page.IsValid == true)
            {
                // Create an instance of the ContactsDB component
                ASPNET.StarterKit.Portal.ContactsDB contacts = new ASPNET.StarterKit.Portal.ContactsDB();

                if (itemId == 0)
                {
                    // Add the contact within the contacts table
                    contacts.AddContact(moduleId, itemId, Context.User.Identity.Name, NameField.Text, RoleField.Text, EmailField.Text, Contact1Field.Text, Contact2Field.Text);
                }
                else
                {
                    // Update the contact within the contacts table
                    contacts.UpdateContact(moduleId, itemId, Context.User.Identity.Name, NameField.Text, RoleField.Text, EmailField.Text, Contact1Field.Text, Contact2Field.Text);
                }

                // Redirect back to the portal home page
                Response.Redirect((String)ViewState["UrlReferrer"]);
            }
        }