Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            using (ServicosDB db = new ServicosDB()) // READ DATABASE
            {
                string        cmd = "select count(rgm) as contagem from coordenador";
                SqlDataReader dr  = db.ExecQuery(
                    cmd
                    );

                if (dr.Read())
                {
                    if (Convert.ToInt32(dr["contagem"]) == 0)
                    {
                        Session["CadastrarPrimeiroCoordenador"] = true;
                        Response.Redirect("CadastrarCoordenador.aspx");
                    }
                }
                dr.Close();
            }

            if (Session["RGM_Usuario"] != null)
            {
                if (Convert.ToBoolean(Session["Coordenador"]))
                {
                    Response.Redirect("HomeCoordenador.aspx");
                }
                else
                {
                    Response.Redirect("HomeParticipante.aspx");
                }
            }
        }
 protected void btnEntrar_Click(object sender, EventArgs e)
 {
     if (validarCampos())
     {
         using (ServicosDB db = new ServicosDB()) // READ DATABASE
         {
             string        cmd = "select rgm, senha from coordenador where rgm = @rgm";
             SqlDataReader dr  = db.ExecQuery(
                 cmd,
                 new SqlParameter("@rgm", SqlDbType.VarChar, 20)
             {
                 Value = txtRGM.Text
             }
                 );
             if (dr.Read())
             {
                 if (Convert.ToString(dr["rgm"]) == txtRGM.Text && Convert.ToString(dr["senha"]) == ServicosDB.stringToSHA256(txtSenha.Text))
                 {
                     Session["RGM_Usuario"] = txtRGM.Text;
                     Session["Coordenador"] = true;
                     Response.Redirect("HomeCoordenador.aspx");
                 }
                 else
                 {
                     alert("RGM não cadastrado ou Senha incorreta!");
                 }
             }
             else
             {
                 alert("RGM não cadastrado ou Senha incorreta!");
             }
             dr.Close();
         }
     }
 }
Пример #3
0
 public void updateGridView()
 {
     using (ServicosDB sdb = new ServicosDB()) {
         GridView1.DataSource = sdb.ExecQuery("select * from fornecedor");
         GridView1.DataBind();
     }
 }
        protected void gvEspacos_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "carregar")
            {
                //try {
                int Linha         = Convert.ToInt32(e.CommandArgument);
                int idEspacoAtual = Convert.ToInt32(gvEspacos.Rows[Linha].Cells[0].Text);

                using (ServicosDB db = new ServicosDB())     // READ DATABASE
                {
                    string        cmd = "select * from espaco where id = @id";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@id", SqlDbType.Int)
                    {
                        Value = idEspacoAtual
                    }
                        );

                    if (dr.Read())
                    {
                        txtID.Text         = Convert.ToString(dr["id"]);
                        txtNome.Text       = Convert.ToString(dr["nome"]);
                        txtCapacidade.Text = Convert.ToString(dr["capacidade"]);
                    }
                    dr.Close();
                }
                //} catch (Exception exception) { alert("Falha ao Carregar Espaço. Erro: " + exception.ToString()); }
            }
        }
Пример #5
0
 private void atualizarGrid()
 {
     using (ServicosDB db = new ServicosDB())
     {
         gvPalestrantes.DataSource = db.ExecQuery($"SELECT [id], [nome], [email], [telefone], [formacao] FROM [Palestrante]");
         gvPalestrantes.DataBind();
     }
 }
 private void atualizarGrid()
 {
     using (ServicosDB db = new ServicosDB())
     {
         gvEspacos.DataSource = db.ExecQuery($"SELECT [id], [nome], [capacidade] FROM [Espaco]");
         gvEspacos.DataBind();
     }
 }
 private void atualizarGrid()
 {
     using (ServicosDB db = new ServicosDB())
     {
         gvPalestras.DataSource = db.ExecQuery($"SELECT [P].[id] as 'ID', [P].[nome] as 'Nome', [P].[dataHorarioInicio] as 'Data e Horário de Início', [P].[dataHorarioTermino] as 'Data e Horário de Término', [E].[nome] as 'Local', [P].[curso] as 'Curso', [PL].[nome] as 'Palestrante', CONCAT(CONCAT([P].[inscritos], '/'), [E].[capacidade]) as 'Inscritos' FROM [Palestra] as P INNER JOIN [Espaco] as E ON E.id = P.idEspaco INNER JOIN [Palestrante] as PL ON PL.id = P.idPalestrante");
         gvPalestras.DataBind();
     }
 }
 private void atualizarGrid()
 {
     using (ServicosDB db = new ServicosDB())
     {
         gvMinhasPalestras.DataSource = db.ExecQuery($"SELECT [P].[id] as 'ID', [P].[nome] as 'Nome', [P].[dataHorarioInicio] as 'Data e Horário de Início', [P].[dataHorarioTermino] as 'Data e Horário de Término', [E].[nome] as 'Sala', [P].[curso] as 'Curso', [PL].[nome] as 'Palestrante', CONCAT(CONCAT([P].[inscritos], '/'), [E].[capacidade]) as 'Inscritos' FROM [Palestra] as P INNER JOIN [Espaco] as E ON E.id = P.idEspaco INNER JOIN [Palestrante] as PL ON PL.id = P.idPalestrante INNER JOIN [Inscricao] as I on P.id = I.idPalestra where I.rgmParticipante = '{Session["RGM_Usuario"]}'");
         gvMinhasPalestras.DataBind();
     }
 }
Пример #9
0
        private bool cadastroPalestranteFullValidation()
        {
            Boolean valid = true;
            int     id    = -1;

            using (ServicosDB db = new ServicosDB()) // READ DATABASE
            {
                string        cmd = "select id from palestrante where id = @id";
                SqlDataReader dr  = db.ExecQuery(
                    cmd,
                    new SqlParameter("@id", SqlDbType.Int)
                {
                    Value = txtID.Text
                });

                if (dr.Read())
                {
                    id = Convert.ToInt32(dr["id"]);
                }
                else
                {
                    id = -1;
                }
                dr.Close();
            }

            // VALIDATE ID
            if (
                id != -1
                )
            {
                valid = false;
                alert("Este ID já está cadastrado! Tente recarregar a página ou apertar o botão Limpar.");
            }

            if (valid)
            {
                valid = cadastroPalestranteValidateCampos();
            }

            return(valid);
        }
        private void atualizarDDLs()
        {
            using (ServicosDB db = new ServicosDB())
            {
                ddlCoordenador.DataSource = db.ExecQuery($"SELECT [rgm], [nome] FROM [Coordenador]");
                ddlCoordenador.DataBind();
            }

            using (ServicosDB db = new ServicosDB())
            {
                ddlPalestrante.DataSource = db.ExecQuery($"SELECT [id], [nome] FROM [Palestrante]");
                ddlPalestrante.DataBind();
            }

            using (ServicosDB db = new ServicosDB())
            {
                ddlEspaco.DataSource = db.ExecQuery($"SELECT [id], [nome], [capacidade] FROM [Espaco]");
                ddlEspaco.DataBind();
            }
        }
Пример #11
0
        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "carregar")
            {
                int    row  = Convert.ToInt32(e.CommandArgument);
                string cnpj = GridView1.Rows[row].Cells[0].Text;

                using (ServicosDB sdb = new ServicosDB())
                {
                    SqlDataReader sda = sdb.ExecQuery($"select * from fornecedor where cnpj_fornecedor = {cnpj}");
                    if (sda.Read())
                    {
                        TextBox1.Text = $"{sda["cnpj_fornecedor"]}";
                        TextBox2.Text = $"{sda["nome_fornecedor"]}";
                        TextBox3.Text = $"{sda["nome_segmento"]}";
                        TextBox4.Text = $"{sda["endereco_fornecedor"]}";
                    }
                    sda.Close();
                }
            }
        }
        public int getNextID()
        {
            using (ServicosDB db = new ServicosDB()) // READ DATABASE
            {
                string        cmd = "select max(id) as lastID from espaco";
                SqlDataReader dr  = db.ExecQuery(cmd);

                if (dr.Read())
                {
                    try
                    {
                        nextID = Convert.ToInt32(dr["lastID"]) + 1;
                    }
                    catch
                    {
                        nextID = 0;
                    }
                }
                dr.Close();
            }
            return(nextID);
        }
Пример #13
0
        protected void gvPalestrantes_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "carregar")
            {
                try
                {
                    int Linha = Convert.ToInt32(e.CommandArgument);
                    int idPalestranteAtual = Convert.ToInt32(gvPalestrantes.Rows[Linha].Cells[0].Text);

                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select * from palestrante where id = @idPalestranteAtual";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@idPalestranteAtual", SqlDbType.Int)
                        {
                            Value = idPalestranteAtual
                        }
                            );

                        if (dr.Read())
                        {
                            txtID.Text       = Convert.ToString(dr["id"]);
                            txtNome.Text     = Convert.ToString(dr["nome"]);
                            txtRG.Text       = Convert.ToString(dr["rg"]);
                            txtCPF.Text      = Convert.ToString(dr["cpf"]);
                            txtEmail.Text    = Convert.ToString(dr["email"]);
                            txtTelefone.Text = Convert.ToString(dr["telefone"]);
                            txtFormacao.Text = Convert.ToString(dr["formacao"]);
                        }
                        dr.Close();
                    }
                }
                catch (Exception exception)
                {
                    alert("Falha ao Carregar Palestrante. Erro: " + exception);
                }
            }
        }
