private void RadioButton3_CheckedChanged_1(object sender, EventArgs e) { //panelProductSuppliers.Show();20190604 //20190604-- panel25.BringToFront(); //panel25.Visible = true; //--20190604 comboBox3.DataSource = ProductsDB.GetProducts(); comboBox3.DisplayMember = "ProdName"; comboBox3.ValueMember = "ProductId"; int fid; bool parseOK = Int32.TryParse(comboBox3.SelectedValue.ToString(), out fid); comboBox4.DataSource = Products_SuppliersDB.GetSuppliersByProductID(fid); comboBox4.DisplayMember = "SupName"; comboBox4.ValueMember = "SupplierId"; comboBox7.DataSource = ProductsDB.GetProducts(); comboBox7.DisplayMember = "ProdName"; comboBox7.ValueMember = "ProductId"; comboBox6.DataSource = Products_SuppliersDB.GetSuppliersByProductID(fid); comboBox6.DisplayMember = "SupName"; comboBox6.ValueMember = "SupplierId"; }
// ------------Added by Wei Guang Yan---------------- // Radio-button-Click event on "Products"----Edit/Add product private void radioButton1_CheckedChanged(object sender, EventArgs e) { //this.panel14.SendToBack(); //Show panel13 //panelProductSuppliers.Hide(); 20190604 this.panel13.BringToFront(); //this.panel13.Visible = true;20190604 // Set combobox's datasource to products table comboBox2.DataSource = ProductsDB.GetProducts(); comboBox2.DisplayMember = "ProdName"; comboBox2.ValueMember = "ProductId"; // Set panel status as "products" for "update" and "add" button checking panelStatus = PanelStatus.Products; // Set desplay of relevant labels and buttons, and clear "Add" textbox lblItemList.Text = "Products"; lblUpdateItem.Text = "Update Product:"; btnUpdate.Text = "Update Product"; lblAddItem.Text = "Add Product:"; btnAdd.Text = "Add Product"; txtAddItem.Clear(); RadioButton rb = sender as RadioButton; if (rb != null) { if (rb.Checked) { // Only one radio button will be checked //Console.WriteLine("Changed: " + rb.Name); //datagridview2.source = DataLayer.ProductsDB.GetProducts(); } } }
// ------------Added by Wei Guang Yan---------------- // Method of inserting product name to database public void AddProduct(string txtAdd) { // Innitialize for messagebox string message; string title = "New Product Insert"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon; // Add new item to database bool flag = ProductsDB.AddProduct(txtAdd); // Check whether adding excution is successful, and show message if (flag == true) { comboBox2.DataSource = ProductsDB.GetProducts(); comboBox2.DisplayMember = "ProdName"; comboBox2.ValueMember = "ProductId"; comboBox2.SelectedIndex = comboBox2.Items.Count - 1; txtAddItem.Text = ""; message = "The product is added successfully!"; icon = MessageBoxIcon.None; } else { message = "Error: Fail to add new product!\n Please try again or contact IT supports."; icon = MessageBoxIcon.Error; } MessageBox.Show(message, title, button, icon); }
// ------------Added by Wei Guang Yan---------------- // Method of updating product name to database public void UpdateProduct(string txtUpdate) { // Initialization for messagebox string message; string title = "Product Update"; MessageBoxButtons button = MessageBoxButtons.OK; MessageBoxIcon icon = MessageBoxIcon.Warning; // Excute updating int id = ProductsDB.GetProductId(comboBox2.Text); bool flag = ProductsDB.UpdateProduct(id, txtUpdate); // Check whether updating is successful, and show message if (flag == true) { int index = comboBox2.SelectedIndex; comboBox2.DataSource = ProductsDB.GetProducts(); comboBox2.DisplayMember = "ProdName"; comboBox2.ValueMember = "ProductId"; comboBox2.SelectedIndex = index; message = "The product is updated successfully!"; icon = MessageBoxIcon.None; } else { message = "Error: Fail to update product!\n Please try again or contact IT support."; icon = MessageBoxIcon.Error; } MessageBox.Show(message, title, button, icon); }
private void Form2_Load(object sender, EventArgs e) { products = ProductsDB.GetProducts(); listBox1.DataSource = products; listBox1.DisplayMember = "ProdName"; int Box1_initialIndex = 0; listBox1.SetSelected(Box1_initialIndex, true); LoadSupplierBox(products[Box1_initialIndex].ProductId); button2.Text = char.ConvertFromUtf32(0x2193); button8.Text = char.ConvertFromUtf32(0x2191); }
// display products after getting list by DB method private void DisplayProducts() { productsList = ProductsDB.GetProducts(); if (productsList != null) // if we have products to display { lstView.Items.Clear(); //start with empty list box foreach (Products prod in productsList) { lstView.Items.Add(prod); } } else // null this product does not exist - need to refresh combo box { MessageBox.Show("There is no product to display."); } }
// UPDATE button click, visibility and read-only toggle private void btnSupplierEdit_Click(object sender, EventArgs e) { btnAcceptEdit.Visible = true; btnSupplierEdit.Visible = false; pnlUpdate.Visible = true; lstProducts.Enabled = true; //txtSupplierID.ReadOnly = false; //txtSupplierID.Enabled = true; txtSupName.ReadOnly = false; txtSupName.Enabled = true; productsList = ProductsDB.GetProducts(); foreach (Products prod in productsList) { cboProducts.Items.Add(prod); } }