Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using MySql.Data.MySqlClient;
- namespace БД_Мессенджера
- {
- public partial class Authorization : Form
- {
- public Authorization()
- {
- InitializeComponent();
- }
- public bool admin = false;
- public bool manager = false;
- public bool user =false;
- public void button1_Click(object sender, EventArgs e)
- {
- try
- {
- MySqlConnection constr = new MySqlConnection("Server=localhost; database=messenger; UID= root; password=Am I so weird?; Integrated Security=True");
- MySqlDataAdapter sda = new MySqlDataAdapter("Select id from user_table where concat(name,' ',surname)='" + textBox1.Text + "'and password='" + textBox2.Text + "'", constr);
- DataTable dt = new DataTable();
- sda.Fill(dt);
- if (dt.Rows[0][0].ToString() == "1")
- {
- admin = true;
- MessageBox.Show("Admin");
- ConnectionWork.SetConnection(0);
- }
- if (dt.Rows[0][0].ToString() == "2")
- {
- manager = true;
- MessageBox.Show("Manager");
- ConnectionWork.SetConnection(1);
- }
- if (dt.Rows[0][0].ToString() != "2" && dt.Rows[0][0].ToString() != "1")
- {
- user = true;
- MessageBox.Show("User");
- ConnectionWork.SetConnection(2);
- }
- admin_form f1 = new admin_form();
- f1.admin = admin;
- f1.manager = manager;
- f1.user = user;
- this.Close();
- }
- catch { MessageBox.Show("incorrect name/password");
- }
- }
- private void Authorization_Load(object sender, EventArgs e)
- {
- }
- private void button2_Click(object sender, EventArgs e)
- {
- this.Close();
- }
- private void Authorization_FormClosed(object sender, FormClosedEventArgs e)
- {
- if (admin == true)
- {
- (Application.OpenForms[0] as admin_form).admin_panel.Visible = true;
- (Application.OpenForms[0] as admin_form).user_panel.Visible = false;
- (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
- (Application.OpenForms[0] as admin_form).button5.Enabled = true;
- (Application.OpenForms[0] as admin_form).button4.Enabled = true;
- }
- else if (user == true)
- {
- (Application.OpenForms[0] as admin_form).admin_panel.Visible = false;
- (Application.OpenForms[0] as admin_form).user_panel.Visible = true;
- (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
- }
- else if (manager == true)
- {
- (Application.OpenForms[0] as admin_form).admin_panel.Visible = true;
- (Application.OpenForms[0] as admin_form).user_panel.Visible = false;
- (Application.OpenForms[0] as admin_form).button5.Enabled = false;
- (Application.OpenForms[0] as admin_form).button4.Enabled = false;
- (Application.OpenForms[0] as admin_form).bunifuCustomDataGrid2.DataSource = null;
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment