Advertisement
Guest User

Untitled

a guest
Feb 6th, 2017
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.41 KB | None | 0 0
  1. static string constring = System.Configuration.ConfigurationManager.ConnectionStrings["Restaurant"].ConnectionString;
  2.         SqlConnection konekcija = new SqlConnection(constring);
  3.         public LogIn()
  4.         {
  5.             InitializeComponent();
  6.         }
  7.  
  8.         private void button1_Click(object sender, EventArgs e)
  9.         {
  10.             string username = textBox1.Text;
  11.             string password = textBox2.Text;
  12.             string stringServer = "SELECT S.Server_password as pass FROM Server as S WHERE S.Server_username LIKE '"+ username +"'";
  13.             string stringManager = "SELECT M.Manager_password as pass FROM Manager as M WHERE M.Manager_username LIKE '" + username + "'";
  14.             string stringKitchen = "SELECT K.Kitchen_staff_password as pass FROM Kitchen_staff as K WHERE K.Kitchen_staff_username LIKE '" + username + "'";
  15.             string stringHostess = "SELECT H.Hostess_password as pass FROM Hostess as H WHERE H.Hostess_username LIKE '" + username + "'";
  16.            
  17.             SqlCommand komandaManager = new SqlCommand(stringHostess, konekcija);
  18.             string komanda = "" + stringServer + "; " + stringManager + "; " + stringKitchen + "; " + stringHostess;
  19.             SqlDataAdapter adapter = new SqlDataAdapter(komanda, konekcija);
  20.             adapter.TableMappings.Add("Table", "Server");
  21.             adapter.TableMappings.Add("Table1", "Manager");
  22.             adapter.TableMappings.Add("Table2", "Kitchen");
  23.             adapter.TableMappings.Add("Table3", "Hostess");
  24.  
  25.             DataSet ds = new DataSet();
  26.  
  27.             try
  28.             {
  29.                 konekcija.Open();
  30.                 adapter.Fill(ds);
  31.                 if (ds.Tables["Server"].Rows.Count != 0)
  32.                 {
  33.                     string s = Convert.ToString(ds.Tables["Server"].Rows[0]["pass"]);
  34.                     if (password.Equals(s))
  35.                     {
  36.                         this.Hide();
  37.                         Hello_Server f = new Hello_Server();
  38.                         f.ShowDialog();
  39.                     }
  40.                     else
  41.                     {
  42.                         MessageBox.Show("Невалиднa лозинка!");
  43.                     }
  44.                 }
  45.                 else if (ds.Tables["Manager"].Rows.Count != 0)
  46.                 {
  47.                     string s = Convert.ToString(ds.Tables["Manager"].Rows[0]["pass"]);
  48.                     if (password.Equals(s))
  49.                     {
  50.                         this.Hide();
  51.                         Hello_Server f = new Hello_Server();
  52.                         f.ShowDialog();
  53.                     }
  54.                     else
  55.                     {
  56.                         MessageBox.Show("Невалиднa лозинка!");
  57.                     }
  58.                 }
  59.                 else if (ds.Tables["Kitchen"].Rows.Count != 0)
  60.                 {
  61.                     string s = Convert.ToString(ds.Tables["Kitchen"].Rows[0]["pass"]);
  62.                     if (password.Equals(s))
  63.                     {
  64.                         this.Hide();
  65.                         Hello_Hostess f = new Hello_Hostess();
  66.                         f.ShowDialog();
  67.                     }
  68.                     else
  69.                     {
  70.                         MessageBox.Show("Невалиднa лозинка!");
  71.                     }
  72.                 }
  73.                 else if (ds.Tables["Hostess"].Rows.Count != 0)
  74.                 {
  75.                     string s = Convert.ToString(ds.Tables["Hostess"].Rows[0]["pass"]);
  76.                     if (password.Equals(s))
  77.                     {
  78.                         this.Hide();
  79.                         Hello_Server f = new Hello_Server();
  80.                         f.ShowDialog();
  81.                     }
  82.                     else
  83.                     {
  84.                         MessageBox.Show("Невалиднa лозинка!");
  85.                     }
  86.                 }
  87.                 else if (ds.Tables[0].Rows.Count == 0 || ds.Tables[1].Rows.Count == 0 ||
  88.                     ds.Tables[2].Rows.Count == 0 || ds.Tables[3].Rows.Count == 0)
  89.                 {
  90.                     MessageBox.Show("Невалидни корисничко име и лозинка!");
  91.                 }
  92.             }
  93.             catch (Exception err)
  94.             {
  95.                 MessageBox.Show(err.Message);
  96.             }
  97.             finally
  98.             {
  99.                 konekcija.Close();
  100.             }
  101.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement