示例#1
0
        /// <summary>
        /// Prepares the custom search fields.
        /// </summary>
        /// <param name="savedSearch">The saved search.</param>
        /// <param name="loadLastSearch">if set to <c>true</c> [load last search].</param>
        private void PrepareCustomSearchFields(SavedSearch savedSearch, bool loadLastSearch)
        {
            SavedSearch lastSearch = null;
            plhMaleSearchTerms.Controls.Clear();
            plhFemaleSearchTerms.Controls.Clear();
            plhCoupleSearchTerms.Controls.Clear();

            if (CurrentUserSession != null)
            {
                if (savedSearch != null)
                    lastSearch = savedSearch;
                else if (loadLastSearch)
                    lastSearch = SavedSearch.Load(CurrentUserSession.Username, "_lastsearch_");

                if (lastSearch != null)
                {
                    dropGender2.SelectedValue = ((int)lastSearch.Gender).ToString();
                }
            }

            ProfileTopic[] profileTopics = ProfileTopic.Fetch();
            if (profileTopics != null)
            {
                foreach (ProfileTopic topic in profileTopics)
                {
                    #region Add boxes for topics

                    LiteralControl ltrTopicHeading = new LiteralControl(
                        String.Format("<h3 class=\"SectionHeading\">{0}</h3>", Config.Misc.EnableProfileDataTranslation 
                        ? Lang.Trans(topic.Name) : topic.Name));

                    switch ((User.eGender)Int32.Parse(dropGender2.SelectedValue))
                    {
                        case Classes.User.eGender.Male:
                            plhMaleSearchTerms.Controls.Add(ltrTopicHeading);
                            break;
                        case Classes.User.eGender.Female:
                            plhFemaleSearchTerms.Controls.Add(ltrTopicHeading);
                            break;
                        case Classes.User.eGender.Couple:
                            plhCoupleSearchTerms.Controls.Add(ltrTopicHeading);
                            break;
                    }
                    #endregion

                    ProfileQuestion[] questions = topic.FetchQuestions();
                    if (questions != null)
                    {
                        Dictionary<int, object> dicQuestions = new Dictionary<int, object>();
                        foreach (ProfileQuestion question in questions)
                        {
                            bool maleVisible = question.VisibleForMale &&
                                               (Int32.Parse(dropGender2.SelectedValue) ==
                                                (int)Classes.User.eGender.Male);
                            bool femaleVisible = question.VisibleForFemale &&
                                                 (Int32.Parse(dropGender2.SelectedValue) ==
                                                  (int)Classes.User.eGender.Female);
                            bool coupleVisible = question.VisibleForCouple &&
                                                 (Int32.Parse(dropGender2.SelectedValue) ==
                                                  (int)Classes.User.eGender.Couple);
                            if (question.SearchStyle == ProfileQuestion.eSearchStyle.Hidden ||
                                !(question.VisibleForMale || question.VisibleForFemale || question.VisibleForCouple)
                                )
                            {
                                continue;
                            }

                            IProfileSearchComponent cProfile = null;

                            switch (question.SearchStyle)
                            {
                                case ProfileQuestion.eSearchStyle.MultiChoiceCheck:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchMultiChoiceCheck.ascx");
                                    break;

                                case ProfileQuestion.eSearchStyle.RangeChoiceSelect:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchRangeChoiceSelect.ascx");
                                    break;

                                case ProfileQuestion.eSearchStyle.MultiChoiceSelect:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchMultiChoiceSelect.ascx");
                                    break;

                                case ProfileQuestion.eSearchStyle.SingleChoice:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchSingleChoice.ascx");
                                    break;

                                default:
                                    break;
                            }
                            if (cProfile != null)
                                (cProfile as Control).ID = question.Id.ToString();

                            if (cProfile == null)
                            {
                                continue;
                            }
                            cProfile.Question = question;

                            if (lastSearch != null)
                            {
                                cProfile.ChoiceIds = lastSearch.ChoiceIds;

                                maleVisible = question.VisibleForMale &&
                                              (Int32.Parse(dropGender2.SelectedValue) == (int)Classes.User.eGender.Male);
                                femaleVisible = question.VisibleForFemale &&
                                                (Int32.Parse(dropGender2.SelectedValue) ==
                                                 (int)Classes.User.eGender.Female);
                                coupleVisible = question.VisibleForCouple &&
                                                (Int32.Parse(dropGender2.SelectedValue) ==
                                                 (int)Classes.User.eGender.Couple);

                                dropGender2_SelectedIndexChanged(null, null);
                            }

                            if (maleVisible)
                            {
                                plhMaleSearchTerms.Controls.Add((Control)cProfile);
                                dicQuestions.Add(question.Id, (Control)cProfile);
                            }
                            else if (femaleVisible)
                            {
                                plhFemaleSearchTerms.Controls.Add((Control)cProfile);
                                dicQuestions.Add(question.Id, (Control)cProfile);
                            }
                            else if (coupleVisible)
                            {
                                plhCoupleSearchTerms.Controls.Add((Control)cProfile);
                                dicQuestions.Add(question.Id, (Control)cProfile);
                            }
                        }

//                        if (lastSearch != null || IsPostBack && !loadLastSearch || loadLastSearch && savedSearch == null)
                        if (IsPostBack || Config.Search.DefaultToCustomSearch)
                            SetCascadeQuestions(questions, dicQuestions);
                    }

                    #region Clear/Close boxes
                    switch ((User.eGender)Int32.Parse(dropGender2.SelectedValue))
                    {
                        case Classes.User.eGender.Male:
                            if (plhMaleSearchTerms.Controls[plhMaleSearchTerms.Controls.Count - 1] is LiteralControl)
                            {
                                plhMaleSearchTerms.Controls.RemoveAt(plhMaleSearchTerms.Controls.Count - 1);
                            }
                            break;
                        case Classes.User.eGender.Female:
                            if (plhFemaleSearchTerms.Controls[plhFemaleSearchTerms.Controls.Count - 1] is LiteralControl)
                            {
                                plhFemaleSearchTerms.Controls.RemoveAt(plhFemaleSearchTerms.Controls.Count - 1);
                            }
                            break;
                        case Classes.User.eGender.Couple:
                            if (plhCoupleSearchTerms.Controls[plhCoupleSearchTerms.Controls.Count - 1] is LiteralControl)
                            {
                                plhCoupleSearchTerms.Controls.RemoveAt(plhCoupleSearchTerms.Controls.Count - 1);
                            }
                            break;
                    }

                    #endregion
                }

                if (lastSearch != null)
                {
                    if (Config.Users.LocationPanelVisible)
                    {
                        CascadingDropDownCountry2.SelectedValue = lastSearch.Country;
                        CascadingDropDownState2.SelectedValue = lastSearch.State;
                        CascadingDropDownCity2.SelectedValue = lastSearch.City;
                        txtZip2.Text = lastSearch.Zip;
                    }

                    dropGender2.SelectedValue = Convert.ToInt32(lastSearch.Gender).ToString();
                    txtAgeFrom2.Text = lastSearch.AgeFrom.ToString();
                    txtAgeTo2.Text = lastSearch.AgeTo.ToString();
                    cbPhotoReq2.Checked = lastSearch.PhotoRequired;
                }
            }
        }
