Example #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (sotr.Text == "")
            {
                datacon          db      = new datacon();
                DataTable        dt      = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter();
                MySqlCommand     command = new MySqlCommand("SELECT * FROM `rab`", db.GetConnection());

                adapter.SelectCommand = command;
                adapter.Fill(dt);
                dataGridView1.DataSource = dt;
            }
            else
            {
                String           vr      = sotr.Text;
                datacon          db      = new datacon();
                DataTable        dt      = new DataTable();
                MySqlDataAdapter adapter = new MySqlDataAdapter();
                MySqlCommand     command = new MySqlCommand("SELECT * FROM `rab` where vremya = @vr", db.GetConnection());
                command.Parameters.Add("@vr", MySqlDbType.VarChar).Value = vr;
                adapter.SelectCommand = command;
                adapter.Fill(dt);
                dataGridView1.DataSource = dt;
            }
        }
Example #2
0
        private void button3_Click(object sender, EventArgs e)
        {
            String dt = AddSotr.Text;
            String ti = AddVrem.Text;
            String ui = Mesto.Text;
            String zi = AddRab.Text;


            datacon      db      = new datacon();
            MySqlCommand command = new MySqlCommand("INSERT INTO `rab`(sotrudnik, vremya, mesto, vidrab) values (@dt, @ti, @ui, @zi)", db.GetConnection());

            command.Parameters.Add("@dt", MySqlDbType.VarChar).Value = dt;
            command.Parameters.Add("@ti", MySqlDbType.VarChar).Value = ti;
            command.Parameters.Add("@ui", MySqlDbType.VarChar).Value = ui;
            command.Parameters.Add("@zi", MySqlDbType.VarChar).Value = zi;

            db.openConnection();
            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Запись добавлена");
            }
            else
            {
                MessageBox.Show("Ошибка");
            }

            db.closeConnection();
            button1.PerformClick();
        }
Example #3
0
        private void aut_Click(object sender, EventArgs e)
        {
            Form1  form1     = new Form1();
            user   userform  = new user();
            admin  adminform = new admin();
            String loginuser = userlogin.Text;
            String password  = userpass.Text;

            datacon db = new datacon();

            DataTable tableuser   = new DataTable();
            DataTable tableadmins = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            if (checkadm.Checked == true)
            {
                MySqlCommand command1 = new MySqlCommand("SELECT * FROM `admins` WHERE `login` = @uL AND `password` = @uP", db.GetConnection());
                command1.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginuser;
                command1.Parameters.Add("@uP", MySqlDbType.VarChar).Value = password;

                adapter.SelectCommand = command1;
                adapter.Fill(tableadmins);
                if (tableadmins.Rows.Count > 0)
                {
                    adminform.Show();
                    this.Hide();
                    userlogin.Text = "";
                    userpass.Text  = "";
                    tableadmins.Clear();
                }
                else
                {
                    MessageBox.Show("User not found,or is not an administrator!");
                }
            }
            else
            {
                MySqlCommand command2 = new MySqlCommand("SELECT * FROM `user` WHERE `login` = @uL AND `password` = @uP", db.GetConnection());
                command2.Parameters.Add("@uL", MySqlDbType.VarChar).Value = loginuser;
                command2.Parameters.Add("@uP", MySqlDbType.VarChar).Value = password;

                adapter.SelectCommand = command2;
                adapter.Fill(tableuser);
                if (tableuser.Rows.Count > 0)
                {
                    userform.UName.Text = loginuser;
                    userform.Show();
                    this.Hide();
                    userlogin.Text = "";
                    userpass.Text  = "";
                    tableuser.Clear();
                }
                else
                {
                    MessageBox.Show("User unexpected!");
                }
            }
        }
Example #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (checkBox1.Checked == true)
            {
                String ti = name.Text;
                String ui = pass.Text;



                datacon      db      = new datacon();
                MySqlCommand command = new MySqlCommand("INSERT INTO `admins`(login, password) values (@ti, @ui)", db.GetConnection());
                command.Parameters.Add("@ti", MySqlDbType.VarChar).Value = ti;
                command.Parameters.Add("@ui", MySqlDbType.VarChar).Value = ui;


                db.openConnection();
                if (command.ExecuteNonQuery() == 1)
                {
                    MessageBox.Show("Пользователь добавлен");
                }
                else
                {
                    MessageBox.Show("Ошибка");
                }

                db.closeConnection();
            }
            else
            {
                String ti = name.Text;
                String ui = pass.Text;



                datacon      db      = new datacon();
                MySqlCommand command = new MySqlCommand("INSERT INTO `user`(login, password) values (@ti, @ui)", db.GetConnection());
                command.Parameters.Add("@ti", MySqlDbType.VarChar).Value = ti;
                command.Parameters.Add("@ui", MySqlDbType.VarChar).Value = ui;


                db.openConnection();
                if (command.ExecuteNonQuery() == 1)
                {
                    MessageBox.Show("Пользователь добавлен");
                }
                else
                {
                    MessageBox.Show("Ошибка");
                }

                db.closeConnection();
            }
        }
Example #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            String  name = UName.Text;
            datacon db   = new datacon();

            MySqlDataAdapter adapter1 = new MySqlDataAdapter();
            MySqlCommand     command1 = new MySqlCommand("SELECT * FROM `rab` WHERE `sotrudnik` = @uL", db.GetConnection());

            command1.Parameters.Add("@uL", MySqlDbType.VarChar).Value = name;
            adapter1.SelectCommand = command1;
            adapter1.Fill(table);
            dataGridView1.DataSource = table;
        }