Example #1
0
        private void LoadAll()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection _con = new SqlConnection(connectionString))
            {
                string queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[user]";

                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)
                    {
                        USER addUser = new USER();
                        addUser.first_name = dr["first_name"].ToString();
                        addUser.last_name  = dr["last_name"].ToString();
                        addUser.email      = dr["email"].ToString();
                        addUser.password   = dr["password"].ToString();
                        addUser.username   = dr["username"].ToString();
                        addUser.user_type  = dr["user_type"].ToString();
                        users.Add(addUser);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[systeminformation]";

                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)
                    {
                        SYSTEMINFORMATION add = new SYSTEMINFORMATION();
                        add.system_id  = Int32.Parse(dr["system_id"].ToString());
                        add.user_codes = dr["user_codes"].ToString();
                        sysinfo.Add(add);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[grocerystore]";

                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);
                    }
                }
            }
        }
Example #2
0
        private void LoadAll()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection _con = new SqlConnection(connectionString))
            {
                string queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[payment] where username = @username";

                using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                {
                    //MessageBox.Show(Globals.Persistent_Current.username);
                    _cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = Globals.Persistent_Current.username;
                    DataTable tb = new DataTable();

                    SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                    _con.Open();
                    _dap.Fill(tb);
                    _con.Close();
                    foreach (DataRow dr in tb.Rows)
                    {
                        PAYMENT addUser = new PAYMENT();
                        addUser.username       = dr["username"].ToString();
                        addUser.payment_name   = dr["payment_name"].ToString();
                        addUser.routing_number = dr["routing_number"].ToString();
                        addUser.account_number = dr["account_number"].ToString();
                        payments.Add(addUser);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[orderr]";

                using (SqlCommand _cmd = new SqlCommand(queryStatement, _con))
                {
                    //MessageBox.Show(Globals.Persistent_Current.username);
                    _cmd.Parameters.Add("@username", SqlDbType.VarChar).Value = Globals.Persistent_Current.username;
                    DataTable tb = new DataTable();

                    SqlDataAdapter _dap = new SqlDataAdapter(_cmd);

                    _con.Open();
                    _dap.Fill(tb);
                    _con.Close();
                    foreach (DataRow dr in tb.Rows)
                    {
                        int temp_id;
                        temp_id = Int32.Parse(dr["order_id"].ToString());
                        order_ids.Add(temp_id);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[user] where user_type = 'deliverer'";
                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)
                    {
                        USER addUser = new USER();
                        addUser.first_name = dr["first_name"].ToString();
                        addUser.last_name  = dr["last_name"].ToString();
                        addUser.email      = dr["email"].ToString();
                        addUser.password   = dr["password"].ToString();
                        addUser.username   = dr["username"].ToString();
                        addUser.user_type  = dr["user_type"].ToString();
                        deliverers.Add(addUser);
                    }
                }
            }
            foreach (var item in payments)
            {
                comboPaymentType.Items.Add(item.payment_name);
            }
            double totalPrice = 0;

            foreach (var item in Globals.cart)
            {
                totalPrice += item.quantity * item.listed_price;
                totalItems += item.quantity;
            }
            textTotalPrice.Text = totalPrice.ToString();
        }
Example #3
0
        private void button_finalize_Click(object sender, EventArgs e)
        {
            foreach (var i in order_ids)
            {
                if (i > orderId)
                {
                    orderId = i;
                }
            }
            orderId++;
            if (String.IsNullOrWhiteSpace(comboDeliveryTime.Text))
            {
                MessageBox.Show("Please enter a time for delivery.");
                return;
            }

            if (String.IsNullOrWhiteSpace(comboPaymentType.Text))
            {
                MessageBox.Show("Please enter a payment type.");
                return;
            }
            persistent_deliverer = deliverers.OrderBy(x => Guid.NewGuid()).FirstOrDefault();
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection _con = new SqlConnection(connectionString))
            {
                string query = "INSERT INTO [GROCERYBAMA1].[dbo].[ORDERR] VALUES (@order_id, @delivery_instructions, @delivery_time, @current_date, @current_time);";
                using (SqlCommand command = new SqlCommand(query, _con))
                {
                    if (String.IsNullOrWhiteSpace(textDeliveryInstructions.Text))
                    {
                        command.Parameters.Add("@delivery_instructions", SqlDbType.VarChar).Value = "NULL";
                    }
                    else
                    {
                        command.Parameters.Add("@delivery_instructions", SqlDbType.VarChar).Value = textDeliveryInstructions.Text;
                    }
                    command.Parameters.Add("@order_id", SqlDbType.Int).Value          = orderId;
                    command.Parameters.Add("@delivery_time", SqlDbType.VarChar).Value = comboDeliveryTime.Text;
                    command.Parameters.Add("@current_date", SqlDbType.VarChar).Value  = DateTime.Now.ToString("yyyy-MM-dd");
                    command.Parameters.Add("@current_time", SqlDbType.VarChar).Value  = DateTime.Now.ToString("HH:mm");
                    _con.Open();
                    int result = command.ExecuteNonQuery();
                    _con.Close();

                    if (result < 0)
                    {
                        MessageBox.Show("There was an error.");
                    }
                }
                query = "INSERT INTO [GROCERYBAMA1].[dbo].[ORDERFROM] VALUES (@store_id, @order_id);";
                using (SqlCommand command = new SqlCommand(query, _con))
                {
                    command.Parameters.Add("@order_id", SqlDbType.Int).Value = orderId;
                    command.Parameters.Add("@store_id", SqlDbType.Int).Value = Globals.Chosen_Store.store_id;
                    _con.Open();
                    int result = command.ExecuteNonQuery();
                    _con.Close();

                    if (result < 0)
                    {
                        MessageBox.Show("There was an error.");
                    }
                }
                query = "INSERT INTO [GROCERYBAMA1].[dbo].[ORDERED_BY] VALUES (@order_id, @username);";
                using (SqlCommand command = new SqlCommand(query, _con))
                {
                    command.Parameters.Add("@order_id", SqlDbType.Int).Value     = orderId;
                    command.Parameters.Add("@username", SqlDbType.VarChar).Value = Globals.Persistent_Current.username;

                    _con.Open();
                    int result = command.ExecuteNonQuery();
                    _con.Close();

                    if (result < 0)
                    {
                        MessageBox.Show("There was an error.");
                    }
                }
                query = "INSERT INTO [GROCERYBAMA1].[dbo].[DELIVEREDBY] VALUES (@order_id, @deliverer_username, '0', NULL, NULL);";
                using (SqlCommand command = new SqlCommand(query, _con))
                {
                    command.Parameters.Add("@order_id", SqlDbType.Int).Value = orderId;
                    command.Parameters.Add("@deliverer_username", SqlDbType.VarChar).Value = persistent_deliverer.username;
                    _con.Open();
                    int result = command.ExecuteNonQuery();
                    _con.Close();

                    if (result < 0)
                    {
                        MessageBox.Show("There was an error.");
                    }
                }
                foreach (var item in Globals.cart)
                {
                    query = "INSERT INTO [GROCERYBAMA1].[dbo].[SELECTITEM] VALUES (@item_id, @quantity, @order_id);";
                    using (SqlCommand command = new SqlCommand(query, _con))
                    {
                        command.Parameters.Add("@item_id", SqlDbType.Int).Value  = item.item_id;
                        command.Parameters.Add("@quantity", SqlDbType.Int).Value = item.quantity;
                        command.Parameters.Add("@order_id", SqlDbType.Int).Value = orderId;

                        _con.Open();
                        int result = command.ExecuteNonQuery();
                        _con.Close();

                        if (result < 0)
                        {
                            MessageBox.Show("There was an error.");
                        }
                    }
                }
                string receipt = "Order successfully submitted. Here is your receipt.\n\nOrder Number: " + orderId + "\nPayment Name: " + comboPaymentType.Text
                                 + "\nDeliverer's Name: " + persistent_deliverer.first_name + "\nNumber of Items: " + totalItems + "\nTime Order Placed: " + DateTime.Now.ToString("HH:mm") + "\nTime of Delivery: " + comboDeliveryTime.Text;
                MessageBox.Show(receipt);
                Globals.cart.Clear();
                this.Close();
            }
        }
