Пример #1
0
        private void dgv_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            newUser = false;
            EnableComponents(true);
            int udId = (int)dgv[0, dgv.CurrentRow.Index].Value;

            ProfDataSet.UserDepartmentDataTable dtud = new ProfDataSet.UserDepartmentDataTable();
            userDepartmentTableAdapter1.FillByDep(dtud, udId);
            ProfDataSet.UsersDataTable udt = new ProfDataSet.UsersDataTable();
            usersTableAdapter1.FillByUser(udt, (int)dtud.Rows[0]["idUser"]);
            ProfDataSet.UserRoleDataTable urdt = new ProfDataSet.UserRoleDataTable();
            userRoleTableAdapter1.FillByUser(urdt, (int)dtud.Rows[0]["idUser"]);
            cb_department.SelectedValue = (int)dtud.Rows[0]["idDepartments"];
            cb_people.SelectedValue     = (int)udt.Rows[0]["idPeople"];
            tb_login.Text         = udt.Rows[0]["login"].ToString();
            cb_role.SelectedValue = (int)urdt.Rows[0]["idRole"];
        }
Пример #2
0
        private void B_delete_Click(object sender, EventArgs e)
        {
            int delId;

            delId = (int)dgv[0, dgv.CurrentRow.Index].Value;
            ProfDataSet.UserDepartmentDataTable dtud = new ProfDataSet.UserDepartmentDataTable();
            userDepartmentTableAdapter1.FillByDep(dtud, delId);
            delId = (int)dtud.Rows[0]["idUser"];

            if (delId != 0 && (MessageBox.Show("Вы уверены в удалении?", "Удаление", MessageBoxButtons.YesNo, MessageBoxIcon.Information) == DialogResult.Yes))
            {
                if (idUser == delId)
                {
                    MessageBox.Show("Вы не можете удалить свою учётную запись!", "Внимание", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    usersTableAdapter1.DeleteUser(delId);
                    loadGrid();
                    EnableComponents(false);
                }
            }
        }
Пример #3
0
        private void b_save_Click(object sender, EventArgs e)
        {
            if (tb_pwd.Text.Trim() == tb_pwdSecond.Text.Trim())
            {
                if (newUser)
                {
                    int           idNewUser = 0;
                    SqlConnection conn      = DB.GetDBConnection();
                    string        sql       = $" INSERT INTO prof.Users (login, idPeople, pwd) " +
                                              $" VALUES(@login, @idPeople, @pwd); " +
                                              $" SELECT SCOPE_IDENTITY() as id";

                    SqlCommand cmd = new SqlCommand(sql);
                    cmd.Parameters.Add("@login", SqlDbType.NVarChar);
                    cmd.Parameters.Add("@idPeople", SqlDbType.Int);
                    cmd.Parameters.Add("@pwd", SqlDbType.NVarChar);
                    cmd.Parameters["@login"].Value    = tb_login.Text;
                    cmd.Parameters["@idPeople"].Value = (int)cb_people.SelectedValue;
                    cmd.Parameters["@pwd"].Value      = sha1(sha1(tb_pwd.Text.Trim() + "$2$4"));
                    cmd.Connection = conn;

                    conn.Open();
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        if (reader.HasRows)
                        {
                            reader.Read();
                            idNewUser = (int)reader.GetDecimal(0);
                        }
                    }
                    userRoleTableAdapter1.Insert(idNewUser, (int)cb_role.SelectedValue);
                    userDepartmentTableAdapter1.Insert(idNewUser, (int)cb_department.SelectedValue);
                }
                else
                {
                    int udId = (int)dgv[0, dgv.CurrentRow.Index].Value;
                    ProfDataSet.UserDepartmentDataTable dtud = new ProfDataSet.UserDepartmentDataTable();
                    userDepartmentTableAdapter1.FillByDep(dtud, udId);
                    ProfDataSet.UsersDataTable udt = new ProfDataSet.UsersDataTable();
                    usersTableAdapter1.FillByUser(udt, (int)dtud.Rows[0]["idUser"]);
                    ProfDataSet.UserRoleDataTable urdt = new ProfDataSet.UserRoleDataTable();
                    userRoleTableAdapter1.FillByUser(urdt, (int)dtud.Rows[0]["idUser"]);
                    DataRow dr = udt.Rows[0];
                    dr["login"]    = tb_login.Text;
                    dr["pwd"]      = tb_pwd.Text.Trim() != "" ? sha1(sha1(tb_pwd.Text.Trim() + "$2$4")) : dr["pwd"];
                    dr["idPeople"] = (int)cb_people.SelectedValue;
                    usersTableAdapter1.Update(dr);
                    dr           = urdt.Rows[0];
                    dr["idUser"] = (int)udt.Rows[0]["id"];
                    dr["idRole"] = (int)cb_role.SelectedValue;
                    userRoleTableAdapter1.Update(dr);
                    dr                  = dtud.Rows[0];
                    dr["idUser"]        = (int)udt.Rows[0]["id"];
                    dr["idDepartments"] = (int)cb_department.SelectedValue;
                    userDepartmentTableAdapter1.Update(dr);
                }
                newUser = false;
                EnableComponents(false);
                loadGrid();
            }
            else
            {
                MessageBox.Show("Пароли не совпадают!");
            }
        }