示例#1
0
        public string Apartment(int id)
        {
            SqlConnection conn = new SqlConnection(
                "Data Source=(local);Initial Catalog=Project;Integrated Security=SSPI");
            SqlDataReader rdr = null;

            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("select * from Buyers", conn);
                rdr = cmd.ExecuteReader();

                rdr.Read();
                Appartment temp = new Appartment("temp", "temp", 2);
                temp.Correct();
                return(temp.GetAp(Convert.ToInt32(rdr[2]), 0, "none", 0));
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
        }
示例#2
0
        public string GetAp(int H, int L, string Ad, int Nr)
        {
            SqlConnection conn = new SqlConnection(
                "Data Source=(local);Initial Catalog=Project;Integrated Security=SSPI");
            SqlDataReader     rdr    = null;
            string            output = "";
            List <Appartment> Ap     = new List <Appartment>();


            try
            {
                conn.Open();
                SqlCommand cmd = new SqlCommand("select * from Apartments", conn);
                rdr = cmd.ExecuteReader();

                while (rdr.Read())
                {
                    Appartment P = new Appartment(Convert.ToString(rdr[1]), Convert.ToString(rdr[2]), Convert.ToInt32(rdr[3]));
                    P.Id = Convert.ToInt32(rdr[0]);
                    if (P.Price < H && P.Price > L)
                    {
                        Ap.Add(P);
                    }
                    Correct();
                }
                List <Appartment> SortedList = Ap.OrderBy(o => o.Price).ToList();
                Ap.Clear();
                foreach (Appartment P in SortedList)
                {
                    if (Ad != "none" && P.Address == Ad)
                    {
                        Ap.Add(P);
                    }
                    if (Nr != 0 && P.NbOfRooms == Nr)
                    {
                        Ap.Add(P);
                    }
                    if (Nr == 0 && Ad == "none")
                    {
                        Ap.Add(P);
                    }
                }
                foreach (Appartment P in Ap)
                {
                    output += "||" + P.Id + "  " + P.Title + "  " + P.Address + "  " + P.NbOfRooms + "  " + P.Price + "||";
                }
                Correct();
                return(output);
            }
            finally
            {
                if (rdr != null)
                {
                    rdr.Close();
                }

                if (conn != null)
                {
                    conn.Close();
                }
            }
        }