Exemplo n.º 1
0
        public void ManejadorVoto(string senador, Votacion.EVoto voto)
        {
            if (this.groupBox2.InvokeRequired)
            {
                Votacion.voto recall = new Votacion.voto(this.ManejadorVoto);
                this.Invoke(recall, new object[] { senador, voto });
            }
            else
            {
                // Leo la banca del Senador actual
                PictureBox p = this.graficos.ElementAt(int.Parse(senador) - 1);
                switch (voto)
                {
                case Votacion.EVoto.Afirmativo:
                    // Sumo votantes al Label correspondiente
                    lblAfirmativo.Text = (int.Parse(lblAfirmativo.Text) + 1).ToString();
                    // Marco la banca con color Verde
                    p.BackColor = Color.Green;
                    break;

                case Votacion.EVoto.Negativo:
                    // Sumo votantes al Label correspondiente
                    lblNegativo.Text = (int.Parse(lblNegativo.Text) + 1).ToString();
                    // Marco la banca con color Rojo
                    p.BackColor = Color.Red;
                    break;

                case Votacion.EVoto.Abstencion:
                    // Sumo votantes al Label correspondiente
                    lblAbstenciones.Text = (int.Parse(lblAbstenciones.Text) + 1).ToString();
                    // Marco la banca con color Amarillo
                    p.BackColor = Color.Yellow;
                    break;
                }
                // Quito un Senador de los que un no votaron, para marcar cuando termina la votación
                int aux = int.Parse(lblEsperando.Text) - 1;
                lblEsperando.Text = aux.ToString();
                // Si finaliza la votación, muestro si Es Ley o No Es Ley
                if (aux == 0)
                {
                    MessageBox.Show((int.Parse(lblAfirmativo.Text) - int.Parse(lblNegativo.Text)) > 0 ? "Es Ley" : "No es Ley", txtLeyNombre.Text);
                    // Guardar resultados
                    string path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\Votacion.xml";
                    SerializarXML <Votacion> serializarXML = new SerializarXML <Votacion>();
                    serializarXML.Guardar(path, this.votacion);
                    Dao sql = new Dao();
                    sql.Guardar("HOLA", this.votacion);
                }
            }
        }
Exemplo n.º 2
0
        public void ErrorArchivo()
        {
            Votacion v = null;

            try
            {
                SerializarXML <Votacion> ser = new SerializarXML <Votacion>();
                ser.Guardar(null, v); //Le mando null al path para que rompa
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(ErrorArchivoException));
            }
        }
Exemplo n.º 3
0
        public void Testxml()
        {
            try
            {
                //Arrange
                SerializarXML <Votacion> ser = new SerializarXML <Votacion>();

                //Act
                ser.Guardar("", new Votacion("Medios", null));
            }
            catch (Exception e)
            {
                throw new ErrorArchivoException(e.Message);
            }
        }
Exemplo n.º 4
0
        public void TestMethod1()
        {
            try
            {
                Votacion vot = new Votacion();

                SerializarXML <Votacion> ser = new SerializarXML <Votacion>();

                ser.Guardar(null, vot); //null para que entre al catch
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ErrorArchivoException));
            }
        }
Exemplo n.º 5
0
        public void TestSerializar()
        {
            Votacion vot = new Votacion();
            SerializarXML <Votacion> serializarXML = new SerializarXML <Votacion>();

            try
            {
                serializarXML.Guardar("Votacion.xml", vot);
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ErrorArchivoException));
            }

            try
            {
                serializarXML.Leer("Votacion.xml");
            }
            catch (Exception e)
            {
                Assert.IsInstanceOfType(e, typeof(ErrorArchivoException));
            }
        }
