185 lines
5.9 KiB
C#
185 lines
5.9 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_cadsubcat : Form
|
|
{
|
|
public string operacao;
|
|
private void clearDisplay()
|
|
{
|
|
this.txt_codSub.Text = "";
|
|
this.txt_namesub.Text = "";
|
|
}
|
|
public frm_cadsubcat()
|
|
{
|
|
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_cadsubcat_Load(object sender, EventArgs e)
|
|
{
|
|
this.alterabotoes(1);
|
|
// this.Size = new Size(1400, 800);
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLCategoria bll = new BLLCategoria(cx);
|
|
cb_cat.DataSource = bll.Localizar("");
|
|
cb_cat.DisplayMember = "cat_nome";
|
|
cb_cat.ValueMember = "cat_cod";
|
|
}//end load form
|
|
|
|
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_consultasubcategoria f = new frm_consultasubcategoria();
|
|
f.ShowDialog();
|
|
if (f.codigo != 0)
|
|
{
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLSubCategoria bll = new BLLSubCategoria(cx);
|
|
ModeloSubCategoria modelo = bll.CarregaModeloSubCategoria(f.codigo);
|
|
txt_codSub.Text = modelo.ScatCod.ToString();
|
|
txt_namesub.Text = modelo.ScatNome;
|
|
cb_cat.SelectedValue = modelo.CatCod;
|
|
this.alterabotoes(3);
|
|
}
|
|
else
|
|
{
|
|
this.clearDisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
f.Dispose();
|
|
|
|
|
|
|
|
}//end seach
|
|
|
|
private void btn_alterar_Click(object sender, EventArgs e)
|
|
{
|
|
this.alterabotoes(2);
|
|
this.operacao = "alterar";
|
|
}//btn update
|
|
|
|
private void btn_excluir_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
DialogResult result = MessageBox.Show("Deseja excluir o Registro?", "Excluindo registro", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
|
|
if (result == DialogResult.Yes)
|
|
{
|
|
DALLconexao conexao = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLSubCategoria bll = new BLLSubCategoria(conexao);
|
|
bll.Excluir(Convert.ToInt32(txt_codSub.Text));
|
|
this.clearDisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
}
|
|
catch
|
|
{
|
|
MessageBox.Show("Impossivel excluir o Registro.O registro provavelmente já foi apagado do sistema", "Erro ao tentar apagar");
|
|
this.alterabotoes(1);
|
|
|
|
}
|
|
}//end delete
|
|
|
|
private void btn_save_Click(object sender, EventArgs e)
|
|
{
|
|
try
|
|
{
|
|
ModeloSubCategoria modelo = new ModeloSubCategoria();
|
|
modelo.ScatNome = txt_namesub.Text;
|
|
modelo.CatCod = Convert.ToInt32(cb_cat.SelectedValue);
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLSubCategoria bsub = new BLLSubCategoria(cx);
|
|
if (this.operacao == "inserir")
|
|
{
|
|
bsub.Incluir(modelo);
|
|
MessageBox.Show("Registro Cadastrado com sucesso! Cód: " + modelo.ScatCod.ToString(), "Sucesso no cadastramento");
|
|
}
|
|
else
|
|
{
|
|
//alterar
|
|
modelo.ScatCod = Convert.ToInt32(txt_codSub.Text);
|
|
bsub.Alterar(modelo);
|
|
MessageBox.Show("Registro alterado com sucesso!", "Atualização realizada");
|
|
}
|
|
this.clearDisplay();
|
|
this.alterabotoes(1);
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
|
|
MessageBox.Show(ex.Message);
|
|
}
|
|
}//end btn save
|
|
|
|
private void btn_addCat_Click(object sender, EventArgs e)
|
|
{
|
|
frm_cadCat f = new frm_cadCat();
|
|
f.ShowDialog();
|
|
f.Dispose();
|
|
DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao);
|
|
BLLCategoria bll = new BLLCategoria(cx);
|
|
cb_cat.DataSource = bll.Localizar("");
|
|
cb_cat.DisplayMember = "cat_nome";
|
|
cb_cat.ValueMember = "cat_cod";
|
|
}//end btn add cat
|
|
|
|
private void btn_cancel_Click(object sender, EventArgs e)
|
|
{
|
|
this.alterabotoes(1);
|
|
this.clearDisplay();
|
|
}//end btn cancel
|
|
|
|
private void pb_exit_Click(object sender, EventArgs e)
|
|
{
|
|
this.Close();
|
|
}//end exit
|
|
|
|
}
|
|
}
|