TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Asyraf MN
NA
28
7.6k
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 :
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
;
}
}
}
}
}
}
}
Reply
Answers (
0
)
How Do I Set The Current Date (Date Only) In My Text Box
how to remove blank spaces in html file name