示例#2
0
 private void PrepareCustomSearchFields(SavedSearch savedSearch)
 {
     PrepareCustomSearchFields(savedSearch, false);
 }
示例#3
0
        /// <summary>
        /// Creates Saved Search object with id = -1.
        /// </summary>
        /// <param name="username">The username.</param>
        /// <param name="name">The name.</param>
        /// <param name="gender">The gender.</param>
        /// <param name="country">The country.</param>
        /// <param name="state">The state.</param>
        /// <param name="zip">The zip.</param>
        /// <param name="city">The city.</param>
        /// <param name="ageFrom">The age from.</param>
        /// <param name="ageTo">The age to.</param>
        /// <param name="photoRequired">if set to <c>true</c> [photo required].</param>
        /// <param name="choiceIds">The choice ids.</param>
        /// <returns>SavedSearch object</returns>
        public static SavedSearch Create(string username, string name, User.eGender gender,
                                         string country, string state, string zip, string city, int ageFrom,
                                         int ageTo, bool photoRequired, int[] choiceIds,
                                         bool emailMatches, int emailFrequency, DateTime? nextEmailDate)
        {
            SavedSearch ss = new SavedSearch();

            ss.username = username;
            ss.name = name;
            ss.gender = gender;
            ss.country = country;
            ss.state = state;
            ss.zip = zip;
            ss.city = city;
            ss.ageFrom = ageFrom;
            ss.ageTo = ageTo;
            ss.photoRequired = photoRequired;
            ss.choiceIds = choiceIds;
            ss.emailMatches = emailMatches;
            ss.emailFrequency = emailFrequency;
            ss.nextEmailDate = nextEmailDate;

            return ss;
        }
