private void InvoiceManagement_Click(object sender, RoutedEventArgs e) { Invoice_Management im = new Invoice_Management(); im.Show(); this.Hide(); }
private void ispaid_Click(object sender, RoutedEventArgs e) { string connectionstring = null; foreach (int o in ListOfSelectedItems) { Console.WriteLine(o); connectionstring = myConnection.connectionString(); MySqlConnection cnn = new MySqlConnection(connectionstring); MySqlCommand command = cnn.CreateCommand(); cnn.Open(); command.Parameters.AddWithValue("@id", LoginWindow.id); command.Parameters.AddWithValue("@IsPaid", o); command.CommandText = "SELECT IsPaid FROM SavedInvoices WHERE InvoiceId=@isPaid AND userid=@id"; MySqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { if (reader.GetBoolean("IsPaid").Equals(false)) { connectionstring = myConnection.connectionString(); MySqlConnection cnn2 = new MySqlConnection(connectionstring); cnn2.Open(); MySqlCommand command2 = cnn2.CreateCommand(); command2.Parameters.AddWithValue("@value", 1); command2.Parameters.AddWithValue("@IsPaid", o); //command2.CommandText = "INSERT INTO SavedInvoices (isPaid) VALUES (1) WHERE InvoiceId=@IsPaid"; command2.CommandText = "UPDATE SavedInvoices SET IsPaid=@value WHERE InvoiceId=@IsPaid"; if (command2.ExecuteNonQuery() > 0) { } else { } cnn2.Close(); } else { connectionstring = myConnection.connectionString(); MySqlConnection cnn2 = new MySqlConnection(connectionstring); cnn2.Open(); MySqlCommand command2 = cnn2.CreateCommand(); command2.Parameters.AddWithValue("@value", 0); command2.Parameters.AddWithValue("@IsPaid", o); command2.CommandText = "UPDATE SavedInvoices SET IsPaid=@value WHERE InvoiceId=@IsPaid"; if (command2.ExecuteNonQuery() > 0) { } else { } cnn2.Close(); } } cnn.Close(); } MessageBox.Show("Invoice Informations were successfuly updated."); Invoice_Management im = new Invoice_Management(); this.Hide(); im.Show(); }