Beispiel #1
0
        protected void Button1_Click2(object sender, EventArgs e)
        {
            var s = new Service1();
            var b = new Bike();

            int ID = Int32.Parse(IDBike.Text);

            b = s.FindBikeById(ID);

            Name.Text = b.Name;
            Category.Text = b.Category;
        }
Beispiel #2
0
        public List<Bike> SortByPrice(List<Bike> bikes)
        {
            List<Bike> sortedBikes = new List<Bike>();
            Bike aux = new Bike();

            for(int i = 0; i < bikes.Count - 1; i++)
            {
                for(int j = i + 1; j < bikes.Count; j++)
                {
                    if(bikes[i].Price > bikes[j].Price)
                    {
                        aux = bikes[j];
                        bikes[j] = bikes[i];
                        bikes[i] = aux;
                    }
                }
            }
            sortedBikes = bikes;

            return sortedBikes;
        }
Beispiel #3
0
 public Bike FindBikeById(int IDBike)
 {
     Bike b = new Bike();
     using (SqlConnection myConnection = new SqlConnection(cnStr))
     {
         string q = " Select * From Bike where IDBike=@IDBike";
         SqlCommand myCommand = new SqlCommand(q, myConnection);
         myCommand.Parameters.AddWithValue("@IDBike", IDBike);
         myConnection.Open();
         using (SqlDataReader myDataReader = myCommand.ExecuteReader())
         {
             if (myDataReader != null)
             {
                 while (myDataReader.Read())
                 {
                     string strId = myDataReader["IDBike"].ToString();
                     b.IDBike = Int32.Parse(strId);
                     b.Name = myDataReader["Name"].ToString();
                     b.Category = myDataReader["Category"].ToString();
                     b.Brand = myDataReader["Brand"].ToString();
                     string strPrice = myDataReader["Price"].ToString();
                     b.Price = Int32.Parse(strPrice);
                     string bWeight = myDataReader["BWeight"].ToString();
                     b.BWeight = float.Parse(bWeight);
                     string strSize = myDataReader["Size"].ToString();
                     b.Size = Int32.Parse(strSize);
                     b.Gender = myDataReader["Gender"].ToString();
                     b.Material = myDataReader["Material"].ToString();
                     b.Colour = myDataReader["Colour"].ToString();
                     string strWsize = myDataReader["WheelSize"].ToString();
                     b.WheelSize = Int32.Parse(strSize);
                     b.Features = myDataReader["Features"].ToString();
                 }
             }
             myConnection.Close();
         }
     }
     return b;
 }
Beispiel #4
0
 public OrderLineBike(Bike Bike, int Amount)
 {
     this.Bike = Bike;
     this.Amount = Amount;
 }
Beispiel #5
0
 public void InsertBike(Bike b)
 {
     bikeCtr.InsertBike(b.IDBike, b.Name, b.Category, b.Brand, b.Price, b.BWeight, b.Size, b.Gender, b.Material, b.Colour, b.WheelSize, b.Features);
 }
Beispiel #6
0
        public List<Bike> GetBikes()
        {
            List<Bike> bikes  = new List<Bike>();
            using (SqlConnection myConnection = new SqlConnection(cnStr))
            {
                string q = " Select * From Bike ";
                SqlCommand myCommand = new SqlCommand(q, myConnection);
                myConnection.Open();
                using (SqlDataReader myDataReader = myCommand.ExecuteReader())
                {
                    if (myDataReader != null)
                    {
                        while (myDataReader.Read())
                        {
                            Bike b = new Bike();
                            string strId = myDataReader["IDBike"].ToString();
                            b.IDBike = Int32.Parse(strId);
                            b.Name = myDataReader["Name"].ToString();
                            b.Category = myDataReader["Category"].ToString();
                            b.Brand = myDataReader["Brand"].ToString();
                            string strPrice = myDataReader["Price"].ToString();
                            b.Price = Int32.Parse(strPrice);
                            string bWeight = myDataReader["BWeight"].ToString();
                            b.BWeight = float.Parse(bWeight);
                            string strSize = myDataReader["Size"].ToString();
                            b.Size = Int32.Parse(strSize);
                            b.Gender = myDataReader["Gender"].ToString();
                            b.Material = myDataReader["Material"].ToString();
                            b.Colour = myDataReader["Colour"].ToString();
                            string strWsize = myDataReader["WheelSize"].ToString();
                            b.WheelSize = Int32.Parse(strSize);
                            b.Features = myDataReader["Features"].ToString();

                            bikes.Add(b);
                        }
                    }
                    myConnection.Close();
                }
            }
            return bikes;
        }