Exemple #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            try
            {
                ImgLoading.ImageUrl = ImgLoading.ImageUrl.ChangeToImageHost();

                H1Results.InnerHtml += " - " + Request.QueryString["sg"]; // insert game name

                #region Search engine
                HttpRequest currentR = Request;

                // Set values of current lang
                LangaugeSystem ls = new LangaugeSystem();
                CurrentLang   = ls.CurrentLang;
                CurrentLangId = ls.CurrentLangId;


                #region Get QueryStringsDatas (Convert to htmlencodes)

                var searchQueryDatas = new
                {
                    ClanSkill       = currentR.QueryString["cs"],
                    ClanContinent   = currentR.QueryString["cct"],
                    ClanCountry     = currentR.QueryString["cc"],
                    SearchSkill     = currentR.QueryString["ss"],
                    SearchContinent = currentR.QueryString["sct"],
                    SearchCountry   = (string)currentR.QueryString["sc"],
                    SearchGame      = (string)currentR.QueryString["sg"],
                    SearchGameMode  = (string)currentR.QueryString["sgt"]
                }.ToAnonymousObjectCollection();

                foreach (AnonymousObject s in searchQueryDatas)
                {
                    s.SetValue(Server.HtmlEncode(Server.UrlDecode(s.GetValue <string>())));
                }

                #endregion

                #region Get QueryStrings custom text data (no validate or convert)

                var searchQueryCustomTextData = new
                {
                    ClanName  = Server.HtmlEncode(Server.UrlDecode(currentR.QueryString["cn"])),
                    SearchMap = Server.HtmlEncode(Server.UrlDecode(currentR.QueryString["sm"]))
                };

                #endregion

                #region Get QueryStrings customdata

                var searchQueryCustomData = new
                {
                    SearchMatchStart = currentR.QueryString["sfd"],
                    SearchXvs        = currentR.QueryString["sxv"],
                    SearchvsX        = currentR.QueryString["svx"]
                };

                #endregion



                try
                {
                    #region Get IDs of searchQueryDatas

                    int?         clanSkillId = null;
                    SkillsSystem ss          = new SkillsSystem();
                    if (!string.IsNullOrEmpty(searchQueryDatas.GetAnonymousObject("ClanSkill").GetValue <string>()))
                    {
                        clanSkillId =
                            ((dynamic)ss.GetSkill(searchQueryDatas.GetAnonymousObject("ClanSkill").GetValue <string>(),
                                                  CurrentLangId)).SearchWarSkillId;
                    }


                    int?searchSkillId = null;
                    if (!string.IsNullOrEmpty(searchQueryDatas.GetAnonymousObject("SearchSkill").GetValue <string>()))
                    {
                        searchSkillId =
                            ((dynamic)ss.GetSkill(searchQueryDatas.GetAnonymousObject("SearchSkill").GetValue <string>(),
                                                  CurrentLangId)).SearchWarSkillId;
                    }
                    ContinentSystem cs = new ContinentSystem();
                    int             clanContinentId = ((dynamic)cs.GetContinent(CurrentLangId,
                                                                                searchQueryDatas.GetAnonymousObject("ClanContinent").
                                                                                GetValue <string>())).SearchWarContinentId;

                    CountrySystem cys           = new CountrySystem();
                    int           clanCountryId = ((dynamic)cys.GetCountry(CurrentLangId,
                                                                           searchQueryDatas.GetAnonymousObject("ClanCountry").GetValue
                                                                           <string>())).SearchWarCountryId;


                    int searchContinent = ((dynamic)cs.GetContinent(CurrentLangId,
                                                                    searchQueryDatas.GetAnonymousObject("SearchContinent")
                                                                    .
                                                                    GetValue <string>())).SearchWarContinentId;


                    int?searchCountryId = null;
                    if (!string.IsNullOrEmpty(searchQueryDatas.GetAnonymousObject("SearchCountry").GetValue <string>()))
                    {
                        searchCountryId = ((dynamic)cys.GetCountry(CurrentLangId,
                                                                   searchQueryDatas.GetAnonymousObject("SearchCountry").
                                                                   GetValue
                                                                   <string>())).SearchWarCountryId;
                    }

                    GamesSystem gs           = new GamesSystem();
                    int         searchGameId = gs.GetGame(searchQueryDatas.GetAnonymousObject("SearchGame").GetValue
                                                          <string>()).SearchWarGameId;

                    int?searchGameModeId = null;
                    if (!string.IsNullOrEmpty(searchQueryDatas.GetAnonymousObject("SearchGameMode").GetValue <string>()))
                    {
                        GameModeSystem gms = new GameModeSystem();
                        searchGameModeId =
                            gms.GetGameType(searchQueryDatas.GetAnonymousObject("SearchGameMode").GetValue
                                            <string>()).SearchWarGameTypeId;
                    }

                    #endregion


                    #region Create url to the "client javascript" (get "data search results" as xml)

                    ANO_User getprofile = ANOProfile.GetCookieValues(CurrentUserIP);
                    Guid     newID      = Guid.NewGuid();
                    ANOProfile.SaveCookies(CurrentUserIP, newID);

                    xmlSearchUrl       = "http://" + GetDomain.GetDomainFromUrl(Context.Request.Url.ToString()) + "/m.ashx";
                    xmlSearchUrlaction = xmlSearchUrl + "?li= " + CurrentLangId.ToString()
                                         + "&cn=" + Server.UrlEncode(searchQueryCustomTextData.ClanName)
                                         + ((clanSkillId.HasValue) ? "&cs=" + clanSkillId.Value.ToString() : "")
                                         + "&cct=" + clanContinentId.ToString()
                                         + "&cc=" + clanCountryId.ToString()
                                         + "&sg=" + searchGameId.ToString()
                                         + ((searchGameModeId.HasValue) ? "&sgt=" + searchGameModeId.Value.ToString() : "")
                                         + ((searchSkillId.HasValue) ? "&ss=" + searchSkillId.Value.ToString() : "")
                                         + "&sct=" + searchContinent.ToString()
                                         + ((searchCountryId.HasValue) ? "&sc=" + searchCountryId.Value.ToString() : "")
                                         + "&sxv=" + searchQueryCustomData.SearchXvs
                                         + "&svx=" + searchQueryCustomData.SearchvsX
                                         +
                                         (!string.IsNullOrEmpty(searchQueryCustomTextData.SearchMap)
                                         ? "&sm=" + Server.UrlEncode(searchQueryCustomTextData.SearchMap)
                                         : "")
                                         + "&sfd=" + Server.UrlEncode(searchQueryCustomData.SearchMatchStart) + "&option=search,chat&action=1";

                    xmlSearchUrl = xmlSearchUrl + "?option=search,chat&li= " + CurrentLangId.ToString();

                    #endregion
                }
                catch
                {
                    // nothing "error"
                }
            }
            catch
            {
            }

            #endregion
        }
    }
    public override void DataBind()
    {
        LangaugeSystem ls = new LangaugeSystem();

        CurrentUserCountry = ls.CurrentUserCountry;

        TxtClanName.Text = "GuestClan" + new Random().Next(1, 9999).ToString();


        SkillsSystem ss = new SkillsSystem();
        // !Skills!
        // check cache
        List <dynamic> getSkills = (List <dynamic>)Cache["WebSearch_getSkills" + CurrentLangId];

        if (getSkills == null)
        {
            getSkills = ss.GetSkills(CurrentLangId);
            if (getSkills != null)
            {
                // add Cache
                Cache.Add("WebSearch_getSkills" + CurrentLangId, getSkills, null, TimeZoneManager.DateTimeNow.AddDays(5),
                          System.Web.Caching.Cache.NoSlidingExpiration,
                          System.Web.Caching.CacheItemPriority.Normal,
                          null);
            }
        }

        DdlClanSkill.Items.Clear();
        DdlClanSkill.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(), string.Empty));
        DdlSearchSkill.Items.Clear();
        DdlSearchSkill.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(), string.Empty));
        foreach (dynamic g in getSkills)
        {
            DdlClanSkill.Items.Add(new ListItem(g.SearchWarSkillName, g.SearchWarSkillId.ToString()));
            DdlSearchSkill.Items.Add(new ListItem(g.SearchWarSkillName, g.SearchWarSkillId.ToString()));

            // DdlSearchSkill.Items.Add(new ListItem(currentSkill.GetAnonymousObject("SearchWarSkillName").GetValue<string>(), currentSkill.GetAnonymousObject("SearchWarSkillId").GetValue<int>().ToString()));
        }

        // !Games!
        // check cache
        GamesSystem             gs       = new GamesSystem();
        List <SW_SearchWarGame> getGames = (List <SW_SearchWarGame>)Cache["WebSearch_getGames"];

        if (getGames == null)
        {
            getGames = gs.GetGames().OrderBy(g => g.SearchWarGameName).ToList <SW_SearchWarGame>();
            if (getGames != null)
            {
                // add Cache
                Cache.Add("WebSearch_getGames", getGames, null, TimeZoneManager.DateTimeNow.AddDays(1),
                          System.Web.Caching.Cache.NoSlidingExpiration,
                          System.Web.Caching.CacheItemPriority.Normal,
                          null);
            }
        }

        DdlSearchGame.Items.Clear();
        DdlSearchGame.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(), string.Empty));
        for (int i = 0; i < getGames.Count(); i++)
        {
            var g = getGames[i];
            DdlSearchGame.Items.Add(new ListItem(g.SearchWarGameName, g.SearchWarGameId.ToString()));
        }


        DdlSearchGameType.Items.Clear();
        DdlSearchGameType.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(), string.Empty));
        HfSearchGameType.Value = DdlSearchGameType.Items.FindByText(GetLocalResourceObject("ListItemChooseResource1").ToString()).Value;


        // !Continents!
        // check cache
        ContinentSystem cs = new ContinentSystem();

        List <dynamic> getContinents = (List <dynamic>)Cache["WebSearch_getContinents" + CurrentLangId];

        if (getContinents == null)
        {
            getContinents = cs.GetContinents(CurrentLangId);
            if (getContinents != null)
            {
                // add Cache
                Cache.Add("WebSearch_getContinents" + CurrentLangId, getContinents, null, TimeZoneManager.DateTimeNow.AddDays(1),
                          System.Web.Caching.Cache.NoSlidingExpiration,
                          System.Web.Caching.CacheItemPriority.Normal,
                          null);
            }
        }
        if (getContinents != null && getContinents.Count > 0)
        {
            DdlClanContinent.Items.Clear();
            DdlClanContinent.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(),
                                                    string.Empty));

            for (int i = 0; i < getContinents.Count(); i++)
            {
                dynamic currentContinent = getContinents[i];

                DdlClanContinent.Items.Add(
                    new ListItem(currentContinent.SearchWarContinentName,
                                 currentContinent.SearchWarContinentId.ToString()));
            }
            DdlClanContinent.DataBind();


            DdlSearchContinent.Items.Clear();
            DdlSearchContinent.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(),
                                                      string.Empty));

            for (int i = 0; i < getContinents.Count(); i++)
            {
                dynamic currentContinent = getContinents[i];

                DdlSearchContinent.Items.Add(
                    new ListItem(currentContinent.SearchWarContinentName,
                                 currentContinent.SearchWarContinentId.ToString()));
            }
            DdlSearchContinent.DataBind();
        }


        // !Countries!
        CountrySystem  CS           = new CountrySystem();
        List <dynamic> getCountries = CS.GetCountries(CurrentLangId);

        if (getCountries != null && getCountries.Count > 0)
        {
            // find contient for usercountry
            for (int i = 0; i < getCountries.Count(); i++)
            {
                dynamic currentCountry = getCountries[i];

                if (CurrentUserCountry ==
                    currentCountry.SearchWarCountryTLD)
                {
                    DdlClanContinent.Items.FindByValue(
                        currentCountry.SearchWarContinentId.ToString()).
                    Selected = true;
                }
            }
            // Remove countries there is not in the continent
            getCountries =
                getCountries.Where(
                    C =>
                    C.SearchWarContinentId ==
                    Convert.ToInt32(DdlClanContinent.SelectedValue)).ToList <dynamic>();



            // Add "Select" for dropdownbox
            DdlClanCountry.Items.Clear();
            DdlClanCountry.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(),
                                                  string.Empty));

            // Loop countries
            for (int i = 0; i < getCountries.Count(); i++)
            {
                dynamic currentCountry = getCountries[i];

                // Add Country to dropdownbox
                DdlClanCountry.Items.Add(
                    new ListItem(currentCountry.SearchWarCountryName,
                                 currentCountry.SearchWarCountryId.ToString()));

                // Select current country
                if (CurrentUserCountry ==
                    currentCountry.SearchWarCountryTLD)
                {
                    // Set current country in dropdownbox
                    DdlClanCountry.Items.FindByValue(
                        currentCountry.SearchWarCountryId.ToString()).Selected
                        = true;

                    // set value in hiddenfield
                    HfClanCountry.Value =
                        DdlClanCountry.Items.FindByValue(currentCountry.SearchWarCountryId.ToString()).
                        Value;
                }
            }


            // Add "Select" for dropdownbox
            DdlSearchCountry.Items.Clear();
            DdlSearchCountry.Items.Add(new ListItem(GetLocalResourceObject("ListItemChooseResource1").ToString(),
                                                    string.Empty));
            // Loop all countries
            for (int i = 0; i < getCountries.Count(); i++)
            {
                dynamic currentCountry = getCountries[i];

                // Add country to dropdownbox
                DdlSearchCountry.Items.Add(
                    new ListItem(currentCountry.SearchWarCountryName,
                                 currentCountry.SearchWarCountryId.ToString()));

                // Select that current country
                if (CurrentUserCountry ==
                    currentCountry.SearchWarCountryTLD)
                {
                    // Set current continent for country
                    DdlSearchContinent.Items.FindByValue(
                        currentCountry.SearchWarContinentId.ToString()).Selected = true;

                    // set value for country ("empty" because the system need to search after more than one country)
                    HfSearchCountry.Value = "";
                }
            }
        }


        // !Players!
        const int maxPlayer = 16;

        DdlSearchXvsX.Items.Clear();
        for (int p = 1; p <= maxPlayer; p++)
        {
            DdlSearchXvsX.Items.Add(new ListItem(p.ToString() + GetLocalResourceObject("LblVersusResource1.Text") + p.ToString(), p.ToString() + "-" + p.ToString()));
        }
        DdlSearchXvsX.Items.FindByValue("5-5").Selected = true;

        // !DATETIME!
        TimeZoneManager timeMng = new TimeZoneManager(CurrentUserIP);

        DateTime datetimeNow         = timeMng.ConvertDateTimeFromUtc(TimeZoneManager.DateTimeNow).AddMinutes(20);
        DateTime getDateTimePlusHour = datetimeNow.AddHours(1);

        txtFromDate.Text = datetimeNow.Day.ToString("00") + "/" + datetimeNow.Month.ToString("00") + "/" + datetimeNow.Year.ToString("0000");
        amorpm.InnerText = datetimeNow.ToString("tt");
        if (CurrentLang.ToLower() == "da-dk")
        {
            txtFromTime.Text = datetimeNow.ToString("HH:mm");
            amorpm.Attributes.Add("style", "display: none");
        }
        else
        {
            txtFromTime.Text = datetimeNow.ToString("hh:mm");
        }
    }