示例#4
0
        /// <summary>
        /// Loads SavedSearch array from database by specified id, username and name.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="username">The username.</param>
        /// <param name="name">The name.</param>
        /// <returns></returns>
        private static SavedSearch[] Load(object id, string username, string name, object emailMatches)
        {
            using (SqlConnection conn = Config.DB.Open())
            {
                SqlDataReader reader =
                    SqlHelper.ExecuteReader(conn, "LoadSavedSearch", id, username, name, emailMatches);

                SavedSearch savedSearch = null;

                List<SavedSearch> lSavedSearches = new List<SavedSearch>();
                while (reader.Read())
                {
                    savedSearch = new SavedSearch();

                    savedSearch.id = (int)reader["ID"];
                    savedSearch.username = (string)reader["Username"];
                    savedSearch.name = (string)reader["Name"];
                    savedSearch.gender = (User.eGender)reader["Gender"];
                    savedSearch.country = (string)reader["Country"];
                    savedSearch.state = (string)reader["State"];
                    savedSearch.zip = (string)reader["Zip"];
                    savedSearch.city = (string)reader["City"];
                    savedSearch.ageFrom = (int)reader["AgeFrom"];
                    savedSearch.ageTo = (int)reader["AgeTo"];
                    savedSearch.photoRequired = (bool)reader["PhotoRequired"];
                    string xmlIds = (string)reader["ChoiceIDs"];

                    MemoryStream ms = new MemoryStream(Encoding.UTF8.GetBytes(xmlIds));
                    XmlSerializer xmls = new XmlSerializer(typeof(int[]));
                    savedSearch.choiceIds = (int[])xmls.Deserialize(ms);

                    savedSearch.emailMatches = (bool)reader["EmailMatches"];
                    savedSearch.emailFrequency = (int)reader["EmailFrequency"];
                    savedSearch.nextEmailDate = reader["NextEmailDate"] == DBNull.Value ? null : (DateTime?)reader["NextEmailDate"];

                    lSavedSearches.Add(savedSearch);
                }
                return lSavedSearches.ToArray();
            }
        }
