在我的预订页面中如何防止许多用户同时选择同一辆卡车 ?
在2个用户选择即时可用的卡车的情况下,我必须只允许第二个客户前几毫秒的第一个用户。
System.Web.UI.WebControls.Button lnkreport1 = (System.Web.UI.WebControls.Button)e.CommandSource;
string[] commandArgs = e.CommandArgument.ToString().Split(new char[] { ';' });
truckid.Text = commandArgs[0];
temp_memory_id.Text = commandArgs[1];
string status=string.Empty;
SqlConnection con12 = new SqlConnection(ConfigurationManager.ConnectionStrings["BUM"].ConnectionString);
SqlCommand cmd12 = new SqlCommand(" select Tr_status from TruckRegistration where Id='" + truckid.Text + "' ", con12);
con12.Open();
SqlDataReader dr = cmd12.ExecuteReader();
while(dr.Read())
{
status = dr["Tr_status"].ToString();
}
con12.Close();
if (temp_memory_id.Text == "Immediate")
{
if (status != "In_process")
{
mp1.Show();
}
else
{
ShowMessage("Another customer has choosen Just before you, kindly choose another Trailor!", MessageType.Warning);
}
}
答案 0 :(得分:-1)
在服务器端为您想要保留的卡车创建共享锁定对象并进行检查。