public void AtualizarGridEquipamento(DialogResult dialogResult) { using (EquipamentoNegocio equipamentoNegocio = new EquipamentoNegocio()) { ValidacaoInterfaces validarInterfaces = new ValidacaoInterfaces(); if (dialogResult == DialogResult.Yes) { try { ListaEquipamento listaEquipamento = equipamentoNegocio.ConsultarPorCodigoOuDescricao(null, "%"); this.dgwSelecionarEquipamento.DataSource = null; this.dgwSelecionarEquipamento.DataSource = listaEquipamento; this.dgwSelecionarEquipamento.Update(); this.dgwSelecionarEquipamento.Refresh(); txtSelecionarCodNome.Focus(); txtSelecionarCodNome.Clear(); return; } catch (Exception ex) { MessageBox.Show("Não foi possível atualizar, após ter inserido ou alterado equipamento. Datalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } } else if (validarInterfaces.ValidarCampoPesquisar(this.txtSelecionarCodNome, "nome") == true) { return; } else if (this.txtSelecionarCodNome.Text.Where(c => char.IsNumber(c)).Count() > 0) { try { ListaEquipamento listaEquipamento = equipamentoNegocio.ConsultarPorCodigoOuDescricao(Convert.ToInt32(this.txtSelecionarCodNome.Text), null); if (listaEquipamento.Count() > 0) { this.dgwSelecionarEquipamento.DataSource = null; this.dgwSelecionarEquipamento.DataSource = listaEquipamento; this.dgwSelecionarEquipamento.Update(); this.dgwSelecionarEquipamento.Refresh(); txtSelecionarCodNome.Focus(); return; } else { MessageBox.Show("Não existe nenhum equipamento com esse código: " + txtSelecionarCodNome.Text, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarCodNome.Focus(); return; } } catch (Exception ex) { MessageBox.Show("Não foi possível inserir equipamento. Datalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSelecionarCodNome.Focus(); return; } } else { try { ListaEquipamento listaEquipamento = equipamentoNegocio.ConsultarPorCodigoOuDescricao(null, this.txtSelecionarCodNome.Text); if (listaEquipamento.Count() > 0) { this.dgwSelecionarEquipamento.DataSource = null; this.dgwSelecionarEquipamento.DataSource = listaEquipamento; this.dgwSelecionarEquipamento.Update(); this.dgwSelecionarEquipamento.Refresh(); txtSelecionarCodNome.Focus(); return; } else { MessageBox.Show("Não existe nenhum equipamento com esse nome: " + txtSelecionarCodNome.Text, "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information); txtSelecionarCodNome.Focus(); return; } } catch (Exception ex) { MessageBox.Show("Não foi possível alterar equipamento. Detalhes: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); txtSelecionarCodNome.Focus(); return; } } } }
public void Dispose() { acessoDadosSqlServer = null; listaEquipamento = null; }