private void btnSave_Click(object sender, EventArgs e) { try { if (ValidateChildren(ValidationConstraints.Enabled)) { FormControls.ShowFields(false, txtProductId, txtName, txtPrice, txtStock, txtDiscount, cbBrand, cbColor, cbSize, rbClothing, rbFemale, rbFootwear, rbKids, rbMale, gb_Subtype, gb_Type, btnCancel, btnSave, label1, label2, label3, label4, label5, label6, label7, label8, label9, label11); SqlCommand command; if (isNew) { command = new SqlCommand("insert into product values ('" + txtProductId.Text + "','" + txtName.Text + "','" + cbBrand.SelectedItem + "','" + CheckedRadioButton(gb_Type) + "','" + CheckedRadioButton(gb_Subtype) + "','" + cbColor.SelectedItem + "','" + cbSize.SelectedItem + "','" + txtPrice.Text + "','" + txtDiscount.Text + "','" + txtStock.Text + "')", FormControls.DbConnection); } else { command = new SqlCommand("update product set product_id = '" + txtProductId.Text + "', name = '" + txtName.Text + "', brand = '" + cbBrand.SelectedItem + "', type = '" + CheckedRadioButton(gb_Type) + "', subtype = '" + CheckedRadioButton(gb_Subtype) + "', color = '" + cbColor.SelectedItem + "', size = '" + cbSize.SelectedItem + "', price = '" + txtPrice.Text + "', discount = '" + txtDiscount.Text + "', stock = '" + txtStock.Text + "' where id = '" + (int)dgv_Product.CurrentRow.Cells[0].Value + "'", FormControls.DbConnection); } command.ExecuteNonQuery(); FormControls.BindData(dgv_Product, "product"); MessageBox.Show("Your data has been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void txtSearch_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(txtSearch.Text)) { FormControls.BindData(dgv_Product, "product"); } }
private void btn_New_Click(object sender, EventArgs e) { NewOrder newOrder = new NewOrder(); newOrder.ShowDialog(this); FormControls.BindData(dgv_Orders, "orders"); }
private void txt_Search_TextChanged(object sender, EventArgs e) { if (string.IsNullOrEmpty(txt_Search.Text)) { FormControls.BindData(dgv_Orders, "orders"); } }
private void btnSave_Click(object sender, EventArgs e) { try { if (ValidateChildren(ValidationConstraints.Enabled)) { FormControls.ShowFields(false, txtName, txtSurname, txtAddress, txtPhoneNum, txtEmail, cBoxType, btnSave, btnCancel, label1, label2, label3, label4, label5, label6); SqlCommand command; if (isNew) { command = new SqlCommand("insert into customer values ('" + txtName.Text + "','" + txtSurname.Text + "','" + txtAddress.Text + "','" + txtPhoneNum.Text + "','" + txtEmail.Text + "','" + cBoxType.Text + "','" + 0 + "')", FormControls.DbConnection); } else { command = new SqlCommand("update customer set name = '" + txtName.Text + "', surname = '" + txtSurname.Text + "', address = '" + txtAddress.Text + "', phone_number = '" + txtPhoneNum.Text + "', email = '" + txtEmail.Text + "', type = '" + cBoxType.Text + "' where customer_id = '" + (int)dgv_Customer.CurrentRow.Cells[0].Value + "'", FormControls.DbConnection); } command.ExecuteNonQuery(); FormControls.BindData(dgv_Customer, "customer"); MessageBox.Show("Your data has been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void txtSearch_KeyDown(object sender, KeyEventArgs e) { SqlCommand command = new SqlCommand("select * from product where product_id LIKE '" + txtSearch.Text + "%' OR name LIKE '" + txtSearch.Text + "%' OR price LIKE '" + txtSearch.Text + "%' OR discount = '" + txtSearch.Text + "'", FormControls.DbConnection); if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(txtSearch.Text)) { FormControls.BindData(dgv_Product, "product", command); } }
private void txt_Search_KeyDown(object sender, KeyEventArgs e) { SqlCommand command = new SqlCommand("select * from customer where order_id = '" + txt_Search.Text + "'", FormControls.DbConnection); if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(txt_Search.Text)) { FormControls.BindData(dgv_Orders, command: command); } }
private void txtSearch_KeyDown(object sender, KeyEventArgs e) { SqlCommand command = new SqlCommand("select * from customer where name LIKE '" + txtSearch.Text + "%' OR surname LIKE '" + txtSearch.Text + "%' OR address LIKE '" + txtSearch.Text + "%' OR phone_number = '" + txtSearch.Text + "' OR email = '" + txtSearch.Text + "' OR type = '" + txtSearch.Text + "'", FormControls.DbConnection); if (e.KeyCode == Keys.Enter && !string.IsNullOrEmpty(txtSearch.Text)) { FormControls.BindData(dgv_Customer, "customer", command); } }
private void btn_Save_Click(object sender, EventArgs e) { try { SqlCommand command = new SqlCommand("update orders set status = '" + gb_Status.Controls.OfType <RadioButton>().Where(r => r.Checked).FirstOrDefault().Text + "' where order_id = '" + (int)dgv_Orders.CurrentRow.Cells[0].Value + "'", FormControls.DbConnection); command.ExecuteNonQuery(); FormControls.BindData(dgv_Orders, "orders"); FormControls.ShowFields(false, gb_Status, gb_OrderDetails, btn_Save, btn_Cancel); MessageBox.Show("Your changes have been successfully saved.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void btnDelete_Click(object sender, EventArgs e) { try { SqlCommand command = new SqlCommand("delete product where id = '" + (int)dgv_Product.CurrentRow.Cells[0].Value + "'", FormControls.DbConnection); if (MessageBox.Show("Are you sure you want to delete selected products?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { command.ExecuteNonQuery(); FormControls.BindData(dgv_Product, "product"); MessageBox.Show("Product successfully removed.", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private void BindFields() { if (dgv_Orders.SelectedRows.Count == 1) { //binding customer who made the order SqlCommand getCustomer = new SqlCommand("select * from customer where customer_id = (select cast(customer_id as int) from customer_orders where order_id = '" + dgv_Orders.CurrentRow.Cells[0].Value + "')", FormControls.DbConnection); FormControls.BindData(dgv_Customer, command: getCustomer); FormControls.HideDGVColumns(dgv_Customer.Columns[0], dgv_Customer.Columns[6], dgv_Customer.Columns[7]); //binding products from order SqlCommand getProducts = new SqlCommand("select * from product where product_id = (select product_id from order_products where order_id = '" + dgv_Orders.CurrentRow.Cells[0].Value + "')", FormControls.DbConnection); FormControls.BindData(dgv_Products, command: getProducts); FormControls.HideDGVColumns(dgv_Products.Columns[1], dgv_Products.Columns[11]); UpdateProductAmount(); //binding order status gb_Status.Controls.OfType <RadioButton>().Where(r => r.Text == dgv_Orders.CurrentRow.Cells[3].Value.ToString().Trim()).FirstOrDefault().Checked = true; } }
private void ProductsManagement_Load(object sender, EventArgs e) { FormControls.ShowFields(false, txtProductId, txtName, txtPrice, txtStock, txtDiscount, cbBrand, cbColor, cbSize, rbClothing, rbFemale, rbFootwear, rbKids, rbMale, gb_Subtype, gb_Type, btnCancel, btnSave, label1, label2, label3, label4, label5, label6, label7, label8, label9, label11); FormControls.SetComboboxDefaultValue(cbBrand, cbColor, cbSize); FormControls.BindData(dgv_Product, "product"); }
private void OrdersManagement_Load(object sender, EventArgs e) { FormControls.BindData(dgv_Orders, "orders"); }
private void CustomersManagement_Load(object sender, EventArgs e) { FormControls.ShowFields(false, txtName, txtSurname, txtAddress, txtPhoneNum, txtEmail, cBoxType, btnSave, btnCancel, label1, label2, label3, label4, label5, label6); FormControls.SetComboboxDefaultValue(cBoxType); FormControls.BindData(dgv_Customer, "customer"); }