コード例 #1
0
    protected void btSalvar_Click(object sender, EventArgs e)
    {
        if (coPermiteExecutar.Value == "True")
        {
            Cadastro Cad = new Cadastro();

            //Inclui apenas o vínculo
            if (tbCPFMatricula.Text != "" && coOperacao.Value == "Incluir")
            {
                PT.PreencheTBUsuarioLogin(ds, tbCPFMatricula.Text.Trim());

                if (ds.TBUsuario.Rows.Count > 0)
                {
                    //NÃO ESQUECER DA MATRICULA
                    msg = Cad.CadastraVinculoUsuario(ds.TBUsuario[0].IDUsuario, Convert.ToInt32(cbTPUsuario.Value),
                                                     Convert.ToInt32(Session["IDEmpresa"]),
                                                     Convert.ToInt32(cbRegimeHora.Value), Convert.ToInt32(cbSetor.Value),
                                                     DateTime.Now, Convert.ToInt32(cbCargo.Value),
                                                     17, cbCadastraDigital.Checked, cbDashboard.Checked, tbEntradaManha.Text.Trim(),
                                                     tbSaidaManha.Text.Trim(), tbEntradaTarde.Text.Trim(),
                                                     tbSaidaTarde.Text.Trim(), Convert.ToInt32(Session["IDUsuario"]), tbPIS.Text.Trim(),
                                                     cbDescontoTotalJornada.Checked, cbIsencaoPonto.Checked);

                    int t = msg.IndexOf("Já existente");

                    if (msg.IndexOf("Já existente") > (-1))
                    {
                        Page.ClientScript.RegisterStartupScript(Page.GetType(), "MSG", @"<script language='javascript'> AbrepopErroKey();</script>");
                    }

                    return;
                }
            }

            if (coCPF.Value == "True")
            {
                primeiroNome = PrimeiroNome(tbNomeCompleto.Text.Trim().ToUpper());

                if (cbTPUsuario.SelectedIndex > 0)
                {
                    if (cbTPUsuario.SelectedItem.Value.ToString() == "3" || cbTPUsuario.SelectedItem.Value.ToString() == "9")
                    {
                        Gerencias = new string[cbLSetores.SelectedItems.Count];

                        for (int i = 0; i <= (cbLSetores.SelectedItems.Count - 1); i++)
                        {
                            Gerencias[i] = cbLSetores.SelectedItems[i].Value.ToString();
                        }
                    }
                }
                try
                {
                    if (coOperacao.Value == "Incluir")
                    {
                        //NAO ESQUECER DA MATRICULA
                        msg = Cad.CadastraUsuario(tbCPFMatricula.Text.Trim().ToUpper(), null, tbNomeCompleto.Text.Trim().ToUpper(),
                                                  17, Convert.ToInt32(cbStatus.SelectedItem.Value), Convert.ToInt32(cbSetor.SelectedItem.Value), Convert.ToInt32(cbTPUsuario.SelectedItem.Value),
                                                  Convert.ToInt32(cbCargo.SelectedItem.Value), Convert.ToInt32(tbTotHoras.Text),
                                                  tbEntradaManha.Text, tbSaidaManha.Text.Trim(), tbEntradaTarde.Value.ToString(), tbSaidaTarde.Text, 1,
                                                  primeiroNome, Convert.ToInt32(Session["IDUsuario"]), "0", rbAcessoEspecial.Checked,
                                                  Convert.ToInt32(Session["IDempresa"]), Convert.ToDateTime("01/01/1900"),
                                                  Convert.ToDateTime("01/01/1900"), tbPIS.Text.Trim(), 1,
                                                  Convert.ToDateTime("01/01/1900"), string.Empty
                                                  , string.Empty, string.Empty, Convert.ToDateTime("01/01/1900"), string.Empty,
                                                  string.Empty, string.Empty, Convert.ToDateTime("01/01/1900"),
                                                  string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty,
                                                  string.Empty, 1, string.Empty, Gerencias, cbDashboard.Checked,
                                                  cbCadastraDigital.Checked, cbPermiteDiaSeguinte.Checked,
                                                  Convert.ToInt32(cbRegimeHora.Value), tbTelSMS.Text.Trim(), tbPIS.Text.Trim(),
                                                  cbIsencaoPonto.Checked);

                        if (msg.IndexOf("Já existete") > (0))
                        {
                            Page.ClientScript.RegisterStartupScript(Page.GetType(), "MSG", @"<script language='javascript'> AbrepopErroKey();</script>");
                        }
                    }
                    else if (coOperacao.Value == "Alterar")
                    {
                        int po = tbNomeCompleto.Text.IndexOf("", 2);

                        if (rbSenha.Checked)
                        {
                            Cad.AlteraUsuarioAdminSenha(tbCPFMatricula.Text.Trim().ToUpper(), tbNomeCompleto.Text.Trim().ToUpper(),
                                                        17,
                                                        Convert.ToInt32(cbStatus.SelectedItem.Value), Convert.ToInt32(cbSetor.SelectedItem.Value),
                                                        Convert.ToInt32(cbTPUsuario.SelectedItem.Value), Convert.ToInt32(cbCargo.SelectedItem.Value),
                                                        Convert.ToInt32(tbTotHoras.Text), tbEntradaManha.Text.Trim(), tbSaidaManha.Text.Trim(),
                                                        tbEntradaTarde.Text.Trim(), tbSaidaTarde.Text.Trim(), 1, primeiroNome,
                                                        Convert.ToInt32(coIDUsuario.Value), "pontonarede", Convert.ToInt32(cbTPUsuario.SelectedItem.Value),
                                                        Convert.ToInt32(cbCargo.SelectedItem.Value), Convert.ToInt32(Session["IDUsuario"]), "1",
                                                        rbAcessoEspecial.Checked, Convert.ToInt32(Session["IDEmpresa"]),
                                                        Convert.ToDateTime("01/01/1900"), Convert.ToDateTime("01/01/1900"),
                                                        tbPIS.Text.Trim(),
                                                        1,
                                                        Convert.ToDateTime("01/01/1900"), string.Empty,
                                                        string.Empty, string.Empty, Convert.ToDateTime("01/01/1900"),
                                                        string.Empty, string.Empty, string.Empty, Convert.ToDateTime("01/01/1900"),
                                                        string.Empty, string.Empty,
                                                        string.Empty, string.Empty, string.Empty, string.Empty,
                                                        string.Empty, 1, string.Empty, Gerencias, cbDashboard.Checked,
                                                        cbCadastraDigital.Checked, cbPermiteDiaSeguinte.Checked, tbTelSMS.Text.Trim());
                        }
                        else
                        {
                            string VLSenha = "";
                            if (cbEspecial.Checked)
                            {
                                VLSenha = "1";
                            }
                            else
                            {
                                VLSenha = "0";
                            }

                            msg = Cad.AlteraUsuarioAdmin(tbCPFMatricula.Text.Trim().ToUpper(), tbNomeCompleto.Text.Trim().ToUpper(),
                                                         17,
                                                         Convert.ToInt32(cbStatus.SelectedItem.Value), Convert.ToInt32(cbSetor.SelectedItem.Value),
                                                         Convert.ToInt32(cbTPUsuario.SelectedItem.Value),
                                                         Convert.ToInt32(cbCargo.SelectedItem.Value), Convert.ToInt32(tbTotHoras.Text),
                                                         tbEntradaManha.Text, tbSaidaManha.Text, tbEntradaTarde.Text, tbSaidaTarde.Text, 2,
                                                         primeiroNome, Convert.ToInt32(coIDUsuario.Value), Convert.ToInt32(cbTPUsuario.SelectedItem.Value),
                                                         Convert.ToInt32(cbCargo.SelectedItem.Value), Convert.ToInt32(Session["IDUsuario"]), VLSenha,
                                                         rbAcessoEspecial.Checked, Convert.ToInt32(Session["IDEmpresa"]),
                                                         Convert.ToDateTime("01/01/1900"), Convert.ToDateTime("01/01/1900"), tbPIS.Text.Trim(),
                                                         1, Convert.ToDateTime("01/01/1900"), "",
                                                         "", "", Convert.ToDateTime("01/01/1900"),
                                                         "", "", "",
                                                         Convert.ToDateTime("01/01/1900"),
                                                         "", "", "", "",
                                                         "", "", "", 1, "", Gerencias, cbDashboard.Checked,
                                                         cbCadastraDigital.Checked, cbPermiteDiaSeguinte.Checked, tbTelSMS.Text.Trim(), cbIsencaoPonto.Checked);

                            if (msg.IndexOf("Já existe") > (0))
                            {
                                Page.ClientScript.RegisterStartupScript(Page.GetType(), "MSG", @"<script language='javascript'> AbrepopErroKey();</script>");
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    ex.ToString();
                }
                Preenchegrid(false);
            }
        }//Permite Executar
    }