Пример #1
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 = (SqlDataReader)
                    SqlHelper.GetDB().ExecuteReader( "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();
            }
        }
Пример #2
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 User.eGender.Male:
                            plhMaleSearchTerms.Controls.Add(ltrTopicHeading);
                            break;
                        case User.eGender.Female:
                            plhFemaleSearchTerms.Controls.Add(ltrTopicHeading);
                            break;
                        case 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)User.eGender.Male);
                            bool femaleVisible = question.VisibleForFemale &&
                                                 (Int32.Parse(dropGender2.SelectedValue) ==
                                                  (int)User.eGender.Female);
                            bool coupleVisible = question.VisibleForCouple &&
                                                 (Int32.Parse(dropGender2.SelectedValue) ==
                                                  (int)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)User.eGender.Male);
                                femaleVisible = question.VisibleForFemale &&
                                                (Int32.Parse(dropGender2.SelectedValue) ==
                                                 (int)User.eGender.Female);
                                coupleVisible = question.VisibleForCouple &&
                                                (Int32.Parse(dropGender2.SelectedValue) ==
                                                 (int)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 User.eGender.Male:
                            if (plhMaleSearchTerms.Controls[plhMaleSearchTerms.Controls.Count - 1] is LiteralControl)
                            {
                                plhMaleSearchTerms.Controls.RemoveAt(plhMaleSearchTerms.Controls.Count - 1);
                            }
                            break;
                        case User.eGender.Female:
                            if (plhFemaleSearchTerms.Controls[plhFemaleSearchTerms.Controls.Count - 1] is LiteralControl)
                            {
                                plhFemaleSearchTerms.Controls.RemoveAt(plhFemaleSearchTerms.Controls.Count - 1);
                            }
                            break;
                        case 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;
                }
            }
        }
Пример #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
 private void PrepareCustomSearchFields(SavedSearch savedSearch)
 {
     PrepareCustomSearchFields(savedSearch, false);
 }