Пример #1
0
        private void handleNewItemFromRFID(RFIDContent newItem)
        {
            if (newItem.bookRfidList.Count() != 0)
            {
                IBookLocationService    bookLocationService    = this.container.Resolve <IBookLocationService>();
                IBookInformationService bookInformationService = this.container.Resolve <IBookInformationService>();

                List <String> bookNameList       = bookInformationService.getBookNameListByRfidList(newItem.bookRfidList);
                List <String> bookAccessCodeList = bookInformationService.getBookAccessCodeListByRfidList(newItem.bookRfidList);
                this.dispatcherService.Dispatch(() =>
                {//显示图书基本信息
                    this.BookName       = bookNameList[0];
                    this.BookAccessCode = bookAccessCodeList[0];
                });

                String shelfRfid          = bookLocationService.getShelfRfidbyBookRfid(newItem.bookRfidList[0]);
                String bookLocationString = bookLocationService.getShelfNameByShelfRfid(shelfRfid);

                //在选定的书架层上绘图
                this.dispatcherService.Dispatch(() =>
                {
                    this.BookLocation = bookLocationString;
                    //test code here ,delete it
                    this.libraryMapService.reinitOneShapMap();//刷新UI
                    this.libraryMapService.drawOneShapeMapBackground();
                    this.libraryMapService.drawSelectedLayerOneShapeMap(bookLocationString);
                    //this.LibraryMapService = this.LibraryMapService; //通知更新UI,没必要重复了,等下面操作一起刷新

                    this.libraryMapService.reinitLibraryShelfMap();
                    this.libraryMapService.drawLibraryShelfMapBackgroundByLibraryName(bookLocationString);
                    this.libraryMapService.drawSelectedShelfLibraryShelfMapByLibraryName(shelfRfid);
                    this.LibraryMapService = this.LibraryMapService;//通知更新UI
                });
            }
        }
Пример #2
0
        private void mainTask()
        {//这个用于扫描的后台线程永远不会退出,如果状态为为false,他将不做任何工作,仅仅是不断睡眠并等待状态为变为true
         //如果这个状态位是true,就会定期扫描标签,并把标签信息用事件发送出去
            Dictionary <String, String> TagList = new Dictionary <String, String>();

            while (true) //扫描主程序,一直会运行
            {
                playSound();
                if (this.backgroundTaskStatus == true)
                {
                    lock (this.rfidLock)
                    {
                        RFIDContent content = new RFIDContent();
                        try
                        {
                            TagList = rfidDevice.readTags();  //该函数会被阻塞,直到读到标签,如果被阻塞在函数内部则等待一段时间并再次读取
                        }
                        catch (Exception e)
                        {
                            eventAggregator.GetEvent <RFIDHardwareEvent>().Publish(e.ToString());
                            //RFIDHardwareEvent 读卡时可能发生错误
                        }
                        foreach (KeyValuePair <String, String> item in TagList)
                        {//从读卡器读到的一批数据,可能有图书的,也可能有书架的,把这些数据进行整理,并准备用event发送出去
                            if (item.Value == "book")
                            {
                                content.bookRfidList.Add(item.Key);
                            }
                            if (item.Value == "shelf")
                            {
                                content.shelfRfidList.Add(item.Key);
                            }
                        }
                        if ((content.bookRfidList.Count() != 0) || (content.shelfRfidList.Count() != 0))
                        {
                            eventAggregator.GetEvent <RFIDNewItemEvent>().Publish(content);
                        }
                        //把读到的内容通过事件发送出去,不管读到的是图书信息还是书架的信息
                        Thread.Sleep(500);
                        //睡眠一定要在所有操作完成后进行,因为醒来后可能状态位已经发生了改变,否则会发生异常
                    }
                }
                else
                {
                    Thread.Sleep(500);
                    //睡眠一定要在所有操作完成后进行,因为醒来后可能状态位已经发生了改变,否则会发生异常
                }
                lock (this.rfidLock)
                {
                    TagList.Clear();
                }
            }
        }