Пример #14
0
        protected void btnAdicionar_Click(object sender, EventArgs e)
        {
            try
            {
                Boolean newRG  = true;
                Boolean newCPF = true;
                string  rg     = "";
                string  cpf    = "";
                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select rg from palestrante where rg = @rg";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@rg", SqlDbType.VarChar, 9)
                    {
                        Value = txtRG.Text
                    });

                    if (dr.Read())
                    {
                        rg = Convert.ToString(dr["rg"]);
                    }
                    dr.Close();
                }
                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select cpf from palestrante where cpf = @cpf";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@cpf", SqlDbType.VarChar, 11)
                    {
                        Value = txtCPF.Text
                    });

                    if (dr.Read())
                    {
                        cpf = Convert.ToString(dr["cpf"]);
                    }
                    dr.Close();
                }
                if (rg == txtRG.Text)
                {
                    newRG = false;
                }
                if (cpf == txtCPF.Text)
                {
                    newCPF = false;
                }

                if (newRG && newCPF)
                {
                    if (cadastroPalestranteFullValidation())
                    {
                        using (ServicosDB db = new ServicosDB())
                        {
                            string cmd = "insert into palestrante values(@nome, @rg, @cpf, @email, @telefone, @formacao)";
                            if (db.ExecUpdate(
                                    cmd,
                                    new SqlParameter("@nome", SqlDbType.VarChar, 100)
                            {
                                Value = txtNome.Text
                            },
                                    new SqlParameter("@rg", SqlDbType.VarChar, 9)
                            {
                                Value = txtRG.Text
                            },
                                    new SqlParameter("@cpf", SqlDbType.VarChar, 11)
                            {
                                Value = txtCPF.Text
                            },
                                    new SqlParameter("@email", SqlDbType.VarChar, 100)
                            {
                                Value = txtEmail.Text
                            },
                                    new SqlParameter("@telefone", SqlDbType.VarChar, 20)
                            {
                                Value = txtTelefone.Text
                            },
                                    new SqlParameter("@formacao", SqlDbType.VarChar, 100)
                            {
                                Value = txtFormacao.Text
                            }
                                    ) > 0)
                            {
                                int id = Convert.ToInt32(db.QueryValue("select @@identity"));
                                txtID.Text = $"{id}";
                                limparCampos();
                            }
                            else
                            {
                                alert("Falha ao adicionar Palestrante!");
                            }
                            atualizarGrid();
                        }
                    }
                    else
                    {
                        alert("Um ou mais campos estão inválidos!");
                    }
                }
                else
                {
                    alert("RG ou CPF já cadastrados ou inválidos!");
                }
                atualizarGrid();
            }
            catch (Exception exception)
            {
                alert("Falha ao Adicionar Palestrante. Erro: " + exception);
            }
        }
        protected void gvMinhasPalestras_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "avaliar")
            {
                int    Linha             = Convert.ToInt32(e.CommandArgument);
                int    idPalestraAtual   = Convert.ToInt32(gvMinhasPalestras.Rows[Linha].Cells[0].Text);
                string nomePalestraAtual = Convert.ToString(gvMinhasPalestras.Rows[Linha].Cells[1].Text);

                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select presente, nota from inscricao where rgmParticipante = @RGM_Usuario and idPalestra = @idPalestraAtual";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                    {
                        Value = Session["RGM_Usuario"]
                    },
                        new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                    {
                        Value = idPalestraAtual
                    });

                    if (dr.Read())
                    {
                        if (Convert.ToBoolean(dr["presente"]))
                        {
                            if (Convert.ToInt32(dr["nota"]) == -1)
                            {
                                Session["Avaliando_Palestra_ID"]   = idPalestraAtual;
                                Session["Avaliando_Palestra_Nome"] = nomePalestraAtual;
                                Response.Redirect("AvaliarPalestra.aspx");
                            }
                            else
                            {
                                alert("Você já avaliou esta Palestra!");
                            }
                        }
                        else
                        {
                            alert("Você não compareceu a esta Palestra!");
                        }
                    }
                    else
                    {
                        alert("Você não compareceu a esta Palestra!");
                    }
                    dr.Close();
                }
            }
            else if (e.CommandName == "imprimirCertificado")
            {
                int Linha           = Convert.ToInt32(e.CommandArgument);
                int idPalestraAtual = Convert.ToInt32(gvMinhasPalestras.Rows[Linha].Cells[0].Text);

                Boolean presente          = false;
                Boolean infoUsuario       = false;
                Boolean infoPalestra      = false;
                Boolean certificadoGerado = false;

                try
                {
                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select presente from inscricao where rgmParticipante = @RGM_Usuario and idPalestra = @idPalestraAtual";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                        {
                            Value = Session["RGM_Usuario"]
                        },
                            new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                        {
                            Value = idPalestraAtual
                        }
                            );

                        if (dr.Read())
                        {
                            if (Convert.ToBoolean(dr["presente"]))
                            {
                                presente = true;
                            }
                            else
                            {
                                alert("Você não compareceu a esta Palestra!");
                            }
                        }
                        dr.Close();
                    }
                }
                catch
                {
                    alert("Falha ao verificar Presença!");
                }

                string nome_usuario          = "";
                string curso_usuario         = "";
                string nome_palestrante      = "";
                string nome_palestra         = "";
                string data_inicio_palestra  = "";
                string data_termino_palestra = "";

                if (presente)
                {
                    try
                    {
                        using (ServicosDB db = new ServicosDB()) // READ DATABASE
                        {
                            string        cmd = "select nome, curso from participante where rgm = @RGM_Usuario";
                            SqlDataReader dr  = db.ExecQuery(
                                cmd,
                                new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                            {
                                Value = Session["RGM_Usuario"]
                            }
                                );

                            if (dr.Read())
                            {
                                nome_usuario  = Convert.ToString(dr["nome"]);
                                curso_usuario = Convert.ToString(dr["curso"]);
                                infoUsuario   = true;
                            }
                            else
                            {
                                alert("Falha ao coletar informações do Usuário!");
                            }
                            dr.Close();
                        }

                        using (ServicosDB db = new ServicosDB()) // READ DATABASE
                        {
                            string        cmd = "select Pe.nome as 'Nome Palestrante', Pa.nome as 'Nome Palestra', Pa.dataHorarioInicio as 'DH Inicio', Pa.dataHorarioTermino as 'DH Termino' from Palestra as Pa INNER JOIN Palestrante as Pe on Pe.id = Pa.idPalestrante where Pa.id = @idPalestraAtual";
                            SqlDataReader dr  = db.ExecQuery(
                                cmd,
                                new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                            {
                                Value = idPalestraAtual
                            }
                                );

                            if (dr.Read())
                            {
                                nome_palestrante      = Convert.ToString(dr["Nome Palestrante"]);
                                nome_palestra         = Convert.ToString(dr["Nome Palestra"]);
                                data_inicio_palestra  = Convert.ToString(dr["DH Inicio"]);
                                data_termino_palestra = Convert.ToString(dr["DH Termino"]);
                                infoPalestra          = true;
                            }
                            else
                            {
                                alert("Falha ao coletar informações da Palestra!");
                            }
                            dr.Close();
                        }
                    }
                    catch
                    {
                        alert("Falha ao coletar informações do Usuário e/ou da Palestra!");
                    }
                }

                if (infoUsuario && infoPalestra)
                {
                    if (gerarCertificado(nome_usuario, curso_usuario, nome_palestrante, nome_palestra, data_inicio_palestra, data_termino_palestra))
                    {
                        Response.Redirect("Certificado.aspx");
                    }
                    else
                    {
                        alert("Falha ao gerar Certificado!");
                    }
                }
            }
        }
        private bool cadastroEspacoValidationINSERT()
        {
            Boolean valid = true;
            int     id    = -1;

            using (ServicosDB db = new ServicosDB()) // READ DATABASE
            {
                string        cmd = "select id from espaco where id = @id";
                SqlDataReader dr  = db.ExecQuery(
                    cmd,
                    new SqlParameter("@id", SqlDbType.Int)
                {
                    Value = txtID.Text
                });

                if (dr.Read())
                {
                    try
                    {
                        id = Convert.ToInt32(dr["id"]);
                    }
                    catch
                    {
                        id = -1;
                    }
                }
                else
                {
                    id = -1;
                }
                dr.Close();
            }

            if (
                id != -1
                )
            {
                valid = false;
                alert("ID inválido! Tente apertar o botão Limpar ou recarregar a página.");
            }
            // VALIDATE Nome
            if (txtNome.Text == "" || txtNome.Text.Length > 100)
            {
                valid = false;
                alert("O campo Nome não pode ser vazio nem ultrapassar os 100 caracteres!");
            }
            // VALIDATE Capacidade
            try
            {
                Convert.ToInt32(txtCapacidade.Text);
            }
            catch
            {
                valid = false;
                alert("O campo Capacidade deve conter apenas números!");
            }
            if (txtCapacidade.Text == "" || txtCapacidade.Text.Length > 9)
            {
                valid = false;
                alert("O campo Capacidade não pode ser vazio nem ultrapassar 9 caracteres!");
            }

            return(valid);
        }
