Пример #1
0
        private void btLocalizar_Click(object sender, EventArgs e)
        {
            //Alterna imagens dos botões
            btLocalizar.ImageIndex = 3;

            frmConsultaSubCategoria frmSubCCateg = new frmConsultaSubCategoria();

            frmSubCCateg.ShowDialog();
            if (frmSubCCateg.codigo != 0)
            {
                DALConexao         cx     = new DALConexao(DadosDaConexao.StringDeConexao);
                DLLSubCategoria    dll    = new DLLSubCategoria(cx);
                ModeloSubCategoria modelo = dll.CarregaModeloSubCategoria(frmSubCCateg.codigo);
                txtSCatCod.Text        = modelo.ScatCod.ToString();
                txtNome.Text           = modelo.ScatNome;
                txtSCatData.Text       = modelo.ScatData;
                cbCatCod.SelectedValue = Convert.ToString(modelo.CatCod);
                label1.Visible         = true;
                this.alteraBotoes(3);
                closeCadSubCategoria = 3;
            }
            else
            {
                this.LimpaTela();
                this.alteraBotoes(1);
                btLocalizar.ImageIndex = 2;
            }
            frmSubCCateg.Dispose();
        }
Пример #2
0
        private void btExcluir_Click(object sender, EventArgs e)
        {
            //Alterna imagens dos botões
            btExcluir.ImageIndex = 7;

            //o try é para tratamento de erros ao inserir objeto
            try
            {
                DialogResult d = MessageBox.Show("Tem certeza que deseja excluir o registro?", "Excluir?", MessageBoxButtons.YesNo);
                if (d.ToString() == "Yes")
                {
                    //MessageBox.Show("Excluindo o registro!");
                    DALConexao      cx  = new DALConexao(DadosDaConexao.StringDeConexao);
                    DLLSubCategoria dll = new DLLSubCategoria(cx);
                    dll.Excluir(Convert.ToInt32(txtSCatCod.Text));
                    this.LimpaTela();
                    this.alteraBotoes(1);
                    closeCadSubCategoria = 1;
                }
                else
                {
                    MessageBox.Show("Erro no valor passado!" + d.ToString());
                }
            }
            catch
            {
                MessageBox.Show("Impossível excluir o registro. \n O registro está sendo utilizado em outro local.");
                this.alteraBotoes(3);
                closeCadSubCategoria = 3;
                //FormPrincipal.toolStripBarStatus.Text = "ERRO! Impossível excluir o registro.";
            }
            btExcluir.ImageIndex   = 6;
            btLocalizar.ImageIndex = 2;
            this.operacao          = "";
        }
Пример #3
0
 private void btBusca_Click(object sender, EventArgs e)
 {
     btBusca.ImageIndex = 1;
     DALConexao cx = new DALConexao(DadosDaConexao.StringDeConexao);
     DLLSubCategoria dll = new DLLSubCategoria(cx);
     dgvDados.DataSource = dll.Localizar(txtNome.Text);
     label2.Visible = true;
     btBusca.ImageIndex = 0;
 }
Пример #4
0
        private void btSalvar_Click(object sender, EventArgs e)
        {
            //Alterna imagens dos botões

            btSalvar.ImageIndex = 9;

            //o try é para tratamento de erros ao inserir objeto
            try
            {
                ModeloSubCategoria modelo = new ModeloSubCategoria();
                modelo.CatCod     = Convert.ToInt32(cbCatCod.SelectedValue);
                modelo.ScatNome   = txtNome.Text;
                modelo.ScatData   = DateTime.Now.ToShortDateString();
                modelo.ScatTime   = DateTime.Now.ToShortTimeString();
                modelo.ScatStatus = "local";

                //Obj para gravar os dados da conexão
                DALConexao      cx  = new DALConexao(DadosDaConexao.StringDeConexao);
                DLLSubCategoria dll = new DLLSubCategoria(cx);

                if (this.operacao == "inserir")
                {
                    //Cadastrar nova categoria
                    dll.Incluir(modelo);
                    MessageBox.Show("Cadastro realizado: Código " + modelo.ScatCod.ToString());
                    //toolStripBarStatus.Text = "Procedimento OK! Item " + modelo.CatCod.ToString() + " cadastrado!";
                }
                else
                {
                    //Alterar Categoria
                    modelo.ScatCod = Convert.ToInt32(txtSCatCod.Text);
                    dll.Alterar(modelo);
                    MessageBox.Show("Cadastro Alterado!");
                    //toolStripBarStatus.Text = "Procedimento OK! Item " + txtcodigo.Text + " alterado!";
                    label1.Visible = false;
                }
                this.LimpaTela();
                this.alteraBotoes(1);
                closeCadSubCategoria = 1;
            }
            catch (Exception erro)
            {
                MessageBox.Show(erro.Message);
                //toolStripBarStatus.Text = "Erro! Cadastro não realizado!";
            }

            //Retorna parâmetros originais
            btSalvar.ImageIndex    = 8;
            btInserir.ImageIndex   = 0;
            btLocalizar.ImageIndex = 2;
            this.operacao          = "";
        }