Exemplo n.º 6
0
        public void ManejadorVoto(string senador, Votacion.EVoto voto)
        {
            if (this.groupBox2.InvokeRequired)
            {
                Voto recall = new Voto(this.ManejadorVoto);
                this.Invoke(recall, new object[] { senador, voto });
            }
            else
            {
                // Leo la banca del Senador actual
                PictureBox p = this.graficos.ElementAt(int.Parse(senador) - 1);
                switch (voto)
                {
                case Votacion.EVoto.Afirmativo:
                    // Sumo votantes al Label correspondiente
                    lblAfirmativo.Text = (int.Parse(lblAfirmativo.Text) + 1).ToString();
                    // Marco la banca con color Verde
                    p.BackColor = Color.Green;
                    break;

                case Votacion.EVoto.Negativo:
                    // Sumo votantes al Label correspondiente
                    lblNegativo.Text = (int.Parse(lblNegativo.Text) + 1).ToString();
                    // Marco la banca con color Rojo
                    p.BackColor = Color.Red;
                    break;

                case Votacion.EVoto.Abstencion:
                    // Sumo votantes al Label correspondiente
                    lblAbstenciones.Text = (int.Parse(lblAbstenciones.Text) + 1).ToString();
                    // Marco la banca con color Amarillo
                    p.BackColor = Color.Yellow;
                    break;
                }
                // Quito un Senador de los que un no votaron, para marcar cuando termina la votación
                int aux = int.Parse(lblEsperando.Text) - 1;
                lblEsperando.Text = aux.ToString();
                // Si finaliza la votación, muestro si Es Ley o No Es Ley
                if (aux == 0)
                {
                    MessageBox.Show((int.Parse(lblAfirmativo.Text) - int.Parse(lblNegativo.Text)) > 0 ? "Es Ley" : "No es Ley", txtLeyNombre.Text);
                    // Guardar resultados
                    SerializarXML xml = new SerializarXML();
                    try
                    {
                        xml.Guardar(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\votacion.xml", votacion);
                        MessageBox.Show("Se guardó los resultados de la votación en archivo XML");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("No se pudo guarda XML");
                    }
                    DAO baseDatos = new DAO();
                    try
                    {
                        baseDatos.Guardar("", votacion);
                        MessageBox.Show("Se guardó los resultados de la votación en la base de datos");
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("No se pudo guarda en Base de Datos");
                    }
                }
            }
        }
Exemplo n.º 7
0
        public void ManejadorVoto(string senador, Votacion.EVoto voto)
        {
            if (this.groupBox2.InvokeRequired)
            {
                Votacion.Voto recall = new Votacion.Voto(this.ManejadorVoto);
                this.Invoke(recall, new object[] { senador, voto });
            }
            else
            {
                // Leo la banca del Senador actual
                PictureBox p = this.graficos.ElementAt(int.Parse(senador) - 1);
                switch (voto)
                {
                case Votacion.EVoto.Afirmativo:
                    // Sumo votantes al Label correspondiente
                    lblAfirmativo.Text = (int.Parse(lblAfirmativo.Text) + 1).ToString();
                    // Marco la banca con color Verde
                    p.BackColor = Color.Green;
                    break;

                case Votacion.EVoto.Negativo:
                    // Sumo votantes al Label correspondiente
                    lblNegativo.Text = (int.Parse(lblNegativo.Text) + 1).ToString();
                    // Marco la banca con color Rojo
                    p.BackColor = Color.Red;
                    break;

                case Votacion.EVoto.Abstencion:
                    // Sumo votantes al Label correspondiente
                    lblAbstenciones.Text = (int.Parse(lblAbstenciones.Text) + 1).ToString();
                    // Marco la banca con color Amarillo
                    p.BackColor = Color.Yellow;
                    break;
                }
                // Quito un Senador de los que un no votaron, para marcar cuando termina la votación
                int aux = int.Parse(lblEsperando.Text) - 1;
                lblEsperando.Text = aux.ToString();
                // Si finaliza la votación, muestro si Es Ley o No Es Ley
                if (aux == 0)
                {
                    MessageBox.Show((int.Parse(lblAfirmativo.Text) - int.Parse(lblNegativo.Text)) > 0 ? "Es Ley" : "No es Ley", txtLeyNombre.Text);
                    // Guardar resultados

                    //---SQL---
                    try
                    {
                        Dao dao = new Dao();
                        dao.Guardar("", this.votacion);
                    }
                    catch (Exception e)
                    {
                        throw new Exception("Error al guardar BD", e);
                    }

                    //---XML---
                    try
                    {
                        SerializarXML <Votacion> xml = new SerializarXML <Votacion>();
                        xml.Guardar("Votacion.xml", this.votacion);
                    }
                    catch (ErrorArchivoException e)
                    {
                        throw new Exception("Error al guarda XML", e);
                    }
                    catch (Exception)
                    {
                        throw;
                    }
                }
            }
        }