Beispiel #1
0
        private void EmailsChangesUpdate(cUser Demography)
        {
            List <cEMail> emails = Session["dem_Emails"] as List <cEMail>;

            int userId = (int)Session["UserID"];
            //For each element of the original list perform one of the following:
            //If update, update information
            //If delete, mark record for delete
            //If new, mark record for adding
            cEMail a1 = null;

            if (Demography.UserEmails != null)
            {
                foreach (cEMail a in Demography.UserEmails)                  //state in database
                {
                    a1 = emails.FirstOrDefault(x => x.EMailID == a.EMailID); //If record not found in memory that means it was deleted
                    if (a1 == null)
                    {
                        a.SaveUpdate(userId, true);
                    }
                    else
                    {
                        a1.SaveUpdate(userId);
                    }
                }
            }

            a1 = emails.FirstOrDefault(x => x.EMailID <= 0);
            if (a1 != null && a1.IsValid()) // If new and valid, let push it to the database
            {
                a1.SaveUpdate(userId);
            }
        }
Beispiel #2
0
        protected void gv_Emails_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            List <cEMail> emails = null;
            int           gindex = -1;
            cEMail        email  = null;

            if (int.TryParse(e.CommandArgument.ToString(), out gindex))
            {
                emails = Session["dem_Emails"] as List <cEMail>;
                if (gindex < emails.Count())
                {
                    email = emails[gindex];
                }
            }
            else
            {
                return;
            }
            switch (e.CommandName.ToUpper())
            {
            case "EDIT":
            case "EDITITEM":
            {
                if (emails != null)
                {
                    gv_Emails.EditIndex = gindex;
                }
                BindAllGrids();
                break;
            }
            }
        }
Beispiel #3
0
        protected void btnDeleteEMail_Click(object sender, EventArgs e)
        {
            int iEMailID;

            if (int.TryParse(hidEnterEMailID.Value, out iEMailID))
            {
                cEMail UpdateEMail = new cEMail(iEMailID, _UserName, _UserID);
                UpdateEMail.SaveUpdate(_UserID, true);
            }
        }
Beispiel #4
0
        protected void btnAddEmail_Click(object sender, EventArgs e)
        {
            List <cEMail> clEMail  = Session["dem_Emails"] as List <cEMail>;
            cEMail        NewEmail = new cEMail();

            clEMail.Add(NewEmail);
            Session["dem_Emails"] = clEMail;
            BindEmails();

            gvEmails.EditIndex = gvEmails.Rows.Count - 1;
            BindEmails();
        }
Beispiel #5
0
        protected void gvEmails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List <cEMail> clEmails = Session["dem_Emails"] as List <cEMail>;

            if (e.RowIndex < clEmails.Count)
            {
                cEMail UpdatedEmail = clEmails[e.RowIndex];

                TextBox tbEmailAddress = (TextBox)gvEmails.Rows[e.RowIndex].FindControl("tbEmailAddress");
                if (tbEmailAddress != null)
                {
                    UpdatedEmail.EmailAddress = tbEmailAddress.Text;
                }

                DropDownList ddlEmailType = (DropDownList)gvEmails.Rows[e.RowIndex].FindControl("ddlEmailType");
                if (ddlEmailType != null)
                {
                    UpdatedEmail.EmailTypeID = ddlEmailType.SelectedValue.ToInt32();
                }

                if (!UpdatedEmail.IsValid())
                {
                    lblMessage.Text = UpdatedEmail.strErrorMessage;
                    e.Cancel        = true;
                }
                else
                {
                    RadioButton rbPrimary = (RadioButton)gvEmails.Rows[e.RowIndex].FindControl("rbPrimary");
                    if (rbPrimary != null)
                    {
                        if (rbPrimary.Checked)
                        {
                            clEmails.ForAll(x => x.IsPrimary = false);
                            UpdatedEmail.IsPrimary           = true;
                        }
                    }
                    Session["dem_Emails"] = clEmails;
                    gvEmails.EditIndex    = -1;
                }
                BindEmails();
            }
            else
            {
                e.Cancel = true;
            }
        }
