private void RemoverContato(string codigo) { var acessoBd = new AcessoDb(); var parametros = new List <KeyValuePair <string, object> >(); parametros.Add(new KeyValuePair <string, object>("@ContatoID", codigo)); acessoBd.Buscar( $"DELETE FROM Contato WHERE ContatoID = @ContatoID", parametros); MessageBox.Show("Contato removido com sucesso!", "Informação", MessageBoxButton.OK, MessageBoxImage.Information); var dtContato = acessoBd.Buscar( "SELECT ContatoID, A.Nome, Empresa, Cargo, Email, CONVERT(NVARCHAR(50), A.DataNascimento, 103) AS DataNascimento, Website, Residencial, Celular, A.ParentescoID, B.Nome AS Parentesco FROM Contato A LEFT JOIN Parentesco B ON A.ParentescoID = B.ParentescoID ORDER BY Nome", new List <KeyValuePair <string, object> >()); DataGrid.ItemsSource = dtContato.DefaultView; Dispatcher.BeginInvoke((Action)(() => DataGrid.Columns[9].Visibility = Visibility.Hidden)); }
private void Window_Loaded(object sender, RoutedEventArgs e) { var acessoBd = new AcessoDb(); var dtTipoAlocacao = acessoBd.Buscar("SELECT * FROM Parentesco ORDER BY Nome", new List <KeyValuePair <string, object> >()); cboParentesco.ItemsSource = dtTipoAlocacao.DefaultView; }
private void TabControl_SelectionChanged(object sender, System.Windows.Controls.SelectionChangedEventArgs e) { if (e.Source is TabControl && tbLista.IsSelected) { var acessoBd = new AcessoDb(); var dtContato = acessoBd.Buscar( "SELECT ContatoID, A.Nome, Empresa, Cargo, Email, CONVERT(NVARCHAR(50), A.DataNascimento, 103) AS DataNascimento, Website, Residencial, Celular, A.ParentescoID, B.Nome AS Parentesco FROM Contato A LEFT JOIN Parentesco B ON A.ParentescoID = B.ParentescoID ORDER BY Nome", new List <KeyValuePair <string, object> >()); DataGrid.ItemsSource = dtContato.DefaultView; Dispatcher.BeginInvoke((Action)(() => DataGrid.Columns[9].Visibility = Visibility.Hidden)); } }
private void CarregaDetalhesContato(string codigo) { var acessoBd = new AcessoDb(); var dtContato = acessoBd.Buscar( $"SELECT ContatoID, A.Nome, Empresa, Cargo, Email, CONVERT(NVARCHAR(50), A.DataNascimento, 103) AS DataNascimento, Website, Residencial, Celular, A.ParentescoID, B.Nome AS Parentesco FROM Contato A LEFT JOIN Parentesco B ON A.ParentescoID = B.ParentescoID WHERE ContatoID = {codigo} ORDER BY Nome", new List <KeyValuePair <string, object> >()); if (dtContato.DefaultView.Count > 0) { txtCodigo.Text = dtContato.DefaultView[0]["contatoId"].ToString(); txtNome.Text = dtContato.DefaultView[0]["Nome"].ToString(); txtEmpresa.Text = dtContato.DefaultView[0]["Empresa"].ToString(); txtCargo.Text = dtContato.DefaultView[0]["Cargo"].ToString(); txtEmail.Text = dtContato.DefaultView[0]["Email"].ToString(); txtResidencial.Text = dtContato.DefaultView[0]["Residencial"].ToString(); txtCelular.Text = dtContato.DefaultView[0]["Celular"].ToString(); dtpData.Text = dtContato.DefaultView[0]["DataNascimento"].ToString(); txtSite.Text = dtContato.DefaultView[0]["Website"].ToString(); cboParentesco.SelectedValue = dtContato.DefaultView[0]["ParentescoId"].ToString(); Dispatcher.BeginInvoke((Action)(() => tabControl1.SelectedIndex = 1)); } }