Ejemplo n.º 1
0
        protected void btnSalvar_Click(object sender, EventArgs e)
        {
            Funcionario funcionario = getData();
            var         db          = new FuncionarioDB();

            if (funcionario.Id == 0)
            {
                if (db.Insert(funcionario))
                {
                    lblMsg.Text = "Registro inserido!";
                }
                else
                {
                    lblMsg.Text = "Erro ao inserir registro!";
                }
            }
            else

            if (db.Update(funcionario))
            {
                lblMsg.Text = "Registro atualizado!";
            }
            else
            {
                lblMsg.Text = "Erro ao atualizar registro!";
            }

            LoadGrid();
        }
Ejemplo n.º 2
0
    protected void btnSalvar_Click(object sender, EventArgs e)
    {
        FunMod funCod = (FunMod)Session["funcionario"];

        string texto = Request.QueryString["pfl"].Replace(" ", "+");
        int    n     = Convert.ToInt32(Funcoes.AESDecodifica(texto));
        FunMod fmp1  = FunModDB.Select(n);

        if (txtNome1.Text != "" && txtSobrenome1.Text != "" && txtDataNas1.Text != "" && ddlCargo.SelectedIndex != 0 && txtMatricula1.Text != "" && txtCPF1.Text != "" && txtRG1.Text != "" && txtCEP1.Text != "" && ddlEstados.SelectedIndex != 0 && txtCidade1.Text != "" && txtBairro1.Text != "" && txtRua1.Text != "" && txtNumero1.Text != "" && txtComplemento1.Text != "")
        {
            FunMod      fmp = new FunMod();
            Funcionario fun = new Funcionario();
            fmp.Funcionario = fun;
            Modulo mod = new Modulo();
            fmp.Modulo = mod;
            Pessoa pes = new Pessoa();
            fmp.Funcionario.Pessoa = pes;
            Perfil pfl = new Perfil();
            fmp.Funcionario.Perfil = new Perfil();
            Setor set = new Setor();
            fmp.Funcionario.Setor = set;
            Cargo car = new Cargo();
            fmp.Funcionario.Cargo = car;
            //Contato con = new Contato();
            //con.Pessoa = pes;

            fmp.Funcionario.Pessoa.Pes_cod            = fmp1.Funcionario.Pessoa.Pes_cod;
            fmp.Funcionario.Pessoa.Pes_tipo           = "Fisica";
            fmp.Funcionario.Pessoa.Pes_ativo          = "Ativo";
            fmp.Funcionario.Pessoa.Cod_fun            = funCod.Funcionario.Pessoa.Pes_cod;
            fmp.Funcionario.Cod_fun                   = funCod.Funcionario.Pessoa.Pes_cod;
            fmp.Funcionario.Pessoa.Pes_nome           = txtNome1.Text;
            fmp.Funcionario.Pessoa.Pes_sobrenome      = txtSobrenome1.Text;
            fmp.Funcionario.Pessoa.Pes_dataNascimento = txtDataNas1.Text;
            fmp.Funcionario.Cargo.Car_cod             = Convert.ToInt32(ddlCargo.SelectedValue);
            fmp.Funcionario.Fun_cod                   = fmp1.Funcionario.Fun_cod;
            fmp.Funcionario.Fun_matricula             = txtMatricula1.Text;
            fmp.Funcionario.Pessoa.Pes_sexo           = rdbSexo.SelectedValue;
            if (rdbUsu.Visible != false)
            {
                fmp.Funcionario.Perfil.Pfl_cod = Convert.ToInt32(rdbUsu.SelectedValue);
            }
            else
            {
                fmp.Funcionario.Perfil.Pfl_cod = 1;
            }
            fmp.Funcionario.Pessoa.Pes_rg          = txtRG1.Text;
            fmp.Funcionario.Pessoa.Pes_cpf         = txtCPF1.Text;
            fmp.Funcionario.Setor.Set_cod          = Convert.ToInt32(ddlSetor.SelectedValue);
            fmp.Funcionario.Pessoa.Pes_estado      = ddlEstados.SelectedValue;
            fmp.Funcionario.Pessoa.Pes_cidade      = txtCidade1.Text;
            fmp.Funcionario.Pessoa.Pes_bairro      = txtBairro1.Text;
            fmp.Funcionario.Pessoa.Pes_rua         = txtRua1.Text;
            fmp.Funcionario.Pessoa.Pes_numero      = txtNumero1.Text;
            fmp.Funcionario.Pessoa.Pes_complemento = txtComplemento1.Text;
            fmp.Funcionario.Pessoa.Pes_cep         = txtCEP1.Text;

            if (rdbChefe.SelectedIndex == 0)
            {
                fmp.Funcionario.Fun_chefeDepartamento = false;
                fmp.Funcionario.Fun_chefeSetor        = false;
            }
            else if (rdbChefe.SelectedIndex == 1)
            {
                fmp.Funcionario.Fun_chefeDepartamento = false;
                fmp.Funcionario.Fun_chefeSetor        = true;
            }
            else if (rdbChefe.SelectedIndex == 2)
            {
                fmp.Funcionario.Fun_chefeDepartamento = true;
                fmp.Funcionario.Fun_chefeSetor        = false;
            }

            string listaPermissao = "";

            //foreach
            foreach (ListItem selecionadas in cblPadrao.Items)
            {
                if (selecionadas.Selected == true)
                {
                    listaPermissao += "('fun_per', " + selecionadas.Value + ", " + funCod.Funcionario.Pessoa.Pes_cod + "),";
                }
            }

            foreach (ListItem selecionadas in checkAdicionais.Items)
            {
                if (selecionadas.Selected == true)
                {
                    listaPermissao += "('fun_per', " + selecionadas.Value + ", " + funCod.Funcionario.Pessoa.Pes_cod + "),";
                }
            }

            listaPermissao = listaPermissao.Substring(0, listaPermissao.Length - 1);

            string retorno = "";

            retorno = FuncionarioDB.Update(fmp, listaPermissao);
            retorno = retorno.Substring(0, 4);

            if (retorno != "Erro")
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>sucess();</script>", false);
            }
            else
            {
                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>error();</script>", false);
            }
        }
        else
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>warning();</script>", false);
        }
    }