using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.SqlClient; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; namespace СУБД_Швейная_фабрика { public partial class FormAuthorization : Form { public FormAuthorization() { InitializeComponent(); } public static string StrCon = @"Data Source=213.155.192.79,3002;Initial Catalog=FabrikaLDA;User ID=u21liseenko;Password=bfg2"; private void cbxPassword_CheckedChanged(object sender, EventArgs e) { tbxPassword.UseSystemPasswordChar = !tbxPassword.UseSystemPasswordChar; } public static string IdUser = ""; private void lblReg_Click(object sender, EventArgs e) { FormRegistration frm = new FormRegistration(); this.Hide(); frm.ShowDialog(); this.Show(); } void GetCaptcha() { string TxtLetter = "QWERTYUIOPASDFGHJKLZXCVBNM"; string TxtDigit = "1234567890"; string captcha = ""; string tmp = TxtDigit + TxtLetter; Random rnd = new Random(); bool fDigit = false; for (int i = 0;i <3;i++) { char sym = tmp[rnd.Next(tmp.Length)]; if (char.IsDigit(sym)) { fDigit = true; } captcha += sym; } if (fDigit == false) captcha += TxtDigit[rnd.Next(TxtDigit.Length)]; else captcha += TxtLetter[rnd.Next(TxtLetter.Length)]; lblCaptcha.Text = captcha; } private void btnLogin_Click(object sender, EventArgs e) { if (lblCaptcha.Text != tbxCaptcha.Text.ToUpper()) { MessageBox.Show("Повторите ввод капчи!","Внимание!",MessageBoxButtons.OK, MessageBoxIcon.Error); GetCaptcha(); return; } SqlConnection con = new SqlConnection(StrCon); SqlCommand cmd = new SqlCommand($"select IdUser,login,Password,Role from Users where Login = '{tbxLogin.Text.Trim()}' and Password = '{tbxPassword.Text.Trim()}'", con); con.Open(); SqlDataReader res = cmd.ExecuteReader(); res.Read(); if (res.HasRows) { if (res["Role"].ToString() == "1") { FormManager frm = new FormManager(); this.Hide(); IdUser = res["IdUser"].ToString(); tbxLogin.Text = ""; tbxPassword.Text = ""; frm.ShowDialog(); this.Show(); } if (res["Role"].ToString() == "2") { FormStorekeeper frm = new FormStorekeeper(); this.Hide(); IdUser = res["IdUser"].ToString(); tbxLogin.Text = ""; tbxPassword.Text = ""; frm.ShowDialog(); this.Show(); } if (res["Role"].ToString() == "3") { FormClient frm = new FormClient(); this.Hide(); IdUser = res["IdUser"].ToString(); tbxLogin.Text = ""; tbxPassword.Text = ""; frm.ShowDialog(); this.Show(); } } else { MessageBox.Show("Ошибка авторизации!","Логин или пароль неправильны",MessageBoxButtons.OK, MessageBoxIcon.Error); GetCaptcha(); return; } con.Close(); } private void FormAuthorization_Load(object sender, EventArgs e) { GetCaptcha(); //14 dawdawd tbxCaptcha.Text = lblCaptcha.Text; // } private void pCap_Paint(object sender, PaintEventArgs e) { Color[] colors = { Color.Green, Color.Black, Color.Yellow, Color.White }; Random rnd = new Random(); for (int i = 0; i < rnd.Next(5, 10); i++) { int x1 = rnd.Next(pCap.Width); int x2 = rnd.Next(pCap.Width); int y1 = rnd.Next(pCap.Height); int y2 = rnd.Next(pCap.Height); Color color = colors[rnd.Next(colors.Length)]; e.Graphics.DrawLine(new Pen(color), x1, y1, x2, y2); } } } }