예제 #1
0
        private void Registration_back_Click(object sender, EventArgs e)
        {
            this.Hide();
            AddData addData = new AddData();

            addData.Show();
        }
예제 #2
0
        private void pictureBox1_Click(object sender, EventArgs e)
        {
            this.Hide();
            AddData addData = new AddData();

            addData.Show();
        }
예제 #3
0
        private void Login_Click(object sender, EventArgs e)
        {
            string UserLogin = LoginField.Text;
            string UserPass  = PassField.Text;

            var           connectionString = ConfigurationManager.ConnectionStrings["Archive_Demo.Properties.Settings.IPSArchiveConnectionString"].ConnectionString;
            SqlConnection connection       = new SqlConnection(connectionString);

            try
            {
                // Открываем подключение
                connection.Open();
                Console.WriteLine("Подключение открыто");
                Console.WriteLine("Свойства подключения:");
                Console.WriteLine("\tСтрока подключения: {0}", connection.ConnectionString);
                Console.WriteLine("\tБаза данных: {0}", connection.Database);
                Console.WriteLine("\tСервер: {0}", connection.DataSource);
                Console.WriteLine("\tВерсия сервера: {0}", connection.ServerVersion);
                Console.WriteLine("\tСостояние: {0}", connection.State);
                Console.WriteLine("\tWorkstationld: {0}", connection.WorkstationId);

                //string sqlExpression ="SELECT * FROM users WHERE 'Login' = @uL AND 'Password'= @uP";


                SqlDataAdapter adapter = new SqlDataAdapter($"SELECT ID FROM Users WHERE Login='******' AND Password='******'", connection);
                //SqlCommand command = new SqlCommand($"SELECT * FROM users WHERE 'Login'='"+ LoginField.Text +"' AND 'Password'='" + PassField.Text + "'", connection);
                //command.Parameters.Add("@uL", SqlDbType.VarChar).Value = UserLogin;
                //command.Parameters.Add("@uP", SqlDbType.VarChar).Value = UserPass;
                DataTable table = new DataTable();
                adapter.Fill(table);
                if (table.Rows.Count > 0)
                {
                    int        s       = table.Rows[0].Field <int>(0);
                    string     sql     = $"UPDATE Users SET Log_Time = '{DateTime.Now}' WHERE Login = '******' AND Password = '******'";
                    SqlCommand command = new SqlCommand(sql, connection);
                    int        number  = command.ExecuteNonQuery();
                    Console.WriteLine("Добавлено объектов: {0}", number);
                    Console.WriteLine("Сеанс записан в базу: {0}", s);

                    sql     = "SELECT Status FROM users WHERE Login='******' AND Password='******'";
                    command = new SqlCommand(sql, connection);
                    SqlDataReader reader = command.ExecuteReader();
                    while (reader.Read())
                    {
                        if (reader.GetValue(0).ToString() == "0")
                        {
                            this.Hide();
                            WorkerForm workerForm = new WorkerForm(s);
                            workerForm.Show();
                        }
                        if (reader.GetValue(0).ToString() == "1")
                        {
                            this.Hide();
                            AddData addData = new AddData(s);
                            addData.Show();
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Данный пользователь не обнаружен!");
                }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

                /* string sqlExpression = "SELECT * FROM users";
                 * SqlCommand command2 = new SqlCommand(sqlExpression, connection);
                 * SqlDataReader reader = command2.ExecuteReader();
                 *
                 * if (reader.HasRows) // если есть данные
                 * {
                 *   // выводим названия столбцов
                 *   Console.WriteLine("{0}\t{1}\t{2}\t{3}\t{4}\t{5}", reader.GetName(0), reader.GetName(1), reader.GetName(2), reader.GetName(3), reader.GetName(4), reader.GetName(5));
                 *
                 *   while (reader.Read()) // построчно считываем данные
                 *   {
                 *       object id = reader.GetValue(0);
                 *       object name = reader.GetValue(1);
                 *       object surname = reader.GetValue(2);
                 *       object login = reader.GetValue(3);
                 *       object pass = reader.GetValue(4);
                 *       object status = reader.GetValue(5);
                 *
                 *   Console.WriteLine("{0} \t{1} \t{2} \t{3} \t{4} \t{5}", id, name, surname, login, pass, status);
                 *   }
                 * }
                 *
                 * reader.Close();*/
                /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            }
            catch (SqlException ex)
            {
                Console.WriteLine(ex.Message);
            }
            finally
            {
                // закрываем подключение
                connection.Close();
                Console.WriteLine("Подключение закрыто...");
            }
        }