private void btnCancelProduct_Click(object sender, EventArgs e)
        {
            this.Hide();
            ChooseProducts chp = new ChooseProducts(clientID, orderID, index);

            chp.ShowDialog();
            this.Close();
        }
        private void btnAddProductToCart_Click(object sender, EventArgs e)
        {
            if (txtQuantity.Text == "")
            {
                MessageBox.Show("Please enter quantity");
            }
            else
            {
                SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-P74G1IQ\SQLEXPRESS;Initial Catalog=GroceryStore;Integrated Security=True");
                con.Open();


                SqlCommand newCmd = new SqlCommand("INSERT INTO Product_Order (Order_ID, Product_ID, Product_Quantity) VALUES (@OrderID, @ProductID, @Quantity)", con);

                newCmd.Parameters.Add("@OrderID", SqlDbType.Int)
                .Value = orderID;

                newCmd.Parameters.Add("@ProductID", SqlDbType.Int)
                .Value = value;

                newCmd.Parameters.Add("@Quantity", SqlDbType.Decimal)
                .Value = System.Convert.ToDecimal(txtQuantity.Text);

                try
                {
                    newCmd.ExecuteNonQuery();
                }
                catch (Exception)
                {
                    MessageBox.Show("You already added " + lblProductName.Text + " to your cart");
                    this.Close();
                }
                SqlCommand cmd1 = new SqlCommand("select Order_ID from \"Order\" where (Client_ID = '" + clientID + "')", con);

                SqlDataReader reader = cmd1.ExecuteReader();
                while (reader.Read())
                {
                    orderID = reader.GetInt32(0);
                }

                con.Close();
                this.Hide();
                ChooseProducts chp = new ChooseProducts(clientID, orderID, index);
                chp.ShowDialog();
                this.Close();
            }
        }
Example #3
0
        private void pictureBox2_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=DESKTOP-P74G1IQ\SQLEXPRESS;Initial Catalog=GroceryStore;Integrated Security=True");

            con.Open();
            SqlCommand command = new SqlCommand("insert into \"Order\" (Client_ID, Order_Date) values ('" + clientID + "', GetDate())", con);
            SqlCommand cmd1    = new SqlCommand("select Order_ID from \"Order\" where (Client_ID = '" + clientID + "')", con);

            command.ExecuteNonQuery();
            SqlDataReader reader = cmd1.ExecuteReader();

            while (reader.Read())
            {
                orderID = reader.GetInt32(0);
            }
            con.Close();
            index = 2;

            this.Hide();
            ChooseProducts cp = new ChooseProducts(clientID, orderID, index);

            cp.ShowDialog();
            this.Close();
        }