private void buttonPay_Click(object sender, EventArgs e) { if (dataGridView1.Rows.Count > 0) { Pay pay = new Pay(); pay.ShowDialog(); this.Close(); } }
private void buttonPay_Click(object sender, EventArgs e) { if (dataGridView2.SelectedCells.Count > 0) { DialogResult dr = MessageBox.Show("Are you sure you want to pay this tab now?" + Environment.NewLine + "The tab must be paid in the full amount and cannot be reversed.", "Delete?", MessageBoxButtons.YesNo); switch (dr) { case DialogResult.Yes: datatabletrans.Rows.Clear(); int selectedrowindex = dataGridView2.SelectedCells[0].RowIndex; DataGridViewRow selectedRow = dataGridView2.Rows[selectedrowindex]; int a = Int32.Parse(selectedRow.Cells[0].Value.ToString()); SqlConnection basket = new SqlConnection(Globals.dataconnection); SqlCommand show = new SqlCommand("SELECT SaleUnitID FROM TabItem WHERE TabID = @id;", basket); basket.Open(); show.Parameters.AddWithValue("@id", a); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = show; da.Fill(datatabletrans); basket.Close(); int index = 0; while (index != datatabletrans.Rows.Count) { SqlConnection newtrans = new SqlConnection(Globals.dataconnection); SqlCommand add = new SqlCommand("INSERT INTO Basket (StaffID, SaleUnitID) VALUES (@staff, @saleunit)", newtrans); newtrans.Open(); add.Parameters.AddWithValue("@staff", Globals.Userno); add.Parameters.AddWithValue("@saleunit", (int)datatabletrans.Rows[index][0]); add.ExecuteNonQuery(); newtrans.Close(); index++; } SqlConnection cat = new SqlConnection(Globals.dataconnection); cat.Open(); SqlCommand delete = new SqlCommand("DELETE FROM Tab WHERE TabID = @id", cat); delete.Parameters.AddWithValue("@id", a); delete.ExecuteNonQuery(); cat.Close(); Pay pay = new Pay(); pay.ShowDialog(); this.Close(); break; case DialogResult.No: break; } } else { MessageBox.Show("Please select a tab from the list"); } }