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 System.Data.SqlClient; namespace konkurs { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button3_Click(object sender, EventArgs e) { } public string constring = "Data Source=CLASS3108;Initial Catalog=konkurs;Integrated Security=True"; private void button2_Click(object sender, EventArgs e) { SqlConnection con = new SqlConnection(constring); SqlDataReader sqlReader = null; con.Open(); SqlCommand command = new SqlCommand("Select * FROM [dbo].[Users] WHERE login = @login AND password = @password", con); command.Parameters.Add("@login", textBox1.Text); command.Parameters.Add("@password", textBox2.Text); try { sqlReader = command.ExecuteReader(); if (!sqlReader.HasRows) { string message = "пароль введен не верно"; string caption = "Form close"; MessageBox.Show(message,caption, MessageBoxButtons.OK, MessageBoxIcon.Error); } while (sqlReader.Read()) { if(sqlReader["Admin"].ToString() == "1") { Form2 fr2 = new Form2(); fr2.Show(); this.Hide(); } if (sqlReader["manager"].ToString() == "1") { Form3 fr3 = new Form3(); fr3.Show(); this.Hide(); } } } catch (Exception ex) { MessageBox.Show(ex.Message.ToString(), ex.Source.ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error); } finally { if (sqlReader != null) sqlReader.Close(); } } private void textBox1_TextChanged(object sender, EventArgs e) { } private void textBox1_Enter(object sender, EventArgs e) { if(textBox1.Text == "введите логин") { textBox1.Text = ""; } } private void textBox1_Leave(object sender, EventArgs e) { if (textBox1.Text == "") { textBox1.Text = "введите логин"; } } private void textBox2_Enter(object sender, EventArgs e) { if (textBox2.Text == "введите пароль") { textBox2.Text = ""; } } private void textBox2_Leave(object sender, EventArgs e) { if (textBox2.Text == "") { textBox2.Text = "введите пароль"; } } } }