Esempio n. 1
0
        private void IntervalCheckProducts(List <TagInfo> tiList)
        {
            foreach (TagInfo ti in tiList)
            {
                strEpc      = ti.epc;
                strAntenaID = ti.antennaID;
                //误读也加入检测中
                //if (ti.antennaID == "01" || ti.antennaID == "02" || ti.antennaID == "04" || ti.antennaID == "08")
                {
                    //如果该epc尚未添加,则只需添加到列表中即可
                    if (this.ProductList.FindIndex(FindEpcProduct) < 0)
                    {
                        EpcProduct new_ep = new EpcProduct(ti);
                        this.ProductList.Add(new_ep);
                    }
                }
            }

            foreach (EpcProduct ep in this.ProductList)
            {
                strEpc      = ep.tagInfo.epc;
                strAntenaID = ep.tagInfo.antennaID;

                if (tiList.FindIndex(IsThisEpc) >= 0)
                {
                    //如果该epc已经存在,更改其读取记录为读取到
                    int OnFloorstate = ep.SetRecordReaded();
                    if (OnFloorstate == 1)
                    {
                        ep.ShiftToBeOnFloor();
                        this.bHasNewMessage = true;
                    }
                }
                else
                {
                    ep.SetRecordUnreaded();
                }

                int state = ep.VoteDecrease(); //每次固定减一
                if (state < 0)                 //表明产品下架了
                {
                    ep.ShiftFromFloor();       //产品下架后才有可能在其它层上架
                    this.bHasNewMessage = true;
                }
            }
            //Debug.WriteLine(string.Format("new message -> port {0}    message  {1}", this.udp_port.ToString(), bHasNewMessage.ToString()));
            if (this.listener != null && this.bHasNewMessage)
            {
                listener.NewTagMessage();
                this.bHasNewMessage = false;
            }
        }
        public void NewTagMessage()
        {
            deleControlInvoke dele = delegate(object o)
            {
                List <EpcProduct> tagList = current_helper.GetCurrentProductList();
                if (tagList.Count > 0)
                {
                    foreach (EpcProduct ep in tagList)
                    {
                        Debug.WriteLine(string.Format("epc => {0}   antena => {1}", ep.tagInfo.epc, ep.tagInfo.antennaID));
                    }
                    #region 检查标签是否应该放在放在的正确的货架
                    //int count4InWrongCarbinet = 0;
                    //foreach (EpcProduct t in tagList)
                    //{
                    //    string tEpc = t.epc;
                    //    if (tEpc.Substring(16, 2) != carbinet_epc_flag)
                    //    {
                    //        count4InWrongCarbinet++;
                    //    }
                    //}
                    //if (count4InWrongCarbinet > 0)
                    //{
                    //    this.lblStatus.Text = "有不属于本货架的产品放置在本货架中,请检查!";
                    //}
                    //else
                    //{
                    //    this.lblStatus.Text = string.Empty;
                    //}
                    #endregion
                }
                else
                {
                    Debug.WriteLine("no products now!!!");
                }

                #region 首先把不再存在的标签从列表中删除
                //
                DataRow[] allRows = MemoryTable.unitTable.Select();
                for (int j = 0; j < allRows.Length; j++)
                {
                    DataRow dr    = allRows[j];
                    string  epc   = (string)dr["epc"];
                    int     floor = int.Parse(dr["floor"].ToString());
                    if (epc != null && epc.Length > 0)
                    {
                        bool bFinded = false;
                        foreach (EpcProduct ti in tagList)
                        {
                            if ((ti.tagInfo.epc == epc) && (this.getFloorByAntennaID(ti.tagInfo.antennaID) == floor))//这里的不存在应该和位置相关
                            {
                                bFinded = true;
                                break;
                            }
                        }
                        if (bFinded == false)//如果列表中不再存在这个标签,就把之前标签占据的位置的状态设为delete
                        {
                            dr["action"] = "delete";
                            MemoryTable.staticsTable.Rows.Add(new object[] { epc, "下架", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });
                        }
                    }
                }
                #endregion

                #region 添加新出现的标签到显示列表中
                //
                for (int i = 0; i < tagList.Count; i++)
                {
                    EpcProduct ti  = tagList[i];
                    string     epc = ti.tagInfo.epc;
                    //if (epc.Substring(16, 2) != carbinet_epc_flag)
                    //{
                    //    continue;
                    //}
                    int anticipatedFloor = 0;
                    try
                    {
                        string strFloor = this.getAnticipatedFloorByEpc(epc);// 18,2
                        anticipatedFloor = int.Parse(strFloor);
                    }
                    catch
                    {
                    }
                    if (anticipatedFloor == 0)
                    {
                        continue;
                    }
                    int tagFloor = this.getFloorByAntennaID(ti.tagInfo.antennaID);

                    bool      bOnWrongFloor = false; //是否放置在错误的货架层上
                    DataRow[] drs           = MemoryTable.unitTable.Select("epc='" + epc + "' and floor=" + tagFloor.ToString());
                    if (drs.Length <= 0)             //说明这个标签还不存在
                    {
                        //Debug.WriteLine("antinna To floor ->  antenna = " + ti.antennaID);
                        int antenna = int.Parse(ti.tagInfo.antennaID);//todo  暂时把设备的天线和货架的层数挂钩
                        int floor   = -1;
                        switch (antenna)
                        {
                        case 1:
                            floor = 1;
                            break;

                        case 2:
                            floor = 2;
                            break;

                        case 4:
                            floor = 3;
                            break;

                        case 8:
                            floor = 4;
                            break;
                        }
                        if (floor != anticipatedFloor)
                        {
                            Debug.WriteLine(string.Format("antinna To floor ->  floor = {0}   anticipatedFloor = {1}", floor.ToString(), anticipatedFloor.ToString()));
                            bOnWrongFloor = true;//设计放产品的层和实际的层不一致
                        }
                        if (floor != -1)
                        {
                            DataRow[] emptyRows = MemoryTable.unitTable.Select("status = 'empty' and floor=" + floor.ToString());
                            if (emptyRows.Length > 0)
                            {
                                Debug.WriteLine(
                                    string.Format("Form1._timer_Tick  -> equipID = {0}"
                                                  , emptyRows[0]["id"]));
                                emptyRows[0]["epc"]    = epc;
                                emptyRows[0]["status"] = "occupied";
                                if (bOnWrongFloor == true)
                                {
                                    emptyRows[0]["action"] = "addOnWrongFloor";
                                }
                                else
                                {
                                    emptyRows[0]["action"] = "add";
                                }
                                if (epc != null && epc.Length >= 23)
                                {
                                    string type = epc.Substring(20, 2);

                                    emptyRows[0]["type"] = type;
                                }
                            }
                        }
                        MemoryTable.staticsTable.Rows.Add(new object[] { epc, "上架", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });
                    }
                }

                #endregion
                #region 其它逻辑处理

                //
                // 1 搜索某类商品
                string productName = this.cmbProductName.Text;
                //            string productName = this.txtProductName.Text;
                if (productName != null && productName.Length > 0 && productName != "无")
                {
                    DataRow[] rowsProduct = MemoryTable.typeMapTable.Select("productName <>'" + productName + "'");
                    for (int j = 0; j < rowsProduct.Length; j++)
                    {
                        DataRow   dr         = rowsProduct[j];
                        string    type       = (string)dr["type"];
                        DataRow[] rowsFilter = MemoryTable.unitTable.Select("type = '" + type + "'");
                        for (int k = 0; k < rowsFilter.Length; k++)
                        {
                            DataRow drFilter = rowsFilter[k];

                            //drFilter["status"] = "empty";
                            drFilter["action"] = "delete";
                        }
                    }
                }

                #endregion


                #region 处理显示
                //
                //需要删除的
                DataRow[] rows = MemoryTable.unitTable.Select("action = 'delete'");
                if (rows.Length > 0)
                {
                    List <epcInfo> epcList = new List <epcInfo>();
                    for (int i = 0; i < rows.Length; i++)
                    {
                        string  id      = (string)rows[i]["id"];
                        string  epc     = (string)rows[i]["epc"];
                        string  type    = (string)rows[i]["type"];
                        epcInfo epcinfo = new epcInfo(epc, type);
                        epcList.Add(epcinfo);
                        if (id != null && id.Length > 0)
                        {
                            int          groupIndex = int.Parse(rows[i]["group"].ToString());
                            Carbinet     _carbinet  = this.groups[groupIndex];
                            DocumentFile df         = _carbinet.getDoc(id);
                            if (df != null)
                            {
                                df.setBackgroundImage(null);
                                df.setBorderWidth(0);
                                df.indexBase = "z" + df.columnNumber.ToString("0000");//重置为基础的排序依据
                            }
                        }

                        rows[i]["action"] = "normal";
                        rows[i]["epc"]    = "";
                        rows[i]["type"]   = "";
                        rows[i]["status"] = "empty";
                    }

                    //TODO 处于防盗模式下需要语音提醒,处于讲解模式下需要对产品进行讲解
                    if (staticClass.mode == MonitorMode.防盗模式)
                    {
                        this.SpeakAboutSomething(epcList);
                    }
                    //else
                    //    if (staticClass.mode == MonitorMode.讲解模式)
                    //    {
                    //        for (int i = 0; i < epcList.Count; i++)
                    //        {
                    //            epcInfo ei = epcList[i];
                    //            MemoryTable.staticsTable.Rows.Add(new object[] { ei.epc, "下架", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") });
                    //        }
                    //    }
                }
                // 需要增加的
                rows = MemoryTable.unitTable.Select("action = 'add' OR action = 'addOnWrongFloor'");
                if (rows.Length > 0)
                {
                    for (int i = 0; i < rows.Length; i++)
                    {
                        int    groupIndex    = int.Parse(rows[i]["group"].ToString());
                        string id            = (string)rows[i]["id"];
                        string epc           = (string)rows[i]["epc"];
                        string action        = (string)rows[i]["action"];
                        bool   bOnWrongFloor = false;
                        if (action == "addOnWrongFloor")
                        {
                            bOnWrongFloor = true;
                        }
                        Carbinet _carbinet = this.groups[groupIndex];
                        // 不同种类的物品设置成不同的大小
                        string type = MemoryTable.getProductTypeID(epc);

                        DataRow[] drsType = MemoryTable.typeMapTable.Select("type='" + type + "'");
                        if (drsType.Length > 0)
                        {
                            int    width  = int.Parse(drsType[0]["width"].ToString());
                            int    height = int.Parse(drsType[0]["height"].ToString());
                            string path   = (string)drsType[0]["picname"];
                            path = PublicConfig.staticClass.PicturePath + path;
                            Image newImage = null;
                            try
                            {
                                newImage = Image.FromFile(path);
                            }
                            catch (System.Exception ex)
                            {
                                Debug.WriteLine(
                                    string.Format("Form1._timer_Tick  -> loadImage error = {0}"
                                                  , ex.Message));
                            }
                            DocumentFile df = _carbinet.getDoc(id);
                            if (df != null)
                            {
                                df.setBackgroundImage(newImage);
                                if (bOnWrongFloor == true)
                                {
                                    df.setBorderWidth(5);
                                }
                                //df.setBorderWidth(0);//边框重置为0
                                df.indexBase = type;
                            }
                            //_carbinet.setDocBGImage(id, newImage);

                            _carbinet.setDocSize(id, width, height);

                            //drsType[0]["count"] = ((int)drsType[0]["count"]) + 1;
                        }
                        rows[i]["action"] = "normal";
                    }
                }

                #endregion



                #region 设置饼图

                //
                DataRow[] typeRows = MemoryTable.typeMapTable.Select();
                decimal[] decimals = new decimal[typeRows.Length];
                string[]  strs     = new string[typeRows.Length];
                Color[]   colors   = new Color[typeRows.Length];
                for (int i = 0; i < typeRows.Length; i++)
                {
                    DataRow[] RowsTemp = MemoryTable.unitTable.Select("type = '" + (string)typeRows[i]["type"] + "'");
                    decimals[i]          = RowsTemp.Length;
                    typeRows[i]["count"] = RowsTemp.Length;
                    //                decimals[i] = (int)typeRows[i]["count"];
                    strs[i] = RowsTemp.Length.ToString();
                    //                strs[i] = typeRows[i]["count"].ToString();
                    //strs[i] = typeRows[i]["productName"] + ":" + typeRows[i]["count"].ToString();
                    colors[i] = Color.FromArgb(alpha,
                                               int.Parse(typeRows[i]["red"].ToString()),
                                               int.Parse(typeRows[i]["green"].ToString()),
                                               int.Parse(typeRows[i]["blue"].ToString()));
                }
                m_panelDrawing.Values = decimals;
                m_panelDrawing.Texts  = strs;
                m_panelDrawing.Colors = colors;
                #endregion
            };

            this.Invoke(dele, new object());
        }
