Пример #1
0
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            if (userNameField.Text.Contains(' ') || userSurnameField.Text.Contains(' ') ||
                textBox_login.Text.Contains(' ') || textBox_pass.Text.Contains(' ') ||
                textBox1_otch.Text.Contains(' ') || textBox1_pol.Text.Contains(' ') ||
                textBox1_pas.Text.Contains(' ') ||
                textBox1_tel.Text.Contains(' ') || textBox1_cat.Text.Contains(' '))
            {
                MessageBox.Show("Введите корректные значения");
                return;
            }
            else
            if (userNameField.Text == "Введите имя" || userSurnameField.Text == "Введите фамилию" ||
                textBox_login.Text == "Введите логин" || textBox_pass.Text == "Введите пароль" ||
                textBox1_otch.Text == "Введите отчество" || textBox1_pol.Text == "Введите подразделение" ||
                textBox1_pas.Text == "Электронная почта" ||
                textBox1_tel.Text == "Номер телефона" || textBox1_cat.Text == "Введите должность")
            {
                MessageBox.Show("Введите данные");
                return;
            }

            if (isUserExists())
            {
                return;
            }

            DB db = new DB();

            MySqlDataReader reader;

            MySqlCommand command = new MySqlCommand("INSERT INTO `oborot`.`sotrudnik` (`Фамилия`, `Имя`, `Отчество`," +
                                                    " `Телефон`, `Электронная почта`, `DOLZNOST_id`, `PODRAZDELENIE_id`)" +
                                                    " VALUES (@surname, @name, @otch, @tel, @mail, @dol_id, @pod_id)", db.getConnection());

            command.Parameters.Add("@name", MySqlDbType.VarChar).Value    = userNameField.Text;
            command.Parameters.Add("@surname", MySqlDbType.VarChar).Value = userSurnameField.Text;
            command.Parameters.Add("@otch", MySqlDbType.VarChar).Value    = textBox1_otch.Text;
            command.Parameters.Add("@tel", MySqlDbType.VarChar).Value     = textBox1_tel.Text;
            command.Parameters.Add("@mail", MySqlDbType.VarChar).Value    = textBox1_pas.Text;
            command.Parameters.Add("@dol_id", MySqlDbType.VarChar).Value  = textBox1_cat.Text;
            command.Parameters.Add("@pod_id", MySqlDbType.VarChar).Value  = textBox1_pol.Text;

            db.openConnection();

            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Аккаунт создан");
            }
            else
            {
                MessageBox.Show("Аккаунт не создан");
            }

            db.closeConnection();

            MySqlCommand command_vxod_id = new MySqlCommand("select id from `sotrudnik` where Имя = @name AND Фамилия = @surname AND Отчество = @otch AND Телефон = @tel AND `Электронная почта` = @mail AND DOLZNOST_id = @dol_id AND PODRAZDELENIE_id = @pod_id", db.getConnection());

            command_vxod_id.Parameters.Add("@name", MySqlDbType.VarChar).Value    = userNameField.Text;
            command_vxod_id.Parameters.Add("@surname", MySqlDbType.VarChar).Value = userSurnameField.Text;
            command_vxod_id.Parameters.Add("@otch", MySqlDbType.VarChar).Value    = textBox1_otch.Text;
            command_vxod_id.Parameters.Add("@tel", MySqlDbType.VarChar).Value     = textBox1_tel.Text;
            command_vxod_id.Parameters.Add("@mail", MySqlDbType.VarChar).Value    = textBox1_pas.Text;
            command_vxod_id.Parameters.Add("@dol_id", MySqlDbType.VarChar).Value  = textBox1_cat.Text;
            command_vxod_id.Parameters.Add("@pod_id", MySqlDbType.VarChar).Value  = textBox1_pol.Text;

            db.openConnection();

            reader = command_vxod_id.ExecuteReader();
            while (reader.Read())
            {
                vxod_id = reader["id"].ToString();
            }

            db.closeConnection();

            MySqlCommand command_vxod = new MySqlCommand("INSERT INTO `oborot`.`vxod` (`login`, `password`, `SOTRUDNIK_id`)" +
                                                         " VALUES (@login, @pas, @sotr_id)", db.getConnection());

            command_vxod.Parameters.Add("@login", MySqlDbType.VarChar).Value   = textBox_login.Text;
            command_vxod.Parameters.Add("@pas", MySqlDbType.VarChar).Value     = textBox_pass.Text;
            command_vxod.Parameters.Add("@sotr_id", MySqlDbType.VarChar).Value = vxod_id;

            db.openConnection();

            command_vxod.ExecuteNonQuery();

            db.closeConnection();
        }
