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 Blanki_ekzamena { public partial class Form1 : Form { public Form1() { InitializeComponent(); } public DataTable Select(string selectSQL) { DataTable dataTable = new DataTable("dataBase"); SqlConnection sqlConnection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357"); sqlConnection.Open(); SqlCommand sqlCommand = sqlConnection.CreateCommand(); sqlCommand.CommandText = selectSQL; SqlDataAdapter sqlDataAdapter = new SqlDataAdapter(sqlCommand); sqlDataAdapter.Fill(dataTable); sqlConnection.Close(); return dataTable; } private void btn_sotr_Click(object sender, EventArgs e) { if (textBox2.UseSystemPasswordChar == true) { textBox2.UseSystemPasswordChar = false; } else { textBox2.UseSystemPasswordChar = true; } } public bool isFormVaid(string a, string b) { if (a.ToString().Trim() == String.Empty || b.ToString().Trim() == String.Empty) { MessageBox.Show("Обезательные поля пустые", "Пожалуйста, заполните обязательные поля", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; } else { return true; } } private bool checkAdmin(string login_sotrd, string password) { const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Администратор'"; DataTable table = new DataTable(); SqlCommand cmd = new SqlCommand(sql, DataBase.connect()); SqlDataAdapter adapter = new SqlDataAdapter(); cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50)); cmd.Parameters["@log"].Value = login_sotrd; cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50)); cmd.Parameters["@pass"].Value = password; adapter.SelectCommand = cmd; adapter.Fill(table); if (table.Rows.Count == 1) { DebugAndTrace hy = new DebugAndTrace(); string[] opisanie = new string[4]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[0] = command3.ExecuteScalar().ToString(); DebugAndTrace.fio = $"{opisanie[0]}"; SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[1] = command4.ExecuteScalar().ToString(); DebugAndTrace.ima = $"{opisanie[1]}"; SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[2] = command5.ExecuteScalar().ToString(); DebugAndTrace.oth = $"{opisanie[2]}"; SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[3] = command6.ExecuteScalar().ToString(); DebugAndTrace.dol = $"{opisanie[3]}"; } DebugAndTrace.login(textBox1.Text); return true; } else { return false; } } private bool checkOperator(string login_sotrd, string password) { const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Оператор'"; DataTable table = new DataTable(); SqlCommand cmd = new SqlCommand(sql, DataBase.connect()); SqlDataAdapter adapter = new SqlDataAdapter(); cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50)); cmd.Parameters["@log"].Value = login_sotrd; cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50)); cmd.Parameters["@pass"].Value = password; adapter.SelectCommand = cmd; adapter.Fill(table); if (table.Rows.Count == 1) { DebugAndTrace hy = new DebugAndTrace(); string[] opisanie = new string[4]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[0] = command3.ExecuteScalar().ToString(); DebugAndTrace.fio = $"{opisanie[0]}"; SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[1] = command4.ExecuteScalar().ToString(); DebugAndTrace.ima = $"{opisanie[1]}"; SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[2] = command5.ExecuteScalar().ToString(); DebugAndTrace.oth = $"{opisanie[2]}"; SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[3] = command6.ExecuteScalar().ToString(); DebugAndTrace.dol = $"{opisanie[3]}"; } DebugAndTrace.login(textBox1.Text); return true; } else { return false; } } private bool checkSotr(string login_sotrd, string password) { const string sql = "Select * from Sotrudnik WHERE Login = @log AND [Password] = @pass and [Dolgnost]='Сотрудник'"; DataTable table = new DataTable(); SqlCommand cmd = new SqlCommand(sql, DataBase.connect()); SqlDataAdapter adapter = new SqlDataAdapter(); cmd.Parameters.Add(new SqlParameter("@log", SqlDbType.NVarChar, 50)); cmd.Parameters["@log"].Value = login_sotrd; cmd.Parameters.Add(new SqlParameter("@pass", SqlDbType.NVarChar, 50)); cmd.Parameters["@pass"].Value = password; adapter.SelectCommand = cmd; adapter.Fill(table); if (table.Rows.Count == 1) { DebugAndTrace hy = new DebugAndTrace(); string[] opisanie = new string[4]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command3 = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[0] = command3.ExecuteScalar().ToString(); DebugAndTrace.fio = $"{opisanie[0]}"; SqlCommand command4 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[1] = command4.ExecuteScalar().ToString(); DebugAndTrace.ima = $"{opisanie[1]}"; SqlCommand command5 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[2] = command5.ExecuteScalar().ToString(); DebugAndTrace.oth = $"{opisanie[2]}"; SqlCommand command6 = new SqlCommand("Select [Dolgnost] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[3] = command6.ExecuteScalar().ToString(); DebugAndTrace.dol = $"{opisanie[3]}"; } DebugAndTrace.login(textBox1.Text); return true; } else { MessageBox.Show("Неправильный логин или пароль! Повторите ввод!"); return false; } } private void btn_reg_Click(object sender, EventArgs e) { if (isFormVaid(textBox1.Text, textBox2.Text)) { if (checkAdmin(textBox1.Text, textBox2.Text)) { Admin nh = new Admin(); string[] opisanie = new string[3]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection); opisanie[0] = command.ExecuteScalar().ToString(); Admin.familia = $"{opisanie[0]}"; SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection); opisanie[1] = command1.ExecuteScalar().ToString(); Admin.ima = $"{opisanie[1]}"; SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'and [Dolgnost]='Администратор'", connection); opisanie[2] = command2.ExecuteScalar().ToString(); Admin.othestvo = $"{opisanie[2]}"; } using (Admin fd = new Admin()) { this.Hide(); fd.ShowDialog(); this.Close(); } } if (checkOperator(textBox1.Text, textBox2.Text)) { Operator nh = new Operator(); string[] opisanie = new string[3]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[0] = command.ExecuteScalar().ToString(); Operator.familia = $"{opisanie[0]}"; SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[1] = command1.ExecuteScalar().ToString(); Operator.ima = $"{opisanie[1]}"; SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[2] = command2.ExecuteScalar().ToString(); Operator.othestvo = $"{opisanie[2]}"; } using (Operator fd = new Operator()) { this.Hide(); fd.ShowDialog(); this.Close(); } } if (checkSotr(textBox1.Text, textBox2.Text)) { Zakaz nd = new Zakaz(); string[] opisanie = new string[7]; using (SqlConnection connection = new SqlConnection("server=ngknn.ru;Trusted_Connection=No;DataBase=31P_Trifonova_PP;User ID=31П;PWD=12357")) { connection.Open(); SqlCommand command = new SqlCommand("Select [Familia] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[0] = command.ExecuteScalar().ToString(); Zakaz.familia = $"{opisanie[0]}"; SqlCommand command1 = new SqlCommand("Select [Ima] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[1] = command1.ExecuteScalar().ToString(); Zakaz.ima = $"{opisanie[1]}"; SqlCommand command2 = new SqlCommand("Select [Otchestvo] From [dbo].[Sotrudnik] where [Login] ='" + textBox1.Text + "' and [Password] ='" + textBox2.Text + "'", connection); opisanie[2] = command2.ExecuteScalar().ToString(); Zakaz.othestvo = $"{opisanie[2]}"; } using (Zakaz fd = new Zakaz()) { this.Hide(); fd.ShowDialog(); this.Close(); } } } } } }