예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            var inForm = new ListandSearch();

            inForm.Show();
            Close();
        }
예제 #2
0
        private void btnClose_Click(object sender, EventArgs e)
        {
            Close();
            ListandSearch listandSearch = new ListandSearch();

            listandSearch.Show();
        }
예제 #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (dataGridView1.SelectedRows.Count != 0)
            {
                var result = MessageBox.Show("Do you want to delete this product?", "Delete Product",
                                             MessageBoxButtons.YesNo, MessageBoxIcon.Question);

                if (result == DialogResult.Yes)
                {
                    var row = dataGridView1.SelectedRows[0];
                    var id  = row.Cells["Id"].Value.ToString();

                    var oleDbConnection = new OleDbConnection(Global.connString);

                    var update = new OleDbCommand("DELETE FROM Stock WHERE ID = " + id + "", oleDbConnection);

                    oleDbConnection.Open();

                    update.ExecuteNonQuery();
                    oleDbConnection.Close();

                    oleDbConnection.Open();
                    var adapt = new OleDbDataAdapter($@"SELECT * FROM Stock WHERE Product LIKE '%{txtSearch.Text}%'",
                                                     oleDbConnection);
                    var dt = new DataTable();
                    adapt.Fill(dt);
                    dataGridView1.DataSource = dt;
                    oleDbConnection.Close();
                    var list = new ListandSearch();
                    Close();
                    list.Show();
                }
            }
        }
예제 #4
0
        private void listProductsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var listfrm = new ListandSearch();

            listfrm.MdiParent     = this;
            listfrm.StartPosition = FormStartPosition.CenterScreen;
            listfrm.Show();
        }
예제 #5
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (txtProductName.Text != "" && txtCost.Text != "" && txtCategory.Text != "" && txtQuantity.Text != "")
            {
                Product  = txtProductName.Text;
                Cost     = double.Parse(txtCost.Text.Replace('.', ','));
                Quantity = int.Parse(txtQuantity.Text);
                Category = txtCategory.Text;
                UpdateProduct(); // roep die method hier
                Close();

                ListandSearch listandSearch = new ListandSearch();
                listandSearch.Show();
            }
            else
            {
                MessageBox.Show("Please enter values into all field", "Missing Entry", MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
예제 #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (!Validation.ProductName(txtProduct.Text))
            {
                lblProduct.ForeColor = Color.Red;
            }
            else
            {
                lblProduct.ForeColor = Color.Black;
            }


            if (!Validation.Cost(txtCost.Text))
            {
                lblCost.ForeColor = Color.Red;
            }
            else
            {
                lblCost.ForeColor = Color.Black;
            }

            if (!Validation.Quantity(txtQuantity.Text))
            {
                lblQuantity.ForeColor = Color.Red;
            }
            else
            {
                lblQuantity.ForeColor = Color.Black;
            }
            if (!Validation.CategoryName(txtCategory.Text))
            {
                lblCategory.ForeColor = Color.Red;
            }
            else
            {
                lblCategory.ForeColor = Color.Black;
            }

            if (Validation.ProductName(txtProduct.Text) && Validation.Cost(txtCost.Text) &&
                Validation.Quantity(txtQuantity.Text) &&
                Validation.CategoryName(txtCategory.Text))
            {
                if (Validation.Cost(txtCost.Text) && Validation.Quantity(txtQuantity.Text))
                {
                    insProduct  = txtProduct.Text;
                    insQuantity = Convert.ToInt16(txtQuantity.Text);
                    insCategory = txtCategory.Text;
                    double insCost = Convert.ToDouble(txtCost.Text.Replace('.', ','));

                    var oleDbConnection = new OleDbConnection(Global.connString);
                    oleDbConnection.Open();
                    var insert = new OleDbCommand(
                        @"Insert Into Stock(Product,Cost,Quantity,Category)Values('" + insProduct + "','" +
                        insCost + "'," + insQuantity + ",'" + insCategory + "')",
                        oleDbConnection);
                    insert.ExecuteNonQuery();
                    MessageBox.Show("Data inserted successfully", "Database Update", MessageBoxButtons.OK,
                                    MessageBoxIcon.Exclamation);
                    oleDbConnection.Close();
                    var list = new ListandSearch();
                    Close();
                    list.Show();
                }
                else
                {
                    MessageBox.Show("Invalid field", "Invalid Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    txtCost.Clear();
                    txtQuantity.Clear();
                    txtCost.Focus();
                }
            }
            else
            {
                MessageBox.Show("Invalid fields", "Invalid Fields", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }