Esempio n. 1
0
        /// <summary>
        /// Handles the ItemDataBound event of the lvNewFamily control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="ListViewItemEventArgs"/> instance containing the event data.</param>
        protected void lvNewFamily_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            if (e.Item.ItemType == ListViewItemType.DataItem)
            {
                SerializedPerson person = ((ListViewDataItem)e.Item).DataItem as SerializedPerson;

                var ddlSuffix = (RockDropDownList)e.Item.FindControl("ddlSuffix");
                ddlSuffix.BindToDefinedType(DefinedTypeCache.Read(new Guid(Rock.SystemGuid.DefinedType.PERSON_SUFFIX)), true);
                if (person.SuffixValueId.HasValue)
                {
                    ddlSuffix.SelectedValue = person.SuffixValueId.ToString();
                }

                var ddlGender = (RockDropDownList)e.Item.FindControl("ddlGender");
                ddlGender.BindToEnum <Gender>();
                if (person.Gender != Gender.Unknown)
                {
                    ddlGender.SelectedIndex = person.Gender.ConvertToInt();
                }

                var ddlAbilityGrade = (RockDropDownList)e.Item.FindControl("ddlAbilityGrade");
                ddlAbilityGrade.LoadAbilityAndGradeItems();
                if (!string.IsNullOrWhiteSpace(person.Ability))
                {
                    ddlAbilityGrade.SelectedValue = person.Ability;
                }
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Handles the PagePropertiesChanging event of the lvNewFamily control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="PagePropertiesChangingEventArgs"/> instance containing the event data.</param>
        protected void lvNewFamily_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
        {
            var newFamilyList = (List <SerializedPerson>)ViewState["newFamily"] ?? new List <SerializedPerson>();
            int currentPage   = e.StartRowIndex / e.MaximumRows;
            int?previousPage  = ViewState["currentPage"] as int?;
            int personOffset  = 0;
            int pageOffset    = 0;

            foreach (ListViewItem item in lvNewFamily.Items)
            {
                var newPerson = new SerializedPerson();
                newPerson.FirstName     = ((TextBox)item.FindControl("tbFirstName")).Text;
                newPerson.LastName      = ((TextBox)item.FindControl("tbLastName")).Text;
                newPerson.SuffixValueId = ((RockDropDownList)item.FindControl("ddlSuffix")).SelectedValueAsId();
                newPerson.BirthDate     = ((DatePicker)item.FindControl("dpBirthDate")).SelectedDate;
                newPerson.Gender        = ((RockDropDownList)item.FindControl("ddlGender")).SelectedValueAsEnum <Gender>();
                newPerson.Ability       = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedValue;
                newPerson.AbilityGroup  = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedItem.Attributes["optiongroup"];

                if (previousPage.HasValue)
                {
                    pageOffset = (int)previousPage * e.MaximumRows;
                }

                if (e.StartRowIndex + personOffset + e.MaximumRows >= newFamilyList.Count)
                {
                    newFamilyList.AddRange(Enumerable.Repeat(new SerializedPerson(), e.MaximumRows));
                }

                newFamilyList[pageOffset + personOffset] = newPerson;
                personOffset++;
            }

            ViewState["currentPage"] = currentPage;
            ViewState["newFamily"]   = newFamilyList;
            dpNewFamily.SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
            lvNewFamily.DataSource = newFamilyList;
            lvNewFamily.DataBind();
            mdlNewFamily.Show();
        }
Esempio n. 3
0
        /// <summary>
        /// Handles the Click event of the lbSaveFamily control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbSaveFamily_Click(object sender, EventArgs e)
        {
            var newFamilyList = (List <SerializedPerson>)ViewState["newFamily"] ?? new List <SerializedPerson>();
            int?currentPage   = ViewState["currentPage"] as int?;
            int personOffset  = 0;
            int pageOffset    = 0;

            // add people from the current page
            foreach (ListViewItem item in lvNewFamily.Items)
            {
                var newPerson = new SerializedPerson();
                newPerson.FirstName      = ((TextBox)item.FindControl("tbFirstName")).Text;
                newPerson.LastName       = ((TextBox)item.FindControl("tbLastName")).Text;
                newPerson.SuffixValueId  = ((RockDropDownList)item.FindControl("ddlSuffix")).SelectedValueAsId();
                newPerson.BirthDate      = ((DatePicker)item.FindControl("dpBirthDate")).SelectedDate;
                newPerson.Gender         = ((RockDropDownList)item.FindControl("ddlGender")).SelectedValueAsEnum <Gender>();
                newPerson.Ability        = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedValue;
                newPerson.AbilityGroup   = ((RockDropDownList)item.FindControl("ddlAbilityGrade")).SelectedItem.Attributes["optiongroup"];
                newPerson.IsSpecialNeeds = ((RockCheckBox)item.FindControl("cbSpecialNeeds")).Checked;

                if (currentPage.HasValue)
                {
                    pageOffset = (int)currentPage * lvNewFamily.DataKeys.Count;
                }

                newFamilyList[pageOffset + personOffset] = newPerson;
                personOffset++;
            }

            List <Person> newPeople = CreatePeople(newFamilyList.Where(p => p.IsValid()).ToList());

            // People passed validation
            if (newPeople.Any())
            {
                // Create family group (by passing null) and add group members
                var familyGroup = AddGroupMembers(null, newPeople);

                var checkInFamily = new CheckInFamily();

                foreach (var person in newPeople)
                {
                    var checkInPerson = new CheckInPerson();
                    checkInPerson.Person       = person;
                    checkInPerson.FirstTime    = true;
                    checkInPerson.Selected     = true;
                    checkInPerson.FamilyMember = true;
                    checkInFamily.People.Add(checkInPerson);
                }

                checkInFamily.Group      = familyGroup;
                checkInFamily.Caption    = familyGroup.Name;
                checkInFamily.SubCaption = string.Join(",", checkInFamily.People.Select(p => p.Person.FirstName));
                checkInFamily.Selected   = true;

                CurrentCheckInState.CheckIn.Families.Clear();
                CurrentCheckInState.CheckIn.Families.Add(checkInFamily);

                ShowHideResults(checkInFamily.People.Count > 0);
                ProcessFamily(checkInFamily);
                ProcessPeople(checkInFamily);
                mdlNewFamily.Hide();
            }
            else
            {
                maWarning.Show("Validation: Name, DOB, and Gender are required.", ModalAlertType.Information);
            }
        }
Esempio n. 4
0
        /// <summary>
        /// Handles the Click event of the lbNewPerson control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void lbNewPerson_Click(object sender, EventArgs e)
        {
            var selectedFamily = CurrentCheckInState.CheckIn.Families.FirstOrDefault(f => f.Selected);

            if (selectedFamily != null)
            {
                // CreatePeople only has a single person to validate/create
                var newPerson = new SerializedPerson()
                {
                    FirstName      = tbPersonFirstName.Text,
                    LastName       = tbPersonLastName.Text,
                    SuffixValueId  = ddlPersonSuffix.SelectedValueAsId(),
                    BirthDate      = dpPersonDOB.SelectedDate,
                    Gender         = ddlPersonGender.SelectedValueAsEnum <Gender>(),
                    Ability        = ddlPersonAbilityGrade.SelectedValue,
                    AbilityGroup   = ddlPersonAbilityGrade.SelectedItem.Attributes["optiongroup"],
                    IsSpecialNeeds = cbPersonSpecialNeeds.Checked
                };

                if (newPerson.IsValid())
                {       // Person passed validation
                    var newPeople = CreatePeople(new List <SerializedPerson>(1)
                    {
                        newPerson
                    });

                    var checkInPerson = new CheckInPerson();
                    checkInPerson.Person    = newPeople.FirstOrDefault();
                    checkInPerson.FirstTime = true;

                    if (!newPersonType.Value.Equals("Visitor"))
                    {   // Family Member
                        AddGroupMembers(selectedFamily.Group, newPeople);
                        hfSelectedPerson.Value    += checkInPerson.Person.Id + ",";
                        checkInPerson.FamilyMember = true;
                    }
                    else
                    {   // Visitor
                        AddVisitorRelationships(selectedFamily, checkInPerson.Person.Id);
                        hfSelectedVisitor.Value   += checkInPerson.Person.Id + ",";
                        checkInPerson.FamilyMember = false;

                        // If a child, make the family group explicitly so the child role type can be selected. If no
                        // family group is explicitly made, Rock makes one with Adult role type by default
                        if (dpPersonDOB.SelectedDate.Age() < 18)
                        {
                            AddGroupMembers(null, newPeople);
                        }
                    }

                    checkInPerson.Selected = true;
                    selectedFamily.People.Add(checkInPerson);
                    selectedFamily.SubCaption = string.Join(",", selectedFamily.People.Select(p => p.Person.FirstName));

                    ProcessPeople(selectedFamily);
                    mdlAddPerson.Hide();
                }
                else
                {
                    maWarning.Show("Validation: Name, DOB, and Gender are required.", ModalAlertType.Information);
                }
            }
        }