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_cadunidademedida : Form { public string operacao; private void cleanDisplay() { this.txt_codMedida.Text = string.Empty; this.txt_nameuni.Text = string.Empty; } 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; } } public frm_cadunidademedida() { InitializeComponent(); } private void btn_inserir_Click(object sender, EventArgs e) { this.operacao = "inserir"; this.alterabotoes(2); }//btn inserir private void btn_localizar_Click(object sender, EventArgs e) { frm_consultaundmedida f = new frm_consultaundmedida(); f.ShowDialog(); if (f.codigo != 0) { DALLconexao conexao = new DALLconexao(DadosDaConexao.StringDeConexao); BLLUnidadeDeMedida bLLUnidadeDeMedida = new BLLUnidadeDeMedida(conexao); ModeloUnidadeDeMedida modelo = bLLUnidadeDeMedida.CarregaModeloUnidadeDeMedida(f.codigo); txt_codMedida.Text = modelo.UmedCod.ToString(); txt_nameuni.Text = modelo.UmedNome.ToString(); this.alterabotoes(3); } else { this.cleanDisplay(); this.alterabotoes(1); } f.Dispose(); }//btn seach private void btn_alterar_Click(object sender, EventArgs e) { this.operacao = "alterar"; this.alterabotoes(2); }//end update 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); BLLUnidadeDeMedida bll = new BLLUnidadeDeMedida(cx); bll.Excluir(Convert.ToInt32(txt_codMedida.Text)); this.cleanDisplay(); this.alterabotoes(1); //MessageBox.Show("mensage"); } } catch { MessageBox.Show("Impossível excluir o registro. \n O registro esta sendo utilizado em outro local."); this.alterabotoes(3); } }//end delete private void btn_save_Click(object sender, EventArgs e) { try { //leitura dos dados ModeloUnidadeDeMedida modelo = new ModeloUnidadeDeMedida(); modelo.UmedNome = txt_nameuni.Text; //obj para gravar os dados no banco DALLconexao cx = new DALLconexao(DadosDaConexao.StringDeConexao); BLLUnidadeDeMedida bll = new BLLUnidadeDeMedida(cx); if (this.operacao == "inserir") { //cadastrar uma categoria bll.Incluir(modelo); MessageBox.Show("Cadastro efetuado: Código " + modelo.UmedCod.ToString()); } else { //alterar uma categoria modelo.UmedCod = Convert.ToInt32(txt_codMedida.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.alterabotoes(1); this.cleanDisplay(); }//end cancel private void frm_cadunidademedida_Load(object sender, EventArgs e) { this.alterabotoes(1); this.cleanDisplay(); }//load form private void pb_exit_Click(object sender, EventArgs e) { this.Close(); }//btn exit } }