171 lines
5.1 KiB
C#
171 lines
5.1 KiB
C#
using DAL;
|
|
using BLL;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
using Modelo;
|
|
|
|
namespace IBRCAD
|
|
{
|
|
public partial class frm_cadtipopagamento : Form
|
|
{
|
|
public string operacao;
|
|
public void alterabotoes(int op)
|
|
{
|
|
pn_data.Enabled = false;
|
|
btn_inserir.Enabled = false;
|
|
btn_localizar.Enabled = false;
|
|
btn_alterar.Enabled = false;
|
|
btn_excluir.Enabled = false;
|
|
btn_cancel.Enabled = false;
|
|
btn_save.Enabled = false;
|
|
|
|
if (op == 1)
|
|
{
|
|
btn_inserir.Enabled = true;
|
|
btn_localizar.Enabled = true;
|
|
}
|
|
if (op == 2)
|
|
{
|
|
pn_data.Enabled = true;
|
|
btn_save.Enabled = true;
|
|
btn_cancel.Enabled = true;
|
|
}
|
|
if (op == 3)
|
|
{
|
|
btn_alterar.Enabled = true;
|
|
btn_excluir.Enabled = true;
|
|
btn_cancel.Enabled = true;
|
|
}
|
|
}//end altera
|
|
|
|
private void cleandisplay()
|
|
{
|
|
this.txt_codpag.Text = string.Empty;
|
|
this.txt_formpag.Text = string.Empty;
|
|
}//end clean
|
|
|
|
|
|
public frm_cadtipopagamento()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void btn_inserir_Click(object sender, EventArgs e)
|
|
{
|
|
this.alterabotoes(2);
|
|
this.operacao = "inserir";
|
|
|
|
}//end inserir
|
|
|
|
private void btn_localizar_Click(object sender, EventArgs e)
|
|
{
|
|
|
|
frm_consultatipopagamento f = new frm_consultatipopagamento();
|
|
f.ShowDialog();
|
|
if (f.codigo != 0)
|
|
{
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLTipoPagamento bll = new BLLTipoPagamento(cx);
|
|
ModeloTipoPagamento modelo = bll.CarregaModeloTipoPagamento(f.codigo);
|
|
txt_codpag.Text = modelo.TpaCod.ToString();
|
|
txt_formpag.Text = modelo.TpaNome;
|
|
this.alterabotoes(3);
|
|
}
|
|
else
|
|
{
|
|
this.cleandisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
f.Dispose();
|
|
|
|
|
|
}//btn localizar
|
|
|
|
private void btn_alterar_Click(object sender, EventArgs e)
|
|
{
|
|
this.operacao = "alterar";
|
|
this.alterabotoes(2);
|
|
}//end alterar
|
|
|
|
private void btn_excluir_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DialogResult d = MessageBox.Show("Deseja excluir o registro?", "Aviso", MessageBoxButtons.YesNo);
|
|
if (d.ToString() == "Yes")
|
|
{
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLTipoPagamento bLL = new BLLTipoPagamento(cx);
|
|
bLL.Excluir(Convert.ToInt32(txt_codpag.Text));
|
|
this.cleandisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
}
|
|
catch (Exception)
|
|
{
|
|
//MessageBox.Show(erro.Message);
|
|
MessageBox.Show("Impossível excluir o registro. \n O registro esta sendo utilizado em outro local.");
|
|
this.alterabotoes(3);
|
|
}
|
|
}//end excluir
|
|
|
|
private void btn_save_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
//leitura dos dados
|
|
ModeloTipoPagamento modelo = new ModeloTipoPagamento();
|
|
modelo.TpaNome = txt_formpag.Text;
|
|
//obj para gravar os dados no banco
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLTipoPagamento bll = new BLLTipoPagamento(cx);
|
|
if (this.operacao == "inserir")
|
|
{
|
|
//cadastrar uma categoria
|
|
bll.Incluir(modelo);
|
|
MessageBox.Show("Cadastro efetuado: Código " + modelo.TpaCod.ToString());
|
|
|
|
}
|
|
else
|
|
{
|
|
//alterar uma categoria
|
|
modelo.TpaCod = Convert.ToInt32(txt_codpag.Text);
|
|
bll.Alterar(modelo);
|
|
MessageBox.Show("Cadastro alterado");
|
|
}
|
|
this.cleandisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
catch (Exception erro)
|
|
{
|
|
MessageBox.Show(erro.Message);
|
|
}
|
|
}//end save
|
|
|
|
private void btn_cancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.cleandisplay();
|
|
this.alterabotoes(1);
|
|
}//end cancell
|
|
|
|
private void pb_exit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}//end close
|
|
|
|
private void frm_cadtipopagamento_Load(object sender, EventArgs e)
|
|
{
|
|
this.cleandisplay();
|
|
this.alterabotoes(1);
|
|
|
|
}//end load form
|
|
}
|
|
}
|