Beispiel #6
0
        protected void gv_Emails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            List <cEMail> emails = null;
            int           gindex = e.RowIndex;
            cEMail        email  = new cEMail();
            GridView      gv     = (GridView)sender;

            emails = Session["dem_Emails"] as List <cEMail>;
            if (gindex < emails.Count())
            {
                email.EmailAddress = ((gv.Rows[gindex].FindControl("gv_txtEmailAddress") as TextBox).Text + string.Empty).Trim();
                int iRetVal = 0;
                int.TryParse((gv.Rows[gindex].FindControl("ddEmailTypeId") as DropDownList).SelectedValue, out iRetVal); //only native types can be returned so temp variable
                email.EmailTypeID = iRetVal;
                email.IsPrimary   = (gv.Rows[gindex].FindControl("rbtnPrimary2") as RadioButton).Checked;
                if (email.IsValid())
                {
                    emails[gindex].EmailAddress = email.EmailAddress;
                    emails[gindex].EmailTypeID  = email.EmailTypeID;
                    emails[gindex].IsPrimary    = email.IsPrimary;
                    if (emails[gindex].EMailID < 1)
                    {
                        emails.Add(new cEMail());
                    }

                    //if the primary record is checked then all other record must not be ckeched
                    if (emails[gindex].IsPrimary)
                    {
                        emails.ForAll(x => x.IsPrimary = false);
                        emails[gindex].IsPrimary       = true;
                    }

                    Session["dem_Emails"]    = emails;
                    gv.Rows[gindex].RowState = DataControlRowState.Normal;
                    gv_Emails.EditIndex      = -1;
                }
                else
                {
                    lblMessage.Text = email.strErrorMessage;
                    e.Cancel        = true;
                }
                BindAllGrids();
            }
        }
Beispiel #7
0
        protected void gvEmails_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if ((e.Row.RowState & DataControlRowState.Edit) > 0)
                {
                    List <cEMail> clEmails     = Session["dem_Emails"] as List <cEMail>;
                    DropDownList  ddlEmailType = (DropDownList)e.Row.FindControl("ddlEmailType");
                    if (ddlEmailType != null)
                    {
                        if (clEmails.Count > 0)
                        {
                            ddlEmailType.DataTextField  = "EmailType";
                            ddlEmailType.DataValueField = "EmailTypeID";

                            ddlEmailType.DataSource = clEmails[0].EmailTypes;
                            ddlEmailType.DataBind();

                            ddlEmailType.ClearSelection();

                            cEMail SourceEmail = e.Row.DataItem as cEMail;

                            foreach (ListItem lItem in ddlEmailType.Items)
                            {
                                if (lItem.Value == SourceEmail.EmailTypeID.ToString())
                                {
                                    ddlEmailType.ClearSelection();
                                    lItem.Selected = true;
                                }
                            }
                        }
                    }

                    TextBox tbTemp;

                    tbTemp = (TextBox)e.Row.FindControl("tbEmail");
                    if (tbTemp != null)
                    {
                        tbTemp.Attributes.Add("PlaceHolder", "Email Address");
                    }
                }
            }
        }
Beispiel #8
0
        protected void btnSaveEMail_Click(object sender, EventArgs e)
        {
            int iEMailID;

            if (int.TryParse(hidEnterEMailID.Value, out iEMailID))
            {
                cEMail UpdateEMail = new cEMail(iEMailID, _UserName, _UserID);
                UpdateEMail.EMailID      = iEMailID;
                UpdateEMail.EmailAddress = tbEnterEMailAddress.Text;

                int iTemp;
                if (int.TryParse(ddlEnterEMailType.SelectedValue, out iTemp))
                {
                    UpdateEMail.EmailTypeID = iTemp;
                }
                UpdateEMail.IsPrimary = cbxEnterEMailPrimary.Checked;

                UpdateEMail.SaveUpdate(_UserID);
            }
        }