private void SaveButton_Click(object sender, EventArgs e) { if (products.FindIndex(p => p.Name == ProductComboBox.Text) >= 0) { dispatchAdapter.Insert((string)ProductComboBox.SelectedValue, getBoxes(), getPackets(), dateTimePicker1.Value.ToString("dd/MM/yyyy")); updateStock(getBoxes(), getPackets(), (string)ProductComboBox.SelectedValue); ProductComboBox.Focus(); BoxTextBox.Text = 0 + ""; PacketTextBox.Text = 0 + ""; bindDataGridView(); } else { MessageBox.Show("No product of such name", "Error", MessageBoxButtons.OK); ProductComboBox.Focus(); } }
/* * Event Handler for Modifying Product Details */ private void ModifyButton_Click(object sender, EventArgs e) { if (ProductComboBox.SelectedIndex == -1) { MessageBox.Show("Please select one product from the drop down list.", "Manual Entry Restricted", MessageBoxButtons.OK, MessageBoxIcon.Error); ProductComboBox.Focus(); } else { String ProdName = ProductComboBox.SelectedItem.ToString(); try { var result = from Prod in ProductList where Prod.ProductName == ProdName select Prod; foreach (var prod in result) { prod.ProductPrice = decimal.Parse(ProductPriceTextBox.Text); prod.ProductQuantity = int.Parse(ProductQuantityTextBox.Text); } EndOfTheDayStock(); MessageBox.Show("Product Updated Successfully", "Updation Completed", MessageBoxButtons.OK, MessageBoxIcon.Information); ProductNameTextBox.Text = ""; ProductCategoryListBox.SelectedItem = -1; ProductPriceTextBox.Text = ""; ProductQuantityTextBox.Text = ""; ProductComboBox.SelectedIndex = -1; } catch { MessageBox.Show("Error Occured while updating the product. Please try again later"); } } }