Exemple #1
0
        private void RefreshInventoryReal(byte btCmd)
        {
            //Create a list to store the result
            List <string>[] list = new List <string> [3];
            Int32           numArticulosRestantes = 1; // 1 = not finished

            list[0] = new List <string>();
            if (this.InvokeRequired)
            {
                RefreshInventoryRealUnsafe InvokeRefresh = new RefreshInventoryRealUnsafe(RefreshInventoryReal);
                this.Invoke(InvokeRefresh, new object[] { btCmd });
            }
            else
            {
                switch (btCmd)
                {
                case 0x89:
                case 0x8B:
                {
                    int      nTagCount          = m_curInventoryBuffer.dtTagTable.Rows.Count;
                    int      nTotalRead         = m_nTotal;// m_curInventoryBuffer.dtTagDetailTable.Rows.Count;
                    TimeSpan ts                 = m_curInventoryBuffer.dtEndInventory - m_curInventoryBuffer.dtStartInventory;
                    int      nTotalTime         = ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
                    int      nCaculatedReadRate = 0;
                    int      nCommandDuation    = 0;

                    if (m_curInventoryBuffer.nReadRate == 0)         //读写器没有返回速度前软件测速度
                    {
                        if (nTotalTime > 0)
                        {
                            nCaculatedReadRate = (nTotalRead * 1000 / nTotalTime);
                        }
                    }
                    else
                    {
                        nCommandDuation    = m_curInventoryBuffer.nDataCount * 1000 / m_curInventoryBuffer.nReadRate;
                        nCaculatedReadRate = m_curInventoryBuffer.nReadRate;
                    }

                    int nEpcCount  = 0;
                    int nEpcLength = m_curInventoryBuffer.dtTagTable.Rows.Count;

                    // Aqui hacemos lo que sea necesario con el EPC y el listado.
                    if (nEpcCount < nEpcLength)
                    {
                        // Last DataRow added
                        DataRow row = m_curInventoryBuffer.dtTagTable.Rows[nEpcLength - 1];
                        // Select Reference from Tag and compare with order. If exist on
                        string EPC    = EPCPassed.Replace(" ", "");
                        string query2 = "SELECT referencia FROM proxPedidosContenido WHERE EPC='" + EPC + "' and uso='' and fechaSalida IS NULL and numAsociado='' and defectuosa='No' and etiquetaImprimida='Si'";
                        if (OpenConnectionMySQL())
                        {
                            MySqlCommand    cmd        = new MySqlCommand(query2, connection2);
                            MySqlDataReader dataReader = cmd.ExecuteReader();
                            while (dataReader.Read())
                            {
                                list[0].Add(dataReader["referencia"] + "");
                            }
                            dataReader.Close();
                            CloseConnectionMySQL();
                        }
                        // Assign reference of EPC
                        if (lastEPC != EPC)
                        {
                            if (list[0].Count > 0)
                            {
                                string referencia = list[0][0].ToString();
                                if (!EPCsPasados.Contains(EPC))
                                {
                                    numArticulosRestantes = 0;
                                    for (int h = 0; h < dataGridView1.Rows.Count; h++)
                                    {
                                        if (dataGridView1[1, h].Value != null && referencia == dataGridView1[1, h].Value.ToString())
                                        {
                                            if (Convert.ToInt32(dataGridView1[3, h].Value) == 0)
                                            {
                                                MessageBox.Show("NO ES NECESARIO MAS CANTIDAD DE ESTE PRODUCTO");
                                                lastEPC = EPC;
                                            }
                                            else
                                            {
                                                //Hacemos lo que haya que hacer en datagridView para restar el producto
                                                dataGridView1[3, h].Value = (Convert.ToInt32(dataGridView1[3, h].Value) - 1).ToString();
                                                dataGridView1[4, h].Value = (Convert.ToInt32(dataGridView1[4, h].Value) - 1).ToString();
                                                if (Convert.ToInt32(dataGridView1[3, h].Value) == 0)
                                                {
                                                    dataGridView1.Rows[h].DefaultCellStyle.BackColor = Color.Green;
                                                }
                                                EPCsPasados.Add(EPC);
                                                lastEPC = EPC;
                                            }
                                        }
                                        numArticulosRestantes = numArticulosRestantes + Convert.ToInt32(dataGridView1[3, h].Value);
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("ESTE PRODUCTO YA ESTA EN ESTE PAQUETE");
                                    lastEPC = EPC;
                                }
                            }
                            else
                            {
                                MessageBox.Show("ARTICULO NO PEDIDO EN ESTE PEDIDO");
                                lastEPC = EPC;
                            }
                        }        //close if (if the product passed is the same)
                        //if (dataGridView1)
                        ListViewItem item = new ListViewItem();
                        if (!listView1.Items.ContainsKey(row[2].ToString()))
                        {
                            item.Name = row[2].ToString();
                            item.Text = (nEpcCount + 1).ToString();
                            item.SubItems.Add(row[2].ToString());
                            item.SubItems.Add(row[0].ToString());
                            item.SubItems.Add(row[5].ToString());
                            item.SubItems.Add((Convert.ToInt32(row[4]) - 129).ToString() + "dBm");
                            item.SubItems.Add(row[6].ToString());
                            listView1.Items.Add(item);
                            listView1.Items[nEpcCount].EnsureVisible();
                        }
                    }

                    //更新列表中读取的次数
                    if (m_nTotal % m_nRealRate == 1)
                    {
                        int nIndex = 0;
                        foreach (DataRow row in m_curInventoryBuffer.dtTagTable.Rows)
                        {
                            ListViewItem item;
                            item = listView1.Items[nIndex];
                            item.SubItems[3].Text = row[5].ToString();
                            item.SubItems[4].Text = (Convert.ToInt32(row[4]) - 129).ToString() + "dBm";
                            item.SubItems[5].Text = row[6].ToString();

                            nIndex++;
                        }
                    }
                    if (numArticulosRestantes == 0)
                    {
                        MessageBox.Show("PEDIDO COMPLETADO");
                        // Hacer lo que sea necesario cuando se completo el pedido (un nuevo formulario o algo).
                    }
                }
                break;


                case 0x00:
                case 0x01:
                {
                    m_bLockTab = false;
                }
                break;

                default:
                    break;
                }
            }
        }
        private void RefreshInventoryReal(byte btCmd)
        {
            if (this.InvokeRequired)
            {
                RefreshInventoryRealUnsafe InvokeRefresh = new RefreshInventoryRealUnsafe(RefreshInventoryReal);
                this.Invoke(InvokeRefresh, new object[] { btCmd });
            }
            else
            {
                switch(btCmd)
                {
                    case 0x89:
                    case 0x8B:
                        {
                            int nTagCount = m_curInventoryBuffer.dtTagTable.Rows.Count;
                            int nTotalRead = m_nTotal;// m_curInventoryBuffer.dtTagDetailTable.Rows.Count;
                            TimeSpan ts = m_curInventoryBuffer.dtEndInventory - m_curInventoryBuffer.dtStartInventory;
                            int nTotalTime = ts.Minutes * 60 * 1000 + ts.Seconds * 1000 + ts.Milliseconds;
                            int nCaculatedReadRate = 0;
                            int nCommandDuation = 0;

                            if (m_curInventoryBuffer.nReadRate == 0) //读写器没有返回速度前软件测速度
                            {
                                if (nTotalTime > 0)
                                {
                                    nCaculatedReadRate = (nTotalRead * 1000 / nTotalTime);
                                }
                            }
                            else
                            {
                                nCommandDuation = m_curInventoryBuffer.nDataCount * 1000 / m_curInventoryBuffer.nReadRate;
                                nCaculatedReadRate = m_curInventoryBuffer.nReadRate;
                            }

                            //列表用变量
                            int nEpcCount = 0;
                            int nEpcLength = m_curInventoryBuffer.dtTagTable.Rows.Count;

                            ledReal1.Text = nTagCount.ToString();
                            ledReal2.Text = nCaculatedReadRate.ToString();

                            ledReal5.Text = nTotalTime.ToString();
                            ledReal3.Text = nTotalRead.ToString();
                            ledReal4.Text = nCommandDuation.ToString();  //实际的命令执行时间
                            tbRealMaxRssi.Text = (m_curInventoryBuffer.nMaxRSSI - 129).ToString() + "dBm";
                            tbRealMinRssi.Text = (m_curInventoryBuffer.nMinRSSI - 129).ToString() + "dBm";
                            lbRealTagCount.Text = "标签EPC号列表(不重复): " + nTagCount.ToString() + "个";

                            nEpcCount = lvRealList.Items.Count;

                            if (nEpcCount < nEpcLength)
                            {
                                DataRow row = m_curInventoryBuffer.dtTagTable.Rows[nEpcLength - 1];

                                ListViewItem item = new ListViewItem();
                                item.Text = (nEpcCount + 1).ToString();
                                item.SubItems.Add(row[2].ToString());
                                item.SubItems.Add(row[0].ToString());
                                item.SubItems.Add(row[5].ToString());
                                item.SubItems.Add((Convert.ToInt32(row[4]) - 129).ToString() + "dBm");
                                item.SubItems.Add(row[6].ToString());
                                lvRealList.Items.Add(item);
                                lvRealList.Items[nEpcCount].EnsureVisible();
                            }
                            //else
                            //{
                            //    int nIndex = 0;
                            //    foreach (DataRow row in m_curInventoryBuffer.dtTagTable.Rows)
                            //    {
                            //        ListViewItem item = ltvInventoryEpc.Items[nIndex];
                            //        item.SubItems[3].Text = row[5].ToString();
                            //        nIndex++;
                            //    }
                            //}

                            //更新列表中读取的次数
                            if (m_nTotal % m_nRealRate == 1)
                            {
                                int nIndex = 0;
                                foreach (DataRow row in m_curInventoryBuffer.dtTagTable.Rows)
                                {
                                    ListViewItem item;
                                    item = lvRealList.Items[nIndex];
                                    item.SubItems[3].Text = row[5].ToString();
                                    item.SubItems[4].Text = (Convert.ToInt32(row[4]) - 129).ToString() + "dBm";
                                    item.SubItems[5].Text = row[6].ToString();

                                    nIndex++;
                                }
                            }

                            //if (ltvInventoryEpc.SelectedIndices.Count != 0)
                            //{
                            //    int nDetailCount = ltvInventoryTag.Items.Count;
                            //    int nDetailLength = m_curInventoryBuffer.dtTagDetailTable.Rows.Count;

                            //    foreach (int nIndex in ltvInventoryEpc.SelectedIndices)
                            //    {
                            //        ListViewItem itemEpc = ltvInventoryEpc.Items[nIndex];
                            //        DataRow row = m_curInventoryBuffer.dtTagDetailTable.Rows[nDetailLength - 1];
                            //        if (itemEpc.SubItems[1].Text == row[0].ToString())
                            //        {
                            //            ListViewItem item = new ListViewItem();
                            //            item.Text = (nDetailCount + 1).ToString();
                            //            item.SubItems.Add(row[0].ToString());

                            //            string strTemp = (Convert.ToInt32(row[1].ToString()) - 129).ToString() + "dBm";
                            //            item.SubItems.Add(strTemp);
                            //            byte byTemp = Convert.ToByte(row[1]);
                            //            if (byTemp > 0x50)
                            //            {
                            //                item.BackColor = Color.PowderBlue;
                            //            }
                            //            else if (byTemp < 0x30)
                            //            {
                            //                item.BackColor = Color.LemonChiffon;
                            //            }

                            //            item.SubItems.Add(row[2].ToString());
                            //            item.SubItems.Add(row[3].ToString());

                            //            ltvInventoryTag.Items.Add(item);
                            //            ltvInventoryTag.Items[nDetailCount].EnsureVisible();
                            //        }
                            //    }
                            //}
                            //else
                            //{
                            //    int nDetailCount = ltvInventoryTag.Items.Count;
                            //    int nDetailLength = m_curInventoryBuffer.dtTagDetailTable.Rows.Count;

                            //    DataRow row = m_curInventoryBuffer.dtTagDetailTable.Rows[nDetailLength - 1];
                            //    ListViewItem item = new ListViewItem();
                            //    item.Text = (nDetailCount + 1).ToString();
                            //    item.SubItems.Add(row[0].ToString());

                            //    string strTemp = (Convert.ToInt32(row[1].ToString()) - 129).ToString() + "dBm";
                            //    item.SubItems.Add(strTemp);
                            //    byte byTemp = Convert.ToByte(row[1]);
                            //    if (byTemp > 0x50)
                            //    {
                            //        item.BackColor = Color.PowderBlue;
                            //    }
                            //    else if (byTemp < 0x30)
                            //    {
                            //        item.BackColor = Color.LemonChiffon;
                            //    }

                            //    item.SubItems.Add(row[2].ToString());
                            //    item.SubItems.Add(row[3].ToString());

                            //    ltvInventoryTag.Items.Add(item);
                            //    ltvInventoryTag.Items[nDetailCount].EnsureVisible();
                            //}

                        }
                        break;

                    case 0x00:
                    case 0x01:
                        {
                            m_bLockTab = false;

                        }
                        break;
                    default:
                        break;
                }
            }
        }