Example #4
0
        private void LoadAll()
        {
            string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["Default"].ConnectionString;

            using (SqlConnection _con = new SqlConnection(connectionString))
            {
                string queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[user]";

                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)
                    {
                        USER addUser = new USER();
                        addUser.first_name = dr["first_name"].ToString();
                        addUser.last_name  = dr["last_name"].ToString();
                        addUser.email      = dr["email"].ToString();
                        addUser.password   = dr["password"].ToString();
                        addUser.username   = dr["username"].ToString();
                        addUser.user_type  = dr["user_type"].ToString();
                        users.Add(addUser);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[buyer]";

                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)
                    {
                        BUYER addBuyer = new BUYER();
                        addBuyer.phone            = dr["phone"].ToString();
                        addBuyer.address          = Int32.Parse(dr["address_id"].ToString());
                        addBuyer.default_payment  = dr["default_payment"].ToString();
                        addBuyer.default_store_id = Int32.Parse(dr["default_store_id"].ToString());
                        addBuyer.username         = dr["username"].ToString();
                        buyers.Add(addBuyer);
                    }
                }

                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[address]";

                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)
                    {
                        ADDRESS addAddress = new ADDRESS();
                        addAddress.id           = Int32.Parse(dr["id"].ToString());
                        addAddress.house_number = dr["house_number"].ToString();
                        addAddress.state        = dr["state"].ToString();
                        addAddress.street       = dr["street"].ToString();
                        addAddress.city         = dr["city"].ToString();
                        addAddress.zip_code     = dr["zip_code"].ToString();
                        addresses.Add(addAddress);
                    }
                }
                queryStatement = "SELECT * FROM [GROCERYBAMA1].[dbo].[grocerystore]";

                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);
                    }
                }
            }
        }