I have a table named members and table named membership records. Currently in table membership records I have column named month in which I'm saving for what month the member payed membership. And with each payment it adds new record in datagridview but for different month. Check image to see how it displays data now when user makes payment.
If I would alter membership records table with month names (January-December) and I want to fill with each payment, for example member John for month January that it fills column name January, and if I wanted to make payment also for member John (same ID, let's say ID 1) and month February that it doesn't add new record in database but that it updates member John ID 1 for column February? So it would show name (John), DoB, OIB (personal identification number), gender, January, February, etc. all the way to December, type of membership (monthly or yearly) and fee of the membership?
Basically I want to display only one record for each member that makes payment but that in one record it holds all months and with each payment for different month it adds month member payed.
This is how I'd like to display it in datagridview. Note that I made this table quickly and it's not the same as in the picture above ^^ and it's here only to show you what I mean, I will delete it and I won't include it in my database and my project.
private void Plati_Clanarinu_tipka_Click(object sender, EventArgs e)
{
MySqlConnection connection;
string conString = "server=localhost; database=bazakudsumari; uid=David; password=root;";
try
{
connection = new MySqlConnection();
connection.ConnectionString = conString;
connection.Open();
if (string.IsNullOrWhiteSpace(iznos_clanarine.Text) || (string.IsNullOrWhiteSpace(odaberi_mjesec.Text)) || (string.IsNullOrWhiteSpace(godina_uplate_clanarine.Text)))
{
MessageBox.Show(" Ispunite sva polja prije naplate članarine! ");
}
else
{
string Query = "INSERT INTO evidencija_clanarina (id_clana, mjesec, godina, vrsta, iznos) VALUES (@id_clana, @mjesec, @godina, @vrsta, @iznos)";
using (MySqlCommand command = new MySqlCommand(Query, connection))
{
command.Parameters.AddWithValue("@id_clana", Convert.ToInt32(id_clana.Text));
command.Parameters.AddWithValue("@mjesec", odaberi_mjesec.Text);
command.Parameters.AddWithValue("@godina", godina_uplate_clanarine.Text);
if (mjesecna_clanarina.Checked)
{
command.Parameters.AddWithValue("@vrsta", "Mjesečna");
command.Parameters.AddWithValue("@iznos", iznos_clanarine.Text);
}
else
{
command.Parameters.AddWithValue("@vrsta", "Godišnja");
command.Parameters.AddWithValue("@iznos", iznos_clanarine.Text);
}
command.ExecuteNonQuery();
}
MessageBox.Show("Uspješno plaćena članarina!");
DialogResult dialogResult = MessageBox.Show(" Želite li naplatiti još jednu članarinu? ", "", MessageBoxButtons.YesNo);
if (dialogResult == DialogResult.Yes)
{
this.Focus();
}
else
{
this.Close();
}
odaberi_mjesec.Text = string.Empty;
iznos_clanarine.Text = string.Empty;
godina_uplate_clanarine.Text = string.Empty;
mjesecna_clanarina.Checked = false;
godisnja_clanarina.Checked = false;
baza_podataka_clanovi_clanarine.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
This is code I'm currently using for making payments, all of the code is in my language (Croatian) and I know that I need to change Query and Parameters. I need to know if it's possible to do what I'm asking and how to do it.
(id_clana = id_member, mjesec = month, godina = year, vrsta = type, Mjesečna = Monthly, iznos = fee, Godišnja = Yearly). This is quick translate of what I have in my code so you guys can manage.