示例#1
0
        private void button_add_item_Click(object sender, EventArgs e)
        {
            if (numericUpDown.Value < 1)
            {
                MessageBox.Show("Enter the quantity of items you want.");
                return;
            }
            ITEM addNew    = new ITEM();
            bool itemFound = false;

            foreach (var item in validItems)
            {
                if (item.item_id.ToString() == comboSelect.Text.Split('-')[0].Trim())
                {
                    itemFound = true;
                    addNew    = item;
                    break;
                }
            }
            if (!itemFound)
            {
                MessageBox.Show("Please select an item.");
                return;
            }
            if (numericUpDown.Value > addNew.quantity)
            {
                MessageBox.Show("The quantity of items you are trying to buy exceeds the amount in stock.");
                return;
            }
            addNew.quantity = Decimal.ToInt32(numericUpDown.Value);
            itemFound       = false;
            foreach (var items in Globals.cart)
            {
                if (addNew.item_id == items.item_id)
                {
                    items.quantity += addNew.quantity;
                    itemFound       = true;
                }
            }
            if (!itemFound)
            {
                Globals.cart.Add(addNew);
            }
            MessageBox.Show("Item added successfully to your cart!");
            this.Close();
        }
示例#2
0
        private void button1_Click(object sender, EventArgs e)
        {
            price_descending = !price_descending;
            validItems.Clear();
            items.Clear();
            if (!price_descending)
            {
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
                string queryStatement   = "SELECT * FROM [GROCERYBAMA1].[dbo].[item] ORDER BY listed_price";
                using (SqlConnection _con = new SqlConnection(connectionString))
                {
                    using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                    {
                        DataTable tb = new DataTable();

                        SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                        _con.Open();
                        _dap.Fill(tb);
                        _con.Close();
                        foreach (DataRow dr in tb.Rows)
                        {
                            ITEM addItem = new ITEM();
                            addItem.item_id         = Int32.Parse(dr["item_id"].ToString());
                            addItem.item_name       = dr["item_name"].ToString();
                            addItem.quantity        = Int32.Parse(dr["quantity"].ToString());
                            addItem.wholesale_price = Double.Parse(dr["wholesale_price"].ToString());
                            addItem.listed_price    = Double.Parse(dr["listed_price"].ToString());
                            addItem.food_group      = dr["food_group"].ToString();
                            addItem.description     = dr["description"].ToString();
                            addItem.exp_date        = dr["exp_date"].ToString();
                            items.Add(addItem);
                        }
                    }
                }
            }
            else
            {
                string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
                string queryStatement   = "SELECT * FROM [GROCERYBAMA1].[dbo].[item] ORDER BY listed_price DESC";
                using (SqlConnection _con = new SqlConnection(connectionString))
                {
                    using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                    {
                        DataTable tb = new DataTable();

                        SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                        _con.Open();
                        _dap.Fill(tb);
                        _con.Close();
                        foreach (DataRow dr in tb.Rows)
                        {
                            ITEM addItem = new ITEM();
                            addItem.item_id         = Int32.Parse(dr["item_id"].ToString());
                            addItem.item_name       = dr["item_name"].ToString();
                            addItem.quantity        = Int32.Parse(dr["quantity"].ToString());
                            addItem.wholesale_price = Double.Parse(dr["wholesale_price"].ToString());
                            addItem.listed_price    = Double.Parse(dr["listed_price"].ToString());
                            addItem.food_group      = dr["food_group"].ToString();
                            addItem.description     = dr["description"].ToString();
                            addItem.exp_date        = dr["exp_date"].ToString();
                            items.Add(addItem);
                        }
                    }
                }
            }
            if (counter % 5 == 0)
            {
                counter -= 5;
            }
            else
            {
                counter -= counter % 5;
            }
            DisplayItems();
        }
示例#3
0
        private void LoadAll()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
            string queryStatement   = "SELECT * FROM [GROCERYBAMA1].[dbo].[grocerystore]";

            using (SqlConnection _con = new SqlConnection(connectionString))
            {
                using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                {
                    DataTable tb = new DataTable();

                    SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                    _con.Open();
                    _dap.Fill(tb);
                    _con.Close();
                    foreach (DataRow dr in tb.Rows)
                    {
                        GROCERYSTORE addStore = new GROCERYSTORE();
                        addStore.store_id     = Int32.Parse(dr["store_id"].ToString());
                        addStore.store_name   = dr["store_name"].ToString();
                        addStore.phone        = dr["phone"].ToString();
                        addStore.address_id   = Int32.Parse(dr["address_id"].ToString());
                        addStore.opening_time = dr["opening_time"].ToString();
                        addStore.closing_time = dr["closing_time"].ToString();
                        stores.Add(addStore);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[item] ORDER BY item_name";
                using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                {
                    DataTable tb = new DataTable();

                    SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                    _con.Open();
                    _dap.Fill(tb);
                    _con.Close();
                    foreach (DataRow dr in tb.Rows)
                    {
                        ITEM addItem = new ITEM();
                        addItem.item_id         = Int32.Parse(dr["item_id"].ToString());
                        addItem.item_name       = dr["item_name"].ToString();
                        addItem.quantity        = Int32.Parse(dr["quantity"].ToString());
                        addItem.wholesale_price = Double.Parse(dr["wholesale_price"].ToString());
                        addItem.listed_price    = Double.Parse(dr["listed_price"].ToString());
                        addItem.food_group      = dr["food_group"].ToString();
                        addItem.description     = dr["description"].ToString();
                        addItem.exp_date        = dr["exp_date"].ToString();
                        items.Add(addItem);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[soldat]";
                using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                {
                    DataTable tb = new DataTable();

                    SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                    _con.Open();
                    _dap.Fill(tb);
                    _con.Close();
                    foreach (DataRow dr in tb.Rows)
                    {
                        SOLDAT addItem = new SOLDAT();
                        addItem.store_id = Int32.Parse(dr["store_id"].ToString());
                        addItem.item_id  = Int32.Parse(dr["item_id"].ToString());
                        items_sold_at.Add(addItem);
                    }
                }
            }
        }