Levelcode-IBRCAD/IBRCAD/frm_cadCat.cs

178 lines
5.3 KiB
C#

using BLL;
using DAL;
using Modelo;
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;
namespace IBRCAD
{
public partial class frm_cadCat : Form
{
public string operacao;
private void clean()
{
this.txt_catName.Text = "";
this.txt_codCat.Text = "";
}
public frm_cadCat()
{
InitializeComponent();
}
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_save.Enabled = false;
btn_cancel.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_save.Enabled = true;
}
if (op == 3)
{
btn_alterar.Enabled = true;
btn_excluir.Enabled = true;
btn_save.Enabled = true;
}
}//end alterar botões
private void frm_modelCad_Load(object sender, EventArgs e)
{
//this.Size = new Size(2000, 1050);
this.alterabotoes(1);
this.clean();
}
private void btn_inserir_Click(object sender, EventArgs e)
{
this.operacao = "inserir";
this.alterabotoes(2);
}// btn inserir
private void btn_alterar_Click(object sender, EventArgs e)
{
this.operacao = "alterar";
this.alterabotoes(2);
}//bnt update
private void btn_save_Click(object sender, EventArgs e)
{
try
{
//leitura dos dados
ModeloCategoria modelo = new ModeloCategoria();
modelo.CatNome = txt_catName.Text;
//obj para gravar os dados no banco
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
if (this.operacao == "inserir")
{
//cadastrar uma categoria
bll.Incluir(modelo);
MessageBox.Show("Cadastro efetuado: Código " + modelo.CatCod.ToString());
}
else
{
//alterar uma categoria
modelo.CatCod = Convert.ToInt32(txt_codCat.Text);
bll.Alterar(modelo);
MessageBox.Show("Cadastro alterado");
}
this.clean();
this.alterabotoes(1);
}
catch (Exception erro)
{
MessageBox.Show(erro.Message);
}
}//btn save
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);
BLLCategoria bll = new BLLCategoria(cx);
bll.Excluir(Convert.ToInt32(txt_codCat.Text));
this.clean();
this.alterabotoes(1);
}
}
catch
{
MessageBox.Show("Impossível excluir o registro. \n O registro esta sendo utilizado em outro local.");
this.alterabotoes(3);
}
}//btn excluir
private void btn_cancel_Click(object sender, EventArgs e)
{
this.alterabotoes(1);
this.clean();
}//btn cancelar
private void pb_exit_Click(object sender, EventArgs e)
{
//frm_main_menu frm_Main_Menu = new frm_main_menu();
//frm_Main_Menu.openChildForm(new frm_dashboard_home());
this.Close();
}
private void btn_localizar_Click(object sender, EventArgs e)
{
frm_consultacategoria f = new frm_consultacategoria();
f.ShowDialog();
if (f.codigo != 0)
{
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
BLLCategoria bll = new BLLCategoria(cx);
ModeloCategoria modelo = bll.CarregaModeloCategoria(f.codigo);
txt_codCat.Text = modelo.CatCod.ToString();
txt_catName.Text = modelo.CatNome;
alterabotoes(3);
}
else
{
this.clean();
this.alterabotoes(1);
}
f.Dispose();
}//btn seach category
private void frm_cadCat_FormClosing(object sender, FormClosingEventArgs e)
{
//frm_main_menu frm_Main_Menu = new frm_main_menu();
//frm_Main_Menu.openChildForm(new frm_dashboard_home());
//this.Close();
}
}
}