Esempio n. 1
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            if (this.checkConfigValid())
            {
                if (!this.copyProductPic())
                {
                    return;
                }

                bool bR = MemoryTable.AddNewConfig(
                    this.txtProductType.Text,
                    this.picName,
                    productWidth,
                    productHeight,
                    minCount,
                    this.txtProductName.Text,
                    red, green, blue,
                    this.txtDescription.Text
                    );
                if (bR == true)
                {
                    this.btnAdd.Enabled = false;
                    this.refreshTypeList();
                }
            }
        }
Esempio n. 2
0
        void refreshTypeList()
        {
            this.lbProductTypes.Items.Clear();

            List <string> list = MemoryTable.getAllConfigTypes();

            foreach (string s in list)
            {
                this.lbProductTypes.Items.Add(s);
            }
            if (lbProductTypes.Items.Count > 0)
            {
                lbProductTypes.SelectedIndex = 0;
            }
            //DataTable dt = MemoryTable.typeMapTable;
            ////DataTable dt = MemoryTable.getAllProductConfigInfo();
            //if (dt != null && dt.Rows.Count > 0)
            //{
            //    for (int i = 0; i < dt.Rows.Count; i++)
            //    {
            //        DataRow dr = dt.Rows[i];
            //        this.lbProductTypes.Items.Add((string)dr["type"]);
            //    }
            //    lbProductTypes.SelectedIndex = 0;
            //}
        }
Esempio n. 3
0
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            if (this.checkConfigValid())
            {
                if (!this.copyProductPic())
                {
                    return;
                }

                bool bR = MemoryTable.updateConfig(
                    this.txtProductType.Text,
                    this.picName,
                    productWidth,
                    productHeight,
                    minCount,
                    this.txtProductName.Text,
                    red, green, blue,
                    this.txtDescription.Text
                    );
                if (bR == true)
                {
                    this.btnAdd.Enabled = false;
                    MessageBox.Show("更改产品信息成功");
                }
            }
        }
Esempio n. 4
0
        public frmRemind()
        {
            InitializeComponent();

            //统一初始化
            if (MemoryTable.isInitialized == false)
            {
                MemoryTable.initializeTabes();
            }


            GraphPane myPane = this.zedGraphControl1.GraphPane;

            // Set the XAxis to Text type
            myPane.XAxis.Type = AxisType.Text;

            // Fill the Axis and Pane backgrounds
            myPane.Chart.Fill = new Fill(Color.White, Color.FromArgb(255, 255, 166), 90F);
            myPane.Fill       = new Fill(Color.FromArgb(250, 250, 255));

            myPane.Title.Text       = "库存预警商品信息";
            myPane.XAxis.Title.Text = "商品名称";
            myPane.YAxis.Title.Text = "商品数量";
            myPane.YAxis.MinSpace   = 1;

            appConfig ac = appConfig.getDefaultConfig();

            _timer.Interval = ac.interval;//5000;
            _timer.Tick    += new EventHandler(_timer_Tick);

            this.Shown       += new EventHandler(frmRemind_Shown);
            this.FormClosing += new FormClosingEventHandler(frmRemind_FormClosing);
        }
        public static void resetConfig()
        {
            //初始化一些设置
            object otagsBufferTime = nsConfigDB.ConfigDB.getConfig("tagsBufferTime");

            if (null != otagsBufferTime)
            {
                staticClass.tagsBufferTime = int.Parse((string)otagsBufferTime);
            }
            object oInterval = nsConfigDB.ConfigDB.getConfig("checkStorageInterval");

            if (oInterval != null)
            {
                staticClass.storageCheckInterval = int.Parse((string)oInterval);
            }
            object oPort = null;

            oPort = nsConfigDB.ConfigDB.getConfig("portListening");
            if (oPort != null)
            {
                staticClass.udpPort = int.Parse((string)oPort);
            }


            MemoryTable.memoryTableInitilize();
        }
