Exemplo n.º 1
0
        public static void DeleteAllOrder(ProductCL b)
        {
            try
            {

                SqlCommand cmd = new SqlCommand("Delete OrderDetails where ProductID = @ProductID", con);
                cmd.Parameters.AddWithValue("@ProductID", b.ProductID);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Exemplo n.º 2
0
        public static void productUpdate(ProductCL a)
        {
            try
            {
                string cm = "Update Products set ProductName = @ProductName,SupplierID = @SupplierID,UnitPrice = @UnitPrice  " + "where ProductID = " + a.ProductID;

                SqlCommand cmd = new SqlCommand(cm, con);
                cmd.Parameters.AddWithValue("@ProductName", a.ProductName);
                cmd.Parameters.AddWithValue("@SupplierID", a.SupplierId);
                cmd.Parameters.AddWithValue("@UnitPrice", a.Price);

                con.Open();
                cmd.ExecuteNonQuery();
                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }
Exemplo n.º 3
0
        public static List<ProductCL> getAllProductSell()
        {
            List<ProductCL> ware = new List<ProductCL>();

            try
            {
                SqlCommand cmd = new SqlCommand("select Products.ProductID,Products.ProductName,Suppliers.CompanyName,Products.UnitPrice from Products, Suppliers where Products.SupplierID = Suppliers.SupplierID", con);
                con.Open();
                SqlDataReader dr = cmd.ExecuteReader();
                if (!dr.HasRows)
                {
                    ware = null;
                }
                else
                {
                    while (dr.Read())
                    {
                        int id = int.Parse(dr[0].ToString());
                        string name = dr[1].ToString();
                        string supName = dr[2].ToString();
                        double price = double.Parse(dr[3].ToString());
                        ProductCL pro = new ProductCL(id, name, supName, price);
                        ware.Add(pro);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            finally
            {
                con.Close();
            }
            return ware;
        }
Exemplo n.º 4
0
        private void button6_Click(object sender, EventArgs e)
        {
            if (button6.Text.Equals("Add"))
            {
                button6.Text = "Save";
                button5.Text = "Cancel";
                button4.Enabled = false;
                textBox10.Text = "" + (SelectDA.GetMax("ProductID", "Products") + 1);
                textBox9.Enabled = true;
                comboBox2.Enabled = true;
                textBox8.Enabled = true;
                return;
            }

            if (button6.Text.Equals("Save"))
            {
                ProductCL a = new ProductCL();
                a.ProductID = SelectDA.GetMax("ProductID", "Products") + 1;
                a.ProductName = textBox9.Text;
                SelectDA.ComboboxItem selectedCar = (SelectDA.ComboboxItem)comboBox2.SelectedItem;
                int selecteVal = Convert.ToInt32(selectedCar.Value);
                a.SupplierId = selecteVal;
                try
                {
                    a.Price = int.Parse(textBox8.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Wrong input for Unit Price !");
                }
                InsertDA.insertProduct(a);
                DataSet ds = SelectDA.SelectDS("SELECT ProductID,ProductName,CompanyName,UnitPrice FROM Products,Suppliers WHERE Products.SupplierID = Suppliers.SupplierID");
                DataView dv = new DataView(ds.Tables[0]);
                dataGridView3.DataSource = dv;
                textBox10.Enabled = false;
                textBox9.Enabled = false;
                comboBox2.Enabled = false;
                textBox8.Enabled = false;
                button6.Text = "Add";
                button5.Text = "Edit";
                button4.Enabled = true;
                textBox10.Text = "";
                textBox9.Text = "";
                textBox8.Text = "";
                comboBox2.SelectedIndex = 0;
                return;
            }
        }
Exemplo n.º 5
0
        private void button5_Click(object sender, EventArgs e)
        {
            if (button5.Text.Equals("Cancel"))
            {
                textBox10.Text = "";
                textBox9.Text = "";
                textBox8.Text = "";
                comboBox2.SelectedIndex = 0;
                textBox10.Enabled = false;
                textBox9.Enabled = false;
                comboBox2.Enabled = false;
                textBox8.Enabled = false;
                button6.Text = "Add";
                button5.Text = "Edit";
                button4.Enabled = true;
                return;
            }

            if (button5.Text.Equals("Edit"))
            {

                try
                {
                    textBox10.Text = "" + int.Parse(dataGridView3.SelectedRows[0].Cells["ProductID"].Value.ToString());
                    textBox9.Text = dataGridView3.SelectedRows[0].Cells["ProductName"].Value.ToString();
                    //comboBox2.SelectedIndex = comboBox2.Items.IndexOf(int.Parse(dataGridView1.SelectedRows[0].Cells["SupplierID"].Value.ToString()));
                    comboBox2.Text = dataGridView3.SelectedRows[0].Cells["CompanyName"].Value.ToString();
                    textBox8.Text = "" + int.Parse(dataGridView3.SelectedRows[0].Cells["UnitPrice"].Value.ToString());
                }
                catch (Exception)
                {
                    MessageBox.Show("You must select a Product !");
                    return;
                }

                button6.Enabled = false;
                button5.Text = "Save";
                button4.Text = "Cancel";
                textBox9.Enabled = true;
                comboBox2.Enabled = true;
                textBox8.Enabled = true;
                dataGridView3.Enabled = false;
                return;
            }

            if (button5.Text.Equals("Save"))
            {
                ProductCL a = new ProductCL();
                a.ProductID = int.Parse(textBox10.Text);
                a.ProductName = textBox9.Text;
                SelectDA.ComboboxItem selectedCar = (SelectDA.ComboboxItem)comboBox2.SelectedItem;
                int selecteVal = Convert.ToInt32(selectedCar.Value);
                a.SupplierId = selecteVal;
                try
                {
                    a.Price = int.Parse(textBox8.Text);
                }
                catch (Exception)
                {
                    MessageBox.Show("Wrong input for Unit Price !");
                }
                UpdateDA.productUpdate(a);
                DataSet ds = SelectDA.SelectDS("SELECT ProductID,ProductName,CompanyName,UnitPrice FROM Products,Suppliers WHERE Products.SupplierID = Suppliers.SupplierID");
                DataView dv = new DataView(ds.Tables[0]);
                dataGridView3.DataSource = dv;
                textBox10.Enabled = false;
                textBox9.Enabled = false;
                comboBox2.Enabled = false;
                textBox8.Enabled = false;
                textBox10.Text = "";
                textBox9.Text = "";
                textBox8.Text = "";
                comboBox2.SelectedIndex = 0;
                button4.Text = "Delete";
                button5.Text = "Edit";
                button6.Enabled = true;
                dataGridView3.Enabled = true;
                return;
            }
        }
Exemplo n.º 6
0
        private void button4_Click(object sender, EventArgs e)
        {
            if (button4.Text.Equals("Cancel"))
            {
                textBox10.Text = "";
                textBox9.Text = "";
                textBox8.Text = "";
                comboBox2.SelectedIndex = 0;
                textBox10.Enabled = false;
                textBox9.Enabled = false;
                comboBox2.Enabled = false;
                textBox8.Enabled = false;
                button6.Text = "Add";
                button5.Text = "Edit";
                button4.Text = "Delete";
                button6.Enabled = true;
                dataGridView3.Enabled = true;
                return;
            }

            if (button4.Text.Equals("Delete"))
            {
                ProductCL a = new ProductCL();
                try
                {
                    a.ProductID = int.Parse(dataGridView3.SelectedRows[0].Cells["ProductID"].Value.ToString());

                }
                catch (Exception)
                {
                    MessageBox.Show("You must select a Product !");
                    return;
                }
                DialogResult result = MessageBox.Show("Do you want to DELETE this product ?", "Confirm", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    DeleteDA.DeleteAllOrder(a);
                    DeleteDA.DeleteProduct(a);
                    DataSet ds = SelectDA.SelectDS("SELECT ProductID,ProductName,CompanyName,UnitPrice FROM Products,Suppliers WHERE Products.SupplierID = Suppliers.SupplierID");
                    DataView dv = new DataView(ds.Tables[0]);
                    dataGridView3.DataSource = dv;
                }
                else
                {
                    return;
                }

            }
        }
Exemplo n.º 7
0
        public static void insertProduct(ProductCL a)
        {
            try
            {

                SqlCommand cmd = new SqlCommand("SET IDENTITY_INSERT Products ON Insert into Products(ProductID,ProductName,SupplierID,UnitPrice) " +
                "values(@ProductID,@ProductName,@SupplierID,@UnitPrice)", con);
                cmd.Parameters.AddWithValue("@ProductID", a.ProductID);
                cmd.Parameters.AddWithValue("@ProductName", a.ProductName);
                cmd.Parameters.AddWithValue("@SupplierID", a.SupplierId);
                cmd.Parameters.AddWithValue("@UnitPrice", a.Price);

                con.Open();

                cmd.ExecuteNonQuery();
                con.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
                return;
            }
        }