Пример #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            login.Value = textBox_login.Text;


            DB db = new DB();

            DataTable table = new DataTable();

            MySqlDataAdapter adapter = new MySqlDataAdapter();

            MySqlDataReader reader;
            MySqlDataReader reader1;
            MySqlDataReader reader2;

            MySqlCommand command               = new MySqlCommand("select * from `vxod` where login = @uL AND password = @uP", db.getConnection());
            MySqlCommand command_category      = new MySqlCommand("select наименование_должности from sotrudnik join dolznost on DOLZNOST_id = dolznost.id join VXOD on SOTRUDNIK_id = SOTRUDNIK.id where login = @uL", db.getConnection());
            MySqlCommand command_name          = new MySqlCommand("select имя from `SOTRUDNIK` join VXOD on SOTRUDNIK_id = SOTRUDNIK.id where login = @uL", db.getConnection());
            MySqlCommand command_podrazdelenie = new MySqlCommand("select PODRAZDELENIE.id from `PODRAZDELENIE` " +
                                                                  "join SOTRUDNIK on PODRAZDELENIE_id = PODRAZDELENIE.id join VXOD on SOTRUDNIK_id = SOTRUDNIK.id " +
                                                                  "where login = @uL;", db.getConnection());

            command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = textBox_login.Text;
            command.Parameters.Add("@uP", MySqlDbType.VarChar).Value = textBox_pass.Text;

            command_category.Parameters.Add("@uL", MySqlDbType.VarChar).Value = textBox_login.Text;

            command_name.Parameters.Add("@uL", MySqlDbType.VarChar).Value = textBox_login.Text;

            command_podrazdelenie.Parameters.Add("@uL", MySqlDbType.VarChar).Value = textBox_login.Text;

            db.openConnection();

            adapter.SelectCommand = command;
            adapter.Fill(table);

            reader = command_category.ExecuteReader();
            while (reader.Read())
            {
                categoryUser.Value = reader["наименование_должности"].ToString();
            }

            db.closeConnection();

            db.openConnection();

            reader2 = command_podrazdelenie.ExecuteReader();
            while (reader2.Read())
            {
                podrazdelenie.Value = reader2["id"].ToString();
            }

            db.closeConnection();

            db.openConnection();

            reader1 = command_name.ExecuteReader();
            while (reader1.Read())
            {
                logos.Value = reader1["имя"].ToString();
            }


            if (table.Rows.Count > 0 && categoryUser.Value == "admin")
            {
                this.Hide();
                MainForm mainForm = new MainForm();
                mainForm.Show();
            }
            else
            if (table.Rows.Count > 0 && categoryUser.Value == "rukovoditel")
            {
                this.Hide();
                RukovosShow RukovosShow = new RukovosShow();

                RukovosShow.Show();
            }
            else
            if (table.Rows.Count > 0 && categoryUser.Value == "sotrudnik")
            {
                this.Hide();
                UserMain UserMain = new UserMain();

                UserMain.Show();
            }
            else
            {
                MessageBox.Show("Неверный логин или пароль");
            }

            db.closeConnection();
        }
