private void EditButton_Click(object sender, EventArgs e) { if (UsersDataGrid.CurrentCell != null) { int index = UsersDataGrid.CurrentCell.RowIndex; int userId = Convert.ToInt32(UsersDataGrid[0, index].Value); string userLogin = Convert.ToString(UsersDataGrid[1, index].Value); string userPassword = Convert.ToString(UsersDataGrid[2, index].Value); string userName = Convert.ToString(UsersDataGrid[3, index].Value); AddUserForm editForm = new AddUserForm { UserLogin = userLogin, Password = userPassword, UserName = userName }; editForm.ShowDialog(); if (editForm.DialogResult == DialogResult.OK) { userLogin = editForm.UserLogin; userPassword = editForm.Password; userName = editForm.UserName; string queryText = "UPDATE userlist SET [login]='" + userLogin + "',[password]='" + Crypto.EncodeDecrypt(userPassword) + "',[username]='" + userName + "' WHERE ID=" + Convert.ToString(userId); ExecuteQuery(queryText); ShowUsers(); } } else { MessageBox.Show("Не выбран пользователь для редактирования!", "Ошибка!", MessageBoxButtons.OK); } }
private void AddButton_Click(object sender, EventArgs e) { AddUserForm addForm = new AddUserForm(); addForm.ShowDialog(); if (addForm.DialogResult == DialogResult.OK) { string userLogin = addForm.UserLogin; string userPassword = addForm.Password; string userName = addForm.UserName; string queryText = "INSERT INTO userlist([login],[password],username) VALUES ('" + userLogin + "','" + Crypto.EncodeDecrypt(userPassword) + "','" + userName + "')"; ExecuteQuery(queryText); ShowUsers(); } }