Exemplo n.º 1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try {
                RestClient restClient = new RestClient();
                restClient.endPoint = "http://192.168.40.21/Invengo/Controller/ControllerInvengo.php?OPC=1";

                string strResponse = string.Empty;
                strResponse = restClient.makeRequest();
                Dao.Dao dao             = new Dao.Dao();
                string  come            = null;
                string  strResponseLast = strResponse.Remove(strResponse.Length - 1, 1);
                int     last            = strResponse.Length;
                string  json            = strResponseLast.Substring(1);

                string[] columna = null;
                string[] fila    = json.Split('{');
                if (dao.deletePersonas())
                {
                    foreach (string data1 in fila)
                    {
                        columna = data1.Split(',');
                        Console.WriteLine("Linea: " + data1 + "\n");
                        int i = 0;

                        foreach (string data2 in columna)
                        {
                            if (i == 9 || i == 0)
                            {
                                this.datos[i] = data2.ToString().Replace('\"', ' ');
                            }
                            else
                            {
                                this.datos[i] = data2.ToString();
                            }

                            i++;
                        }

                        if (!dao.addPersona(this.datos[0], this.datos[2], this.datos[1], this.datos[3], this.datos[4], this.datos[5], this.datos[6], this.datos[7], this.datos[8], this.datos[9], this.datos[10]))
                        {
                            Console.WriteLine("Error al insertar persona");
                            //break;
                        }
                        Console.WriteLine("Sincronizacion Finalizada!");
                    }
                }
                else
                {
                    Console.WriteLine("Error al eliminar la tabla de personas");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("No se puede conectar con el servidor\nIntentalo mas tarde!");
            }


            //this.label2.Text = registros[0][3];
        }
