Hi, currently i'm working on a lucky draw system. So for the registration part user need to scan their barcode into the system as an attendance for the event. How can i make a validation if user scan twice or more barcode at the same time. Thanks.
Code :
- using System;
- using System.Collections.Generic;
- using System.Configuration;
- using System.Data;
- using System.Data.SqlClient;
- using System.IO;
- using System.Linq;
- using System.Web;
- using System.Web.UI;
- using System.Web.UI.WebControls;
- public partial class Attendance : System.Web.UI.Page
- {
- string constr = ConfigurationManager.ConnectionStrings["lucky"].ConnectionString;
- protected void Page_Load(object sender, EventArgs e)
- {
- txtText.Focus();
- }
- protected void btnSave_Click(object sender, EventArgs e)
- {
- bool Idcheckbool = Idcheck();
- if (Idcheckbool)
- {
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand("UPDATE Emp_Info SET Attendance = 'Present' WHERE Emp_id= @id"))
- {
- using (SqlDataAdapter sda = new SqlDataAdapter())
- {
- cmd.Connection = con;
- sda.SelectCommand = cmd;
- cmd.Parameters.AddWithValue("@id", txtText.Text);
- using (DataTable dt = new DataTable())
- {
- sda.Fill(dt);
- con.Open();
- cmd.ExecuteNonQuery();
- con.Close();
- txtText.Text = string.Empty;
- }
- }
- }
- }
- }
- }
- public bool Idcheck()
- {
- string query = "select Emp_Name from Emp_Info where Emp_id='" + txtText.Text + "'";
- using (SqlConnection con = new SqlConnection(constr))
- {
- using (SqlCommand cmd = new SqlCommand(query))
- {
- using (SqlDataAdapter sda = new SqlDataAdapter())
- {
- cmd.Connection = con;
- sda.SelectCommand = cmd;
- using (DataTable dt = new DataTable())
- {
- sda.Fill(dt);
- if (dt.Rows.Count > 0)
- {
- lblError.Text = "Welcome "+ dt.Rows[0]["Emp_Name"].ToString();
- Response.AddHeader("REFRESH", "4;URL=Attendance.aspx");
- return true;
- }
- else
- {
- lblError.Text += "ID Doest Not Exist! ";
- lblError.BackColor = System.Drawing.Color.Yellow;
- Response.AddHeader("REFRESH", "3;URL=Attendance.aspx");
- return false;
- }
- }
- }
- }
- }
- }
- }
Replies
Know the answer? Post it — somebody with the same question will find it here.