// 29 137
        // 166 282
        // 311 427
        // 456 562
        // 25 553

        private void InitialClassRoom()
        {
            int numberOfGroup = 1;
            int widthOfRoom   = this.pictureBox1.Width;
            int heightofRoom  = this.pictureBox1.Height;
            int floorGap      = 35;
            int heightOfRow   = 140;

            int totalColumns = numberOfGroup;

            totalColumns = 10;
            int numberOfUnit     = totalColumns + numberOfGroup - 1;
            int widthOfUnit      = widthOfRoom / numberOfUnit;
            int groupInitialLeft = 0;

            for (int i = 0; i < numberOfGroup; i++)
            {
                int numberofColumn = 10;
                int numberOfRow    = 3;
                //heightOfRow = (heightofRoom - floorGap * numberOfRow) / numberOfRow;
                int groupWidth = 528;
                //                int groupWidth = numberofColumn * widthOfUnit;

                Carbinet group = new Carbinet(this.pictureBox1.Controls);
                group.Left = groupInitialLeft;
                group.Top  = 0;
                this.groups.Add(group);
                //初始化每一排的行
                int initialTop = 32;
                for (int irow = 1; irow <= numberOfRow; irow++, initialTop = initialTop + (int)(heightOfRow + floorGap))
                {
                    CarbinetFloor row = new CarbinetFloor(group, irow, this.pictureBox1.Controls);
                    row.Width        = groupWidth;
                    row.Height       = heightOfRow;
                    row.relativeTop  = initialTop;
                    row.relativeLeft = 25;

                    group.AddFloor(row);

                    for (int k = 1; k <= numberofColumn; k++)
                    {
                        string _equipmentID = i.ToString() + "," + irow.ToString() + "," + k.ToString();

                        DocumentFile df = new DocumentFile(_equipmentID, irow);
                        df.Width         = widthOfUnit;
                        df.Height        = heightOfRow;
                        df.carbinetIndex = i;
                        df.floorNumber   = irow;
                        df.columnNumber  = k;
                        df.indexBase     = "z" + k.ToString("0000");

                        MemoryTable.unitTable.Rows.Add(new object[] { _equipmentID, "", i, irow, "empty", "normal" });

                        df.Click += new EventHandler(df_Click);
                        group.AddDocFile(df);
                    }
                }
                groupInitialLeft += groupWidth + widthOfUnit;
            }
        }
        void ClearControls()
        {
            #region 清空货架 清空table
            DataRow[] rows = MemoryTable.unitTable.Select("status = 'occupied'");
            if (rows.Length > 0)
            {
                for (int i = 0; i < rows.Length; i++)
                {
                    string id = (string)rows[i]["id"];
                    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";
                }
            }
            #endregion

            #region 初始化饼图
            m_panelDrawing.Values = new decimal[] { 0, 0 };
            // m_panelDrawing.Values = new decimal[] { 0 };

            m_panelDrawing.Colors = new Color[] { Color.FromArgb(alpha, Color.Gray), Color.FromArgb(alpha, Color.GreenYellow) };
            //m_panelDrawing.SliceRelativeDisplacements = new float[] { 0.1F, 0.2F, 0.2F, 0.2F };
            m_panelDrawing.Texts = new string[] { " ", " " };
            //            m_panelDrawing.Texts = new string[] { "未知", "A", "B", "C", "D" };
            m_panelDrawing.ToolTips = new string[] { "", "" };
            #endregion
        }
        private void InitialCarbinet(Control.ControlCollection controls, int carbinet_index)
        {
            //防止重复操作
            if (controls.Count <= 0)
            //if (this.pictureBox1.Controls.Count <= 0)
            {
                //Control.ControlCollection controls = this.pictureBox1.Controls;
                //货架数目
                int numberOfGroup = 1;
                //整个可用空间的宽度
                int widthOfRoom = this.work_width;
                //隔层的高度
                int floorGap = height_of_gap;
                //总共有多少列
                int totalColumns = 10;
                //总共要分多少列,包括两个货架之间,货架之间的间隔暂时采用和普通列同一宽度的做法
                int numberOfUnit = totalColumns + numberOfGroup - 1;
                // 可以计算出没一列的宽度
                int widthOfUnit = widthOfRoom / numberOfUnit;
                // 货架上的物品区域距离货架左边缘的距离
                int groupInitialLeft = 0;                                                                 //货架距离整个区域的左边缘的距离
                int groupWidth       = (widthOfRoom - widthOfUnit * (numberOfGroup - 1)) / numberOfGroup; //计算每一个货架的宽度,需要减去货架之间间隔的宽度

                //for (int i = 0; i < numberOfGroup; i++)
                {
                    int numberofColumn = 20;//预设值,之后需要作为参数提取
                    int numberOfRow    = number_of_row;

                    Carbinet group = new Carbinet(controls);
                    //Carbinet group = new Carbinet(this.pictureBox1.Controls);
                    group.Left = groupInitialLeft;
                    group.Top  = 0;
                    if (carbinet_index == 0 && this.groups.Count > 0)//保证货架的顺序对应
                    {
                        this.groups.Insert(0, group);
                    }
                    else
                    {
                        this.groups.Add(group);
                    }
                    //初始化每一排的行
                    int initialTop = top_of_first_row;

                    for (int irow = 1; irow <= numberOfRow; irow++, initialTop = initialTop + (int)(height_of_row + floorGap))
                    {
                        CarbinetFloor row = new CarbinetFloor(group, irow, controls);
                        //CarbinetFloor row = new CarbinetFloor(group, irow, this.pictureBox1.Controls);
                        row.Width        = groupWidth;
                        row.Height       = height_of_row;
                        row.relativeTop  = initialTop;
                        row.relativeLeft = this.broadslide_width;

                        group.AddFloor(row);

                        for (int k = 1; k <= numberofColumn; k++)
                        {
                            string _equipmentID = carbinet_index.ToString() + "," + irow.ToString() + "," + k.ToString();

                            DocumentFile df = new DocumentFile(_equipmentID, irow);
                            df.Width         = widthOfUnit;
                            df.Height        = height_of_row;
                            df.carbinetIndex = carbinet_index;
                            df.floorNumber   = irow;
                            df.columnNumber  = k;
                            df.indexBase     = "z" + k.ToString("0000");

                            MemoryTable.unitTable.Rows.Add(new object[] { _equipmentID, "", carbinet_index, irow, "empty", "normal" });

                            df.Click += new EventHandler(df_Click);
                            group.AddDocFile(df);
                        }
                    }
                    groupInitialLeft += groupWidth + widthOfUnit;
                }
            }
        }
        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());
        }
        void _timer_Tick(object sender, EventArgs e)
        {
            this.udp_server.Manualstate.WaitOne();
            this.udp_server.Manualstate.Reset();
            string str = this.udp_server.sbuilder.ToString();

            this.udp_server.sbuilder.Remove(0, str.Length);

            this.udp_server.Manualstate.Set();
            helper.ParseDataToTag(str);
            if (str != null && str.Length >= 0)
            {
                //this.txtLog.Text = str + "\r\n" + this.txtLog.Text;
                //Debug.WriteLine(
                //    string.Format(".  _timer_Tick -> string = {0}"
                //    , str));
            }
            //处理列表
            List <TagInfo> tagList = helper.getTagList();//先拿到读取到的标签

            #region 检查标签是否应该放在放在的正确的货架
            int count4InWrongCarbinet = 0;
            foreach (TagInfo t in tagList)
            {
                string tEpc = t.epc;
                if (tEpc.Substring(16, 2) != "01")
                {
                    count4InWrongCarbinet++;
                }
            }
            if (count4InWrongCarbinet > 0)
            {
                this.lblStatus.Text = "有不属于本货架的产品放置在本货架中,请检查!";
            }
            else
            {
                this.lblStatus.Text = string.Empty;
            }
            #endregion


            #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)
                {
                    //int tagFloor = -1;
                    //tagFloor=this.getFloorByAntennaID()
                    bool bFinded = false;
                    foreach (TagInfo ti in tagList)
                    {
                        if ((ti.epc == epc) && (this.getFloorByAntennaID(ti.antennaID) == floor))//这里的不存在应该和位置相关
                        //if (ti.epc == epc)
                        {
                            bFinded = true;
                            break;
                        }
                    }
                    if (bFinded == false)//如果列表中不再存在这个标签,就把之前标签占据的位置的状态设为delete
                    {
                        //dr["epc"] = "";
                        //dr["status"] = "empty";
                        dr["action"] = "delete";
                    }
                }
            }


            #endregion

            #region 添加新出现的标签到显示列表中

            //
            for (int i = 0; i < tagList.Count; i++)
            {
                TagInfo ti  = tagList[i];
                string  epc = ti.epc;
                if (epc.Substring(16, 2) != "01")
                {
                    continue;
                }
                int anticipatedFloor = 0;
                try
                {
                    string strFloor = this.getAnticipatedFloorByEpc(epc);// 18,2
                    anticipatedFloor = int.Parse(strFloor);
                }
                catch (System.Exception ex)
                {
                }
                if (anticipatedFloor == 0)
                {
                    continue;
                }
                int tagFloor = this.getFloorByAntennaID(ti.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.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;
                            }
                        }
                    }
                }
            }

            #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);
                //}
            }
            // 需要增加的
            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
        }
        void _timer_Tick(object sender, EventArgs e)
        {
            UDPServer.Manualstate.WaitOne();
            UDPServer.Manualstate.Reset();
            string str = UDPServer.sbuilder.ToString();

            UDPServer.sbuilder.Remove(0, str.Length);

            UDPServer.Manualstate.Set();
            helper.ParseDataToTag(str);
            if (str != null && str.Length >= 0)
            {
                //this.txtLog.Text = str + "\r\n" + this.txtLog.Text;
                //Debug.WriteLine(
                //    string.Format(".  _timer_Tick -> string = {0}"
                //    , str));
            }
            //处理列表
            List <TagInfo> tagList = helper.getTagList();//先拿到读取到的标签

            //首先把不再存在的标签从列表中删除
            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)dr["floor"];
                if (epc != null && epc.Length > 0)
                {
                    //int tagFloor = -1;
                    //tagFloor=this.getFloorByAntennaID()
                    bool bFinded = false;
                    foreach (TagInfo ti in tagList)
                    {
                        if ((ti.epc == epc) && (this.getFloorByAntennaID(ti.antennaID) == floor))//这里的不存在应该和位置相关
                        //if (ti.epc == epc)
                        {
                            bFinded = true;
                            break;
                        }
                    }
                    if (bFinded == false)//如果列表中不再存在这个标签,就把之前标签占据的位置的状态设为delete
                    {
                        //dr["epc"] = "";
                        //dr["status"] = "empty";
                        dr["action"] = "delete";
                    }
                }
            }
            // 添加新出现的标签到显示列表中
            for (int i = 0; i < tagList.Count; i++)
            {
                TagInfo ti       = tagList[i];
                string  epc      = ti.epc;
                int     tagFloor = this.getFloorByAntennaID(ti.antennaID);

                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.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;
                    }
                    Debug.WriteLine("antinna To floor ->  floor = " + floor.ToString());

                    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";
                            emptyRows[0]["action"] = "add";
                            if (epc != null && epc.Length >= 23)
                            {
                                string type = epc.Substring(20, 2);

                                emptyRows[0]["type"] = type;
                            }
                        }
                    }
                }
            }

            //其它逻辑处理
            // 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";
                    }
                }
            }

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

                    // 不同种类的物品减去消失标签的数量
                    //string epc = (string)rows[i]["epc"];
                    //if (epc.Length >= 22)
                    //{
                    //    string type = epc.Substring(20, 2);
                    //    DataRow[] drsType = MemoryTable.typeMapTable.Select("type='" + type + "'");
                    //    if (drsType.Length > 0)
                    //    {

                    //        drsType[0]["count"] = ((int)drsType[0]["count"]) - 1;

                    //    }
                    //}
                    rows[i]["action"] = "normal";
                    rows[i]["epc"]    = "";
                    rows[i]["type"]   = "";
                    rows[i]["status"] = "empty";
                }
            }
            // 需要增加的
            rows = MemoryTable.unitTable.Select("action = 'add'");
            if (rows.Length > 0)
            {
                for (int i = 0; i < rows.Length; i++)
                {
                    int      groupIndex = (int)rows[i]["group"];
                    string   id         = (string)rows[i]["id"];
                    string   epc        = (string)rows[i]["epc"];
                    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);
                            df.indexBase = type;
                        }
                        //_carbinet.setDocBGImage(id, newImage);

                        _carbinet.setDocSize(id, width, height);

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

            //设置饼图
            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;
        }
示例#7
0
        //string strClickedType = string.Empty;
        void _timer_Tick(object sender, EventArgs e)
        {
            this.update_cabinet_data(this.udp_server1, this.helper1, 0);
            this.update_cabinet_data(this.udp_server2, this.helper2, 1);


            #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);
                //}
            }
            // 需要增加的
            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
        }