コード例 #1
0
    protected void Page_Load(object sender, System.EventArgs e)
    {
        RegionCountriesAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "select distinct Country,Region from Countries inner join Regions on Countries.RegionID=Regions.ID " +
                                                                " inner join StateProvinces on StateProvinces.CountryID=Countries.ID " +
                                                                "where (RegionID=@RegionID)  AND EXISTS (" +
                                                                " SELECT * FROM Properties INNER JOIN Cities ON Properties.CityID = Cities.ID" +
                                                                " WHERE (Properties.IfFinished = 1) AND (Properties.IfApproved = 1)" +
                                                                " AND (Cities.StateProvinceID = StateProvinces.ID) " +
                                                                " AND NOT EXISTS (SELECT * FROM Auctions WHERE PropertyID = Properties.ID)) " +
                                                                "ORDER BY Country", SqlDbType.Int);
        StateProvincesAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "SELECT StateProvinces.* " +
                                                               "FROM StateProvinces " +
                                                               "WHERE (StateProvinces.CountryID = @CountryID) AND EXISTS (" +
                                                               " SELECT * FROM Properties INNER JOIN Cities ON Properties.CityID = Cities.ID" +
                                                               " WHERE (Properties.IfFinished = 1) AND (Properties.IfApproved = 1)" +
                                                               " AND (Cities.StateProvinceID = StateProvinces.ID) " +
                                                               " AND NOT EXISTS (SELECT * FROM Auctions WHERE PropertyID = Properties.ID)) " +
                                                               "ORDER BY StateProvince", SqlDbType.Int);
        // StateCodeInfo.Text = SqlDbType.Int.
        CitiesAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), String.Format(STR_SELECTCitiesFROMCitiesWHERECitiesStateProvinceID), SqlDbType.Int);

        const string STR_SELECTPropertiesInfo = "SELECT Properties.Name2 as PropertyName2, Properties.Name, Properties.NumBedrooms, Properties.NumBaths, Properties.NumSleeps, Properties.NumTVs, Properties.NumVCRs, Properties.CityID, Properties.NumCDPlayers, Properties.ID, CASE WHEN EXISTS (SELECT * FROM PropertiesAmenities INNER JOIN Amenities ON PropertiesAmenities.AmenityID = Amenities.ID WHERE (PropertiesAmenities.PropertyID = Properties.ID) AND (Amenities.Amenity = 'Beach Front')) THEN 'Beach Front' ELSE '' END AS BeachFront, CASE WHEN EXISTS (SELECT * FROM PropertiesAmenities INNER JOIN Amenities ON PropertiesAmenities.AmenityID = Amenities.ID WHERE (PropertiesAmenities.PropertyID = Properties.ID) AND (Amenities.Amenity = 'Seaside')) THEN 'Seaside' ELSE '' END AS Seaside, CASE WHEN EXISTS (SELECT * FROM PropertiesAmenities INNER JOIN Amenities ON PropertiesAmenities.AmenityID = Amenities.ID WHERE (PropertiesAmenities.PropertyID = Properties.ID) AND (Amenities.Amenity = 'Lake Front')) THEN 'Lake Front' ELSE '' END AS LakeFront, CASE WHEN EXISTS (SELECT * FROM PropertiesAmenities INNER JOIN Amenities ON PropertiesAmenities.AmenityID = Amenities.ID WHERE (PropertiesAmenities.PropertyID = Properties.ID) AND (Amenities.Amenity = 'River Front')) THEN 'River Front' ELSE '' END AS RiverFront, CASE WHEN EXISTS (SELECT * FROM PropertiesAmenities INNER JOIN Amenities ON PropertiesAmenities.AmenityID = Amenities.ID WHERE (PropertiesAmenities.PropertyID = Properties.ID) AND (Amenities.Amenity = 'Ski In Ski Out')) THEN 'Ski In Ski Out' ELSE '' END AS Ski, Cities.City, StateProvinces.StateProvince, Countries.Country, Regions.Region, MinimumNightlyRentalTypes.Name AS MinimumNightlyRental, PropertyTypes.Name AS Type FROM Properties INNER JOIN Cities ON Properties.CityID = Cities.ID INNER JOIN StateProvinces ON StateProvinces.ID = Cities.StateProvinceID INNER JOIN Countries ON StateProvinces.CountryID = Countries.ID INNER JOIN Regions ON Countries.RegionID = Regions.ID INNER JOIN Users ON Properties.UserID = Users.ID LEFT OUTER JOIN MinimumNightlyRentalTypes ON Properties.MinimumNightlyRentalID = MinimumNightlyRentalTypes.ID LEFT OUTER JOIN PropertyTypes ON Properties.TypeID = PropertyTypes.ID WHERE (Properties.IfFinished = 1) AND (Properties.IfApproved = 1) AND (StateProvinces.CountryID = @CountryID) AND NOT EXISTS (SELECT * FROM Auctions WHERE PropertyID = Properties.ID) ORDER BY StateProvinces.StateProvince, Cities.City, Type, CASE WHEN EXISTS (SELECT * FROM Invoices WHERE (PropertyID = Properties.ID) AND (PaymentAmount >= InvoiceAmount) AND (GETDATE() <= Invoices.RenewalDate)) THEN 1 ELSE 0 END DESC, Properties.ID";

        PropertiesAdapter  = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), String.Format(STR_SELECTPropertiesInfo), SqlDbType.Int);
        Properties2Adapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "Select * from Properties", SqlDbType.Int);

        AmenitiesAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "SELECT Amenities.ID, Amenity," +
                                                          " PropertiesAmenities.PropertyID " +
                                                          "FROM Amenities INNER JOIN PropertiesAmenities ON Amenities.ID = PropertiesAmenities.AmenityID" +
                                                          " INNER JOIN Properties ON PropertiesAmenities.PropertyID = Properties.ID " +
                                                          " INNER JOIN Cities ON Properties.CityID = Cities.ID INNER JOIN StateProvinces ON StateProvinces.ID = Cities.StateProvinceID " +
                                                          "WHERE (Properties.IfFinished = 1) AND (Properties.IfApproved = 1) AND (StateProvinces.CountryID = @CountryID)" +
                                                          " AND NOT EXISTS (SELECT * FROM Auctions WHERE PropertyID = Properties.ID) AND (Amenities.Amenity NOT IN" +
                                                          " ('Lake Front', 'Beach Front', 'River Front', 'Seaside', 'Ski In Ski Out', 'TV', 'VCR', 'CD Player'))",
                                                          SqlDbType.Int);

        LocationAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "SELECT StateProvinces.ID AS StateProvinceID," +
                                                         " StateProvinces.StateProvince, Countries.ID AS CountryID, Countries.Country, Regions.ID AS RegionID," +
                                                         " Regions.Region, Countries.titleoverride, stateprovinces.descriptionoverride " +
                                                         "FROM StateProvinces INNER JOIN Countries ON StateProvinces.CountryID = Countries.ID" +
                                                         " INNER JOIN Regions ON Countries.RegionID = Regions.ID WHERE (Countries.ID = @CountryId)",
                                                         SqlDbType.Int);

        PropertyTypesAdapter = CommonFunctions.PrepareAdapter(CommonFunctions.GetConnection(), "SELECT     PropertyTypes.Name,COUNT(*) as Count, PropertyTypes.ID " +
                                                              " FROM         Cities INNER JOIN " +
                                                              " Properties ON Cities.ID = Properties.CityID  " +
                                                              " INNER JOIN " +
                                                              " PropertyTypes ON Properties.TypeID = PropertyTypes.ID INNER JOIN " +
                                                              " StateProvinces ON Cities.StateProvinceID = StateProvinces.ID INNER JOIN " +
                                                              " Countries ON StateProvinces.CountryID = Countries.ID  WHERE (Countries.ID = @CountryId) " +
                                                              "group by PropertyTypes.Name,PropertyTypes.ID",
                                                              SqlDbType.Int);

        if ((Request.Params["CountryID"] != null))
        {
            try
            {
                countryid = Convert.ToInt32(Request.Params["CountryID"]);
            }
            catch (Exception)
            {
            }
        }

        if (countryid == -1)
        {
            Response.Redirect(CommonFunctions.PrepareURL("InternalError1.aspx"));
        }
        CitiesAdapter.SelectCommand.Parameters["@CountryId"].Value        = countryid;
        LocationAdapter.SelectCommand.Parameters["@CountryId"].Value      = countryid;
        PropertiesAdapter.SelectCommand.Parameters["@CountryId"].Value    = countryid;
        AmenitiesAdapter.SelectCommand.Parameters["@CountryId"].Value     = countryid;
        PropertyTypesAdapter.SelectCommand.Parameters["@CountryId"].Value = countryid;

        Session["CountryID"] = countryid;
        if (LocationAdapter.Fill(MainDataSet, "Location") > 0)
        {
            regionid      = (int)MainDataSet.Tables["Location"].Rows[0]["RegionID"];
            countryid     = (int)MainDataSet.Tables["Location"].Rows[0]["CountryID"];
            region        = (string)MainDataSet.Tables["Location"].Rows[0]["Region"];
            country       = (string)MainDataSet.Tables["Location"].Rows[0]["Country"];
            stateprovince = (string)MainDataSet.Tables["Location"].Rows[0]["StateProvince"];
        }
        else
        {
            Response.Redirect(CommonFunctions.PrepareURL("InternalError.aspx"));
        }

        StateProvincesAdapter.SelectCommand.Parameters["@CountryID"].Value = countryid;
        RegionCountriesAdapter.SelectCommand.Parameters["@RegionId"].Value = regionid;
        CitiesAdapter.Fill(MainDataSet, "Cities");
        PropertiesAdapter.Fill(MainDataSet, "Properties");
        Properties2Adapter.Fill(SecondaryDataSet, "Properties");
        AmenitiesAdapter.Fill(MainDataSet, "Amenities");
        StateProvincesAdapter.Fill(MainDataSet, "StateProvinces");
        PropertyTypesAdapter.Fill(MainDataSet, "PropertyTypes");
        RegionCountriesAdapter.Fill(MainDataSet, "CountriesRegion");
        DBConnection objTemp = new DBConnection();

        try
        {
            MainDataSet.Relations.Add("CitiesProperties", MainDataSet.Tables["Cities"].Columns["ID"],
                                      MainDataSet.Tables["Properties"].Columns["CityID"]);
            MainDataSet.Relations.Add("PropertiesAmenities", MainDataSet.Tables["Properties"].Columns["ID"],
                                      MainDataSet.Tables["Amenities"].Columns["PropertyID"]);
        }
        catch (Exception ex) {  }
        finally { objTemp.CloseConnection(); }

        foreach (DataRow datarow in MainDataSet.Tables["Cities"].Rows)
        {
            if (datarow["City"] is string)
            {
                cities += " " + (string)datarow["City"];
            }
        }
        HtmlHead head = Page.Header;

        DataBind();

        /////// common for postback and ! postback
        List <string> vList        = new List <string>();
        DataTable     dt           = new DataTable();
        DataTable     dtCategories = new DataTable();
        DBConnection  obj          = new DBConnection();

        try
        {
            dt = VADBCommander.CityTextInd(cityid.ToString());
        }
        catch (Exception ex) { lblInfo22.Text = ex.Message; }
        finally { obj.CloseConnection(); }

        //NO NEED TO CHECK IF EMPTY FOR BOTTOM, OK TO SHOW NOTHING


        if (!IsPostBack)
        {
            DataTable     dt1  = new DataTable();
            DataFunctions obj1 = new DataFunctions();

            try
            {
                dt1 = obj1.PropertiesByCase(vList, countryid, "Country");
                DataView dv = dt1.DefaultView;
                // dv.Sort = "minNightRate desc";
                dt1 = dv.ToTable();

                FillPropertiesBox(dt1, string.Empty);

                //create rdo items from categories table
                dtCategories = obj1.FindNumCategories(dt1);
                //int vCategoryCount = 0;


                DataView dvMax = dtCategories.DefaultView;
                // dvMax.Sort = "count desc";
                DataTable dtMax          = dvMax.ToTable();
                int       vCategoryCount = 0;
                string    firstCategory  = "";
                string    PropertyName   = "";
                string    subCategory    = "";

                foreach (DataRow row in dtMax.Rows)
                {
                    int index = dtMax.Rows.IndexOf(row);
                    if (index == 0)
                    {
                        firstCategory = row["category"].ToString();
                        subCategory   = dt1.Rows[0]["SubCategory"].ToString();
                    }
                    PropertyName = PropertyName + row["category"].ToString() + "s" + ", ";
                    string vTemp = row["category"].ToString() + " (" + row["count"].ToString() + ")";
                    vTemp = vTemp.Replace(" ", "&nbsp;");
                    //rdoTypes.Items.Add(vTemp + " ");
                    vCategoryCount = vCategoryCount + Convert.ToInt32(row["count"].ToString());
                }

                if (!IsPostBack)
                {
                    Session["t"] = dtCategories;
                }

                Page page = (Page)HttpContext.Current.Handler;

                if (dt1.Rows.Count <= 10)
                {
                    //Implement 404 logic less then 10 property with Prorerty in URL - Develop By Nimesh Sapovadiya
                    if (Request.QueryString["category"] != null)
                    {
                        Response.Clear();
                        Response.StatusCode = 404;
                        Response.End();
                    }
                    string dispString2 = "";
                    string dispString  = "";

                    if (firstCategory.Contains("_"))
                    {
                        string[] strSplit = firstCategory.Split('_');
                        dispString2 = UppercaseFirst(strSplit[0]) + " " + UppercaseFirst(strSplit[1]) + "s";
                    }
                    else
                    {
                        dispString2 = UppercaseFirst(firstCategory) + "s";
                    }

                    Session["dtRecalc"] = dt1;
                    Session["dt"]       = dt1;

                    //City_datagrid.DataSource = dt1;
                    //City_datagrid.DataBind();


                    ltrH11.Text = "Vacation Properties in " + country;


                    hyplnkCountryBackLink.NavigateUrl = "/" + country.ToLower().Replace(" ", "_") + "/default.aspx";
                    ltrCountryBackText.Text           = country + "<<";

                    page.Title = "Vacation Properties in " + country;
                }
                else
                {
                    if (Request.QueryString["category"] != null)
                    {
                        firstCategory = Convert.ToString(Request.QueryString["category"]);

                        string dispString = "";
                        if (firstCategory.Contains("_"))
                        {
                            string[] strSplit = firstCategory.Split('_');
                            dispString = UppercaseFirst(strSplit[0]) + " " + UppercaseFirst(strSplit[1]) + "s";
                            foreach (DataRow dr in dt1.Rows)
                            {
                                if (dr["Category"].ToString().ToLower().Contains(strSplit[0]))
                                {
                                    subCategory = dr["SubCategory"].ToString();
                                    break;
                                }
                            }
                        }
                        else
                        {
                            dispString = UppercaseFirst(firstCategory) + "s";
                            foreach (DataRow dr in dt1.Rows)
                            {
                                if (dr["Category"].ToString().ToLower().Equals(firstCategory))
                                {
                                    subCategory = dr["SubCategory"].ToString();
                                    break;
                                }
                            }
                        }



                        ltrH11.Text = char.ToUpper(city[0]) + city.Substring(1) + " " + dispString;

                        hyplnkCountryBackLink.NavigateUrl = "/" + country.ToLower().Replace(" ", "_") + "/default.aspx";
                        ltrCountryBackText.Text           = country + "<<";

                        page.Title = country + " " + dispString + " " + "and" + " " + char.ToUpper(city[0]) + city.Substring(1) + " " + "Property Rentals | Vacations Abroad";
                    }
                    else
                    {
                        string dispString  = "";
                        string dispString2 = "";

                        if (firstCategory.Contains("_"))
                        {
                            string[] strSplit = firstCategory.Split('_');
                            dispString2 = UppercaseFirst(strSplit[0]) + " " + UppercaseFirst(strSplit[1]) + "s";
                        }
                        else
                        {
                            dispString2 = UppercaseFirst(firstCategory) + "s";
                        }

                        ltrH11.Text = "Vacation Properties in " + country;

                        hyplnkCountryBackLink.NavigateUrl = "/" + country.ToLower().Replace(" ", "_") + "/default.aspx";
                        ltrCountryBackText.Text           = country + "<<";

                        page.Title = "Vacation Properties in " + country;
                    }
                    DataTable dtCategory = dt1.Clone();



                    foreach (DataRow dr in dt1.Rows)
                    {
                        string vTemp = dr["category"].ToString().Replace("&", "and").ToLower(); //+ " (" + dr["count"].ToString() + ")";
                                                                                                // vTemp = vTemp.Replace(" ", "&nbsp;");

                        if (vTemp.ToLower().Replace(" ", "").Trim() == firstCategory.ToLower().Replace("_", " ").Replace(" ", ""))
                        {
                            //subCategory = dr["SubCategory"].ToString();
                            dtCategory.ImportRow(dr);
                        }
                    }
                    Session["dtRecalc"] = dtCategory.DefaultView.Table;
                    Session["dt"]       = dtCategory.DefaultView.Table;

                    DataView dv1 = dtCategory.DefaultView;
                    //   dv1.Sort = "MinNightRate asc";



                    //Session["dt"] = dv1.ToTable();
                    //City_datagrid.DataSource = dv1;
                    //City_datagrid.DataBind();
                }
            }
            catch (Exception ex) { lblInfo22.Text = ex.Message; }
        }

        //add cities to right column
        DBConnection obj3 = new DBConnection();

        try
        {
            #region Cities within State
            SqlDataReader reader3 = obj3.ExecuteRecordSetArtificial("SELECT Cities.* FROM Cities WHERE (Cities.StateProvinceID = " + stateprovinceid + ") AND EXISTS ( SELECT * FROM Properties WHERE (Properties.IfFinished = 1) AND (Properties.IfApproved = 1) AND (Properties.CityID = Cities.ID)  AND NOT EXISTS (SELECT * FROM Auctions WHERE PropertyID = Properties.ID)) ORDER BY City");
            while (reader3.Read())
            {
                if (reader3["City"] is string)
                {
                    string temp = "/" + country + "/" + stateprovince + "/" + reader3["city"].ToString() + "/default.aspx";
                    temp = temp.ToLower();
                    temp = temp.Replace(' ', '_');
                }
            }
            reader3.Close();

            #endregion

            #region States within Country
            DataTable dtCountries = new DataTable();
            dtCountries = obj3.spStateProvByCountries(countryid);
            foreach (DataRow row in dtCountries.Rows)
            {
                if (row["stateprovince"] is string)
                {
                    string temp = CommonFunctions.GetSiteAddress() + "/" + country + "/" + row["stateprovince"].ToString() + "/default.aspx";
                    temp = temp.ToLower();
                    temp = temp.Replace(' ', '_');

                    // divCitiesRt.InnerHtml += "<a  href=\"" + temp + "\">" + row["stateprovince"].ToString().Replace(" ", "&nbsp;") + "</a>, ";
                }
            }
            //divCitiesRt.InnerHtml = divCitiesRt.InnerHtml.Remove(divCitiesRt.InnerHtml.Length - 2, 2);
            #endregion
        }
        catch (Exception ex) { lblInfo22.Text = ex.Message + "22"; }
        finally { obj3.CloseConnection(); }

        Session["state"]   = stateprovince;
        Session["country"] = country;


//        Page.Header.Controls.Add(new LiteralControl("<link href='http://vacations-abroad.com/css/StyleSheetBig4.css' rel='stylesheet' type='text/css' />"));
        //Page.Header.Controls.Add(new LiteralControl("<script src='http://vacations-abroad.com/wz_tooltip.js' type='text/javascript'></script>"));
    }