コード例 #1
0
        //public SqlDataReader getNeighbourhood(int hoodId)
        //{
        //    newConnection.Open();
        //    string query = $"select * from Neighbourhood where neighbourhoodId = {hoodId}";
        //    command = new SqlCommand(query, newConnection);

        //    return command.ExecuteReader();
        //}
        public Neighbourhood getNeighbourhood2(int hoodId)
        {
            Neighbourhood hood = new Neighbourhood();

            newConnection.Open();
            string query = $"select * from Neighbourhood where neighbourhoodId = {hoodId}";

            command = new SqlCommand(query, newConnection);
            SqlDataReader reader = command.ExecuteReader();

            if (reader.HasRows)
            {
                reader.Read();
                hood.NeighbourhoodId          = reader.GetInt32(0);
                hood.CoordinateId             = reader.GetInt32(1);
                hood.Name                     = reader.GetString(2);
                hood.OveralRate               = reader.GetInt32(3);
                hood.OveralCrimeRate          = reader.GetInt32(4);
                hood.OveralTransportationRate = reader.GetInt32(5);
                hood.OveralHousingRate        = reader.GetInt32(6);
                hood.OveralEntertainmentRate  = reader.GetInt32(7);
                hood.OveralSchoolRate         = reader.GetInt32(8);
                hood.OveralShoppingRate       = reader.GetInt32(9);
                hood.Description              = reader.GetString(10);
            }

            newConnection.Close();
            return(hood);
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            Latitude = Convert.ToDouble(Session["Lat"]);
            Lngitude = Convert.ToDouble(Session["Lng"]);

            if (Session["hoodId"] != null)
            {
                Latitude = Convert.ToDouble(Session["Lat"]);
                Lngitude = Convert.ToDouble(Session["Lng"]);

                newConnection = new Connection();
                int hoodIdInt = Convert.ToInt16(Session["hoodId"]);

                hood = newConnection.getNeighbourhood2(hoodIdInt);


                //DetailsView1.DataSource = newConnection.getNeighbourhood(hoodIdInt);
                //DetailsView1.DataBind();
                //newConnection.CloseConnection();

                //hood = new Neighbourhood(); try later move entity objects using Session
                //lbl_Title.Text = Session["hoodIdReview"].ToString();
                lbl_Title.Text       = hood.Name.ToString();
                lblCrime.Text        = hood.OveralCrimeRate.ToString();
                lbl_rate.Text        = hood.OveralRate.ToString();
                lblHouse.Text        = hood.OveralHousingRate.ToString();
                lblTrans.Text        = hood.OveralTransportationRate.ToString();
                lblEnter.Text        = hood.OveralEntertainmentRate.ToString();
                lblShopping.Text     = hood.OveralShoppingRate.ToString();
                lblSchool.Text       = hood.OveralSchoolRate.ToString();
                lbl_description.Text = hood.Description.ToString();
                Session["hoodName"]  = lbl_Title.Text;

                //adding user comments


                try
                {
                    UserMasterPage masterPage = Master as UserMasterPage;
                    rptRate.DataSource = newConnection.showUserComments(masterPage, hoodIdInt);
                    rptRate.DataBind();
                    newConnection.CloseConnection();
                }
                finally
                {
                    newConnection.CloseConnection();
                }
            }
        }