123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- 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 = "введите пароль";
- }
- }
- }
- }
|