private void btnOk_Click(object sender, EventArgs e) { Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("id", user_id); parameters.Add("login", tbLogin.Text); parameters.Add("role_id", dt_roles.Rows[cbRole.SelectedIndex]["id"]); if (user_id != 0) { if (tbPassword.Text == "") { DBFunctions.ExecuteCommand("UPDATE auth_user SET login=@login,role_id=@role_id WHERE id=@id", parameters); } else { if (tbCredentials.Text == "") { System.Windows.Forms.MessageBox.Show("Должно быть заполнено поле \"Данные подключения\"", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } parameters.Add("encrypted_credentials", Encryption.Encrypt(tbCredentials.Text, tbPassword.Text)); DBFunctions.ExecuteCommand("UPDATE auth_user SET login=@login,role_id=@role_id,encrypted_credentials=@encrypted_credentials WHERE id=@id", parameters); } } else { if (tbPassword.Text == "") { System.Windows.Forms.MessageBox.Show("Должно быть заполнено поле \"Пароль\"", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } if (tbCredentials.Text == "") { System.Windows.Forms.MessageBox.Show("Должно быть заполнено поле \"Данные подключения\"", "Ошибка", System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error); return; } parameters.Add("encrypted_credentials", Encryption.Encrypt(tbCredentials.Text, tbPassword.Text)); DBFunctions.ExecuteCommand("INSERT INTO auth_user SET login=@login,role_id=@role_id,encrypted_credentials=@encrypted_credentials", parameters); } DialogResult = System.Windows.Forms.DialogResult.OK; Close(); }
private void tsbDelete_Click(object sender, EventArgs e) { DataRow curr_row = GreenLight.Tools.FindCurrentRow(dgUsers); if (curr_row == null) { return; } int curr_id = (int)curr_row["Идентификатор"]; Dictionary <string, object> parameters = new Dictionary <string, object>(); parameters.Add("id", curr_id); DBFunctions.ExecuteCommand("DELETE FROM auth_user WHERE id = @id", parameters); int col = dgUsers.CurrentCell.ColumnIndex; int row = dgUsers.CurrentCell.RowIndex; FillDataGrid(); dgUsers.CurrentCell = dgUsers[col, Math.Min(row, dgUsers.Rows.Count - 1)]; }