Пример #3
0
 private static void RFIDNewItemHander(RFIDContent obj)
 {
     if ((obj.bookRfidList.Count == 0) && (obj.shelfRfidList.Count == 0))
     {
         return;
     }
     Console.WriteLine("new item");
     Console.Write("book:");
     foreach (String item in obj.bookRfidList)
     {
         Console.Write(item + "  ");
     }
     Console.WriteLine();
     Console.Write("shelf:");
     foreach (String item in obj.shelfRfidList)
     {
         Console.Write(item + "  ");
     }
     Console.WriteLine("end");
 }
Пример #4
0
 private void mainTask()  
 {//这个用于扫描的后台线程永远不会退出,如果状态为为false,他将不做任何工作,仅仅是不断睡眠并等待状态为变为true
  //如果这个状态位是true,就会定期扫描标签,并把标签信息用事件发送出去            
     Dictionary<String, String> TagList = new Dictionary<String, String>();   
     while (true) //扫描主程序,一直会运行
     {
         playSound();
         if (this.backgroundTaskStatus == true)
         {
             lock(this.rfidLock)
             {
                 RFIDContent content = new RFIDContent();
                 try
                 {
                     TagList = rfidDevice.readTags();  //该函数会被阻塞,直到读到标签,如果被阻塞在函数内部则等待一段时间并再次读取
                 }
                 catch (Exception e)
                 {
                     eventAggregator.GetEvent<RFIDHardwareEvent>().Publish(e.ToString());
                     //RFIDHardwareEvent 读卡时可能发生错误
                 }
                 foreach (KeyValuePair<String, String> item in TagList)
                 {//从读卡器读到的一批数据,可能有图书的,也可能有书架的,把这些数据进行整理,并准备用event发送出去
                     if (item.Value == "book")
                     {
                         content.bookRfidList.Add(item.Key);
                     }
                     if (item.Value == "shelf")
                     {
                         content.shelfRfidList.Add(item.Key);
                     }
                 }
                 if ((content.bookRfidList.Count() != 0) || (content.shelfRfidList.Count() != 0))
                 {
                     eventAggregator.GetEvent<RFIDNewItemEvent>().Publish(content);
                 }
                 //把读到的内容通过事件发送出去,不管读到的是图书信息还是书架的信息
                 Thread.Sleep(500);
                 //睡眠一定要在所有操作完成后进行,因为醒来后可能状态位已经发生了改变,否则会发生异常
         
             }
             
         }
         else
         {                    
             Thread.Sleep(500);
             //睡眠一定要在所有操作完成后进行,因为醒来后可能状态位已经发生了改变,否则会发生异常
         }
         lock (this.rfidLock)
         {
             TagList.Clear();
         }                
     }
 }
        private void handleNewItemFromRFID(RFIDContent newItem)
        {
            if (newItem.bookRfidList.Count() != 0)
            {//只有当当前在某个书架上的图书不为空的时候才继续处理
                IBookInformationService bookInformationService = container.Resolve<IBookInformationService>();
                IBookLocationService bookLocationService = this.container.Resolve<IBookLocationService>();
                if(!String.IsNullOrEmpty(this.ShelfLocationString))//  书架位置信息不空,这时有必要继续执行
                {
                    //如果出现不在该架位的图书,则提示该书不属于当前书架
                    foreach (String bookrfid in newItem.bookRfidList)
                    {
                        String shelfRfid=bookLocationService.getShelfRfidbyBookRfid(bookrfid);
                        if (shelfRfid != this.shelfRfid)
                        {
                            try
                            {
                                List<String> bookNameList = bookInformationService.getBookNameListByRfidList(new List<String>() { bookrfid });
                                String bookName = bookNameList[0];
                                String message = "图书名称:" + bookName + "图书扫描码:" + bookrfid + "不属于该书架";
                                MessageBox.Show(message);
                            }
                            catch (Exception)
                            {
                                String message = "查询数据库出错,图书扫描码为:" + bookrfid+",请检查是否登记该图书 !";
                                MessageBox.Show(message);
                            }                            
                        }
                    }
                    //图书的rfid是否有重复,删除掉重复的部分,并刷新UI,但ID编号可能不连续,重新更新ID编号                 
                    this.dispatcherService.Dispatch(() =>
                    {
                        List<BookItemOfWrongLocation> tempList = new List<BookItemOfWrongLocation>();
                        //把原始的datagrid中的内容存入临时的列表中,并清空该列表
                        foreach (BookItemOfWrongLocation item in this.NotOnThisShelfBookList)
                        {
                            tempList.Add(item);
                        }
                        this.NotOnThisShelfBookList.Clear();
                        //查看临时列表中与新读入标签重复的地方
                        int index=0;
                        while(true){
                            if (index >= tempList.Count())
                            {
                                break;
                            }
                            BookItemOfWrongLocation item = tempList[index];
                            if (newItem.bookRfidList.Contains(item.BookRFIDCode))
                            {
                                tempList.Remove(item);
                            }
                            index = index + 1;
                        }
                        //把临时标签的内容复制入datagrid,并重新计算ID,因为ID可能经过删除有不连续的现象
                        int count = 1;
                        foreach (BookItemOfWrongLocation item in tempList)
                        {
                            item.ID = Convert.ToString(count);
                            this.NotOnThisShelfBookList.Add(item);
                            count = count + 1;
                        }
                        //刷新UI
                        this.NotOnThisShelfBookList = this.NotOnThisShelfBookList;

                    });
                }
            }
            if (newItem.shelfRfidList.Count() != 0) //发现有新的书架信息
            {
                //清除原有信息
                this.dispatcherService.Dispatch(() =>
                {
                    this.OnThisShelfAllBookList.Clear();
                    this.NotOnThisShelfBookList.Clear();
                });          
                //在书架位置的文本框内显示数据的位置
                IBookInformationService bookInformationService = container.Resolve<IBookInformationService>();
                IBookLocationService bookLocationService = this.container.Resolve<IBookLocationService>();
                this.shelfRfid = newItem.shelfRfidList[0];
                this.ShelfLocationString = bookLocationService.getShelfNameByShelfRfid(newItem.shelfRfidList[0]);                
                //查询数据库,在本书架应有图书中显示所有的图书
                List<String> bookRfidList = bookLocationService.getBookRfidListOnShelfRfid(this.shelfRfid);
                List<String> bookNameList=bookInformationService.getBookNameListByRfidList(bookRfidList);
                List<String> bookAccessCodeList=bookInformationService.getBookAccessCodeListByRfidList(bookRfidList);
                if ((bookRfidList.Count() == bookNameList.Count()) && (bookNameList.Count() == bookAccessCodeList.Count()))
                {//查询到的图书名称和图书索取码必须与图书rfid字符串长度相等
                    for (int i = 0; i < bookRfidList.Count(); i++)
                    {

                        BookItemOfWrongLocation newBookItem = new BookItemOfWrongLocation() 
                        {
                            ID=Convert.ToString(i+1),
                            BookName=bookNameList[i],
                            BookAccessCode=bookAccessCodeList[i],
                            BookRFIDCode=bookRfidList[i]
                        };
                        BookItemOfWrongLocation newBookItemInOtherGrid = (BookItemOfWrongLocation)newBookItem.Clone();
                        this.dispatcherService.Dispatch(() =>
                        {
                            this.OnThisShelfAllBookList.Add(newBookItem);
                            this.notOnThisShelfBookList.Add(newBookItemInOtherGrid);
                        });
                    }
                    this.dispatcherService.Dispatch(() =>
                    {
                        this.OnThisShelfAllBookList = this.OnThisShelfAllBookList;
                        this.NotOnThisShelfBookList = this.NotOnThisShelfBookList;
                    });
                }

            }
        }
        private void handleNewItemFromRFID(RFIDContent newItem)
        {
            //判断是不是没有数据
            if (newItem.bookRfidList.Count() != 0)
            {
                //从newItem中获取图书数据并开始查询
                IBookInformationService bookInformationService = this.container.Resolve<IBookInformationService>();
                List<String> bookRfidList = newItem.bookRfidList;
                //查看图形界面中的图书列表,即bookItemList与bookRfidList是否有重复,消除掉重复的部分
                foreach (BookItem item in this.bookItemList)
                {
                    if(bookRfidList.Contains(item.BookRFIDCode))
                    {
                        bookRfidList.Remove(item.BookRFIDCode);//删除后链表可能为空
                    }
                }
                if (bookRfidList.Count() == 0) { return; }

                List<String> bookNameList = bookInformationService.getBookNameListByRfidList(bookRfidList);
                List<String> bookAccessCodeList = bookInformationService.getBookAccessCodeListByRfidList(bookRfidList);
                //这里有个bug,就是三个列表长度不同,研究下为什么,暂时先用比较长度的方式来解决
                if (bookRfidList.Count() != bookNameList.Count()){return;}
                if (bookRfidList.Count() != bookAccessCodeList.Count()) { return; }
                if (bookNameList.Count() != bookAccessCodeList.Count()) { return; }
                this.dispatcherService.Dispatch(() =>
                {
                    for (int i = 0; i < bookRfidList.Count(); i++)
                    {
                        this.bookItemList.Add(new BookItem() { 
                            ID = Convert.ToString(this.bookItemCount), 
                            BookName = bookNameList[i], 
                            BookAccessCode = bookAccessCodeList[i], 
                            BookRFIDCode = bookRfidList[i] });
                        this.bookItemCount = this.bookItemCount + 1;
                    }
                });
            }
            if (newItem.shelfRfidList.Count() != 0)
            {
                IBookLocationService bookLocationService = this.container.Resolve<IBookLocationService>();
                this.ShelfName = bookLocationService.getShelfNameByShelfRfid(newItem.shelfRfidList[0]);
                this.shelfRfid = newItem.shelfRfidList[0];
            }
            //通过赋值激活set,并更新UI
            this.BookItemList = this.BookItemList;
            /***
            if ((newItem.bookRfidList.Count() != 0) || (newItem.shelfRfidList.Count() != 0))
            {
                this.dispatcherService.Dispatch(() =>
                {
                    ((DelegateCommand)this.RecodeBookLocationAddBookListCommand).RaiseCanExecuteChanged();
                    ((DelegateCommand)this.RecodeBookLocationCleanBookListCommand).RaiseCanExecuteChanged();

                });   
            }***/
            //throw new NotImplementedException();
            //开始处理读取到的数据,并显示在图形界面中
            //begin at this next time
            
            //this.bookItemList.Add(new BookItem() { ID = "2", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });
            //this.bookItemList.Add(new BookItem() { ID = "3", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });
            //this.bookItemList.Add(new BookItem() { ID = "4", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });

        }