Esempio n. 3
0
 static bool ProductOnFloor(EpcProduct ep)
 {
     return(ep.IsOnFloor);
 }
Esempio n. 4
0
 private static bool FindEpcProductOnFloorWithoutAntena(EpcProduct ep)
 {
     return(ep.tagInfo.epc == strEpc && ep.IsOnFloor);
 }
Esempio n. 5
0
 private static bool FindEpcProduct(EpcProduct ep)
 {
     return(ep.tagInfo.epc == strEpc && ep.tagInfo.antennaID == strAntenaID);
 }
        private void IntervalCheckProducts(List <TagInfo> tiList)
        {
            foreach (TagInfo ti in tiList)
            {
                strEpc      = ti.epc;
                strAntenaID = ti.antennaID;
                //如果是误读的标签,则不加入到检测中
                if (ti.antennaID == "01" || ti.antennaID == "02" || ti.antennaID == "04" || ti.antennaID == "08")
                {
                    //如果该epc尚未添加,则只需添加到列表中即可
                    if (this.ProductList.FindIndex(FindEpcProduct) < 0)
                    {
                        EpcProduct new_ep = new EpcProduct(ti);
                        this.ProductList.Add(new_ep);
                    }
                }
            }

            foreach (EpcProduct ep in this.ProductList)
            {
                strEpc      = ep.tagInfo.epc;
                strAntenaID = ep.tagInfo.antennaID;

                if (tiList.FindIndex(IsThisEpcAndAntena) >= 0)
                {
                    //如果该epc已经存在,更改其读取记录为读取到
                    int OnFloorstate = ep.SetRecordReaded();
                    // 当本产品本身满足上架条件并且整个货架上没有相同Epc的产品在架时,才能上架
                    // 这是为了防止一个标签同时被两个天线读到导致同一产品在不同层上架的情况发生
                    if (OnFloorstate == 1 && this.ProductList.FindIndex(FindEpcProductOnFloorWithoutAntena) < 0)
                    {
                        ep.ShiftToBeOnFloor();
                        this.bHasNewMessage = true;
                    }
                }
                else
                {
                    ep.SetRecordUnreaded();
                }

                //关于误读得到的数据的处理
                //如果有标签在货架上,则认为这是该层读到的,否则放弃
                if (tiList.FindIndex(IsJustThisEpcAndWrongAntena) >= 0 && ep.IsOnFloor)
                {
                    ep.SetRecordReaded();
                }

                int state = ep.VoteDecrease(); //每次固定减一
                if (state < 0)                 //表明产品下架了
                {
                    ep.ShiftFromFloor();       //产品下架后才有可能在其它层上架
                    this.bHasNewMessage = true;
                }
            }
            //Debug.WriteLine(string.Format("new message -> port {0}    message  {1}", this.udp_port.ToString(), bHasNewMessage.ToString()));
            if (this.listener != null && this.bHasNewMessage)
            {
                listener.NewTagMessage();
                this.bHasNewMessage = false;
            }
        }