Esempio n. 6
0
        private void lbProductTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = this.lbProductTypes.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }
            string  type = (string)this.lbProductTypes.Items[selectedIndex];
            DataRow dr   = MemoryTable.getSpecifiedProductConfigInfo(type);

            if (dr != null)
            {
                this.txtProductType.Text = type;
                //DataRow dr = dt.Rows[0];
                string productName = (string)dr["productName"];
                string width       = dr["width"].ToString();
                string height      = dr["height"].ToString();
                string mincount    = dr["minCount"].ToString();
                this.txtProductName.Text = productName;
                this.numHeight.Value     = int.Parse(height);
                this.numWidth.Value      = int.Parse(width);
                this.txtMinCount.Text    = mincount;
                this.txtDescription.Text = (string)dr["description"];
                try
                {
                    productWidth  = int.Parse(width);
                    productHeight = int.Parse(height);
                    minCount      = int.Parse(mincount);

                    red   = int.Parse(dr["red"].ToString());
                    green = int.Parse(dr["green"].ToString());
                    blue  = int.Parse(dr["blue"].ToString());
                    Color color = Color.FromArgb(red, green, blue);
                    this.btnShowColor.BackColor = color;

                    this.picName = dr["picname"].ToString();
                    string path     = PublicConfig.staticClass.PicturePath + picName;
                    Image  newImage = null;
                    try
                    {
                        Stream s = File.Open(path, FileMode.Open);
                        pictureBox1.Image = Image.FromStream(s);
                        s.Close();
                        //newImage = Image.FromFile(path);
                        //newImage = (Image)newImage.Clone();
                    }
                    catch
                    {
                    }
                    //this.pictureBox1.Image = newImage;
                    this.pictureBox1.Width  = (int)this.numWidth.Value;
                    this.pictureBox1.Height = (int)this.numHeight.Value;
                }
                catch
                {
                }
            }
        }
 private void initialInfoTable()
 {
     //统一初始化
     if (MemoryTable.isInitialized == false)
     {
         MemoryTable.initializeTabes();
     }
 }
        private void lbProductTypes_SelectedIndexChanged(object sender, EventArgs e)
        {
            int selectedIndex = this.lbProductTypes.SelectedIndex;

            if (selectedIndex < 0)
            {
                return;
            }
            string    type = (string)this.lbProductTypes.Items[selectedIndex];
            DataTable dt   = MemoryTable.getSpecifiedProductConfigInfo(type);

            if (dt != null && dt.Rows.Count > 0)
            {
                this.txtProductType.Text = type;
                DataRow dr          = dt.Rows[0];
                string  productName = (string)dr["PRODUCTNAME"];
                string  width       = dr["WIDTH"].ToString();
                string  height      = dr["HEIGHT"].ToString();
                string  mincount    = dr["MINCOUNT"].ToString();
                this.txtProductName.Text = productName;
                this.txtWidth.Text       = width;
                this.txtHeight.Text      = height;
                this.txtMinCount.Text    = mincount;
                try
                {
                    productWidth  = int.Parse(width);
                    productHeight = int.Parse(height);
                    minCount      = int.Parse(mincount);

                    red   = int.Parse(dr["RED"].ToString());
                    green = int.Parse(dr["GREEN"].ToString());
                    blue  = int.Parse(dr["BLUE"].ToString());
                    Color color = Color.FromArgb(red, green, blue);
                    this.btnShowColor.BackColor = color;

                    this.picName = dr["PICNAME"].ToString();
                    string path     = PublicConfig.staticClass.PicturePath + picName;
                    Image  newImage = null;
                    try
                    {
                        newImage = Image.FromFile(path);
                    }
                    catch
                    {
                    }
                    this.pictureBox1.Image = newImage;
                }
                catch
                {
                }
            }
        }
        void refreshTypeList()
        {
            this.lbProductTypes.Items.Clear();

            DataTable dt = MemoryTable.getAllProductConfigInfo();

            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    this.lbProductTypes.Items.Add((string)dr["VTYPE"]);
                }
                lbProductTypes.SelectedIndex = 0;
            }
        }
Esempio n. 10
0
 private void btnDelete_Click(object sender, EventArgs e)
 {
     if (this.checkConfigValid())
     {
         bool bExist = MemoryTable.ConfigExists(this.txtProductType.Text);
         if (bExist == false)
         {
             MessageBox.Show("不存在该类型的产品");
             return;
         }
         bool bR = MemoryTable.deleteConfig(this.txtProductType.Text);
         if (bR == true)
         {
             this.refreshTypeList();
         }
     }
 }
Esempio n. 11
0
        void helper_RequestCompleted_get_category_list(object o)
        {
            string strres = (string)o;

            Debug.WriteLine(
                string.Format("helper_RequestCompleted_get_category_list  ->  = {0}"
                              , strres));
            object olist = fastJSON.JSON.Instance.ToObjectList(strres, typeof(List <ProductCategory>), typeof(ProductCategory));
            List <ProductCategory> resList = (List <ProductCategory>)olist;

            if (resList.Count > 0)
            {
                for (int i = 0; i < resList.Count; i++)
                {
                    ProductCategory pc = resList[i];
                    MemoryTable.AddNewConfig(
                        pc.category_id,
                        pc.category_image,
                        default_image_width,
                        default_image_height,
                        default_min_count,
                        pc.category_name,
                        (int)default_product_color.R, (int)default_product_color.G, default_product_color.B,
                        "尚未设置"
                        );
                }
            }

            //deleControlInvoke dele = delegate(object ol)
            //{

            //};
            //this.Invoke(dele, olist);
            ResSyncer rs = new ResSyncer();

            rs.start_sync("ProductCategory");
        }
        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;
        }
Esempio n. 15
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
        }