//Cargamos los datos en el datagrid de los candidatos public void CargarCandidatos() { MetodosCandidatos Candidatos = new MetodosCandidatos(); DGTCandidatos.DataSource = Candidatos.ObtenerCandidatos(); if (Candidatos.Is_Error) { MessageBox.Show(Candidatos.ErrorDescripcion, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Stop); } }
private void BtonEmitirVoto_Click(object sender, EventArgs e) { MetodosCandidatos candidato = new MetodosCandidatos(); List<Candidato> ListaCandidato = candidato.ObtenerCandidatos(); MetodosVotantes Votantes = new MetodosVotantes(); List<Votante> votante = Votantes.ObtenerVotantes(); MetodosNulosBlancos NB = new MetodosNulosBlancos(); NB.IDPeriodo = IDPeriodo; NB.Agregar(); List<NulosBlancos> NBS = NB.ObtenerNulosOBlancos(); int cont = 0; for (int i = 0; i < dtagridVoto.RowCount; i++) { bool estado = Convert.ToBoolean(dtagridVoto.Rows[i].Cells[4].Value); if (estado == true) { cont++;//Contamos cuantos checkbocks estan en true } } if (cont == 1)//Consultamos si fue solo un checkbocks se comprueba cual posiciion era para saber que candidato hay que editar { for (int i = 0; i < dtagridVoto.RowCount; i++) { bool estado = Convert.ToBoolean(dtagridVoto.Rows[i].Cells[4].Value); if (estado == true) { candidato.EditarCandidato(ListaCandidato[i].ID, ListaCandidato[i].Nombre, ListaCandidato[i].Apellidos, ListaCandidato[i].PartidoPolitico, Convert.ToInt32(ListaCandidato[i].Votos) + 1, ListaCandidato[i].IDPeriodo); break; } } } if (cont == 0) { NB.EditarNuloOBlanco(NBS[0].ID, Convert.ToInt32(NBS[0].Votos) + 1);//SE EDITAN LOS BALNCOS DEL PERIODO } else if (cont > 1) { NB.EditarNuloOBlanco(NBS[1].ID, Convert.ToInt32(NBS[0].Votos) + 1);//Se editan los nulos del periodo } for (int i = 0; i < votante.Count; i++) { if (votante[i].Cedula == CedulaVotante)//Se comprueba si son iguales para saber cual cambiar { Votantes.EditarVotante(votante[i].Cedula, votante[i].Contraseña, votante[i].Tipo, votante[i].Nombre, votante[i].Apellido1, votante[i].Apellido2, "Si"); //Se edita el votante el estado a SI DE SI HA VOTADO this.Close(); break; } else { } } }
/// <summary> /// Metodo que usamos para ingresar el candidato /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// private void botonIngresarCandidato_Click(object sender, EventArgs e) { MetodosCandidatos NuevoCandidato = new MetodosCandidatos(); List<Candidato> ListaCandidatos = NuevoCandidato.ObtenerCandidatos(); if (textID.Text == "" || textApellidos.Text == "" || textNombreCandidato.Text == "" || textApellidos.Text == "" || textPartido.Text == "" || ESpacioCamara.Image==null || EspacioBandera.Image==null)//Se comprueba si todos //los componentes que se utilizan para agregar datos estan completos o tienen inforamcion para que no haya problemas a la hora de agregar { MessageBox.Show("Ingresa Todos los datos", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { bool esta = false; for (int i = 0; i < ListaCandidatos.Count; i++)//Se comprueba si hay candidatos { if (ListaCandidatos[i].ID == textID.Text)//Se comprueba si el textid y el id de la posicion de la longitud de la lista son iguales //de serlo quiere decir que ese id ya esta asignando a otro candidato { esta = true; break; } } if (esta == true) { MessageBox.Show("Ese Candidato ya existe", "Informacion", MessageBoxButtons.OK, MessageBoxIcon.Information); textID.Text = ""; } else { NuevoCandidato.AgregarCandidato(textID.Text, textNombreCandidato.Text, textApellidos.Text, textPartido.Text, 0,IDPeriodo);//Se agrega toda la informacion ESpacioCamara.Image.Save(@Application.StartupPath + "/datosProyecto/Candidatos/" + textID.Text + ".JPEG");//Agremos la foto en el la ruta EspacioBandera.Image.Save(@Application.StartupPath + "/datosProyecto/Candidatos/" + "BANDERA" + textID.Text + ".JPEG");//Se agrega la bandera en la misma ruta que la foto this.Close(); } } }
private void frmResultados_Load(object sender, EventArgs e) { MetodosCandidatos candidato = new MetodosCandidatos(); List<Candidato> ListaCandidato = candidato.ObtenerCandidatos(); NB.IDPeriodo = IDPeriodo; NBS = NB.ObtenerNulosOBlancos(); for (int i = 0; i < ListaCandidato.Count; i++) { if (ListaCandidato[i].IDPeriodo == IDPeriodo) { if (primer_lugar < ListaCandidato[i].Votos) { tercer_lugar = segundo_lugar; segundo_lugar = primer_lugar; primer_lugar = ListaCandidato[i].Votos; } else { if (segundo_lugar < ListaCandidato[i].Votos) { tercer_lugar = segundo_lugar; segundo_lugar = ListaCandidato[i].Votos; } else { if (tercer_lugar < ListaCandidato[i].Votos) { tercer_lugar = ListaCandidato[i].Votos; } } } this.CharGraficos.Series["Porcentaje de votos"].Points.AddXY(ListaCandidato[i].Nombre + " " + ListaCandidato[i].Votos, Convert.ToDouble(ListaCandidato[i].Votos)); Total_votos = Total_votos + Convert.ToInt16(ListaCandidato[i].Votos); } } this.CharGraficos.Series["Porcentaje de votos"].Points.AddXY(NBS[0].ID + " " + NBS[0].Votos, Convert.ToDouble((NBS[0].Votos))); Total_votos = Total_votos + Convert.ToInt16( (NBS[0].Votos)); this.CharGraficos.Series["Porcentaje de votos"].Points.AddXY(NBS[1].ID + " " + NBS[1].Votos, Convert.ToDouble((NBS[1].Votos))); Total_votos = Total_votos + Convert.ToInt16((NBS[1].Votos)); double porcentajea; porcentajea = (Convert.ToDouble(NBS[0].Votos) * 100) / Total_votos; this.charporcentaje.Series["Porcentaje de votos"].Points.AddXY(NBS[0].ID + " " + string.Format("{0:0.00}", porcentajea), porcentajea); porcentajea = (Convert.ToDouble(NBS[1].Votos) * 100) / Total_votos; this.charporcentaje.Series["Porcentaje de votos"].Points.AddXY(NBS[1].ID + " " + string.Format("{0:0.00}", porcentajea), porcentajea); for (int i = 0; i < ListaCandidato.Count; i++) { try { if (ListaCandidato[i].IDPeriodo == IDPeriodo) { if (ListaCandidato[i].Votos == primer_lugar) { pictureprimero.Image = Image.FromFile((@Application.StartupPath + @"\datosProyecto\Candidatos\" + ListaCandidato[i].ID + ".JPEG")); lblprimero.Text = ListaCandidato[i].Nombre; } if (ListaCandidato[i].Votos == segundo_lugar) { picturesegundo.Image = Image.FromFile((@Application.StartupPath + @"\datosProyecto\Candidatos\" + ListaCandidato[i].ID + ".JPEG")); lblsegundo.Text = ListaCandidato[i].Nombre; } if (ListaCandidato[i].Votos == tercer_lugar) { picturetercero.Image = Image.FromFile((@Application.StartupPath + @"\datosProyecto\Candidatos\" + ListaCandidato[i].ID + ".JPEG")); lbltercero.Text = ListaCandidato[i].Nombre; } } } catch (Exception) { } } textCantidadVotos.Text = Convert.ToString(Total_votos); for (int i = 0; i < ListaCandidato.Count; i++) { if (ListaCandidato[i].IDPeriodo == IDPeriodo) { double porcentaje; porcentaje = (Convert.ToDouble(ListaCandidato[i].Votos) * 100) / Total_votos; this.charporcentaje.Series["Porcentaje de votos"].Points.AddXY(ListaCandidato[i].Nombre + " " + string.Format("{0:0.00}", porcentaje), porcentaje); } } }
private void frmEmitirVoto_Load(object sender, EventArgs e) { DataTable tabla = new DataTable(); MetodosCandidatos candidato = new MetodosCandidatos(); List<Candidato> ListaCandidato = candidato.ObtenerCandidatos(); string cedula = ListaCandidato[0].ID; for (int i = 0; i < ListaCandidato.Count; i++) { if (ListaCandidato[i].IDPeriodo ==IDPeriodo)//Lo usamos apra cargar solo los candidatos del periodo que tenemos activo { try { dtagridVoto.RowTemplate.Height = 70; dtagridVoto.Rows.Add((System.Drawing.Image.FromFile(@Application.StartupPath + "/datosProyecto/Candidatos/" + ListaCandidato[i].ID + ".JPEG")), (System.Drawing.Image.FromFile(@Application.StartupPath + "/datosProyecto/Candidatos/" + "BANDERA" + ListaCandidato[i].ID + ".JPEG")), ListaCandidato[i].PartidoPolitico, ListaCandidato[i].Nombre, false); } catch (Exception) { throw; } } else { } } }
private void dtagridVoto_CellMouseClick(object sender, DataGridViewCellMouseEventArgs e) { try { posicion = e.RowIndex; MetodosCandidatos candidato = new MetodosCandidatos(); List<Candidato> ListaCandidato = candidato.ObtenerCandidatos(); Emitir_Voto(ListaCandidato[posicion].ID); dtagridVoto.Rows[posicion].Cells[4].Value = true; ptCandidato.Image = Image.FromFile(@Application.StartupPath + @"\datosProyecto\Candidatos\" + ListaCandidato[posicion].ID + ".JPEG"); LblNombreCandidato.Text = ListaCandidato[posicion].Nombre + " " + ListaCandidato[posicion].Apellidos; lblPartido.Text = ListaCandidato[posicion].PartidoPolitico ; } catch (Exception) { throw; } }