//CARREGAR FORMA PAGAMENTO
 public Modelo_formaPagamento carregaFormaPag(int codigo)
 {
     try
     {
         conexao.AbrirConexao();
         Modelo_formaPagamento formaPagamento = new Modelo_formaPagamento();
         MySqlCommand          cmd            = new MySqlCommand();
         cmd.Connection  = conexao.Conexao;
         cmd.CommandText = "SELECT * FROM FORMAPAGAMENTO WHERE ID = @ID";
         cmd.Parameters.AddWithValue("@ID", codigo);
         MySqlDataReader dt = cmd.ExecuteReader();
         if (dt.HasRows)
         {
             dt.Read();
             formaPagamento.id        = Convert.ToInt32(dt["id"]);
             formaPagamento.descricao = Convert.ToString(dt["descricao"]);
         }
         return(formaPagamento);
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         conexao.FecharConexao();
     }
 }
        //METEDO GRAVAR NO BANCO
        public void SalvarFormaPag(Modelo_formaPagamento pagamento)
        {
            if (pagamento.descricao.Trim().Length == 0)
            {
                throw new Exception("O Nome da Descrição é bobrigatorio");
            }
            Negocio_FormaPagamento formaPagamento = new Negocio_FormaPagamento(conexao);

            formaPagamento.SalvarFormaPag(pagamento);
        }
        //METEDO EDITAR FORMA DE PAGAMENTO
        public void EditarFormaPag(Modelo_formaPagamento pagamento)
        {
            if (pagamento.id <= 0)
            {
                throw new Exception("selecione uma Condição");
            }
            if (pagamento.descricao.Trim().Length == 0)
            {
                throw new Exception("O Nome da Descrição é bobrigatorio");
            }
            Negocio_FormaPagamento formaPagamento = new Negocio_FormaPagamento(conexao);

            formaPagamento.EditarFormaPag(pagamento);
        }
 //METEDO GRAVAR NO BANCO
 public void SalvarFormaPag(Modelo_formaPagamento pagamento)
 {
     try
     {
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection  = conexao.Conexao;
         cmd.CommandText = "INSERT INTO FORMAPAGAMENTO (DESCRICAO) VALUES(@DESCRICAO)";
         cmd.Parameters.AddWithValue("@DESCRICAO", pagamento.descricao);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         conexao.FecharConexao();
     }
 }
 //METEDO EDITAR FORMA DE PAGAMENTO
 public void EditarFormaPag(Modelo_formaPagamento pagamento)
 {
     try
     {
         MySqlCommand cmd = new MySqlCommand();
         cmd.Connection  = conexao.Conexao;
         cmd.CommandText = "UPDATE FORMAPAGAMENTO SET DESCRICAO = @DESCRICAO WHERE ID = @ID";
         cmd.Parameters.AddWithValue("@DESCRICAO", pagamento.descricao);
         cmd.Parameters.AddWithValue("@ID", pagamento.id);
         cmd.ExecuteNonQuery();
     }
     catch (Exception ex)
     {
         throw new Exception(ex.Message);
     }
     finally
     {
         conexao.FecharConexao();
     }
 }
 //METEDO GRAVAR
 private void btnGravar_Click(object sender, EventArgs e)
 {
     try
     {
         conexao.AbrirConexao();
         Validacao_FormaPagamento formaPagamento = new Validacao_FormaPagamento(conexao);
         Modelo_formaPagamento    modelo         = new Modelo_formaPagamento();
         if (operacao == "Cadastrar")
         {
             modelo.descricao = txtFormaPag.Text;
             formaPagamento.SalvarFormaPag(modelo);
             MetroMessageBox.Show(this, "\n\n Salvo com Sucesso ", "Cadastrado",
                                  MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.AlterarBotao(1);
             this.LimpaCampo();
             this.DesabilitaCampos();
         }
         else
         {
             modelo.descricao = txtFormaPag.Text;
             modelo.id        = Convert.ToInt32(txtId.Text);
             formaPagamento.EditarFormaPag(modelo);
             MetroMessageBox.Show(this, "\n\n Alterado com Sucesso ", "Editado",
                                  MessageBoxButtons.OK, MessageBoxIcon.Information);
             this.AlterarBotao(1);
             this.LimpaCampo();
             this.DesabilitaCampos();
         }
     }
     catch (Exception ex)
     {
         MetroMessageBox.Show(this, ex.Message + "\n\n Ops Aconteceu Algum Erro \n\n Chame o Administrador do Sistema? ", "ATENÇÃO ERRO",
                              MessageBoxButtons.OK, MessageBoxIcon.Error);
         this.AlterarBotao(3);
         txtFormaPag.Focus();
     }
     finally
     {
         conexao.FecharConexao();
     }
 }
        private void btnPesquisar_Click(object sender, EventArgs e)
        {
            frmRelatorioFormaPag formaPag = new frmRelatorioFormaPag();

            formaPag.ShowDialog();
            if (formaPag.codigo != 0)
            {
                Validacao_FormaPagamento validacao = new Validacao_FormaPagamento(conexao);
                Modelo_formaPagamento    modelo    = validacao.carregaFormaPag(formaPag.codigo);
                txtId.Text       = Convert.ToString(modelo.id);
                txtFormaPag.Text = modelo.descricao;
                AlterarBotao(3);
            }
            else
            {
                this.LimpaCampo();
                this.txtFormaPag.Focus();
                AlterarBotao(1);
            }
            formaPag.Dispose();
        }