Пример #7
0
 private void handleNewItemFromRFID(RFIDContent newItem)
 {
     if (newItem.bookRfidList.Count() != 0)
     {//只有当当前在某个书架上的图书不为空的时候才继续处理
         IBookInformationService bookInformationService = container.Resolve <IBookInformationService>();
         IBookLocationService    bookLocationService    = this.container.Resolve <IBookLocationService>();
         if (!String.IsNullOrEmpty(this.ShelfLocationString))//  书架位置信息不空,这时有必要继续执行
         {
             //如果出现不在该架位的图书,则提示该书不属于当前书架
             foreach (String bookrfid in newItem.bookRfidList)
             {
                 String shelfRfid = bookLocationService.getShelfRfidbyBookRfid(bookrfid);
                 if (shelfRfid != this.shelfRfid)
                 {
                     try
                     {
                         List <String> bookNameList = bookInformationService.getBookNameListByRfidList(new List <String>()
                         {
                             bookrfid
                         });
                         String bookName = bookNameList[0];
                         String message  = "图书名称:" + bookName + "图书扫描码:" + bookrfid + "不属于该书架";
                         MessageBox.Show(message);
                     }
                     catch (Exception)
                     {
                         String message = "查询数据库出错,图书扫描码为:" + bookrfid + ",请检查是否登记该图书 !";
                         MessageBox.Show(message);
                     }
                 }
             }
             //图书的rfid是否有重复,删除掉重复的部分,并刷新UI,但ID编号可能不连续,重新更新ID编号
             this.dispatcherService.Dispatch(() =>
             {
                 List <BookItemOfWrongLocation> tempList = new List <BookItemOfWrongLocation>();
                 //把原始的datagrid中的内容存入临时的列表中,并清空该列表
                 foreach (BookItemOfWrongLocation item in this.NotOnThisShelfBookList)
                 {
                     tempList.Add(item);
                 }
                 this.NotOnThisShelfBookList.Clear();
                 //查看临时列表中与新读入标签重复的地方
                 int index = 0;
                 while (true)
                 {
                     if (index >= tempList.Count())
                     {
                         break;
                     }
                     BookItemOfWrongLocation item = tempList[index];
                     if (newItem.bookRfidList.Contains(item.BookRFIDCode))
                     {
                         tempList.Remove(item);
                     }
                     index = index + 1;
                 }
                 //把临时标签的内容复制入datagrid,并重新计算ID,因为ID可能经过删除有不连续的现象
                 int count = 1;
                 foreach (BookItemOfWrongLocation item in tempList)
                 {
                     item.ID = Convert.ToString(count);
                     this.NotOnThisShelfBookList.Add(item);
                     count = count + 1;
                 }
                 //刷新UI
                 this.NotOnThisShelfBookList = this.NotOnThisShelfBookList;
             });
         }
     }
     if (newItem.shelfRfidList.Count() != 0) //发现有新的书架信息
     {
         //清除原有信息
         this.dispatcherService.Dispatch(() =>
         {
             this.OnThisShelfAllBookList.Clear();
             this.NotOnThisShelfBookList.Clear();
         });
         //在书架位置的文本框内显示数据的位置
         IBookInformationService bookInformationService = container.Resolve <IBookInformationService>();
         IBookLocationService    bookLocationService    = this.container.Resolve <IBookLocationService>();
         this.shelfRfid           = newItem.shelfRfidList[0];
         this.ShelfLocationString = bookLocationService.getShelfNameByShelfRfid(newItem.shelfRfidList[0]);
         //查询数据库,在本书架应有图书中显示所有的图书
         List <String> bookRfidList       = bookLocationService.getBookRfidListOnShelfRfid(this.shelfRfid);
         List <String> bookNameList       = bookInformationService.getBookNameListByRfidList(bookRfidList);
         List <String> bookAccessCodeList = bookInformationService.getBookAccessCodeListByRfidList(bookRfidList);
         if ((bookRfidList.Count() == bookNameList.Count()) && (bookNameList.Count() == bookAccessCodeList.Count()))
         {//查询到的图书名称和图书索取码必须与图书rfid字符串长度相等
             for (int i = 0; i < bookRfidList.Count(); i++)
             {
                 BookItemOfWrongLocation newBookItem = new BookItemOfWrongLocation()
                 {
                     ID             = Convert.ToString(i + 1),
                     BookName       = bookNameList[i],
                     BookAccessCode = bookAccessCodeList[i],
                     BookRFIDCode   = bookRfidList[i]
                 };
                 BookItemOfWrongLocation newBookItemInOtherGrid = (BookItemOfWrongLocation)newBookItem.Clone();
                 this.dispatcherService.Dispatch(() =>
                 {
                     this.OnThisShelfAllBookList.Add(newBookItem);
                     this.notOnThisShelfBookList.Add(newBookItemInOtherGrid);
                 });
             }
             this.dispatcherService.Dispatch(() =>
             {
                 this.OnThisShelfAllBookList = this.OnThisShelfAllBookList;
                 this.NotOnThisShelfBookList = this.NotOnThisShelfBookList;
             });
         }
     }
 }
        private void handleNewItemFromRFID(RFIDContent newItem)
        {
            if (newItem.bookRfidList.Count() != 0)
            {
                IBookLocationService bookLocationService = this.container.Resolve<IBookLocationService>();
                IBookInformationService bookInformationService = this.container.Resolve<IBookInformationService>();
                
                List<String> bookNameList = bookInformationService.getBookNameListByRfidList(newItem.bookRfidList);
                List<String> bookAccessCodeList = bookInformationService.getBookAccessCodeListByRfidList(newItem.bookRfidList);
                this.dispatcherService.Dispatch(() =>
                {//显示图书基本信息
                    this.BookName = bookNameList[0];
                    this.BookAccessCode = bookAccessCodeList[0];
                });               

                String shelfRfid = bookLocationService.getShelfRfidbyBookRfid(newItem.bookRfidList[0]);
                String bookLocationString = bookLocationService.getShelfNameByShelfRfid(shelfRfid);

                //在选定的书架层上绘图
                this.dispatcherService.Dispatch(() =>
                {
                    this.BookLocation = bookLocationString;
                    //test code here ,delete it 
                    this.libraryMapService.reinitOneShapMap();//刷新UI
                    this.libraryMapService.drawOneShapeMapBackground();
                    this.libraryMapService.drawSelectedLayerOneShapeMap(bookLocationString);
                    //this.LibraryMapService = this.LibraryMapService; //通知更新UI,没必要重复了,等下面操作一起刷新

                    this.libraryMapService.reinitLibraryShelfMap();
                    this.libraryMapService.drawLibraryShelfMapBackgroundByLibraryName(bookLocationString);
                    this.libraryMapService.drawSelectedShelfLibraryShelfMapByLibraryName(shelfRfid);
                    this.LibraryMapService = this.LibraryMapService;//通知更新UI

                });
            }
        }
