Пример #1
0
        private void _timer_Elapsed15(object sender, ElapsedEventArgs e)
        {
            Procesos proceso = new Procesos();

            proceso.proceso_cseiio(pos15);
        }
Пример #2
0
        private void dtConexiones_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            int currentRow = int.Parse(e.RowIndex.ToString());//Obtiene la fila actual

            if (e.ColumnIndex >= 0 && this.dtConexiones.Columns[e.ColumnIndex].Name == "conectar" && e.RowIndex >= 0)
            {
                Procesos proceso = new Procesos();
                dtConexiones[0, currentRow].Style.BackColor = Color.Green;
                dtConexiones[1, currentRow].Style.BackColor = Color.Green;
                dtConexiones[2, currentRow].Style.BackColor = Color.Green;
                dtConexiones[3, currentRow].Style.BackColor = Color.Green;
                dtConexiones[4, currentRow].Style.BackColor = Color.Green;

                String update;
                string servidor  = "localhost";
                string baseDatos = "rjchcseiio";
                string usuario   = "root";
                string password  = "";

                // ---------------- ACTUALIZAR BANDERA DE ENCENDIDO --------------------------
                MessageBox.Show("Conectandose al dispositivo: " + Convert.ToString(dtConexiones[4, currentRow].Value) + " del BIC: " + Convert.ToString(dtConexiones[3, currentRow].Value), "Obteniendo IP", MessageBoxButtons.OK, MessageBoxIcon.Information);
                //Despues de seleccionar el boton de conectar en la tabla, se crea el proceso con la ip que se obtiene de la tabla.

                int id = Convert.ToInt32(dtConexiones[2, currentRow].Value);
                ipdispositivo        = Convert.ToString(dtConexiones[4, currentRow].Value);
                btnAgregar.Enabled   = false;
                btnEliminar.Enabled  = false;
                btnModificar.Enabled = false;

                String banderaon = "on";
                update = string.Format("Update controlip set bandera='{0}' where id_registro={1}", banderaon, id);

                //Creamos la conexión a la base de datos
                MySqlConnection _conexion = new MySqlConnection();
                _conexion.ConnectionString = "Data Source=" + servidor + "; Database=" + baseDatos + "; Uid=" + usuario + "; Pwd=" + password;
                _conexion.Open();
                //Se muestra un mensaje de Asistencia Agregada
                MySqlCommand C = new MySqlCommand(update, _conexion);

                C.ExecuteNonQuery();
                _conexion.Close();
                // ---------------- FINALIZACIÓN DE ACTUALIZAR BANDERA DE ENCENCIDO --------------------------
                // ----- SWITCHEO BASADO EN EL ID ASOCIADO A LA POSICION DE LA IP EN EL FORMULARIO -----
                switch (id)
                {
                case 3:
                    Thread hilo1 = new Thread(new ParameterizedThreadStart(crearTimer));
                    pos1 = Convert.ToString(dtConexiones[4, 0].Value);
                    hilo1.Start(pos1);
                    break;

                case 4:
                    Thread hilo2 = new Thread(new ParameterizedThreadStart(crearTimer2));
                    pos2 = Convert.ToString(dtConexiones[4, 1].Value);
                    hilo2.Start(pos2);
                    break;

                case 5:
                    Thread hilo3 = new Thread(new ParameterizedThreadStart(crearTimer3));
                    pos3 = Convert.ToString(dtConexiones[4, 2].Value);
                    hilo3.Start(pos3);
                    break;

                case 6:
                    Thread hilo4 = new Thread(new ParameterizedThreadStart(crearTimer4));
                    pos4 = Convert.ToString(dtConexiones[4, 3].Value);
                    hilo4.Start(pos4);
                    break;

                case 14:
                    Thread hilo5 = new Thread(new ParameterizedThreadStart(crearTimer5));
                    pos5 = Convert.ToString(dtConexiones[4, 4].Value);
                    hilo5.Start(pos5);
                    break;

                case 15:
                    Thread hilo6 = new Thread(new ParameterizedThreadStart(crearTimer6));
                    pos6 = Convert.ToString(dtConexiones[4, 5].Value);
                    hilo6.Start(pos6);
                    break;

                case 16:
                    Thread hilo7 = new Thread(new ParameterizedThreadStart(crearTimer7));
                    pos7 = Convert.ToString(dtConexiones[4, 6].Value);
                    hilo7.Start(pos7);
                    break;

                case 17:
                    Thread hilo8 = new Thread(new ParameterizedThreadStart(crearTimer8));
                    pos8 = Convert.ToString(dtConexiones[4, 7].Value);
                    hilo8.Start(pos8);
                    break;

                case 18:
                    Thread hilo9 = new Thread(new ParameterizedThreadStart(crearTimer9));
                    pos9 = Convert.ToString(dtConexiones[4, 8].Value);
                    hilo9.Start(pos9);
                    break;

                case 19:
                    Thread hilo10 = new Thread(new ParameterizedThreadStart(crearTimer10));
                    pos10 = Convert.ToString(dtConexiones[4, 9].Value);
                    hilo10.Start(pos10);
                    break;

                case 20:
                    Thread hilo11 = new Thread(new ParameterizedThreadStart(crearTimer11));
                    pos11 = Convert.ToString(dtConexiones[4, 10].Value);
                    hilo11.Start(pos11);
                    break;

                case 21:
                    Thread hilo12 = new Thread(new ParameterizedThreadStart(crearTimer12));
                    pos12 = Convert.ToString(dtConexiones[4, 11].Value);
                    hilo12.Start(pos12);
                    break;

                case 22:
                    Thread hilo13 = new Thread(new ParameterizedThreadStart(crearTimer13));
                    pos13 = Convert.ToString(dtConexiones[4, 12].Value);
                    hilo13.Start(pos13);
                    break;

                case 23:
                    Thread hilo14 = new Thread(new ParameterizedThreadStart(crearTimer14));
                    pos14 = Convert.ToString(dtConexiones[4, 13].Value);
                    hilo14.Start(pos14);
                    break;

                case 24:
                    Thread hilo15 = new Thread(new ParameterizedThreadStart(crearTimer15));
                    pos15 = Convert.ToString(dtConexiones[4, 14].Value);
                    hilo15.Start(pos15);
                    break;

                default:
                    break;
                }

                /*
                 * 1.- Bandera de conexion desde la base, comprobar si estan conectados desde la base de datos con una bandera OFF / ON
                 * 2.- Combrobar si la ip esta conectada
                 * 3.- Posteriormente ejecutar el proceso.procesocseiio con la IP que tenga la bandera ON
                 * 4.- Si un IP(Dispositivo) se agrega se comprueba si esta activada
                 * 5.- Se crea un hilo por cada dispositivo que se encuentre en ON
                 * 6.- Se le asigna un id a cada hilo y este aumenta en uno cuando la bandera esta en ON
                 */
                // Aqui se ejecutaria la cosulta mediante un while, dentro de ese while se crearia el proceso de obtencion de informacion
                //1.- Hacer una consulta a la base de datos para verificar cuantos registros hay
            }

            if (e.ColumnIndex >= 0 && this.dtConexiones.Columns[e.ColumnIndex].Name == "desconectar" && e.RowIndex >= 0)
            {
                bandera = false;
                dtConexiones[0, currentRow].Style.BackColor = Color.Red;
                dtConexiones[1, currentRow].Style.BackColor = Color.Red;
                dtConexiones[2, currentRow].Style.BackColor = Color.Red;
                dtConexiones[3, currentRow].Style.BackColor = Color.Red;
                dtConexiones[4, currentRow].Style.BackColor = Color.Red;

                String update;
                string servidor  = "localhost";
                string baseDatos = "rjchcseiio";
                string usuario   = "root";
                string password  = "";


                MessageBox.Show("Desconectandose al dispositivo: " + Convert.ToString(dtConexiones[4, currentRow].Value) + " del BIC: " + Convert.ToString(dtConexiones[3, currentRow].Value), "Obteniendo IP", MessageBoxButtons.OK, MessageBoxIcon.Error);
                int id = Convert.ToInt32(dtConexiones[2, currentRow].Value);
                ipdispositivo = Convert.ToString(dtConexiones[4, currentRow].Value);
                String banderaoff = "off";
                update = string.Format("Update controlip set bandera='{0}' where id_registro={1}", banderaoff, id);

                //Creamos la conexión a la base de datos
                MySqlConnection _conexion = new MySqlConnection();
                _conexion.ConnectionString = "Data Source=" + servidor + "; Database=" + baseDatos + "; Uid=" + usuario + "; Pwd=" + password;
                _conexion.Open();
                //Se muestra un mensaje de Asistencia Agregada
                MySqlCommand C = new MySqlCommand(update, _conexion);

                C.ExecuteNonQuery();
                _conexion.Close();

                btnAgregar.Enabled   = true;
                btnEliminar.Enabled  = true;
                btnModificar.Enabled = true;
            }
        }