Exemplo n.º 2
0
        private void AddToList(object sender, EventArgs e)
        {
            Dao.Dao dao = new Dao.Dao();
            if (lvCodes.Items.Count > 1000)
            {
                //MessageBox.Show("2");
                lvCodes.Items.Clear();
            }
            string msg    = (string)sender;
            bool   exists = false;

            //foreach (ListViewItem lvi in lvCodes.Items)
            //{
            //    if (lvi == null)
            //        continue;
            //    if (msg == lvi.SubItems[0].Text)
            //    {
            //        exists = true;
            //        int ic = Convert.ToInt32(lvi.SubItems[1].Text);
            //        ic += 1;
            //        lvi.SubItems[1].Text = ic.ToString();

            //        break;
            //    }
            //}

            if (!exists)
            {
                this.res = "";
                ListViewItem lvi = new ListViewItem(new string[] { msg, "1" });
                this.res = dao.getPersonaByCredencial(msg, this.comedor);
                Thread ATM2 = new Thread(new ThreadStart(ThreadProc));
                ATM2.Start();

                lvCodes.Items.Add(lvi);
                lvCodes.EnsureVisible(lvCodes.Items.Count - 1);
                scanner.StopScan();
                btscan.Text = "Scan";
                btscan.Tag  = "start";
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Add To List
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddToList(object sender, EventArgs e)
        {
            totalTimes++;//总次数

            TagView1 msg    = (TagView1)sender;
            bool     exists = false;

            foreach (ListViewItem lvi in lvCodes.Items)
            {
                if (lvi == null)
                {
                    continue;
                }
                if (msg.Userdata != "")
                {
                    if (msg.Userdata == lvi.SubItems[3].Text)
                    {
                        exists = true;
                        int ic = Convert.ToInt32(lvi.SubItems[0].Text);
                        ic += 1;
                        lvi.SubItems[0].Text = ic.ToString();
                        MessageBox.Show(ic.ToString());
                        if (msg.RSSI != "")
                        {
                            lvi.SubItems[4].Text = msg.RSSI;
                        }
                        break;
                    }
                }
                else if (msg.Epc != "" && msg.ID == "")
                {
                    if (lvi.SubItems[2].Text == msg.Epc)
                    {
                        exists = true;
                        int ic = Convert.ToInt32(lvi.SubItems[0].Text);
                        ic += 1;
                        lvi.SubItems[0].Text = ic.ToString();
                        if (msg.RSSI != "")
                        {
                            lvi.SubItems[4].Text = msg.RSSI;
                        }
                        break;
                    }
                }
                else
                {
                    if (lvi.SubItems[1].Text == msg.ID)
                    {
                        exists = true;
                        int ic = Convert.ToInt32(lvi.SubItems[0].Text);
                        ic += 1;
                        lvi.SubItems[0].Text = ic.ToString();
                        break;
                    }
                }
            }

            if (!exists)
            {
                try
                {
                    string[] arrayCodigo    = null;
                    string[] arrayResultado = null;
                    string   codigo         = null;
                    string   nombre         = null;
                    Dao.Dao  dao            = new Dao.Dao();


                    arrayCodigo = msg.Epc.Split(' ');
                    codigo      = arrayCodigo[2] + arrayCodigo[3][0] + arrayCodigo[3][1];
                    int lectura = (int)Int64.Parse(codigo, System.Globalization.NumberStyles.HexNumber);


                    string res = dao.getPersonaByUHFComedor(lectura.ToString());
                    arrayResultado = res.Split(',');
                    nombre         = arrayResultado[1];
                    ListViewItem lvi = new ListViewItem(new string[] { "1", msg.ID, nombre, msg.Epc, msg.Userdata, msg.RSSI.ToString() });
                    //strmsg = msg.Userdata
                    lvCodes.Items.Add(lvi);
                    lvCodes.EnsureVisible(lvCodes.Items.Count - 1);
                    readSnd.Set();
                    stopSearching();


                    FrInfo frInfo = new FrInfo(res);
                    frInfo.ShowDialog();

                    totalTags  = 1;
                    totalTimes = 1;
                }
                catch (Exception ex) {
                    MessageBox.Show("Lectura de tarjeta incorrecta!\n Tarjeta dañada o ajena al establecimiento");
                    stopSearching();
                }
            }
            totalTags    = lvCodes.Items.Count;//
            lblStat.Text = "Credenciales:" + lvCodes.Items.Count;
        }
Exemplo n.º 4
0
        public void syncPhoto()
        {
            try
            {
                //Vamos a borrar la carpeta y crearla de nuevo
                string path = @"\Storage Card\Img";
                if (Directory.Exists(path))
                {
                    System.IO.Directory.Delete(path, true);

                    System.IO.Directory.CreateDirectory(path);
                }
                else
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                //aqui vamos a obtener un listado de todos los ids para las fotos
                RestClient restClient = new RestClient();
                restClient.endPoint = "http://192.168.40.21/Invengo/Controller/ControllerInvengo.php?OPC=3";
                string strResponse = string.Empty;
                strResponse = restClient.makeRequest();
                Dao.Dao  dao             = new Dao.Dao();
                string   strResponseLast = strResponse.Remove(strResponse.Length - 1, 1);
                string   json            = strResponseLast.Substring(1);
                string[] fila            = json.Split(',');
                foreach (string id in fila)
                {
                    try
                    {
                        //aqui va a descargar la img
                        Console.WriteLine("Imagen Sincronizada : " + id + ".jpg");
                        string         imageUrl     = @"http://192.168.40.21/Invengo/Img/" + id + ".jpg";
                        string         saveLocation = @"\Storage Card\Img\" + id + ".jpg";
                        byte[]         imageBytes;
                        HttpWebRequest imageRequest   = (HttpWebRequest)WebRequest.Create(imageUrl);
                        WebResponse    imageResponse  = imageRequest.GetResponse();
                        Stream         responseStream = imageResponse.GetResponseStream();
                        using (BinaryReader br = new BinaryReader(responseStream))
                        {
                            imageBytes = br.ReadBytes(300000);
                            br.Close();
                        }
                        responseStream.Close();
                        imageResponse.Close();

                        FileStream   fs = new FileStream(saveLocation, FileMode.Create);
                        BinaryWriter bw = new BinaryWriter(fs);
                        try
                        {
                            bw.Write(imageBytes);
                        }
                        catch (Exception ex)
                        {
                            Console.Write("Intermitencia en la señal\n " + ex.Message);
                            // break;
                        }
                        finally
                        {
                            fs.Close();
                            bw.Close();
                        }
                    }
                    catch (Exception exp)
                    {
                        Console.Write("Imagen no sincronizada : " + id + ".jpg\n itermitencia en la señal\n Por favor reinicia la sincronización!");
                    }
                }
            }
            catch (Exception e) {
                MessageBox.Show("No es Posible Conectar con el servidor\nIntentelo mas tarde!");
            }
        }
Exemplo n.º 5
0
 private void button2_Click_1(object sender, EventArgs e)
 {
     Dao.Dao dao = new Dao.Dao();
     dao.syncMarcaje();
     dao.syncMarcajeComedor();
 }