示例#1
0
 public void Delete(Drink entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("DELETE FROM Drinks where DrinkId = @DrinkId"))
     {
         cmd.Parameters.AddWithValue("DrinkId", entity.DrinkId);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
示例#2
0
 public void Add(Drink entity)
 {
     using (SqlCommand cmd = new SqlCommand("INSERT INTO Drinks (Name,perPackage,UnitPrice) VALUES (@Name,@perPackage,@UnitPrice)"))
     {
         cmd.Parameters.AddWithValue("Name", entity.Name);
         cmd.Parameters.AddWithValue("perPackage", entity.perPackage);
         cmd.Parameters.AddWithValue("UnitPrice", entity.UnitPrice);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
示例#3
0
 public void Update(Drink entity)
 {
     using (SqlCommand cmd =
                new SqlCommand("UPDATE Drinks set Name = @Name, perPackage = @perPackage, UnitPrice = @UnitPrice where DrinkId = @DrinkId"))
     {
         cmd.Parameters.AddWithValue("DrinkId", entity.DrinkId);
         cmd.Parameters.AddWithValue("Name", entity.Name);
         cmd.Parameters.AddWithValue("perPackage", entity.perPackage);
         cmd.Parameters.AddWithValue("UnitPrice", entity.UnitPrice);
         VTYS.SqlExecuteNonQuery(cmd);
     }
 }
示例#4
0
        public List <Drink> GetAll()
        {
            var        drinkList = new List <Drink>();
            SqlCommand cmd       = new SqlCommand("Select * from Drinks");

            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Drink drink = new Drink
                {
                    DrinkId    = Convert.ToInt32(reader[0]),
                    Name       = reader[1].ToString(),
                    perPackage = double.Parse(reader[2].ToString()),
                    UnitPrice  = decimal.Parse(reader[3].ToString())
                };

                drinkList.Add(drink);
            }
            return(drinkList);
        }
示例#5
0
        public Drink Get(int id)
        {
            SqlCommand cmd = new SqlCommand("Select * from Drinks where DrinkId=@DrinkId");

            cmd.Parameters.AddWithValue("DrinkId", id);
            SqlDataReader reader = VTYS.SqlExecuteReader(cmd);

            while (reader.Read())
            {
                Drink drink = new Drink
                {
                    DrinkId    = Convert.ToInt32(reader[0]),
                    Name       = reader[1].ToString(),
                    perPackage = double.Parse(reader[2].ToString()),
                    UnitPrice  = decimal.Parse(reader[3].ToString())
                };

                return(drink);
            }
            return(null);
        }