Beispiel #1
0
        private void btnEquipamentoCadastrar_Click(object sender, EventArgs e)
        {
            using (EquipamentoNegocio equipamentoNegocio = new EquipamentoNegocio())
            {
                ValidacaoInterfaces validarInterfaces = new ValidacaoInterfaces();
                if (validarInterfaces.validarCampoCadastrar(this.grpEquipamento.Controls) == true)
                {
                    return;
                }
                else if (validarInterfaces.ValidarRadioButton(this.rbtCadastrarAtivoSim, this.rbtCadastrarAtivoNao) == true)
                {
                    return;
                }

                if (acaoNaTelaInformada == AcaoNaTela.Inserir)
                {
                    Equipamento equipamentoInserir = new Equipamento()
                    {
                        Nome       = this.txtCadastrarNomeEquipamento.Text,
                        Quantidade = Convert.ToInt32(this.txtCadastrarQuantidade.Text),
                        Ativo      = this.rbtCadastrarAtivoSim.Checked == true? true: false
                    };

                    string retorno = equipamentoNegocio.Inserir(equipamentoInserir);

                    try
                    {
                        int codigo = Convert.ToInt32(retorno);
                        MessageBox.Show("Equipamento cadastrado com sucesso. Código: " + codigo.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                    }
                    catch
                    {
                        MessageBox.Show("Não foi possível cadastrar o equipamento. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
                else if (acaoNaTelaInformada == AcaoNaTela.Alterar)
                {
                    Equipamento equipamentoAlterar = new Equipamento()
                    {
                        IDEquipamento = Convert.ToInt32(this.txtCadastrarCodigo.Text),
                        Nome          = txtCadastrarNomeEquipamento.Text,
                        Quantidade    = Convert.ToInt32(this.txtCadastrarQuantidade.Text),
                        Ativo         = this.rbtCadastrarAtivoSim.Checked == true? true: false
                    };

                    string retorno = equipamentoNegocio.Alterar(equipamentoAlterar);

                    try
                    {
                        int codigo = Convert.ToInt32(retorno);
                        MessageBox.Show("Equipamento alterado com sucesso. Código: " + codigo.ToString(), "Aviso", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        this.DialogResult = System.Windows.Forms.DialogResult.Yes;
                    }
                    catch
                    {
                        MessageBox.Show("Não foi possível alterar o equipamento. Detalhes: " + retorno, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
        }
Beispiel #2
0
 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;
             }
         }
     }
 }