Пример #17
0
        protected void btnCadastrarPart_Click(object sender, EventArgs e)
        {
            try
            {
                Boolean newRGM = true;

                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select count(rgm) as contagem from participante where rgm = @rgm";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@rgm", SqlDbType.VarChar, 11)
                    {
                        Value = txtRGM.Text
                    }
                        );

                    if (dr.Read())
                    {
                        if (Convert.ToInt32(dr["contagem"]) > 0)
                        {
                            newRGM = false;
                        }
                        else
                        {
                        }
                    }
                    dr.Close();
                }

                if (newRGM)
                {
                    if (cadastroPartValidation())
                    {
                        using (ServicosDB db = new ServicosDB()) // INSERT DATABASE
                        {
                            string cmd = "insert into participante values(@rgm, @email, @senha, @nome, @dataNasc, @rg, @cpf, @curso)";
                            if (db.ExecUpdate(
                                    cmd,
                                    new SqlParameter("@rgm", SqlDbType.VarChar, 11)
                            {
                                Value = txtRGM.Text
                            },
                                    new SqlParameter("@email", SqlDbType.VarChar, 100)
                            {
                                Value = txtEmail.Text
                            },
                                    new SqlParameter("@senha", SqlDbType.VarChar, 256)
                            {
                                Value = ServicosDB.stringToSHA256(pwdSenha.Text)
                            },
                                    new SqlParameter("@nome", SqlDbType.VarChar, 100)
                            {
                                Value = txtNome.Text
                            },
                                    new SqlParameter("@dataNasc", SqlDbType.Date)
                            {
                                Value = txtDataNasc.Text
                            },
                                    new SqlParameter("@rg", SqlDbType.VarChar, 9)
                            {
                                Value = txtRG.Text
                            },
                                    new SqlParameter("@cpf", SqlDbType.VarChar, 11)
                            {
                                Value = txtCPF.Text
                            },
                                    new SqlParameter("@curso", SqlDbType.VarChar, 100)
                            {
                                Value = txtCurso.Text
                            }
                                    ) > 0)
                            {
                                alert("Cadastro efetuado com sucesso!");
                            }
                            else
                            {
                                alert("Falha ao cadastrar Participante!");
                            }
                        }
                        Response.Redirect("Home.aspx");
                    }
                    else
                    {
                        alert("Um ou mais campos estão inválidos!");
                    }
                }
                else
                {
                    alert("Este RGM já está cadastrado!");
                }
            }
            catch (Exception exception)
            {
                alert("Falha ao Cadastrar Participante. Erro: " + exception);
            }
        }
        protected void gvPalestras_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "carregar")
            {
                try
                {
                    int Linha           = Convert.ToInt32(e.CommandArgument);
                    int idPalestraAtual = Convert.ToInt32(gvPalestras.Rows[Linha].Cells[0].Text);

                    using (ServicosDB db = new ServicosDB())
                    {
                        SqlDataReader dr = db.ExecQuery(
                            "select * from palestra where id = @idPalestraAtual",
                            new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                        {
                            Value = idPalestraAtual
                        });

                        if (dr.Read())
                        {
                            txtID.Text = $"{dr["id"]}";
                            ddlPalestrante.SelectedValue = $"{dr["idPalestrante"]}";
                            ddlCoordenador.SelectedValue = $"{dr["rgmCoordenador"]}";
                            txtNome.Text = $"{dr["nome"]}";
                            txtDataHorarioInicio.Text  = $"{Convert.ToDateTime(dr["dataHorarioInicio"]).ToString("yyyy-dd-MM HH:mm:ss")}";
                            txtDataHorarioTermino.Text = $"{Convert.ToDateTime(dr["dataHorarioTermino"]).ToString("yyyy-dd-MM HH:mm:ss")}";
                            txtCurso.Text           = $"{dr["curso"]}";
                            ddlEspaco.SelectedValue = $"{dr["idEspaco"]}";
                            txtNota.Text            = $"{dr["nota"]}";
                            txtInscritos.Text       = $"{dr["inscritos"]}";
                            atualizarDDLs();
                        }
                        dr.Close();
                    }
                }
                catch (Exception exception)
                {
                    alert("Falha ao Carregar Palestra. Erro: " + exception.ToString());
                }
            }

            if (e.CommandName == "enviar_presenca")
            {
                try
                {
                    int      Linha = Convert.ToInt32(e.CommandArgument);
                    DateTime dataHorarioTermino = Convert.ToDateTime(gvPalestras.Rows[Linha].Cells[3].Text);
                    if (dataHorarioTermino < DateTime.Now)
                    {
                        Session["Enviar_Presenca_Palestra_ID"]   = Convert.ToString(gvPalestras.Rows[Linha].Cells[0].Text);
                        Session["Enviar_Presenca_Palestra_Nome"] = Convert.ToString(gvPalestras.Rows[Linha].Cells[1].Text);
                        Response.Redirect("EnviarPresenca.aspx");
                    }
                    else
                    {
                        alert("Esta Palestra ainda não acabou!");
                    }
                }
                catch
                {
                    alert("Falha ao entrar na tela de envio de presença.");
                }
            }
        }
        protected void btnEnviar_Click(object sender, EventArgs e)
        {
            int rgmLength = 0;

            if (Convert.ToBoolean(Session["EsqueciASenhaCoordenador"]))
            {
                rgmLength = 6;
            }
            else
            {
                rgmLength = 11;
            }

            if (txtRGM.Text != "" && txtRGM.Text.Length == rgmLength)
            {
                //try {
                string nova_senha = "";
                string rgm        = "";
                string email      = "";


                if (Convert.ToBoolean(Session["EsqueciASenhaCoordenador"]))
                {
                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select rgm, email from coordenador where rgm = @RGM_Usuario";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 20)
                        {
                            Value = txtRGM.Text
                        }
                            );

                        if (dr.Read())
                        {
                            try
                            {
                                rgm   = Convert.ToString(dr["rgm"]);
                                email = Convert.ToString(dr["email"]);
                            }
                            catch
                            {
                                alert("RGM não cadastrado!");
                            }
                        }
                        else
                        {
                            alert("RGM não cadastrado!");
                        }
                        dr.Close();
                    }
                }
                else
                {
                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select rgm, email from participante where rgm = @RGM_Usuario";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                        {
                            Value = txtRGM.Text
                        }
                            );

                        if (dr.Read())
                        {
                            try
                            {
                                rgm   = Convert.ToString(dr["rgm"]);
                                email = Convert.ToString(dr["email"]);
                            }
                            catch
                            {
                                alert("RGM não cadastrado!");
                            }
                        }
                        else
                        {
                            alert("RGM não cadastrado!");
                        }
                        dr.Close();
                    }
                }


                if (rgm != "" && rgm.Length == rgmLength && email != "")
                {
                    string emailAlertSplit = email.Split('@')[0];
                    string emailAlert      = "";
                    for (int i = 0; i < emailAlertSplit.Length; i++)
                    {
                        if (i > emailAlertSplit.Length / 10 && i < (emailAlertSplit.Length - (emailAlertSplit.Length / 10 + 1)))
                        {
                            emailAlert = emailAlert + '*';
                        }
                        else
                        {
                            emailAlert = emailAlert + emailAlertSplit[i];
                        }
                    }
                    emailAlert = emailAlert + "@" + email.Split('@')[1];

                    try
                    {
                        DateTime data = DateTime.Now;
                        int      seed = Convert.ToInt32(data.Month.ToString() + data.Day.ToString() + data.Minute.ToString() + data.Second.ToString());
                        Random   dice = new Random(seed);
                        nova_senha = Convert.ToString(dice.Next(111111111, 999999999));
                    }
                    catch
                    {
                        alert("Erro ao gerar nova senha. Tente novamente mais tarde.");
                    }

                    try
                    {
                        if (Convert.ToBoolean(Session["EsqueciASenhaCoordenador"]))
                        {
                            using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                            {
                                string cmd = "UPDATE coordenador SET senha = @senha where rgm = @rgm";
                                if (db.ExecUpdate(
                                        cmd,
                                        new SqlParameter("@senha", SqlDbType.VarChar, 256)
                                {
                                    Value = ServicosDB.stringToSHA256(nova_senha)
                                },
                                        new SqlParameter("@rgm", SqlDbType.VarChar, 20)
                                {
                                    Value = rgm
                                }
                                        ) > 0)
                                {
                                }
                                else
                                {
                                    alert("Falha ao adicionar Palestrante!");
                                }
                            }
                        }
                        else
                        {
                            using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                            {
                                string cmd = "UPDATE participante SET senha = @senha where rgm = @rgm";
                                if (db.ExecUpdate(
                                        cmd,
                                        new SqlParameter("@senha", SqlDbType.VarChar, 256)
                                {
                                    Value = ServicosDB.stringToSHA256(nova_senha)
                                },
                                        new SqlParameter("@rgm", SqlDbType.VarChar, 11)
                                {
                                    Value = rgm
                                }
                                        ) > 0)
                                {
                                }
                                else
                                {
                                    alert("Falha ao adicionar Palestrante!");
                                }
                            }
                        }

                        if (enviarEmailNovaSenha(email, rgm, nova_senha))
                        {
                            alert("Requisição efetuada! Dentro de alguns minutos, você deverá receber no email \"" + emailAlert + "\" a sua nova senha para o RGM \"" + rgm + "\"");
                        }
                    }
                    catch
                    {
                        alert("Requisição malsucedida! Verifique se o RGM digitado está correto e que este existe no sistema!");
                    }
                }
                else
                {
                    alert("Email ou RGM inválidos!");
                }
                //} catch {  }
            }
            else
            {
                alert("RGM inválido!");
            }
        }
        private bool cadastroPalestraValidation()
        {
            Boolean valid = true;

            #region prevenir conflito de horario e espaco
            try
            {
                Boolean conflito = false;
                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select count(id) as conflitos from Palestra where idEspaco = @idEspaco and (@dataHorarioInicio = dataHorarioInicio or (@dataHorarioInicio > dataHorarioInicio and @dataHorarioInicio < dataHorarioTermino) or (@dataHorarioTermino > dataHorarioInicio and @dataHorarioTermino < dataHorarioTermino) or @dataHorarioTermino = dataHorarioTermino)";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@idEspaco", SqlDbType.Int)
                    {
                        Value = ddlEspaco.SelectedValue
                    },
                        new SqlParameter("@dataHorarioInicio", SqlDbType.VarChar, 30)
                    {
                        Value = txtDataHorarioInicio.Text
                    },
                        new SqlParameter("@dataHorarioTermino", SqlDbType.VarChar, 30)
                    {
                        Value = txtDataHorarioTermino.Text
                    }
                        );

                    if (dr.Read())
                    {
                        conflito = Convert.ToInt32(dr["conflitos"]) > 0;
                    }
                    dr.Close();
                }

                if (conflito)
                {
                    alert("Este horário conflita com uma Palestra já existente no mesmo local!");
                    valid = false;
                }
            }
            catch (Exception exception)
            {
                alert("Falha ao Verificar Conflitos de Horário. Erro: " + exception.ToString());
            }
            #endregion

            #region validar data e horario
            try
            {
                String[] dataHorarioInicioPair = txtDataHorarioInicio.Text.Split(' ');
                String[] splitDateInicio       = dataHorarioInicioPair[0].Split('-');
                String[] splitTimeInicio       = dataHorarioInicioPair[1].Split(':');
                anoI     = Convert.ToInt32(splitDateInicio[0]);
                mesI     = Convert.ToInt32(splitDateInicio[2]);
                diaI     = Convert.ToInt32(splitDateInicio[1]);
                horaI    = Convert.ToInt32(splitTimeInicio[0]);
                minutoI  = Convert.ToInt32(splitTimeInicio[1]);
                segundoI = Convert.ToInt32(splitTimeInicio[2]);
                DateTime dataHorarioInicio = new DateTime(anoI, mesI, diaI, horaI, minutoI, segundoI);
                stringDataHorarioInicio = splitDateInicio[0] + "-" + splitDateInicio[2] + "-" + splitDateInicio[1] + " " + splitTimeInicio[0] + ":" + splitTimeInicio[1] + ":" + splitTimeInicio[2];

                String[] dataHorarioTerminoPair = txtDataHorarioTermino.Text.Split(' ');
                String[] splitDateTermino       = dataHorarioTerminoPair[0].Split('-');
                String[] splitTimeTermino       = dataHorarioTerminoPair[1].Split(':');
                anoT     = Convert.ToInt32(splitDateTermino[0]);
                mesT     = Convert.ToInt32(splitDateTermino[2]);
                diaT     = Convert.ToInt32(splitDateTermino[1]);
                horaT    = Convert.ToInt32(splitTimeTermino[0]);
                minutoT  = Convert.ToInt32(splitTimeTermino[1]);
                segundoT = Convert.ToInt32(splitTimeTermino[2]);
                DateTime dataHorarioTermino = new DateTime(anoT, mesT, diaT, horaT, minutoT, segundoT);
                stringDataHorarioTermino = splitDateTermino[0] + "-" + splitDateTermino[2] + "-" + splitDateTermino[1] + " " + splitTimeTermino[0] + ":" + splitTimeTermino[1] + ":" + splitTimeTermino[2];


                if (dataHorarioInicio == dataHorarioTermino || dataHorarioInicio > dataHorarioTermino)
                {
                    alert("Data e Horário inválidos!");
                    valid = false;
                }
            }
            catch (Exception ignored)
            {
                alert("Os campos Data e Horário devem ser preenchidos conforme o modelo!");
                valid = false;
            }
            #endregion

            #region validar curso e nome
            if (txtNome.Text == "" || txtNome.Text.Length > 100 ||
                txtCurso.Text == "" || txtCurso.Text.Length > 100)
            {
                alert("Os campos Nome e Curso não podem ser vazios, nem ultrapassar 100 caracteres cada.");
                valid = false;
            }
            #endregion

            if (ddlEspaco.Items.Count == 0)
            {
                alert("Você deve ter um Espaco cadastrado e selecionado para criar uma Palestra!");
                valid = false;
            }

            if (ddlPalestrante.Items.Count == 0)
            {
                alert("Você deve ter um Palestrante cadastrado e selecionado para criar uma Palestra!");
                valid = false;
            }

            return(valid);
        }
Пример #21
0
        private bool alterarSenhaValidation()
        {
            Boolean novaSenhaValida   = true;
            Boolean senhaAtualCorreta = false;

            // Senha validation
            if (Convert.ToBoolean(Session["AlterarSenhaCoordenador"]))
            {
                try
                {
                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select senha from coordenador where rgm = @RGM_Usuario";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 20)
                        {
                            Value = txtRGM.Text
                        }
                            );

                        if (dr.Read())
                        {
                            if (Convert.ToString(dr["senha"]) == ServicosDB.stringToSHA256(txtSenhaAtual.Text))
                            {
                                senhaAtualCorreta = true;
                            }
                            else
                            {
                                senhaAtualCorreta = false;
                            }
                        }
                        dr.Close();
                    }
                }
                catch
                {
                    alert("Falha ao confirmar Senha Atual!");
                }
            }
            else
            {
                try
                {
                    using (ServicosDB db = new ServicosDB()) // READ DATABASE
                    {
                        string        cmd = "select senha from participante where rgm = @RGM_Usuario";
                        SqlDataReader dr  = db.ExecQuery(
                            cmd,
                            new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                        {
                            Value = txtRGM.Text
                        }
                            );

                        if (dr.Read())
                        {
                            if (Convert.ToString(dr["senha"]) == ServicosDB.stringToSHA256(txtSenhaAtual.Text))
                            {
                                senhaAtualCorreta = true;
                            }
                            else
                            {
                                senhaAtualCorreta = false;
                            }
                        }
                        dr.Close();
                    }
                }
                catch
                {
                    alert("Falha ao confirmar Senha Atual!");
                }
            }

            if (!senhaAtualCorreta)
            {
                alert("Senha Atual incorreta!");
            }

            if (txtNovaSenha.Text != txtConfirmarNovaSenha.Text || txtNovaSenha.Text.Length > 30 || txtNovaSenha.Text == "" || txtNovaSenha.Text == txtSenhaAtual.Text)
            {
                novaSenhaValida = false;
                alert("Nova Senha inválida! Ambos os campos de Nova Senha devem ser iguais e ter um máximo de 30 caracteres, além de não poderem ser iguais à senha atual nem vazios.");
            }

            return(novaSenhaValida && senhaAtualCorreta);
        }
Пример #22
0
        protected void gvPalestras_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "inscrever")
            {
                Boolean naoInscrito       = false;
                Boolean inscricaoEfetuada = false;
                Boolean naoCheia          = false;

                int Linha           = Convert.ToInt32(e.CommandArgument);
                int idPalestraAtual = Convert.ToInt32(gvPalestras.Rows[Linha].Cells[0].Text);

                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select count(I.rgmParticipante) as contagem from inscricao as I inner join palestra as P on P.id = I.idPalestra where I.rgmParticipante = @RGM_Usuario and I.idPalestra = @idPalestraAtual";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                    {
                        Value = Session["RGM_Usuario"]
                    },
                        new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                    {
                        Value = idPalestraAtual
                    }
                        );

                    if (dr.Read())
                    {
                        if (Convert.ToInt32(dr["contagem"]) > 0)
                        {
                            alert("Você já se inscreveu nesta Palestra!");
                        }
                        else
                        {
                            naoInscrito = true;
                        }
                    }
                    dr.Close();
                }

                using (ServicosDB db = new ServicosDB()) // READ DATABASE
                {
                    string        cmd = "select (select count(I.rgmParticipante) from Inscricao as I INNER JOIN Palestra as P on P.id = I.idPalestra where P.id = @idPalestraAtual) as 'Inscritos', (select E.capacidade from Espaco as E INNER JOIN Palestra as P on E.id = P.idEspaco where P.id = @idPalestraAtual) as 'Capacidade'";
                    SqlDataReader dr  = db.ExecQuery(
                        cmd,
                        new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                    {
                        Value = idPalestraAtual
                    });

                    if (dr.Read())
                    {
                        if (Convert.ToInt32(dr["Capacidade"]) > Convert.ToInt32(dr["Inscritos"]))
                        {
                            naoCheia = true;
                        }
                    }
                    dr.Close();
                }

                try
                {
                    if (naoInscrito && naoCheia)
                    {
                        using (ServicosDB db = new ServicosDB()) // INSERT DATABASE
                        {
                            string cmd = "insert into inscricao values(@RGM_Usuario, @idPalestraAtual, 0, -1)";
                            if (db.ExecUpdate(
                                    cmd,
                                    new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
                            {
                                Value = Session["RGM_Usuario"]
                            },
                                    new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                            {
                                Value = idPalestraAtual
                            }
                                    ) > 0)
                            {
                            }
                            else
                            {
                                alert("Falha ao inscrever-se na palestra!");
                            }
                            atualizarGrid();
                        }
                        alert("Inscrição efetuada com sucesso!");
                        inscricaoEfetuada = true;
                    }
                }
                catch (Exception ignored)
                {
                    inscricaoEfetuada = false;
                }

                if (inscricaoEfetuada)
                {
                    try
                    {
                        using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                        {
                            string cmd = "UPDATE palestra SET inscritos = (select count(idPalestra) from inscricao where idPalestra = @idPalestraAtual) where id = @idPalestraAtual";
                            if (db.ExecUpdate(
                                    cmd,
                                    new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                            {
                                Value = idPalestraAtual
                            }
                                    ) > 0)
                            {
                            }
                            else
                            {
                                alert("Falha ao falha ao atualizar contagem de inscritos!");
                            }
                            atualizarGrid();
                        }
                    }
                    catch (Exception ignored)
                    { }
                }
                else
                {
                    alert("Inscrição malsucedida!");
                }
            }
        }