private void btnAdd_Click(object sender, EventArgs e) { //Thread t = new Thread(new ThreadStart(GifLoadingSaveSales)); try { if (txtSupName.SelectedValue == null) { MessageBox.Show("Invalid Supplier Name"); txtSupName.ResetText(); txtSupName.DataSource = null; txtSupName.DataSource = bank; txtSupName.ValueMember = "Id"; txtSupName.DisplayMember = "Company"; return; } if (txtSupName.Text == "SalesReturnStock") { MetroMessageBox.Show(this, "Selected suppilier name is system reserved keyword. You can't use this record, Please try another suppilier name or add a new name", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; } //MessageBox.Show(txtSupName.SelectedValue.ToString()); //MessageBox.Show(txtSupName.Text.ToString()); if (string.IsNullOrEmpty(txtSupName.Text) || string.IsNullOrEmpty(txtInvoiceNo.Text) || string.IsNullOrEmpty(txtStockID.Text) || string.IsNullOrEmpty(cmbDate.Text) || txtSupName.SelectedValue == null) { MetroMessageBox.Show(this, "Please enter valid data to the text fields", "System Message", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } bool resul = stock_product_list.Any(); if (!resul) { MessageBox.Show("No Product details were added to the stock"); return; } else { // t.Start(); using (TransactionScope txScope = new TransactionScope()) { DateTime d; d = Convert.ToDateTime(cmbDate.Text); int stockID = Convert.ToInt32(txtStockID.Text); string supName = txtSupName.Text; string invoiceNo = txtInvoiceNo.Text; Stock stock = new Stock(); stock.invoice_no = invoiceNo; stock.stock_id = stockID; stock.sup_name = supName; stock.s_date = d; stock.Sup_id = Convert.ToInt32(txtSupName.SelectedValue.ToString()); if (stock.Add(con)) { string query = @"select IDENT_CURRENT('_Stokc')"; int lastInsertedID = Convert.ToInt32(Sales_BM.getScalar(con, query)); stockID = lastInsertedID; int count = 0; foreach (var item in stock_product_list) { item.stock_id = lastInsertedID; item.Add(con); count++; } int cehckPurchase = 0; Purchase pr = new Purchase(); if (pr.AddPurchase(con, lastInsertedID)) { pr.AddPurchaseProduct(con, lastInsertedID); cehckPurchase++; } // t.Abort(); if (cehckPurchase > 0 && count > 0) { txScope.Complete();//transaction commit //MessageBox.Show("Products were added"); PopupNotifier pop = new PopupNotifier(); pop.ContentText = "Products Stock data stored to the system"; pop.TitleText = "Notification"; pop.Image = Resources.success_48; // or Image.FromFile(--Path--) pop.IsRightToLeft = false; pop.ContentHoverColor = Color.Teal; pop.Popup(); MetroMessageBox.Show(this, "Stock Details stored to the system. :-P ", "Successfull!", MessageBoxButtons.OKCancel, MessageBoxIcon.Asterisk); refresh(); } else { MetroMessageBox.Show(this, "Something Went Wrong. Please restrart the form and try again... ", "Unexpected Interuption!", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); } } else { // t.Abort(); MetroMessageBox.Show(this, "Something Went Wrong. Please restrart the form and try again... ", "Unexpected Interuption!", MessageBoxButtons.OKCancel, MessageBoxIcon.Stop); } }//end of using statement } } catch (Exception ex) { //t.Abort(); MetroMessageBox.Show(this, ex.Message, "System Error!", MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } finally { // t.Abort(); } }