/// <summary>
        /// Gets triggered when the user clicks on delete button
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void grdWebsites_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            try
            {
                //Get the list of websites
                List<Website> websites = (List<Website>)Session["Websites"];
                Website websiteToDelete = null;
                DBUtility dbUtility = new DBUtility();
                String dbName = Configurations.DatabaseName;
                String tableName = Configurations.Websites;

                //Get the website which has to be deleted
                websiteToDelete = websites[e.RowIndex];

                if (!dbUtility.Delete(dbName, tableName, websiteToDelete))
                    throw new Exception("Error while deleting");

                //Bind the data again
                BindData();
            }
            catch (Exception ex)
            {
                DisplayMessage("Unable to delete the website");
                Logger.Log("grdWebsites_RowDeleting: " + ex.Message);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Binds the data to UI
        /// </summary>
        private void BindData()
        {
            try
            {
                //Declarations
                DBUtility dbUtility = new DBUtility();
                Person person;
                String[] phone;
                String tableName, dataBaseName;

                //Get the table name and datatbase name from the configuration file
                tableName = Configurations.TableName;
                dataBaseName = Configurations.DatabaseName;

                drpMonth.CssClass = "input-success";

                //Bind the days
                drpDay.DataSource = Utility.GetTableData(1, 31);
                drpDay.DataBind();
                drpDay.CssClass = "input-success";

                //Bind the years
                drpYear.DataSource = Utility.GetTableData(1900, 1996);
                drpYear.DataBind();
                drpYear.CssClass = "input-success";

                //Get the person data
                person = dbUtility.getData(dataBaseName, tableName, lblName.Text);

                //Check if the person has a data or it has been configured not to display the PII
                if (person == null || !Configurations.DisplayPII)
                    return;

                //Set the birth dates
                drpMonth.SelectedValue = person.MonthOfBirth;
                drpMonth.CssClass = "input-success";
                drpDay.SelectedValue = person.DayOfBirth;
                drpDay.CssClass = "input-success";
                drpYear.SelectedValue = person.YearOfBirth;
                drpYear.CssClass = "input-success";

                //Bind the personal information
                txtName.Text = person.FullName;
                txtName.CssClass = "input-success";
                txtCity.Text = person.City;
                txtCity.CssClass = "input-success";
                txtEmail.Text = person.EmailAddress;
                txtEmail.CssClass = "input-success";
                txtSpouse.Text = person.SpouseName;
                txtSpouse.CssClass = "input-success";
                txtState.Text = person.State;
                txtState.CssClass = "input-success";
                txtStreet.Text = person.StreetAddress;
                txtStreet.CssClass = "input-success";
                txtZip.Text = person.Zip;
                txtZip.CssClass = "input-success";

                txtCurrentEmployer.Text = Utility.AppendWithComma(person.CurrentEmployers);
                txtCurrentEmployer.CssClass = "input-success";
                txtPastEmployer.Text = Utility.AppendWithComma(person.PastEmployers);
                txtPastEmployer.CssClass = "input-success";
                txtChildren.Text = Utility.AppendWithComma(person.Children);
                txtChildren.CssClass = "input-success";
                txtGrandChildren.Text = Utility.AppendWithComma(person.GrandChildren);
                txtGrandChildren.CssClass = "input-success";

                //Populate the phone
                phone = person.PhoneNumber.Split(new Char[] { '-' });
                txtPhone1.Text = phone[0];
                txtPhone1.CssClass = "input-success";
                txtPhone2.Text = phone[1];
                txtPhone2.CssClass = "input-success";
                txtPhone3.Text = phone[2];
                txtPhone3.CssClass = "input-success";

                lblUpdatedOn.Text = "Last updated on: " + person.LastUpdatedOn ;
            }
            catch (Exception ex)
            {
                Logger.Log("BindData: " + ex.Message);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Persists the user PII data to the database
        /// </summary>
        private void PersistData()
        {
            try
            {
                Person person;
                Char[] splitter = new Char[] { ',' };
                String tableName, dataBaseName;

                //Get the table name and datatbase name from the configuration file
                tableName = Configurations.TableName;
                dataBaseName = Configurations.DatabaseName;

                //Check if the data is valid
                if (!ValidateData())
                    return;

                person = new Person
                {
                    Volunteer = lblName.Text.Trim(),
                    Children = txtChildren.Text.Trim().Split(splitter),
                    GrandChildren = txtGrandChildren.Text.Trim().Split(splitter),
                    City = txtCity.Text,
                    CurrentEmployers = txtCurrentEmployer.Text.Trim().Split(splitter),
                    MonthOfBirth = drpMonth.SelectedValue,
                    DayOfBirth = drpDay.SelectedValue,
                    YearOfBirth = drpYear.SelectedValue,
                    EmailAddress = txtEmail.Text.Trim(),
                    FullName = txtName.Text.Trim(),
                    PastEmployers = txtPastEmployer.Text.Trim().Split(splitter),
                    PhoneNumber = txtPhone1.Text.Trim() + "-" + txtPhone2.Text.Trim() + "-" + txtPhone3.Text.Trim(),
                    SpouseName = txtSpouse.Text.Trim(),
                    State = txtState.Text.Trim(),
                    StreetAddress = txtStreet.Text.Trim(),
                    Zip = txtZip.Text.Trim(),
                    LastUpdatedOn = DateTime.Now.ToShortDateString()
                };

                //Insert the data to database
                DBUtility dbUtility = new DBUtility();
                dbUtility.UpdateData(dataBaseName, tableName, person);

                DisplayMessage("Successfully updated your data");
            }
            catch (Exception ex)
            {
                DisplayMessage("Unable to update your data");
                Logger.Log("PersistData: " + ex.Message);
            }
        }
        /// <summary>
        /// Binds the data to the grid view
        /// </summary>
        private void BindData()
        {
            try
            {
                //Declarations
                DBUtility dbUtility = new DBUtility();
                String dbName = Configurations.DatabaseName;
                String tableName = Configurations.Websites;
                List<Website> websites;

                //Bind the grid view
                grdWebsites.DataSource = dbUtility.getData(dbName, tableName, out websites);
                grdWebsites.DataBind();

                //Add the list to session
                Session.Add("Websites", websites ?? new List<Website>());
            }
            catch (Exception ex)
            {
                Logger.Log("BindData: " + ex.Message);
            }
        }
        /// <summary>
        /// Persists the website data to the database
        /// </summary>
        private void PersistData()
        {
            //Declaratoins
            DBUtility dbUtility = new DBUtility();
            String dbName = Configurations.DatabaseName;
            String tableName = Configurations.Websites;

            try
            {
                //Check if the data is valid
                if (!ValidateData())
                    return;

                Website website = new Website();

                website.Name = txtName.Text;
                website.URL = txtURL.Text;
                website.IsActive = true;
                website.LastUpdatedOn = DateTime.Now.ToShortDateString();

                //Update the data
                dbUtility.UpdateData(dbName, tableName, website);

                //Clear the textboxes
                txtName.Text = String.Empty;
                txtURL.Text = String.Empty;
            }
            catch (Exception ex)
            {
                DisplayMessage("Unable to update your data");
                Logger.Log("PersistData: " + ex.Message);
            }
        }