我是一名新的 C# 和 ASP.NET 开发人员。我正在为我的公司开发一个简单的 Intranet 预订管理系统。我希望系统检查用户是否在活动之前进行了预订。
我有以下数据库设计:
Users Table: UserID, Name
Events Table: ID, Title, Description, Location, NumberOfSeats, StartDateTime, EndDateTime, IsActive
Booking Table: BookingID, EventID, UserID
到目前为止,我所做的是检查用户 ID(当用户单击预订按钮时)是否在用户表中。如果没有,他将被自动添加到数据库中。现在我想通过检查 BookingDetails 表来检查他是否在该活动中进行了预订,但我不知道该怎么做?
你能帮我设计这个条件吗?
这是我检查用户名的方法:
protected void checkUserID(string userID) {
int eventID = Convert.ToInt32(HiddenField1.Value);
string NetworkID = userID;
string Name = Service.(".......");
string BadgeNo = Service("ffffff");
string DepartmentCode = Service("ffffff");
string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=RegistrationSysDB;Integrated Security=True;";
//if the user is not in the system database, add him
if (Security.isExisted(userID) == false)
{
//string connString = "Data Source=localhost\\sqlexpress;Initial Catalog=RegistrationSysDB;Integrated Security=True;";
string insertCommand = "INSERT INTO Users (NetworkID, Name, BadgeNo, DepartmentCode) values (@NetworkID, @Name, @BadgeNo, @DepartmentCode)";
using(SqlConnection conn = new SqlConnection(connString))
{
//Open DB Connection
conn.Open();
using(SqlCommand cmd = new SqlCommand(insertCommand, conn))
{
cmd.Parameters.Clear();
cmd.Parameters.AddWithValue("@NetworkID", NetworkID);
cmd.Parameters.AddWithValue("@Name", Name);
cmd.Parameters.AddWithValue("@BadgeNo", BadgeNo);
cmd.Parameters.AddWithValue("@DepartmentCode", DepartmentCode);
cmd.ExecuteNonQuery();
}
conn.Close();
}
}
}