Пример #1
0
        public bool IsUserExists()
        {
            DataTable        dataTable        = new DataTable();
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            MySqlConnection  _connection      = DataBaseUtils.GetMySqlConnection();



            MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM `users` WHERE `login` = @uL", _connection);

            sqlCommand.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginField.Text;

            mySqlDataAdapter.SelectCommand = sqlCommand;
            mySqlDataAdapter.Fill(dataTable);

            if (dataTable.Rows.Count == 0)
            {
                Debug_text.Text += "\r\n нет таких пользователей ";
                return(true);
            }
            else
            {
                Debug_text.Text += "\r\n записано";
                return(false);
            }
        }
Пример #2
0
        private void button_Register_Click(object sender, EventArgs e)
        {
            string loginUser   = loginField.Text;
            string passUser    = PassField.Text;
            string nameUser    = NameField.Text;
            string surnameUser = SurnameField.Text;

            DataTable        dataTable        = new DataTable();
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            MySqlConnection  _connection      = DataBaseUtils.GetMySqlConnection();

            //OPEN CONNECTION
            try
            {
                Debug_text.Text = "Connection Getting...";
                _connection.Open();
                Debug_text.Text += "\r\nConnection Open...";
            }
            catch
            {
                Debug_text.Text += "\r\nConnection Close";
            }

            if (NameField.Text == "Enter name" || SurnameField.Text == "Enter surname" || loginField.Text == "Enter login" || PassField.Text == "Enter password")
            {
                Debug_text.Text += "\r\nAccount was not created(Fill in all the fields)...";
                return;
            }
            else
            {
                Debug_text.Text += "\r\nAccount has been created.";
            }

            if (IsUserExists())
            {
                return;
            }

            Debug_text.Text += "\r\nRegistration completed.";


            MySqlCommand sqlCommand = new MySqlCommand("INSERT INTO `users` (`id`, `login`, `pass`, `name`, `surname`) VALUES (NULL, @uLogin, @uPassword, @uName, @uSurname);", _connection);

            sqlCommand.Parameters.Add("@uLogin", MySqlDbType.VarChar).Value    = loginUser;
            sqlCommand.Parameters.Add("@uPassword", MySqlDbType.VarChar).Value = passUser;
            sqlCommand.Parameters.Add("@uName", MySqlDbType.VarChar).Value     = nameUser;
            sqlCommand.Parameters.Add("@uSurname", MySqlDbType.VarChar).Value  = surnameUser;


            mySqlDataAdapter.SelectCommand = sqlCommand;
            mySqlDataAdapter.Fill(dataTable);


            //CLOSE CONNECTION
            _connection.Close();
            Debug_text.Text += "\r\nConnection Close";
        }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            string nameSUser    = NameS.Text;
            string loginUser    = loginField.Text;
            string surnameSUser = SurnameS.Text;
            string numberSUser  = NumberS.Text;

            DataTable        dataTable        = new DataTable();
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            MySqlConnection  _connection      = DataBaseUtils.GetMySqlConnection();

            try
            {
                Debug_text.Text = "Connection Getting...";
                _connection.Open();
                Debug_text.Text += "\r\nConnection Open...";
            }
            catch
            {
                Debug_text.Text += "\r\nConnection Close";
            }

            if (IsUserExists())
            {
                return;
            }

            //СЛОЖНО
            using (MySqlCommand sqlCommand = new MySqlCommand(" INSERT INTO `books` (`name`, `surname`, `number`,`id_book`,`login`) VALUES ( @nameS, @surnameS, @numberS,NULL,@loginUser)", _connection))
            {
                //СЛОЖНО
                sqlCommand.Parameters.Add("@loginUser", MySqlDbType.VarChar).Value = loginUser;
                sqlCommand.Parameters.Add("@nameS", MySqlDbType.VarChar).Value     = nameSUser;
                sqlCommand.Parameters.Add("@surnameS", MySqlDbType.VarChar).Value  = surnameSUser;
                sqlCommand.Parameters.Add("@numberS", MySqlDbType.VarChar).Value   = numberSUser;


                try
                {
                    mySqlDataAdapter.SelectCommand = sqlCommand;
                    mySqlDataAdapter.Fill(dataTable);
                }
                catch (Exception)
                {
                    Debug_text.Text += "\r\nERROR FOR ID ROW 1";
                }
            }

            Debug_text.Text += "\r\n" + nameSUser + " = name\r\n" + surnameSUser + " = surname\r\n" + numberSUser + " = number";
        }
Пример #4
0
        private void button_Enter_Click(object sender, EventArgs e)
        {
            string loginUser = loginField.Text;
            string passUser  = PassField.Text;

            DataTable        dataTable        = new DataTable();
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            MySqlConnection  _connection      = DataBaseUtils.GetMySqlConnection();

            try
            {
                Debug_text.Text = "Openning Connection ...";
                _connection.Open();
                Debug_text.Text += "\r\nConnection successful!\r\n...";
            }
            catch
            {
                Debug_text.Text += "\r\nError";
            }

            MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM `users` WHERE `login` = @uL AND `pass`  = @uP", _connection);

            sqlCommand.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginUser;
            sqlCommand.Parameters.Add("@uP", MySqlDbType.VarChar).Value = passUser;

            mySqlDataAdapter.SelectCommand = sqlCommand;
            mySqlDataAdapter.Fill(dataTable);

            if (dataTable.Rows.Count > 0)
            {
                Hide();
                MainForm mainForm = new MainForm();
                mainForm.Show();
            }
            else
            {
                Debug_text.Text += "\r\nuser is NOT registered";
            }
        }
Пример #5
0
        private void Show_Bill_Click(object sender, EventArgs e)
        {
            string          loginUser = get_bill_login.Text;
            List <string[]> data      = new List <string[]>();


            DataTable        dataTable        = new DataTable();
            MySqlDataAdapter mySqlDataAdapter = new MySqlDataAdapter();
            MySqlConnection  _connection      = DataBaseUtils.GetMySqlConnection();

            //if (IsUserExists())
            //   return;

            MySqlCommand sqlCommand = new MySqlCommand("SELECT * FROM books WHERE login = @loginUser", _connection);

            sqlCommand.Parameters.Add("@loginUser", MySqlDbType.VarChar).Value = loginUser;

            MySqlDataReader dataReader = sqlCommand.ExecuteReader();

            DataTable schemaTable = dataReader.GetSchemaTable();

            while (dataReader.Read())
            {
                for (int i = 0; i < dataReader.FieldCount; i++)
                {
                    Debug_text.Text += dataReader.GetString(i);
                }
            }

            dataReader.Close();

            Debug_text.Text += "\r\n" + data;

            mySqlDataAdapter.SelectCommand = sqlCommand;
            mySqlDataAdapter.Fill(dataTable);
        }