private void NewStockAdditionCompleted(object sender, RunWorkerCompletedEventArgs e) { bool isProductDetailsSaved = (bool)e.Result; progressBar.Close(); if (isProductDetailsSaved) { ProductId_textBox.Focus(); MessageBox.Show(Constants.PRODUCT_ADDED_MESSAGE); ListViewItem listView = new ListViewItem((AllProduct_ListView.Items.Count > 0 ? (Convert.ToInt64(AllProduct_ListView.Items[AllProduct_ListView.Items.Count - 1].SubItems[0].Text) + 1).ToString() : "1")); listView.SubItems.Add(ProductId_textBox.Text); listView.SubItems.Add(ProductName_textBox.Text); listView.SubItems.Add(string.Format("{0:0.00}", Quantity_Textbox.Text)); listView.SubItems.Add(string.Format("{0:0.00}", BuyingPrice_Textbox.Text)); listView.SubItems.Add(string.Format("{0:0.00}", RetailPrice_Textbox.Text)); listView.SubItems.Add(string.Format("{0:0.00}", WholesalePrice_Textbox.Text)); listView.SubItems.Add(string.Format("{0:0.00}", CreditPrice_Textbox.Text)); listView.SubItems.Add(GST_ComboBox.SelectedItem.ToString()); AllProduct_ListView.Items.Add(listView); EnableDisableFormControls(); } else { MessageBox.Show("Error occured while adding Product to the database"); } }
private void EnableDisableFormControls() { ProductId_textBox.Focus(); AddProduct_button.Enabled = true; UpdateProduct_button.Enabled = false; DeleteProduct_button.Enabled = false; ProductId_textBox.ReadOnly = false; ProductId_textBox.Text = string.Empty; ProductName_textBox.Text = string.Empty; Quantity_Textbox.Text = string.Empty; BuyingPrice_Textbox.Text = string.Empty; RetailPrice_Textbox.Text = string.Empty; WholesalePrice_Textbox.Text = string.Empty; CreditPrice_Textbox.Text = string.Empty; GST_ComboBox.SelectedItem = null; AvailableStock_Search_Textbox.Text = string.Empty; }
private void DeleteProduct_button_Click(object sender, EventArgs e) { try { if (MessageBox.Show(Constants.DELETE_PRODUCT_CONFORMATION_MESSAGE, Constants.DELETE_PRODUCT_MESSAGE_BOX_CAPTION, MessageBoxButtons.OKCancel) == DialogResult.OK) { CreateProgressInstance(); progressBar.worker.DoWork += DeleteSelectedProductFromListView; progressBar.worker.RunWorkerCompleted += LoadProductDetailsAfterDeletion; progressBar.worker.RunWorkerAsync(); ProductId_textBox.Focus(); } } catch (Exception ex) { MessageBox.Show(ex.StackTrace.ToString(), "Error Occured at AddStockPage", MessageBoxButtons.OK); } }
private void AddProduct_button_Click(object sender, EventArgs e) { try { if (!string.IsNullOrWhiteSpace(ProductId_textBox.Text) && !string.IsNullOrWhiteSpace(ProductName_textBox.Text) && !string.IsNullOrWhiteSpace(Quantity_Textbox.Text) && !string.IsNullOrWhiteSpace(RetailPrice_Textbox.Text) && !string.IsNullOrWhiteSpace(WholesalePrice_Textbox.Text) && !string.IsNullOrWhiteSpace(CreditPrice_Textbox.Text) && !string.IsNullOrWhiteSpace(BuyingPrice_Textbox.Text) && GST_ComboBox.SelectedItem != null && !string.IsNullOrWhiteSpace(GST_ComboBox.SelectedItem.ToString())) { bool isProductIdUsedAlready = admin.IsProductIdAvailable(Convert.ToDouble(ProductId_textBox.Text)); if (!isProductIdUsedAlready) { selectedGst = Convert.ToInt32(GST_ComboBox.SelectedItem); CreateProgressInstance(); progressBar.worker.DoWork += NewStockAdditionDoWork; progressBar.worker.RunWorkerCompleted += NewStockAdditionCompleted; progressBar.worker.RunWorkerAsync(); } else { MessageBox.Show(Constants.PRODUCT_ID_AVAILABLE_MESSAGE); ProductId_textBox.Focus(); } } else { MessageBox.Show(Constants.ENTER_ALL_TEXTFIELD_MESSAGE); ProductId_textBox.Focus(); } } catch (Exception ex) { this.Invoke((System.Action)(() => { progressBar.Close(); }), null); MessageBox.Show(ex.StackTrace.ToString(), "Error Occured at AddStockPage", MessageBoxButtons.OK); } }