123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- 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 KokursTest2
- {
- public partial class Form1 : Form
- {
- public Form1()
- {
- InitializeComponent();
- }
- private void Form1_Load(object sender, EventArgs e)
- {
- }
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- }
- private void button1_Click(object sender, EventArgs e)
- {
- String connstring = "Data Source=DESKTOP-Q8BTJMH;Initial Catalog=konkurs;Integrated Security=True";
- SqlConnection conn = new SqlConnection(connstring);
- conn.Open();
- SqlCommand command = new SqlCommand("Select * From users WHERE login = @login AND password = @password", conn);
- command.Parameters.Add("@login",textBox1.Text);
- command.Parameters.Add("@password", textBox2.Text);
- SqlDataReader reader = null;
-
- try{
- reader = command.ExecuteReader();
- if (reader.HasRows)
- {
- reader.Read();
- if (reader["admin"].ToString() == "1")
- {
- Form2 fr2 = new Form2();
- fr2.Show();
- this.Hide();
- }
- if (reader["manager"].ToString() == "1")
- {
- Form3 fr3 = new Form3();
- fr3.Show();
- this.Hide();
- }
- }
- else{
- MessageBox.Show("парроль введен неверно", "авторизация", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- }
- catch(Exception ex)
- {
- MessageBox.Show(ex.Message.ToString(), "", MessageBoxButtons.OK, MessageBoxIcon.Error);
- }
- finally
- {
- }
- }
- 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 = "Введите пароль";
- }
- }
- 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_TextChanged(object sender, EventArgs e)
- {
- }
- }
- }
|