示例#5
0
        /// <summary>
        /// Prepares the custom search fields.
        /// </summary>
        /// <param name="savedSearch">The saved search.</param>
        /// <param name="loadLastSearch">if set to <c>true</c> [load last search].</param>
        private void PrepareCustomSearchFields(SavedSearch savedSearch, bool loadLastSearch)
        {
            profileQuestions = new List<ProfileQuestion>();
            dicQuestions = new Dictionary<int, object>();
            plhCustomSearch.Controls.Clear();

            SavedSearch lastSearch = null;

            if (CurrentUserSession != null)
            {
                if (savedSearch != null)
                    lastSearch = savedSearch;
                else if (loadLastSearch)
                    lastSearch = SavedSearch.Load(CurrentUserSession.Username, "_lastsearch_");

                if (lastSearch != null)
                {
                    dropGender.SelectedValue = ((int) lastSearch.Gender).ToString();
                    if (Config.Users.LocationPanelVisible)
                    {
                        selectedCountry = lastSearch.Country;
                        selectedState = lastSearch.State;
                        selectedCity = lastSearch.City;
                        txtZip.Text = lastSearch.Zip;
                    }

                    dropGender.SelectedValue = Convert.ToInt32(lastSearch.Gender).ToString();
                    txtAgeFrom.Text = lastSearch.AgeFrom.ToString();
                    txtAgeTo.Text = lastSearch.AgeTo.ToString();
                    cbPhotoReq.Checked = lastSearch.PhotoRequired;
                    cbOnlineOnly.Checked = lastSearch.OnlineOnly;
                }
            }

            ProfileTopic[] profileTopics = ProfileTopic.Fetch();

            if (profileTopics != null)
            {
                foreach (ProfileTopic topic in profileTopics)
                {
                    #region Add boxes for topics

                    var divTopicContainer = new HtmlGenericControl("div");
                    plhCustomSearch.Controls.Add(divTopicContainer);

                    var ltrTopicHeading = new LiteralControl(
                        String.Format("<div class=\"panel-heading\"><h4 class=\"panel-title\"><a class=\"collapsed\" data-toggle=\"collapse\" href=\".topic_{1}\">{0}</a></h4></div>",
                                      Config.Misc.EnableProfileDataTranslation ? Lang.Trans(topic.Name) : topic.Name, topic.ID));

                    divTopicContainer.Controls.Add(ltrTopicHeading);

                    var ltrTopicBody = new HtmlGenericControl("div");
                    ltrTopicBody.Attributes.Add("class", "panel-collapse collapse topic_" + topic.ID);
                    //ltrTopicBody.Style.Add("display", "none");

                    divTopicContainer.Controls.Add(ltrTopicBody);

                    #endregion

                    ProfileQuestion[] questions = topic.FetchQuestions();
                    if (questions != null)
                    {
                        foreach (ProfileQuestion question in questions)
                        {
                            if (question.SearchStyle == ProfileQuestion.eSearchStyle.Hidden ||
                                !(question.VisibleForMale || question.VisibleForFemale || question.VisibleForCouple))
                                continue;

                            IProfileSearchComponent cProfile = null;

                            switch (question.SearchStyle)
                            {
                                case ProfileQuestion.eSearchStyle.MultiChoiceSelect:
                                case ProfileQuestion.eSearchStyle.MultiChoiceCheck:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchMultiChoiceCheck2.ascx");
                                    break;

                                case ProfileQuestion.eSearchStyle.RangeChoiceSelect:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchRangeChoiceSelect2.ascx");
                                    break;

                                case ProfileQuestion.eSearchStyle.SingleChoice:
                                    cProfile = (IProfileSearchComponent)
                                               LoadControl("~/Components/Search/SearchSingleChoice2.ascx");
                                    break;

                                default:
                                    break;
                            }

                            if (cProfile == null) continue;

                            ((Control) cProfile).ID = question.Id.ToString();

                            cProfile.Question = question;

                            if (lastSearch != null)
                            {
                                cProfile.ChoiceIds = lastSearch.ChoiceIds;
                            }

                            if (!question.VisibleForPaidOnly ||
                                (CurrentUserSession != null && CurrentUserSession.Paid))
                            {
                                var divQuestionContainer = new HtmlGenericControl("div");
                                divQuestionContainer.Controls.Add((Control)cProfile);
                                ltrTopicBody.Controls.Add(divQuestionContainer);

                                dicQuestions.Add(question.Id, (Control) cProfile);

                                if (!Config.Users.DisableGenderInformation)
                                {
                                    string genderClasses = (cProfile.UserControlPanel.Attributes["class"] ?? "")
                                                           + " " +
                                                           (question.VisibleForMale
                                                                ? "visibleformale"
                                                                : "invisibleformale")
                                                           + " " +
                                                           (question.VisibleForFemale
                                                                ? "visibleforfemale"
                                                                : "invisibleforfemale")
                                                           + " " +
                                                           (question.VisibleForCouple
                                                                ? "visibleforcouple"
                                                                : "invisibleforcouple") + " panel-body";

                                    divQuestionContainer.Attributes["class"] = genderClasses.Trim();

                                    if ((Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Male
                                         && !question.VisibleForMale) ||
                                        (Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Female
                                         && !question.VisibleForFemale) ||
                                        (Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Couple
                                         && !question.VisibleForCouple))
                                    {
                                        divQuestionContainer.Style["display"] = "none";
                                    }
                                }
                            }

                            profileQuestions.Add(question);
                        }
                    }

                    #region Remove empty topics

                    if (ltrTopicBody.Controls.Count == 0)
                    {
                        plhCustomSearch.Controls.Remove(divTopicContainer);
                    }

                    if (questions != null)
                    {
                        string genderClasses =
                            (questions.Any(q => q.VisibleForMale) ? "visibleformale" : "invisibleformale") + " " +
                            (questions.Any(q => q.VisibleForFemale) ? "visibleforfemale" : "invisibleforfemale") + " " +
                            (questions.Any(q => q.VisibleForCouple) ? "visibleforcouple" : "invisibleforcouple") + " panel";

                        divTopicContainer.Attributes["class"] = genderClasses;

                        if ((Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Male
                             && !questions.Any(q => q.VisibleForMale)) ||
                            (Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Female
                             && !questions.Any(q => q.VisibleForFemale)) ||
                            (Int32.Parse(dropGender.SelectedValue) == (int) Classes.User.eGender.Couple
                             && !questions.Any(q => q.VisibleForCouple)))
                        {
                            divTopicContainer.Style["display"] = "none";
                        }
                    }

                    #endregion
                }
            }
        }