// Save and Complete Sales private void btnSubmit_Click(object sender, EventArgs e) { DialogResult result = MessageBox.Show("Do you want to Complete Sale and Print? ", "Yes or No", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2); if (result == DialogResult.Yes) { if (lblTotal.Text == "0") { MessageBox.Show("Sorry ! you have not enough product \n Please Purchase product or Increase Product Quantity"); } //else if (Convert.ToInt32(txtinvoiceNo.Text) >= 53) //Please uncommet this section //{ // MessageBox.Show("Sorry ! Demo version has limited transaction \n Please buy it \n contact at : [email protected]", "Yes or No", MessageBoxButtons.OK, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); //} else if (CmbWarehouse.Text == string.Empty) { MessageBox.Show("Please Select WareHouse .. "); CmbWarehouse.Focus(); } else { try { //Save payment info into 'sales_payment' table payment_item(); //Save Sales item into 'sales_item' table sales_item(); //Save Sale info into 'tbl_saleInfo' table SaleInfo(); // 5 % Rewards Point add to customer Account for total Payable amount // AddCredit(); // Inventory.InvoicePrint go = new Inventory.InvoicePrint(txtinvoiceNo.Text); View_Sales_invoice go = new View_Sales_invoice(txtinvoiceNo.Text); go.ShowDialog(); ShowSales_id_increment(); ClearForm2(); } catch (Exception exp) { MessageBox.Show(exp.Message); } } } }
private void btnSave_Click(object sender, EventArgs e) { if (Validation() == true) { string ans = (MessageBox.Show("Do you want to Continue Save", "Save", MessageBoxButtons.YesNo, MessageBoxIcon.Information)).ToString(); if (ans == "Yes") { try { using (SqlConnection connection = new SqlConnection(connectionString)) { connection.Open(); SqlCommand command = connection.CreateCommand(); SqlTransaction transaction; // Start a local transaction. transaction = connection.BeginTransaction("SampleTransaction"); // Must assign both transaction object and connection // to Command object for a pending local transaction try { for (int i = 0; i < Convert.ToInt32(dataGridView1.Rows.Count - 1); i++) { //command.Connection = connection; // command.Transaction = transaction; command = new SqlCommand("Rack_Save", connection, transaction); command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@WH_ID", GID); command.Parameters.AddWithValue("@WareHouse_Name", CmbWarehouse.Text.TrimEnd().TrimStart()); command.Parameters.AddWithValue("@RackName", dataGridView1.Rows[i].Cells[0].Value.ToString()); command.Parameters.AddWithValue("@EnterBy", username); command.Parameters.AddWithValue("@Company", company); command.ExecuteNonQuery(); } // Attempt to commit the transaction. transaction.Commit(); MessageBox.Show("Saved Successfully...", "Save", MessageBoxButtons.OK, MessageBoxIcon.Information); Clear(); } catch { // Attempt to roll back the transaction. try { transaction.Rollback(); MessageBox.Show("Save was unsuccessful...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Clear(); } catch (Exception ex2) { } } } } catch { } } dr.Close(); } else { CmbWarehouse.Focus(); } }