protected void btnSalvar_Click(object sender, EventArgs e)
    {
        DataSet dsCliente = ClientesDB.SelectLogin(TextUsuario.Text, ClientesDB.PWD(TextSenha.Text));
        int     qtdCli    = dsCliente.Tables[0].Rows.Count;

        DataSet dsEmpresa = EmpresasDB.SelectLogin(TextUsuario.Text, EmpresasDB.PWD(TextSenha.Text));
        int     qtdEmp    = dsEmpresa.Tables[0].Rows.Count;


        if (qtdCli == 1 && qtdEmp == 0)
        {
            Clientes cli = new Clientes();
            cli.Cli_nome            = dsCliente.Tables[0].Rows[0]["cli_nome"].ToString();
            cli.Cli_email           = dsCliente.Tables[0].Rows[0]["cli_email"].ToString();
            cli.Cli_data_nascimento = Convert.ToDateTime(dsCliente.Tables[0].Rows[0]["cli_data_nascimento"].ToString());

            cli.Cli_id = Convert.ToInt32(dsCliente.Tables[0].Rows[0]["cli_id"]);

            Session["cli_cliente"] = cli;

            Response.Redirect("../PaginaCliente/MeusDados.aspx");
        }
        else if (qtdCli == 0 && qtdEmp == 1)
        {
            Empresas emp = new Empresas();
            emp.Emp_id              = Convert.ToInt32(dsEmpresa.Tables[0].Rows[0]["emp_id"]);
            emp.Emp_razao_social    = dsEmpresa.Tables[0].Rows[0]["emp_razao_social"].ToString();
            emp.Emp_nome_fantasia   = dsEmpresa.Tables[0].Rows[0]["emp_nome_fantasia"].ToString();
            emp.Emp_cnpj            = dsEmpresa.Tables[0].Rows[0]["emp_cnpj"].ToString();
            emp.Emp_email           = dsEmpresa.Tables[0].Rows[0]["emp_email"].ToString();
            emp.Emp_senha           = dsEmpresa.Tables[0].Rows[0]["emp_senha"].ToString();
            emp.Emp_numero_endereco = dsEmpresa.Tables[0].Rows[0]["emp_numero_endereco"].ToString();

            Session["emp_empresa"] = emp;
            Response.Redirect("../PaginaEmpresa/EmpDados.aspx");
        }
        else
        {
            ltl.Text = "<p class='text-success'>Erro no Login</p>";
            Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
        }
    }
Example #2
0
    protected void btnConta_Click(object sender, EventArgs e)
    {
        if (EscolhePessoa.SelectedValue == "1")
        {
            Clientes cli = new Clientes();
            cli.Cli_nome            = textNome.Text;
            cli.Cli_email           = textEmail.Text;
            cli.Cli_senha           = ClientesDB.PWD(textSenha.Text);
            cli.Cli_sexo            = Convert.ToChar(rblSexo.SelectedValue);
            cli.Cli_data_nascimento = Convert.ToDateTime(textCalendario.Text);
            cli.Cli_celular         = textCelular.Text;
            cli.Cli_id = ClientesDB.Insert(cli);

            Cidades cid = new Cidades();

            Bairros bai = new Bairros();
            bai.Bai_nome = textBairro.Text;
            bai.Bai_rua  = textRua.Text;
            //FK
            cid.Cid_id = Convert.ToInt32(rblCidade.SelectedValue);
            bai.Cid_id = cid;
            bai.Bai_id = BairrosDB.Insert(bai);

            Enderecos end = new Enderecos();
            end.End_cep  = textCep.Text;
            end.End_tipo = textComplemento.Text;
            //FK
            end.Bai_id = bai;
            end.End_id = EnderecosDB.Insert(end);

            ClienteEndereco cle = new ClienteEndereco();
            cle.Cle_num       = textNumero.Text;
            cle.Cle_principal = true;
            //FK
            cle.Cli_id = cli;
            cle.End_id = end;


            switch (ClienteEnderecoDB.Insert(cle))
            {
            case 0:
                Session["cli_cliente"] = cli;
                Response.Redirect("../PaginaCliente/MeusDados.aspx");
                break;

            case -2:
                ltl.Text = "<p class='text-success'>Erro no cadastro</p>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#myModal').modal('show');</script>", false);
                break;
            }
        }
        else
        {
            Cidades cid = new Cidades();

            Bairros bai = new Bairros();
            bai.Bai_nome = textBairro.Text;
            bai.Bai_rua  = textRua.Text;
            //FK
            cid.Cid_id = Convert.ToInt32(rblCidade.SelectedValue);
            bai.Cid_id = cid;
            bai.Bai_id = BairrosDB.Insert(bai);

            Enderecos end = new Enderecos();
            end.End_cep  = textCep.Text;
            end.End_tipo = textComplemento.Text;
            //FK
            end.Bai_id = bai;
            end.End_id = EnderecosDB.Insert(end);

            Empresas emp = new Empresas();
            emp.Emp_razao_social    = textSocial.Text;
            emp.Emp_email           = textEmail2.Text;
            emp.Emp_nome_fantasia   = textNomeFantasia.Text;
            emp.Emp_cnpj            = textCNPJ.Text;
            emp.Emp_senha           = EmpresasDB.PWD(textSenha2.Text);
            emp.Emp_numero_endereco = textNumero.Text;
            //FK
            emp.End_id = end;
            emp.Emp_id = EmpresasDB.Insert(emp);

            Telefones tel = new Telefones();
            tel.Tel_ddd = Convert.ToString(textDDD.Text);
            tel.Tel_num = Convert.ToString(textTelefone.Text);
            //FK
            tel.Emp_id = emp;

            switch (TelefonesDB.Insert(tel))
            {
            case -2:
                ltl.Text = "<p class='text-success'>Erro no cadastro</p>";
                Page.ClientScript.RegisterStartupScript(this.GetType(), "script", "<script>$('#modalUpdate').modal('show');</script>", false);
                break;

            default:
                Session["emp_empresa"] = emp;
                Response.Redirect("../PaginaEmpresa/EmpDados.aspx");
                break;
            }
        }
    }