Asyraf MN

Asyraf MN

  • NA
  • 28
  • 7k

How to make a validation when user scan barcode twice

Apr 16 2018 8:31 PM
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 : 
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Configuration;  
  4. using System.Data;  
  5. using System.Data.SqlClient;  
  6. using System.IO;  
  7. using System.Linq;  
  8. using System.Web;  
  9. using System.Web.UI;  
  10. using System.Web.UI.WebControls;  
  11.   
  12.   
  13.   
  14. public partial class Attendance : System.Web.UI.Page  
  15. {  
  16.     string constr = ConfigurationManager.ConnectionStrings["lucky"].ConnectionString;  
  17.   
  18.   
  19.     protected void Page_Load(object sender, EventArgs e)  
  20.     {  
  21.           
  22.         txtText.Focus();  
  23.          
  24.           
  25.     }  
  26.   
  27.       
  28.     protected void btnSave_Click(object sender, EventArgs e)  
  29.     {  
  30.   
  31.         bool Idcheckbool = Idcheck();  
  32.          
  33.         if (Idcheckbool)  
  34.         {  
  35.             using (SqlConnection con = new SqlConnection(constr))  
  36.             {  
  37.                 using (SqlCommand cmd = new SqlCommand("UPDATE Emp_Info SET Attendance = 'Present' WHERE  Emp_id= @id"))  
  38.                 {  
  39.                     using (SqlDataAdapter sda = new SqlDataAdapter())  
  40.                     {  
  41.                         cmd.Connection = con;  
  42.                         sda.SelectCommand = cmd;  
  43.                         cmd.Parameters.AddWithValue("@id", txtText.Text);  
  44.                         using (DataTable dt = new DataTable())  
  45.                         {  
  46.                             sda.Fill(dt);  
  47.                             con.Open();  
  48.                             cmd.ExecuteNonQuery();  
  49.                             con.Close();  
  50.                             txtText.Text = string.Empty;  
  51.   
  52.                         }  
  53.                     }  
  54.   
  55.                 }  
  56.             }  
  57.         }  
  58.   
  59.     }  
  60.   
  61.     public bool Idcheck()  
  62.     {  
  63.           
  64.         string query = "select Emp_Name from Emp_Info where Emp_id='" + txtText.Text + "'";  
  65.          
  66.         using (SqlConnection con = new SqlConnection(constr))  
  67.         {  
  68.             using (SqlCommand cmd = new SqlCommand(query))  
  69.             {  
  70.                 using (SqlDataAdapter sda = new SqlDataAdapter())  
  71.                 {  
  72.                      
  73.                     cmd.Connection = con;  
  74.                     sda.SelectCommand = cmd;  
  75.                     using (DataTable dt = new DataTable())  
  76.                     {  
  77.                       
  78.                         sda.Fill(dt);  
  79.                         if (dt.Rows.Count > 0)  
  80.                         {  
  81.                             lblError.Text = "Welcome  "+ dt.Rows[0]["Emp_Name"].ToString();  
  82.                             Response.AddHeader("REFRESH""4;URL=Attendance.aspx");  
  83.                             return true;  
  84.                               
  85.                         }  
  86.   
  87.                         else  
  88.                         {  
  89.                             lblError.Text += "ID Doest Not Exist! ";  
  90.                             lblError.BackColor = System.Drawing.Color.Yellow;  
  91.                             Response.AddHeader("REFRESH""3;URL=Attendance.aspx");  
  92.                             return false;  
  93.                               
  94.                         }  
  95.   
  96.                     }  
  97.                 }  
  98.             }  
  99.         }  
  100.   
  101.     }  
  102.   
  103.   
  104.   
  105.   
  106. }  
  107.   
  108.   
  109.   
  110.   
  111.