首页 > 解决方案 > 登录时的签到情况

问题描述

你能帮我解决我的问题吗?我正在使用 SQL Server 数据库和 c# 我有一个健身房,我想用他的报价签入我的登录客户端。

报价表:

| ID | startdate |  month |  day  |  enddate  |      type        |
| 1  | 2019-03-05|   3    | null  |2019-06-05 |Business Calendar |
| 2  | 2019-03-05|  null  |   30  |2019-04-04 |Day Calendar      |

我试试这段代码:

try
{
    string che = @"(select count(*)from table where id='" + ID.Text + "' and startdate <='" + DateTime.Now + "' and endDate >='" + DateTime.Now + "' )";
    con.Open();
    SqlCommand sda = new SqlCommand(che, con);
    int count = (int)sda.ExecuteScalar();
    if (count > 0)
    {
        using (SqlCommand com = new SqlCommand("INSERT INTO [checkin] (ID,time,username) VALUES (@ID,@time,@username)", con))
        {
            com.Parameters.AddWithValue("@ID", ID.Text);

            com.Parameters.AddWithValue("@time", txttime.Text);

            com.Parameters.AddWithValue("@username", txtusername.Text);
            com.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();
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message);
}
finally
{
    if(con.State == ConnectionState.Open)
        con.Close();
}

我正在寻找的是在此代码中添加一些内容,如果它的日历天数不检查结束日期以使 ID 过期

三个月后我有她的第一个条件第二个登录30次或一天

标签: c#sql-serverdatabasevisual-studio

解决方案


推荐阅读