I have a table membership where I'm saving all paid or owed months for every user, but I have a problem where member A can pay January 2019 or any other month unlimited amount of times. I need to check if member A (or whatever ID is for another member) paid for January 2019 (or any other month/year) and if he did, upon making same payment (January 2019) to throw an error that member A paid that month in 2019 already.
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
{
ConnectionString = conString
};
connection.Open();
if (string.IsNullOrWhiteSpace(iznos_clanarine.Text) || string.IsNullOrWhiteSpace(odaberi_mjesec.Text) || (!placeno.Checked && !duzan.Checked) || string.IsNullOrWhiteSpace(godina_uplate_clanarine.Text) || string.IsNullOrWhiteSpace(ime.Text) || string.IsNullOrWhiteSpace(prezime.Text) || string.IsNullOrWhiteSpace(datum_rodenja.Text) || string.IsNullOrWhiteSpace(oib.Text))
{
MessageBox.Show("Odaberite člana i ispunite sva potrebna polja prije naplate članarine!");
}
else
{
string Query = "INSERT INTO evidencija_clanarina (id_clana, mjesec, godina, vrsta, iznos, dug) VALUES (@id_clana, @mjesec, @godina, @vrsta, @iznos, @dug)";
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 (placeno.Checked)
{
command.Parameters.AddWithValue("@dug", placeno.Text);
}
else
{
command.Parameters.AddWithValue("@dug", duzan.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;
placeno.Checked = false;
duzan.Checked = false;
baza_podataka_clanovi_clanarine.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}