Goran Bibic

Goran Bibic

  • 482
  • 2.9k
  • 197.9k

Select IMAGE from SQL BASE to picturebox C#

Apr 29 2018 1:53 PM
Code working fine
 
I need to put picture from sql to picturebox in my code
 
 
  1. private void prijavaAction()  //04.04. final doradjena perfect  
  2.        {  
  3.   
  4.            {  
  5.                SqlConnection con = new SqlConnection(cs);  
  6.   
  7.                if (textBox1.Text.All(char.IsDigit))  
  8.   
  9.                {  
  10.                    string queryString = "SELECT [ime_prezime] FROM dbo.radnici WHERE bar_kod = '" + textBox1.Text + "'";// pronaci radnika u bazi  
  11.                    using (SqlConnection connection = new SqlConnection(cs))  
  12.                    {  
  13.                        SqlCommand command = new SqlCommand(queryString, connection);  
  14.                        connection.Open();  
  15.                        SqlDataReader reader = command.ExecuteReader();  
  16.   
  17.   
  18.   
  19.                        string commanda = "select case when (SELECT (DATEDIFF(SECOND, Max(vrijemeprijave), GETDATE()) / 60) from dbo.prijava_radnika where status='prijavljen' and radnik= (" + queryString + ")) < 5 THEN 1 ELSE 0 END";  
  20.                        SqlConnection connection3 = new SqlConnection(cs);  
  21.                        SqlCommand command2 = new SqlCommand(commanda, connection3);  
  22.                        connection3.Open();  
  23.   
  24.                        int broj = Convert.ToInt32(command2.ExecuteScalar());  
  25.   
  26.   
  27.   
  28.                        string commanda2 = "select case when (SELECT (DATEDIFF(SECOND, Max(vrijemeodjave), GETDATE()) / 60) from dbo.prijava_radnika where status='odjavljen' and radnik= (" + queryString + ")) < 5 THEN 1 ELSE 0 END";  
  29.                        SqlConnection connection4 = new SqlConnection(cs);  
  30.                        SqlCommand command4 = new SqlCommand(commanda2, connection4);  
  31.                        connection4.Open();  
  32.   
  33.                        int broj2 = Convert.ToInt32(command4.ExecuteScalar());  
  34.   
  35.                        if (broj == 1 || broj2 == 1)  
  36.   
  37.                        {  
  38.                            notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FD7400");  
  39.                            messageLabel.Text = "Prijava i odjava su blokirani 5 minuta \nza ovog radnika";  
  40.                            textBox1.Text = "";  
  41.                        }  
  42.                        else  
  43.                        {  
  44.   
  45.   
  46.   
  47.   
  48.                            try  
  49.                            {  
  50.                                if (reader.Read())  
  51.   
  52.                                {  
  53.   
  54.                                    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";  
  55.                                    SqlCommand provjeraprijaveradnika = new SqlCommand(prijava, con);  
  56.                                    con.Open();  
  57.                                    int result = Convert.ToInt32(provjeraprijaveradnika.ExecuteScalar());  
  58.   
  59.                                    con.Close();  
  60.                                    if ((result == 0))  
  61.   
  62.                                    {  
  63.                                        String saveStaff = "INSERT INTO dbo.prijava_radnika (vrijemeprijave, status, radnik,idfakture) VALUES(@vrijemeprijave,'prijavljen', '" + readerresultTextbox.Text + "',@idfakture)";  
  64.                                        using (SqlConnection openCon2 = new SqlConnection(cs))  
  65.                                        {  
  66.                                            using (SqlCommand querySaveStaff = new SqlCommand(saveStaff))  
  67.                                            {  
  68.                                                querySaveStaff.Connection = openCon2;  
  69.                                                querySaveStaff.Parameters.Add("@vrijemeprijave", SqlDbType.DateTime).Value = DateTime.Now;  
  70.                                                querySaveStaff.Parameters.Add("@idfakture", SqlDbType.Int).Value = id_fakture;  
  71.                                                openCon2.Open();  
  72.                                                querySaveStaff.ExecuteNonQuery();  
  73.                                                openCon2.Close();  
  74.   
  75.                                                notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#2EFF36");  
  76.                                            //  messageLabel.Text = (reader["ime_prezime"].ToString()) + " je prijavljen u \n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");  
  77.                                                messageLabel.Text = ("Dobro došli na posao...\n" + reader["ime_prezime"].ToString()) + " \nPrijavljeni ste od\n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");  
  78.                                                readerresultTextbox.Text = (reader["ime_prezime"].ToString());  
  79.                                            }  
  80.                                        }  
  81.                                    }  
  82.                                    else  
  83.                                    {  
  84.   
  85.                                        String updateStaff = " declare @maxNo integer = 0 select @maxNo = isnull(max(redni_broj), 0) from[dbo].[prijava_radnika] UPDATE[dbo].[prijava_radnika] SET"  
  86.                                            + " [vrijemeodjave] = @vrijemeodjave,[redni_broj] = (@maxNo+1),[status] = 'odjavljen' WHERE radnik = '" + readerresultTextbox.Text + "'and [status] = 'prijavljen'";  
  87.   
  88.   
  89.   
  90.                                        using (SqlConnection connection1 = new SqlConnection(cs))  
  91.                                        {  
  92.                                            SqlCommand command1 = new SqlCommand(queryString, connection1);  
  93.                                            connection1.Open();  
  94.                                            SqlDataReader reader1 = command1.ExecuteReader();  
  95.                                            connection.Close();  
  96.                                            try  
  97.                                            {  
  98.                                                if (reader1.Read())  
  99.                                                {  
  100.   
  101.   
  102.                                                    using (SqlConnection openCon3 = new SqlConnection(cs))  
  103.                                                    {  
  104.                                                        using (SqlCommand queryupdateStaff = new SqlCommand(updateStaff))  
  105.                                                        {  
  106.                                                            queryupdateStaff.Connection = openCon3;  
  107.                                                            queryupdateStaff.Parameters.Add("@vrijemeodjave", SqlDbType.DateTime).Value = DateTime.Now;  
  108.                                                            openCon3.Open();  
  109.                                                            queryupdateStaff.ExecuteNonQuery();  
  110.                                                            openCon3.Close();  
  111.   
  112.                                                        }  
  113.                                                    }  
  114.   
  115.                                                    notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FFE11A");  
  116.                                                    messageLabel.Text = (reader1["ime_prezime"].ToString()) + " je odjavljen u \n " + DateTime.Now.ToString("dd.MM.yyyy HH:mm:ss");  
  117.                                                }  
  118.                                            }  
  119.                                            catch { }  
  120.   
  121.   
  122.                                        }  
  123.   
  124.   
  125.   
  126.                                        reader.Close();  
  127.                                    }  
  128.   
  129.                                }  
  130.                                else  
  131.                                {  
  132.                                    notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FD7400");  
  133.                                    messageLabel.Text = "Radnik ne postoji u bazi! \nProverite vašu karticu ili probajte ponovo!";  
  134.                                    textBox1.Text = "";  
  135.   
  136.   
  137.                                }  
  138.                            }  
  139.                            finally  
  140.                            {  
  141.   
  142.                            }  
  143.                        }  
  144.   
  145.   
  146.   
  147.                    }  
  148.                }  
  149.   
  150.                else  
  151.                {  
  152.                    notificationPanel.BackColor = System.Drawing.ColorTranslator.FromHtml("#FD7400");  
  153.                    messageLabel.Text = "Bar kod nije važeci ili nije bar kod";  
  154.                    textBox1.Text = "";  
  155.                }  
  156.   
  157.   
  158.   
  159.   
  160.   
  161.            }  
  162.        } 

Answers (2)