Could you please help me to get a solution to my issue. I am using a SQL Server database, it is a gymnastics program, and I want to get check in the client when he comes to the gym , I have two way of offering the first one is a monthly way , and the second is a daily, the first I don't have a problem with it and I use this code for checkin;
using (SqlCommand com = new SqlCommand("select count(*)from enddate where ID=@ID and startdate <=@C1 and endDate >=@C2", con))
{
com.Parameters.AddWithValue("@ID", ID.Text);
com.Parameters.AddWithValue("@C1", DateTime.Now);
com.Parameters.AddWithValue("@C2", DateTime.Now);
int count = (int)com.ExecuteScalar();
if (count > 0)
{
using (SqlCommand com1 = new SqlCommand("INSERT INTO [checkin] (ID,time,username) VALUES (@ID,@time,@username)", con))
{
com1.Parameters.AddWithValue("@ID", ID.Text);
com1.Parameters.AddWithValue("@time", txttime.Text);
com1.Parameters.AddWithValue("@username", txtusername.Text);
com1.ExecuteNonQuery();
}
MetroFramework.MetroMessageBox.Show(this, "Check In Sucssesfuly ................... ", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
MetroFramework.MetroMessageBox.Show(this, "this ID Expired .....................", "Message", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
con.Close();
}
I want to add to this code the second condition ( the daily offer ) I have the enddate table like ;
| ID | Startdate | month | day | enddate | offer |
| 1 | 20-3-2019 | 3 |null |20-6-2019|( summer ) monthly |
| 2 | 20-3-2019 | null | 5 |20-3-2019|( student ) daily |
in this case, the first one can come anytime for 3 months, in the second ID he can come for 5 times only.
my checkin table ;
| ID | Time | username |
| 1 | 21-3-2019| test |
| 1 | 25-3-2019| test |
| 2 | 27-3-2019| test 2 |
I can count how many time he comes to the gym but I don't know how to add it in my code