Пример #9
0
        private void handleNewItemFromRFID(RFIDContent newItem)
        {
            //判断是不是没有数据
            if (newItem.bookRfidList.Count() != 0)
            {
                //从newItem中获取图书数据并开始查询
                IBookInformationService bookInformationService = this.container.Resolve <IBookInformationService>();
                List <String>           bookRfidList           = newItem.bookRfidList;
                //查看图形界面中的图书列表,即bookItemList与bookRfidList是否有重复,消除掉重复的部分
                foreach (BookItem item in this.bookItemList)
                {
                    if (bookRfidList.Contains(item.BookRFIDCode))
                    {
                        bookRfidList.Remove(item.BookRFIDCode);//删除后链表可能为空
                    }
                }
                if (bookRfidList.Count() == 0)
                {
                    return;
                }

                List <String> bookNameList       = bookInformationService.getBookNameListByRfidList(bookRfidList);
                List <String> bookAccessCodeList = bookInformationService.getBookAccessCodeListByRfidList(bookRfidList);
                //这里有个bug,就是三个列表长度不同,研究下为什么,暂时先用比较长度的方式来解决
                if (bookRfidList.Count() != bookNameList.Count())
                {
                    return;
                }
                if (bookRfidList.Count() != bookAccessCodeList.Count())
                {
                    return;
                }
                if (bookNameList.Count() != bookAccessCodeList.Count())
                {
                    return;
                }
                this.dispatcherService.Dispatch(() =>
                {
                    for (int i = 0; i < bookRfidList.Count(); i++)
                    {
                        this.bookItemList.Add(new BookItem()
                        {
                            ID             = Convert.ToString(this.bookItemCount),
                            BookName       = bookNameList[i],
                            BookAccessCode = bookAccessCodeList[i],
                            BookRFIDCode   = bookRfidList[i]
                        });
                        this.bookItemCount = this.bookItemCount + 1;
                    }
                });
            }
            if (newItem.shelfRfidList.Count() != 0)
            {
                IBookLocationService bookLocationService = this.container.Resolve <IBookLocationService>();
                this.ShelfName = bookLocationService.getShelfNameByShelfRfid(newItem.shelfRfidList[0]);
                this.shelfRfid = newItem.shelfRfidList[0];
            }
            //通过赋值激活set,并更新UI
            this.BookItemList = this.BookItemList;

            /***
             * if ((newItem.bookRfidList.Count() != 0) || (newItem.shelfRfidList.Count() != 0))
             * {
             *  this.dispatcherService.Dispatch(() =>
             *  {
             *      ((DelegateCommand)this.RecodeBookLocationAddBookListCommand).RaiseCanExecuteChanged();
             *      ((DelegateCommand)this.RecodeBookLocationCleanBookListCommand).RaiseCanExecuteChanged();
             *
             *  });
             * }***/
            //throw new NotImplementedException();
            //开始处理读取到的数据,并显示在图形界面中
            //begin at this next time

            //this.bookItemList.Add(new BookItem() { ID = "2", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });
            //this.bookItemList.Add(new BookItem() { ID = "3", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });
            //this.bookItemList.Add(new BookItem() { ID = "4", BookName = "123", BookAccessCode = "TP123", BookRFIDCode = "0x123" });
        }