Пример #3
0
        private void button2_Click(object sender, EventArgs e)
        {
            obnovTbl = "2";
            if (logos.Value == "office")
            {
                button5.Visible = false;
                flagTblcomp     = "1";
            }
            else
            if (logos.Value == "company")
            {
                button5.Visible = true;
            }

            if (logos.Value == "company")
            {
                flagTbl = "1";
                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from work_user_doc where users_id = (select id from users where логин = @uL)", db.getConnection());

                command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = login.Value;

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (logos.Value == "office")
            {
                flagTbl = "2";
                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from work_user_doc", db.getConnection());

                command.Parameters.Add("@uL", MySqlDbType.VarChar).Value = login.Value;

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
        }
Пример #4
0
        private void button3_Click(object sender, EventArgs e)
        {
            if (flagTbl == "SOTRUDNIK")
            {
                flagTable = 1;
                flagTbl   = "SOTRUDNIK";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from SOTRUDNIK", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (flagTbl == "VXOD")
            {
                flagTable = 2;
                flagTbl   = "VXOD";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from VXOD", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (flagTbl == "PODRAZDELENIE")
            {
                flagTable = 3;
                flagTbl   = "PODRAZDELENIE";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from PODRAZDELENIE", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            //else
            //if (flagTbl == "sessions")
            //{
            //    flagTable = 5;
            //    flagTbl = "sessions";

            //    ds.Reset();
            //    MySqlDataAdapter adapter = new MySqlDataAdapter();

            //    DB db = new DB();

            //    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //    dataGridView1.AllowUserToAddRows = false;

            //    MySqlCommand command = new MySqlCommand("select * from session", db.getConnection());

            //    db.openConnection();

            //    adapter.SelectCommand = command;
            //    adapter.Fill(ds);
            //    dataGridView1.DataSource = ds.Tables[0];

            //    db.closeConnection();

            //}
            else
            if (flagTbl == "DOLZNOST")
            {
                flagTable = 4;
                flagTbl   = "DOLZNOST";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from DOLZNOST", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (flagTbl == "HISTORY")
            {
                flagTable = 6;
                flagTbl   = "HISTORY";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from HISTORY", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (flagTbl == "DOKUMENT")
            {
                flagTable = 7;
                flagTbl   = "DOKUMENT";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from DOKUMENT", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            else
            if (flagTbl == "TIP_DOKUMENTA")
            {
                flagTable = 8;
                flagTbl   = "TIP_DOKUMENTA";

                ds.Reset();
                MySqlDataAdapter adapter = new MySqlDataAdapter();

                DB db = new DB();

                dataGridView1.SelectionMode      = DataGridViewSelectionMode.FullRowSelect;
                dataGridView1.AllowUserToAddRows = false;

                MySqlCommand command = new MySqlCommand("select * from TIP_DOKUMENTA", db.getConnection());

                db.openConnection();

                adapter.SelectCommand = command;
                adapter.Fill(ds);
                dataGridView1.DataSource = ds.Tables[0];

                db.closeConnection();
            }
            //else
            //if (flagTbl == "gotov_doc")
            //{
            //    flagTable = 9;
            //    flagTbl = "gotov_doc";

            //    ds.Reset();
            //    MySqlDataAdapter adapter = new MySqlDataAdapter();

            //    DB db = new DB();

            //    dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
            //    dataGridView1.AllowUserToAddRows = false;

            //    MySqlCommand command = new MySqlCommand("select * from gotov_doc", db.getConnection());

            //    db.openConnection();

            //    adapter.SelectCommand = command;
            //    adapter.Fill(ds);
            //    dataGridView1.DataSource = ds.Tables[0];

            //    db.closeConnection();
            //}
            else
            if (flagTbl == "")
            {
                MessageBox.Show("Выберите таблицу");
            }
        }
Пример #5
0
        public void noneid_PODRAZDELENIE()
        {
            string ids = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString();

            DB           db      = new DB();
            MySqlCommand command = new MySqlCommand("DELETE FROM PODRAZDELENIE " +
                                                    " WHERE `id` = @idx", db.getConnection());

            command.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            db.openConnection();
            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Запись удалена");
            }
            else
            {
                MessageBox.Show("Запись не удалена");
            }

            db.closeConnection();

            //Это было до изменения программы может пригодится
            //DB db = new DB();
            //MySqlCommand command = new MySqlCommand("DELETE FROM company " +
            //    " WHERE `id` = @idx", db.getConnection());
            //MySqlCommand command1 = new MySqlCommand("DELETE FROM adres " +
            //    " WHERE `company_id` = @idx", db.getConnection());
            //MySqlCommand command2 = new MySqlCommand("DELETE FROM doc " +
            //    " WHERE `company_id` = @idx", db.getConnection());
            //MySqlCommand command3 = new MySqlCommand("DELETE FROM work_user_doc " +
            //    " WHERE `doc_id` IN (select id from doc where company_id = @idx)", db.getConnection());
            //MySqlCommand command4 = new MySqlCommand("DELETE FROM gotov_doc " +
            //    " WHERE `doc_id` IN (select id from doc where company_id = @idx)", db.getConnection());

            //command.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            //command1.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            //command2.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            //command3.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            //command4.Parameters.Add("@idx", MySqlDbType.Int32).Value = ids;

            //db.openConnection();
            //command4.ExecuteNonQuery();
            //command3.ExecuteNonQuery();
            //command1.ExecuteNonQuery();
            //command2.ExecuteNonQuery();

            //if (command.ExecuteNonQuery() == 1)
            //{

            //    MessageBox.Show("Запись удалена");
            //}
            //else
            //    MessageBox.Show("Запись не удалена");

            //db.closeConnection();
        }
Пример #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            if (flagTable == 0)
            {
                MessageBox.Show("Выберите таблицу");
                return;
            }
            if (flagTable == 1)
            {
                noneid_SOTRUDNIK();
                return;
            }
            if (flagTable == 2)
            {
                noneidVXOD();
                return;
            }
            if (flagTable == 3)
            {
                noneid_PODRAZDELENIE();
                return;
            }
            if (flagTable == 4)
            {
                noneid_DOLZNOST();
                return;
            }
            if (flagTable == 6)
            {
                noneid_HISTORY();
                return;
            }
            if (flagTable == 7)
            {
                noneid_DOKUMENT();
                return;
            }

            if (flagTable == 8)
            {
                noneidWork();
                return;
            }
            if (flagTable == 9)
            {
                noneidWork();
                return;
            }

            string ids = dataGridView1[0, dataGridView1.CurrentRow.Index].Value.ToString();
            int    id  = int.Parse(ids);

            DB           db      = new DB();
            MySqlCommand command = new MySqlCommand("DELETE FROM " + flagTbl +
                                                    " WHERE `id` = @idx", db.getConnection());

            command.Parameters.Add("@idx", MySqlDbType.Int32).Value = id;

            db.openConnection();

            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Запись удалена");
            }
            else
            {
                MessageBox.Show("Запись не удалена");
            }

            db.closeConnection();
        }
Пример #7
0
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            DB db = new DB();

            MySqlDataReader reader;

            MySqlCommand command_log = new MySqlCommand("select sotrudnik.id from `sotrudnik` join vxod on SOTRUDNIK.id = SOTRUDNIK_id WHERE login = @login", db.getConnection());

            command_log.Parameters.Add("@login", MySqlDbType.VarChar).Value = userNameField.Text;


            db.openConnection();

            reader = command_log.ExecuteReader();
            while (reader.Read())
            {
                log_id = reader["id"].ToString();
            }

            db.closeConnection();

            MySqlCommand command_vxod_id = new MySqlCommand("select vxod.id from `sotrudnik` join vxod on SOTRUDNIK.id = SOTRUDNIK_id WHERE login = @login", db.getConnection());

            command_vxod_id.Parameters.Add("@login", MySqlDbType.VarChar).Value = userNameField.Text;


            db.openConnection();

            reader = command_vxod_id.ExecuteReader();
            while (reader.Read())
            {
                vxod_id = reader["id"].ToString();
            }

            db.closeConnection();

            MySqlCommand command_del_vxod = new MySqlCommand("DELETE FROM `oborot`.`vxod` WHERE (`id` = @vxod_id);", db.getConnection());

            command_del_vxod.Parameters.Add("@vxod_id", MySqlDbType.VarChar).Value = vxod_id;

            db.openConnection();

            command_del_vxod.ExecuteNonQuery();

            db.closeConnection();

            MySqlCommand command = new MySqlCommand("DELETE FROM `oborot`.`sotrudnik` WHERE (`id` = @log_id);", db.getConnection());

            command.Parameters.Add("@log_id", MySqlDbType.VarChar).Value = log_id;

            db.openConnection();

            if (command.ExecuteNonQuery() == 1)
            {
                MessageBox.Show("Аккаунт удален");
            }
            else
            {
                MessageBox.Show("Аккаунт не удален");
            }

            db.closeConnection();
        }