예제 #1
0
        public List <ShoppingCartDetails> dbGetShoppingCart(string id)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            List <ShoppingCartDetails> listShoppingCartDetails = new List <ShoppingCartDetails>();
            SqlCommand cmd = new SqlCommand("SELECT * FROM [ShoppingCart] INNER JOIN [Groceries] ON ShoppingCart.GroceryName=Groceries.Name WHERE GroupID=@id", con);

            cmd.Parameters.Add("@id", System.Data.SqlDbType.VarChar).Value = id;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ShoppingCartDetails shoppingCart = new ShoppingCartDetails();
                GroceryDetails      grocery      = new GroceryDetails();
                shoppingCart.Amount  = float.Parse(reader.GetValue(0).ToString());
                shoppingCart.GroupID = reader.GetValue(2).ToString();
                grocery.Name         = reader.GetValue(3).ToString();
                grocery.Image        = null;
                grocery.Unit         = reader.GetValue(5).ToString();
                grocery.Category     = reader.GetValue(6).ToString();
                shoppingCart.Grocery = grocery;
                listShoppingCartDetails.Add(shoppingCart);
            }
            reader.Close();
            cmd.Dispose();
            con.Close();
            return(listShoppingCartDetails);
        }
예제 #2
0
        public List <ContainsDetails> dbGetContains(int IdRecepta)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            List <ContainsDetails> listContainsDetails = new List <ContainsDetails>();
            SqlCommand             cmd = new SqlCommand("SELECT * FROM [Contain] INNER JOIN [Groceries] ON Contain.GroceryName=Groceries.Name WHERE RecipeID=@ID", con);

            cmd.Parameters.Add("@ID", SqlDbType.Int).Value = IdRecepta;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                ContainsDetails contains = new ContainsDetails();
                GroceryDetails  grocery  = new GroceryDetails();
                contains.Amount   = float.Parse(reader.GetValue(2).ToString());
                contains.RecipeID = int.Parse(reader.GetValue(1).ToString());
                grocery.Image     = null;
                grocery.Name      = reader.GetValue(3).ToString();
                grocery.Unit      = reader.GetValue(5).ToString();
                grocery.Category  = reader.GetValue(6).ToString();
                contains.Grocery  = grocery;
                listContainsDetails.Add(contains);
            }
            reader.Close();
            cmd.Dispose();
            con.Close();
            return(listContainsDetails);
        }
예제 #3
0
        public List <AvailableGroceriesDetails> dbGetAvailableGroceries(string id)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            List <AvailableGroceriesDetails> listAvailableGroceries = new List <AvailableGroceriesDetails>();
            SqlCommand cmd = new SqlCommand("SELECT * FROM [AvailableGroceries] INNER JOIN [Groceries] ON AvailableGroceries.GroceryName=Groceries.Name WHERE GroupID=@id", con);

            cmd.Parameters.Add("@id", System.Data.SqlDbType.VarChar).Value = id;
            SqlDataReader reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                AvailableGroceriesDetails availableGroceries = new AvailableGroceriesDetails();
                GroceryDetails            grocery            = new GroceryDetails();
                availableGroceries.Amount  = float.Parse(reader.GetValue(0).ToString());
                availableGroceries.GroupID = reader.GetValue(2).ToString();
                grocery.Name = reader.GetValue(3).ToString();
                if (reader.GetValue(4) != null)
                {
                    grocery.Image = Convert.FromBase64String(reader.GetValue(4).ToString());
                }
                grocery.Unit               = reader.GetValue(5).ToString();
                grocery.Category           = reader.GetValue(6).ToString();
                availableGroceries.Grocery = grocery;
                listAvailableGroceries.Add(availableGroceries);
            }
            reader.Close();
            cmd.Dispose();
            con.Close();
            return(listAvailableGroceries);
        }
예제 #4
0
        public void loadGrocerie(GroceryDetails grocery)
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            SqlCommand cmd = new SqlCommand("INSERT into [Groceries](Name,Unit,Category) VALUES(@Name,@Unit,@Category)", con);

            cmd.Parameters.Add("@Name", System.Data.SqlDbType.VarChar).Value     = grocery.Name;
            cmd.Parameters.Add("@Unit", System.Data.SqlDbType.VarChar).Value     = grocery.Unit;
            cmd.Parameters.Add("@Category", System.Data.SqlDbType.VarChar).Value = grocery.Category;
            int test = cmd.ExecuteNonQuery();

            cmd.Dispose();
            con.Close();
        }
예제 #5
0
        public List <GroceryDetails> dbGetgroceriesName()
        {
            if (con.State != System.Data.ConnectionState.Open)
            {
                con.Open();
            }
            List <GroceryDetails> lista  = new List <GroceryDetails>();
            SqlCommand            cmd    = new SqlCommand("SELECT * FROM [Groceries]", con);
            SqlDataReader         reader = cmd.ExecuteReader();

            while (reader.Read())
            {
                GroceryDetails grocery = new GroceryDetails();
                grocery.Name     = reader.GetValue(0).ToString();
                grocery.Image    = null;
                grocery.Unit     = reader.GetValue(2).ToString();
                grocery.Category = reader.GetValue(3).ToString();
                lista.Add(grocery);
            }
            reader.Close();
            cmd.Dispose();
            con.Close();
            return(lista);
        }