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
Goran Bibic
482
2.9k
197.1k
After reader read wrong value insert new row...????
Apr 4 2018 4:01 AM
After reader read wrong value insert new row...????
I need to reader do NOTHING
private
void
prijavaAction()
//testna
{
{
SqlConnection con =
new
SqlConnection(cs);
if
(textBox1.Text.All(
char
.IsDigit))
{
string queryString =
"SELECT [ime_prezime] FROM dbo.radnici WHERE bar_kod = '"
+ textBox1.Text +
"'"
;
// pronaci radnika u bazi
using
(SqlConnection connection =
new
SqlConnection(cs))
{
SqlCommand command =
new
SqlCommand(queryString, connection);
connection.Open();
SqlDataReader reader = command.ExecuteReader();
try
{
if
(reader.Read())
//radi
//while (reader.Read()) //radi
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#2EFF36"
);
messageLabel.Text = (reader[
"ime_prezime"
].ToString()) +
" je prijavljen u \n "
+ DateTime.Now.ToString(
"dd.MM.yyyy HH:mm:ss"
);
readerresultTextbox.Text = (reader[
"ime_prezime"
].ToString());
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Radnik ne postoji u bazi! \nProverite vašu karticu ili probajte ponovo!"
;
textBox1.Text =
""
;
readerresultTextbox.Clear();
}
}
finally
{
string prijava =
"SELECT count(*) from dbo.prijava_radnika where vrijemeprijave is not null and vrijemeodjave is null and radnik = '"
+ readerresultTextbox.Text +
"' and redni_broj is NULL"
;
SqlCommand provjeraprijaveradnika =
new
SqlCommand(prijava, con);
con.Open();
int
result = Convert.ToInt32(provjeraprijaveradnika.ExecuteScalar());
//con.Open();
con.Close();
if
((result == 0))
//radi
//if ((prijava !))
{
String saveStaff =
"INSERT INTO dbo.prijava_radnika (vrijemeprijave, status, radnik,idfakture) VALUES(@vrijemeprijave,'prijavljen', '"
+ readerresultTextbox.Text +
"',@idfakture)"
;
using
(SqlConnection openCon2 =
new
SqlConnection(cs))
{
using
(SqlCommand querySaveStaff =
new
SqlCommand(saveStaff))
{
querySaveStaff.Connection = openCon2;
querySaveStaff.Parameters.Add(
"@vrijemeprijave"
, SqlDbType.DateTime).Value = DateTime.Now;
querySaveStaff.Parameters.Add(
"@idfakture"
, SqlDbType.Int).Value = id_fakture;
openCon2.Open();
querySaveStaff.ExecuteNonQuery();
openCon2.Close();
//notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFE11A");
// messageLabel.Text = (reader["ime_prezime"].ToString()) + " je prijavljen u \n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");
}
}
}
else
{
String updateStaff =
" declare @maxNo integer = 0 select @maxNo = isnull(max(redni_broj), 0) from[dbo].[prijava_radnika] UPDATE[dbo].[prijava_radnika] SET"
+
" [vrijemeodjave] = @vrijemeodjave,[redni_broj] = (@maxNo+1),[status] = 'odjavljen' WHERE radnik = '"
+ readerresultTextbox.Text +
"'and[status] = 'prijavljen'"
;
//string queryString = "SELECT [ime_prezime] FROM dbo.radnici WHERE bar_kod = '" + textBox1.Text + "'";// pronaci radnika u bazi
using
(SqlConnection connection1 =
new
SqlConnection(cs))
{
SqlCommand command1 =
new
SqlCommand(queryString, connection1);
connection1.Open();
SqlDataReader reader1 = command1.ExecuteReader();
connection.Close();
try
{
if
(reader1.Read())
{
using
(SqlConnection openCon3 =
new
SqlConnection(cs))
{
using
(SqlCommand queryupdateStaff =
new
SqlCommand(updateStaff))
{
queryupdateStaff.Connection = openCon3;
queryupdateStaff.Parameters.Add(
"@vrijemeodjave"
, SqlDbType.DateTime).Value = DateTime.Now;
openCon3.Open();
queryupdateStaff.ExecuteNonQuery();
openCon3.Close();
}
}
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FFE11A"
);
messageLabel.Text = (reader1[
"ime_prezime"
].ToString()) +
" je odjavljen u \n "
+ DateTime.Now.ToString(
"dd.MM.yyyy HH:mm:ss"
);
}
}
catch
{ }
}
// Always call Close when done reading.
reader.Close();
}
}
}
}
else
{
notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml(
"#FD7400"
);
messageLabel.Text =
"Bar kod nije važeci ili nije bar kod"
;
textBox1.Text =
""
;
}
}
}
Reply
Answers (
19
)
How to redirect to an actionmethod which has a parameter
how to ajax call change event on dropdown in mvc