Пример #1
0
 protected void btnAvaliar_Click(object sender, EventArgs e)
 {
     if (notaIsValid())
     {
         using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
         {
             string cmd = "UPDATE inscricao SET nota = @nota WHERE rgmParticipante = @RGM_Usuario and idPalestra = @Avaliando_Palestra_ID";
             if (db.ExecUpdate(
                     cmd,
                     new SqlParameter("@nota", SqlDbType.Int)
             {
                 Value = txtNota.Text
             },
                     new SqlParameter("@RGM_Usuario", SqlDbType.VarChar, 11)
             {
                 Value = Session["RGM_Usuario"]
             },
                     new SqlParameter("@Avaliando_Palestra_ID", SqlDbType.Int)
             {
                 Value = Session["Avaliando_Palestra_ID"]
             }
                     ) > 0)
             {
             }
             else
             {
                 alert("Falha ao adicionar Palestrante!");
             }
         }
         Response.Redirect("MinhasPalestras.aspx");
     }
     else
     {
     }
 }
 protected void btnAdicionar_Click(object sender, EventArgs e)
 {
     if (cadastroPalestraValidation())
     {
         using (ServicosDB db = new ServicosDB()) // INSERT DATABASE
         {
             string cmd = "insert into palestra values(@idPalestrante, @rgmCoordenador, @nome, @dataHorarioInicio, @dataHorarioTermino, @curso, @idEspaco, NULL, 0)";
             if (db.ExecUpdate(
                     cmd,
                     new SqlParameter("@idPalestrante", SqlDbType.Int)
             {
                 Value = ddlPalestrante.SelectedValue
             },
                     new SqlParameter("@rgmCoordenador", SqlDbType.VarChar, 20)
             {
                 Value = ddlCoordenador.SelectedValue
             },
                     new SqlParameter("@nome", SqlDbType.VarChar, 100)
             {
                 Value = txtNome.Text
             },
                     new SqlParameter("@dataHorarioInicio", SqlDbType.DateTime)
             {
                 Value = stringDataHorarioInicio
             },
                     new SqlParameter("@dataHorarioTermino", SqlDbType.DateTime)
             {
                 Value = stringDataHorarioTermino
             },
                     new SqlParameter("@curso", SqlDbType.VarChar, 100)
             {
                 Value = txtCurso.Text
             },
                     new SqlParameter("@idEspaco", SqlDbType.Int)
             {
                 Value = ddlEspaco.SelectedValue
             }
                     ) > 0)
             {
                 int id = Convert.ToInt32(db.QueryValue("select @@identity"));
                 txtID.Text = $"{id}";
                 limparCampos();
                 atualizarDDLs();
             }
             else
             {
                 alert("Falha ao adicionar Palestra!");
             }
             atualizarGrid();
         }
     }
 }
Пример #3
0
 protected void Button2_Click(object sender, EventArgs e)
 {
     using (ServicosDB sdb = new ServicosDB())
     {
         String sql = $"insert into fornecedor values ('{TextBox1.Text}','{TextBox2.Text}','{TextBox3.Text}','{TextBox4.Text}')";
         if (sdb.ExecUpdate(sql) > 0)
         {
             alert("Usuario inserido com sucesso");
             clear();
             updateGridView();
         }
         else
         {
             alert("Não foi possivel inserir o usuario.");
         }
     }
 }
Пример #4
0
 protected void Button3_Click(object sender, EventArgs e)
 {
     using (ServicosDB sdb = new ServicosDB())
     {
         String sql = $"update fornecedor set nome_fornecedor = '{TextBox2.Text}', nome_segmento = '{TextBox3.Text}', endereco_fornecedor = '{TextBox4.Text}' where cnpj_fornecedor = '{TextBox1.Text}'";
         if (sdb.ExecUpdate(sql) > 0)
         {
             alert("Usuario atualizado com sucesso");
             clear();
             updateGridView();
         }
         else
         {
             alert("Não foi possivel atualizar o usuario.");
         }
     }
 }
Пример #5
0
 protected void Button4_Click(object sender, EventArgs e)
 {
     using (ServicosDB sdb = new ServicosDB())
     {
         String sql = $"delete from fornecedor where cnpj_fornecedor = {TextBox1.Text}";
         if (sdb.ExecUpdate(sql) > 0)
         {
             alert("O usuario foi deletado com sucesso!");
             clear();
             updateGridView();
         }
         else
         {
             alert("O usuario não pôde ser deletado.");
         }
     }
 }
        protected void btnExcluir_Click(object sender, EventArgs e)
        {
            Boolean successful = false;

            try
            {
                if (Convert.ToInt32(txtID.Text) < getNextID())
                {
                    using (ServicosDB db = new ServicosDB()) // DELETE DATABASE
                    {
                        string cmd = "delete from espaco where id = @id";
                        if (db.ExecUpdate(
                                cmd,
                                new SqlParameter("@id", SqlDbType.Int)
                        {
                            Value = txtID.Text
                        }
                                ) > 0)
                        {
                            limparCampos();
                            successful = true;
                        }
                        else
                        {
                            alert("Falha ao excluir Espaço!");
                        }
                        atualizarGrid();
                    }
                }
                else
                {
                    alert("Carregue um Espaço primeiro!");
                }
                limparCampos();
                atualizarGrid();
            }
            catch (Exception exception)
            {
                successful = false;
            }

            if (!successful)
            {
                alert("Falha ao Excluir Espaço. Talvez este espaço esteja ocupado por alguma palestra?");
            }
        }
 protected void btnAlterar_Click(object sender, EventArgs e)
 {
     //try {
     if (Convert.ToInt32(txtID.Text) < getNextID())
     {
         using (ServicosDB db = new ServicosDB())     // UPDATE DATABASE
         {
             if (cadastroEspacoValidation())
             {
                 string cmd = "UPDATE espaco SET nome = @nome, capacidade = @capacidade where id = @id";
                 if (db.ExecUpdate(
                         cmd,
                         new SqlParameter("@nome", SqlDbType.VarChar, 100)
                 {
                     Value = txtNome.Text
                 },
                         new SqlParameter("@capacidade", SqlDbType.Int)
                 {
                     Value = txtCapacidade.Text
                 },
                         new SqlParameter("@id", SqlDbType.Int)
                 {
                     Value = txtID.Text
                 }
                         ) > 0)
                 {
                 }
             }
             else
             {
                 alert("Um ou mais campos inválidos!");
             }
             atualizarGrid();
         }
     }
     else
     {
         alert("Carregue um Espaço primeiro!");
     }
     limparCampos();
     atualizarGrid();
     //} catch (Exception exception) { alert("Falha ao Alterar Espaço. Erro: " + exception); }
 }
 protected void btnExcluir_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToInt32(txtID.Text) < getNextID())
         {
             using (ServicosDB db = new ServicosDB()) // DELETE DATABASE
             {
                 string cmd = "delete from palestra where id = @idPalestraAtual";
                 if (db.ExecUpdate(
                         cmd,
                         new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                 {
                     Value = txtID.Text
                 }
                         ) > 0)
                 {
                     limparCampos();
                     atualizarDDLs();
                 }
                 else
                 {
                     alert("Falha ao excluir Palestra!");
                 }
                 atualizarGrid();
             }
         }
         else
         {
             alert("Carregue uma Palestra primeiro!");
         }
         limparCampos();
         atualizarGrid();
     }
     catch
     {
         alert("Esta Palestra já possui participantes inscritos!");
     }
 }
Пример #9
0
 protected void btnExcluir_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToInt32(txtID.Text) < getNextID())
         {
             using (ServicosDB db = new ServicosDB()) // DELETE DATABASE
             {
                 string cmd = "delete from palestrante where id = @id";
                 if (db.ExecUpdate(
                         cmd,
                         new SqlParameter("@id", SqlDbType.Int)
                 {
                     Value = txtID.Text
                 }
                         ) > 0)
                 {
                     limparCampos();
                 }
                 else
                 {
                     alert("Falha ao excluir Palestrante!");
                 }
                 atualizarGrid();
             }
         }
         else
         {
             alert("Carregue um Palestrante primeiro!");
         }
         limparCampos();
         atualizarGrid();
     }
     catch (Exception exception)
     {
         alert("Falha ao Excluir Palestrante. Erro: " + exception);
     }
 }
 protected void btnAdicionar_Click(object sender, EventArgs e)
 {
     //try {
     if (cadastroEspacoValidationINSERT())
     {
         using (ServicosDB db = new ServicosDB())     // INSERT DATABASE
         {
             string cmd = "insert into espaco values(@nome, @capacidade)";
             if (db.ExecUpdate(
                     cmd,
                     new SqlParameter("@nome", SqlDbType.VarChar, 100)
             {
                 Value = txtNome.Text
             },
                     new SqlParameter("@capacidade", SqlDbType.Int)
             {
                 Value = txtCapacidade.Text
             }
                     ) > 0)
             {
             }
             else
             {
                 alert("Falha ao adicionar Palestrante!");
             }
             atualizarGrid();
         }
     }
     else
     {
         alert("Um ou mais campos estão inválidos!");
     }
     atualizarGrid();
     limparCampos();
     //} catch (Exception exception) { alert("Falha ao Adicionar Espaço. Erro: " + exception); }
 }
Пример #11
0
 protected void btnAlterar_Click(object sender, EventArgs e)
 {
     try
     {
         if (Convert.ToInt32(txtID.Text) < getNextID())
         {
             if (cadastroPalestranteValidateCampos())
             {
                 using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                 {
                     string cmd = "UPDATE palestrante SET nome = @nome, rg = @rg, cpf = @cpf, email = @email, telefone = @telefone, formacao = @formacao where id = @id";
                     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
                     },
                             new SqlParameter("@id", SqlDbType.Int)
                     {
                         Value = txtID.Text
                     }
                             ) > 0)
                     {
                         limparCampos();
                     }
                     else
                     {
                         alert("Falha ao alterar Palestrante!");
                     }
                 }
             }
             else
             {
                 alert("Um ou mais campos inválidos!");
             }
         }
         else
         {
             alert("Carregue um Palestrante primeiro!");
         }
         atualizarGrid();
     }
     catch (Exception exception)
     {
         alert("Falha ao Alterar Palestrante. Erro: " + exception);
     }
 }
Пример #12
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 btnAlterar_Click(object sender, EventArgs e)
 {
     //try {
     if (cadastroPalestraValidationUPDATE())
     {
         if (Convert.ToInt32(txtID.Text) < getNextID())
         {
             using (ServicosDB db = new ServicosDB())     // UPDATE DATABASE
             {
                 string cmd = "update palestra set idPalestrante = @idPalestrante, rgmCoordenador = @rgmCoordenador, nome = @nome, dataHorarioInicio = @dataHorarioInicio, dataHorarioTermino = @dataHorarioTermino, curso = @curso, idEspaco = @idEspaco where id = @idPalestraAtual";
                 if (db.ExecUpdate(
                         cmd,
                         new SqlParameter("@idPalestrante", SqlDbType.Int)
                 {
                     Value = ddlPalestrante.SelectedValue
                 },
                         new SqlParameter("@rgmCoordenador", SqlDbType.VarChar, 20)
                 {
                     Value = ddlCoordenador.SelectedValue
                 },
                         new SqlParameter("@nome", SqlDbType.VarChar, 100)
                 {
                     Value = txtNome.Text
                 },
                         new SqlParameter("@dataHorarioInicio", SqlDbType.DateTime)
                 {
                     Value = stringDataHorarioInicio
                 },
                         new SqlParameter("@dataHorarioTermino", SqlDbType.DateTime)
                 {
                     Value = stringDataHorarioTermino
                 },
                         new SqlParameter("@curso", SqlDbType.VarChar, 100)
                 {
                     Value = txtCurso.Text
                 },
                         new SqlParameter("@idEspaco", SqlDbType.Int)
                 {
                     Value = ddlEspaco.SelectedValue
                 },
                         new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                 {
                     Value = txtID.Text
                 }
                         ) > 0)
                 {
                     limparCampos();
                     atualizarDDLs();
                 }
                 else
                 {
                     alert("Falha ao alterar Palestra!");
                 }
             }
         }
         else
         {
             alert("Carregue uma Palestra primeiro!");
         }
     }
     else
     {
         alert("Um ou mais campos inválidos!");
     }
     atualizarGrid();
     //} catch (Exception exception) { alert("Falha ao Alterar Palestra. Erro: " + exception.ToString()); }
 }
        protected void btnEnviar_Click(object sender, EventArgs e)
        {
            int    sucesso       = 0;
            int    erro          = 0;
            String presentesErro = "";
            String presentes     = txtPresentes.Text;

            String[] presentesList = presentes.Replace("\r\n", "Ñ").Split('Ñ');
            for (int i = 0; i < presentesList.Length; i++)
            {
                try
                {
                    Convert.ToInt64(presentesList[i]);
                    if (presentesList[i] == "" || presentesList[i].Length != 11)
                    {
                        erro++;
                        if (presentesErro.Contains("\""))
                        {
                            presentesErro = presentesErro + ",";
                        }
                        presentesErro = presentesErro + " \"" + presentesList[i] + "\"";
                    }
                    else
                    {
                        using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                        {
                            string cmd = "UPDATE inscricao SET presente = 1 where idPalestra = @idPalestraAtual and rgmParticipante = @rgmParticipante";
                            if (db.ExecUpdate(
                                    cmd,
                                    new SqlParameter("@idPalestraAtual", SqlDbType.Int)
                            {
                                Value = txtID.Text
                            },
                                    new SqlParameter("@rgmParticipante", SqlDbType.VarChar, 11)
                            {
                                Value = presentesList[i]
                            }
                                    ) > 0)
                            {
                            }
                            else
                            {
                                erro++;
                                if (presentesErro.Contains("\""))
                                {
                                    presentesErro = presentesErro + ",";
                                }
                                presentesErro = presentesErro + " \"" + presentesList[i] + "\"";
                            }
                        }
                        sucesso++;
                    }
                }
                catch
                {
                    erro++;
                    if (presentesErro.Contains("\""))
                    {
                        presentesErro = presentesErro + ",";
                    }
                    presentesErro = presentesErro + " \"" + presentesList[i] + "\"";
                }
            }
            if (erro > 0)
            {
                alert("As seguintes linhas não foram identificadas como RGMs válidos:" + presentesErro);
                alert("Presença atribuída para todos os RGMs inseridos, exceto os presentes na lista de erros!");
            }
            else
            {
                alert("Presença atribuída para todos os RGMs inseridos!");
            }
        }
Пример #15
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);
            }
        }
Пример #16
0
 protected void btnAlterar_Click(object sender, EventArgs e)
 {
     if (alterarSenhaValidation())
     {
         if (Convert.ToBoolean(Session["AlterarSenhaCoordenador"]))
         {
             try
             {
                 using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                 {
                     string cmd = "UPDATE coordenador SET senha = @novaSenha where rgm = @rgm";
                     if (db.ExecUpdate(
                             cmd,
                             new SqlParameter("@novaSenha", SqlDbType.VarChar, 256)
                     {
                         Value = ServicosDB.stringToSHA256(txtNovaSenha.Text)
                     },
                             new SqlParameter("@rgm", SqlDbType.VarChar, 20)
                     {
                         Value = txtRGM.Text
                     }
                             ) > 0)
                     {
                         alert("Senha alterada com sucesso!");
                     }
                     else
                     {
                         alert("Falha ao efetuar alteração!");
                     }
                 }
             }
             catch
             {
                 alert("Falha ao efetuar alteração!");
             }
         }
         else
         {
             try
             {
                 using (ServicosDB db = new ServicosDB()) // UPDATE DATABASE
                 {
                     string cmd = "UPDATE participante SET senha = @novaSenha where rgm = @rgm";
                     if (db.ExecUpdate(
                             cmd,
                             new SqlParameter("@novaSenha", SqlDbType.VarChar, 256)
                     {
                         Value = ServicosDB.stringToSHA256(txtNovaSenha.Text)
                     },
                             new SqlParameter("@rgm", SqlDbType.VarChar, 11)
                     {
                         Value = txtRGM.Text
                     }
                             ) > 0)
                     {
                         alert("Senha alterada com sucesso!");
                     }
                     else
                     {
                         alert("Falha ao efetuar alteração!");
                     }
                 }
             }
             catch
             {
                 alert("Falha ao efetuar alteração!");
             }
         }
     }
 }
        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!");
            }
        }
Пример #18
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!");
                }
            }
        }