Guest User

Untitled

a guest
Mar 27th, 2018
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.78 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace БД_Мессенджера
  13. {
  14.     public partial class Authorization : Form
  15.     {
  16.         public Authorization()
  17.         {
  18.             InitializeComponent();
  19.         }
  20.  
  21.     public  bool admin = false;
  22.     public  bool manager = false;
  23.     public  bool user =false;
  24.  
  25.         public void button1_Click(object sender, EventArgs e)
  26.         {
  27.             try
  28.             {
  29.                 MySqlConnection constr = new MySqlConnection("Server=localhost; database=messenger; UID= root; password=Am I so weird?; Integrated Security=True");
  30.                 MySqlDataAdapter sda = new MySqlDataAdapter("Select id from user_table where concat(name,' ',surname)='" + textBox1.Text + "'and password='" + textBox2.Text + "'", constr);
  31.                 DataTable dt = new DataTable();
  32.                 sda.Fill(dt);
  33.                 if (dt.Rows[0][0].ToString() == "1")
  34.                 {
  35.                     admin = true;
  36.                     MessageBox.Show("Admin");
  37.  
  38.                     ConnectionWork.SetConnection(0);                    
  39.                 }
  40.                 if (dt.Rows[0][0].ToString() == "2")
  41.                 {
  42.                     manager = true;
  43.                     MessageBox.Show("Manager");
  44.                     ConnectionWork.SetConnection(1);
  45.                 }
  46.  
  47.                 if (dt.Rows[0][0].ToString() != "2" && dt.Rows[0][0].ToString() != "1")
  48.                 {
  49.                     user = true;
  50.                     MessageBox.Show("User");
  51.                     ConnectionWork.SetConnection(2);
  52.                 }
  53.                 admin_form f1 = new admin_form();
  54.                 f1.admin = admin;
  55.                 f1.manager = manager;
  56.                 f1.user = user;
  57.                 this.Close();
  58.             }
  59.             catch { MessageBox.Show("incorrect name/password");
  60.  
  61.                     }
  62.         }
  63.  
  64.         private void Authorization_Load(object sender, EventArgs e)
  65.         {
  66.            
  67.         }
  68.  
  69.         private void button2_Click(object sender, EventArgs e)
  70.         {
  71.             this.Close();
  72.         }
  73.  
  74.         private void Authorization_FormClosed(object sender, FormClosedEventArgs e)
  75.         {
  76.          
  77.            
  78.             if (admin == true)
  79.             {
  80.                 (Application.OpenForms[0] as admin_form).admin_panel.Visible = true;
  81.                 (Application.OpenForms[0] as admin_form).user_panel.Visible = false;
  82.                 (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
  83.                 (Application.OpenForms[0] as admin_form).button5.Enabled = true;
  84.                 (Application.OpenForms[0] as admin_form).button4.Enabled = true;
  85.             }
  86.            
  87.             else if (user == true)
  88.             {
  89.                 (Application.OpenForms[0] as admin_form).admin_panel.Visible = false;
  90.                 (Application.OpenForms[0] as admin_form).user_panel.Visible = true;
  91.                 (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
  92.             }
  93.            
  94.             else if (manager == true)
  95.             {
  96.                 (Application.OpenForms[0] as admin_form).admin_panel.Visible = true;
  97.                 (Application.OpenForms[0] as admin_form).user_panel.Visible = false;
  98.                 (Application.OpenForms[0] as admin_form).button5.Enabled = false;
  99.                 (Application.OpenForms[0] as admin_form).button4.Enabled = false;
  100.                 (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
  101.             }
  102.         }
  103.     }
  104. }
Add Comment
Please, Sign In to add comment