Beispiel #1
0
 private void btnCadastrar_Click(object sender, EventArgs e)
 {
     try
     {
         if (acao == "Cadastrar" && btnCadastrar.Text == "Cadastrar" && ValidarCampos())
         {
             modelCliente.Nome = txtNome.Text;
             CamposCrud();
             if (!controllerCliente.VerificarClienteCadastrado(modelCliente) && controllerCliente.Cadastrar(modelCliente))
             {
                 MessageBox.Show("Cadastrado com sucesso!", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 printFont = new Font("Arial", 9);
                 PrintDocument pd = new PrintDocument();
                 printDialog1.Document = pd;
                 var result = printDialog1.ShowDialog();
                 if (result == DialogResult.OK)
                 {
                     pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                     pd.Print();
                 }
                 this.Close();
                 this.Close();
             }
             else
             {
                 MessageBox.Show("Nome já cadastrado!", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else if (acao == "Editar" && btnCadastrar.Text == "Editar")
         {
             pnlInformacoesDoCliente.Enabled             = true;
             pnlHabitosHistoricoClinicoDaCliente.Enabled = true;
             btnCadastrar.Text = "Salvar";
             btnCancelar.Text  = "Cancelar";
         }
         else if (acao == "Editar" && btnCadastrar.Text == "Salvar" && ValidarCampos())
         {
             modelCliente.Codigo = codigo;
             CamposCrud();
             if (controllerCliente.Editar(modelCliente))
             {
                 MessageBox.Show("Editado com sucesso!", "Alerta!", MessageBoxButtons.OK, MessageBoxIcon.Information);
                 printFont = new Font("Arial", 9);
                 PrintDocument pd = new PrintDocument();
                 printDialog1.Document = pd;
                 var result = printDialog1.ShowDialog();
                 if (result == DialogResult.OK)
                 {
                     pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                     pd.Print();
                 }
                 this.Close();
             }
         }
         else if (acao == "Consultar" && btnCadastrar.Text == "Imprimir")
         {
             CamposCrud();
             try
             {
                 printFont = new Font("Arial", 9);
                 PrintDocument pd = new PrintDocument();
                 printDialog1.Document = pd;
                 var result = printDialog1.ShowDialog();
                 if (result == DialogResult.OK)
                 {
                     pd.PrintPage += new PrintPageEventHandler(printDocument1_PrintPage);
                     pd.Print();
                 }
             }
             catch (Exception)
             {
                 throw;
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Erro!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }