Пример #1
0
        public JsonResult listarCaderno()
        {
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();

                SACommand cmd = new SACommand("listarCaderno", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SADataReader            reader            = cmd.ExecuteReader();
                List <cadernoEleitoral> cadernoEleitorals = new List <cadernoEleitoral>();
                while (reader.Read())
                {
                    cadernoEleitorals.Add(new cadernoEleitoral {
                        id = Int32.Parse(reader.GetString(0)), periodo = reader.GetString(1)
                    });
                }

                reader.Close();
                conn.Close();

                return(Json(cadernoEleitorals));
            }
            catch (SAException ex)
            {
                conn.Close();
                return(Json(false));
            }
        }
Пример #2
0
        public JsonResult listarEleicoes(bool isActive)
        {
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();

                SACommand cmd = new SACommand("listarEleicoes", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SADataReader   reader        = cmd.ExecuteReader();
                List <Eleicao> listaEleicoes = new List <Eleicao>();

                DateTime tmpInicio;
                DateTime tmpFim;
                DateTime today = DateTime.Now.Date;
                while (reader.Read())
                {
                    tmpInicio = reader.GetDateTime(2);
                    tmpFim    = reader.GetDateTime(3);

                    if (isActive)
                    {
                        if (today >= tmpInicio && today < tmpFim)
                        {
                            listaEleicoes.Add(new Eleicao {
                                id = reader.GetInt32(0), nome = reader.GetString(1), inicio = reader.GetDateTime(2), fim = reader.GetDateTime(3)
                            });
                        }
                    }
                    else
                    {
                        listaEleicoes.Add(new Eleicao {
                            id = reader.GetInt32(0), nome = reader.GetString(1), inicio = reader.GetDateTime(2), fim = reader.GetDateTime(3)
                        });
                    }
                }

                reader.Close();
                conn.Close();

                return(Json(listaEleicoes));
            }
            catch (SAException ex)
            {
                conn.Close();
                return(Json(false));
            }
        }
Пример #3
0
        public JsonResult mostrarListaPartidos()
        {
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();

                SACommand cmd = new SACommand("listarPartidos", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SADataReader   reader        = cmd.ExecuteReader();
                List <Partido> listaPartidos = new List <Partido>();
                while (reader.Read())
                {
                    listaPartidos.Add(new Partido {
                        id = reader.GetInt32(0), nome = reader.GetString(1)
                    });
                }

                reader.Close();
                conn.Close();

                return(Json(listaPartidos));
            }
            catch (SAException ex)
            {
                conn.Close();
                return(Json(false));
            }
        }
Пример #4
0
        public ActionResult electionMain()
        {
            if (Session["UserID"] != null)
            {
                SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

                conn.Open();

                SACommand cmd = new SACommand("listarCandidatos", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SADataReader     reader          = cmd.ExecuteReader();
                List <Candidato> listaCandidatos = new List <Candidato>();
                while (reader.Read())
                {
                    listaCandidatos.Add(new Candidato {
                        id = reader.GetInt32(0), nomeCandidato = reader.GetString(1), nomePartido = reader.GetString(2)
                    });
                }

                reader.Close();
                conn.Close();

                ViewBag.listaCandidatos = listaCandidatos;


                return(View());
            }
            else
            {
                return(RedirectToAction("Login"));
            }
        }
Пример #5
0
        public ActionResult Login(string login, string password)
        {
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();

                SACommand cmd = new SACommand("getAdmin", conn);
                cmd.CommandType = CommandType.StoredProcedure;

                SADataReader reader     = cmd.ExecuteReader();
                string       dbUserName = "";
                string       dbPassword = "";

                //List<Partido> listaPartidos = new List<Partido>();
                while (reader.Read())
                {
                    dbUserName = reader.GetString(0);
                    dbPassword = reader.GetString(1);
                }
                reader.Close();
                conn.Close();

                if (dbUserName == login && dbPassword == password)
                {
                    Session["UserID"]   = 1;
                    Session["UserName"] = "******";
                    ViewBag.Message     = "";
                    return(RedirectToAction("Index"));
                }
                else
                {
                    ViewBag.Message = "Login inválido!";
                    return(View());
                }



                // return Json(listaPartidos);
            }
            catch (SAException ex)
            {
                conn.Close();
                return(RedirectToAction("Login"));
            }
        }
Пример #6
0
        public JsonResult listarEleitores(int idCaderno)
        {
            // CALL "dev"."listarEleitores"("idCaderno" = 4)
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();


                SACommand cmd = new SACommand("CALL listarEleitores(\"idCaderno\" = ?)", conn);
                cmd.CommandType = CommandType.Text;

                SAParameter param = cmd.CreateParameter();
                param.SADbType  = SADbType.Integer;
                param.Direction = ParameterDirection.Input;
                param.Value     = idCaderno;
                cmd.Parameters.Add(param);

                SADataReader          reader           = cmd.ExecuteReader();
                List <cadernoEleitor> cadernoEleitores = new List <cadernoEleitor>();
                while (reader.Read())
                {
                    cadernoEleitores.Add(new cadernoEleitor {
                        nome = reader.GetString(0), cc = reader.GetString(1), isVoted = reader.GetBoolean(2)
                    });
                }
                reader.Close();
                conn.Close();
                return(Json(cadernoEleitores));
            }
            catch (SAException ex)
            {
                //Console.WriteLine(ex.Errors[0].Source + " : " + ex.Errors[0].Message + " (" + ex.Errors[0].NativeError.ToString() + ")", "Failed to connect");​
                conn.Close();
                return(Json(false));
            }
        }
Пример #7
0
        public JsonResult loadBoletim(int idEleicao)
        {
            //carregarBoletim
            SAConnection conn = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();


                SACommand cmd = new SACommand("CALL carregarBoletim(\"idEleicao\" = ?)", conn);
                cmd.CommandType = CommandType.Text;

                SAParameter param = cmd.CreateParameter();
                param.SADbType  = SADbType.Integer;
                param.Direction = ParameterDirection.Input;
                param.Value     = idEleicao;
                cmd.Parameters.Add(param);

                SADataReader   reader       = cmd.ExecuteReader();
                List <Boletim> itensBoletim = new List <Boletim>();
                while (reader.Read())
                {
                    itensBoletim.Add(new Boletim {
                        idCandidato = reader.GetInt32(0), nomeCandidato = reader.GetString(1), nomePartido = reader.GetString(2), idEleicao = idEleicao
                    });
                }
                reader.Close();
                conn.Close();
                return(Json(itensBoletim));
            }
            catch (SAException ex)
            {
                //Console.WriteLine(ex.Errors[0].Source + " : " + ex.Errors[0].Message + " (" + ex.Errors[0].NativeError.ToString() + ")", "Failed to connect");​
                conn.Close();
                return(Json(false));
            }
        }
Пример #8
0
        public JsonResult contarVotos(int idEleicao)
        {
            string       outMessage = "";
            SAConnection conn       = new SAConnection("Data Source=eleicoes_conn");

            try
            {
                conn.Open();
                SACommand cmd = new SACommand("CALL contarVotos(\"idEleicao\" = ? )", conn);
                cmd.CommandType = CommandType.Text;


                SAParameter param1 = cmd.CreateParameter();
                param1.SADbType  = SADbType.Integer;
                param1.Direction = ParameterDirection.Input;
                param1.Value     = idEleicao;
                cmd.Parameters.Add(param1);

                SAParameter outP = cmd.CreateParameter();
                outP.SADbType  = SADbType.Integer;
                outP.Direction = ParameterDirection.Output;
                cmd.Parameters.Add(outP);

                SADataReader     reader        = cmd.ExecuteReader();
                int              flagResultado = (int)outP.Value;//1-> integridade dos resultados afectada 2->eleição ainda a decorrer 0 -> ok!!!!
                List <Resultado> resultados    = new List <Resultado>();
                int              winnerId      = 0;

                if (flagResultado == 0)
                {
                    while (reader.Read())
                    {
                        resultados.Add(new Resultado {
                            id = reader.GetInt32(0), nomeCandidato = reader.GetString(1), nomePartido = reader.GetString(2), nomeEleicao = reader.GetString(3), nrVotos = reader.GetInt32(4)
                        });
                    }
                    if (resultados.Count > 0)
                    {
                        winnerId = resultados.Where(x => x.nrVotos == resultados.Max(y => y.nrVotos)).SingleOrDefault().id;
                    }
                    reader.Close();
                }
                else if (flagResultado == 1)
                {
                    outMessage = "Integridade dos resultados corrompida!!!!";
                }
                else
                {
                    outMessage = "A eleição ainda está a decorrer";
                }

                if (outMessage.Length > 0)
                {
                    conn.Close();
                    return(Json(outMessage));
                }
                else
                {
                    conn.Close();
                    return(Json(new { R = resultados, W = winnerId }));
                }
            }
            catch (SAException ex)
            {
                conn.Close();
                return(Json(false));
            }
        }