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 }); } }
public static void testShelfPositonDatabase(IUnityContainer container) { IBookLocationService locationService = container.Resolve <IBookLocationService>(); locationService.ServerIp = "DESKTOP-PSQP38H"; locationService.ServerUsername = "******"; locationService.ServerPassword = "******"; List <String> shelfRfidList = new List <string>(); shelfRfidList.Add("6W22A0304"); shelfRfidList.Add("6W22A0305"); shelfRfidList.Add("3W01A0103"); shelfRfidList.Add("3W01A0503"); Console.WriteLine("Shelf Rfid List:"); displayList(shelfRfidList); List <String> shelfNameList = new List <String>(); foreach (String item in shelfRfidList) { String name = locationService.getShelfNameByShelfRfid(item); shelfNameList.Add(name); } Console.WriteLine("Shelf Name List:"); displayList(shelfNameList); }
//管理配置文件的类 public SystemSettingViewModel(IUnityContainer container, IRegionManager regionManager) { this.container = container; this.regionManager = regionManager; //初始化时从配置文件中载入基本配置,并在点击保存按钮时把配置保存下来 this.databaseAndSerialSettingsServices = new DatabaseAndSerialSettingsServices(); this.bookInformationServerSettings = databaseAndSerialSettingsServices.loadBookInformationServerSettings(); this.bookLocationServerSettings = databaseAndSerialSettingsServices.loadBookLocationServerSettings(); this.serialSettings = databaseAndSerialSettingsServices.loadSerialSettings(); //把配置信息放到容器中的相应对象中,因此这部分必须要比其他的viewModel和view首先被初始化 //此后容器里的两个数据库服务,和一个RFID服务就有了配置信息 IBookInformationService bookInformationSrv = this.container.Resolve <IBookInformationService>(); bookInformationSrv.ServerIp = BookInformationServer.IP; bookInformationSrv.ServerUsername = BookInformationServer.Username; bookInformationSrv.ServerPassword = BookInformationServer.Password; IBookLocationService bookLocationSrv = container.Resolve <IBookLocationService>(); bookLocationSrv.ServerIp = BookLocationServer.IP; bookLocationSrv.ServerUsername = BookLocationServer.Username; bookLocationSrv.ServerPassword = BookLocationServer.Password; ISerialService serialSrv = container.Resolve <ISerialService>(); serialSrv.Serial = Serial.Serial; serialSrv.Speed = Serial.Speed; //把系统配置信息放置在RFID服务中 IRFIDService rfidService = container.Resolve <IRFIDService>(); rfidService.HardwareInterface = serialSrv.Serial; rfidService.HardwareInterfaceConnectionSpeed = serialSrv.Speed; }
private void onRecodeBookLocationAddBookListCommandExecute() { IBookLocationService bookLocationService = this.container.Resolve <IBookLocationService>(); String currentShelfRfid = this.shelfRfid; List <String> bookRfidList = new List <String>(); //如果图书列表和书架信息为空,则不执行插入操作 if (this.onRecodeBookLocationAddBookListCommandCanExecute() == false) { return; } //把新的信息加入数据库 foreach (BookItem oneBook in this.BookItemList) { bookRfidList.Add(oneBook.BookRFIDCode); } bookLocationService.setBookRfidListOnShelfRfid(currentShelfRfid, bookRfidList); this.clearBookListAndShelfInformation(); //throw new NotImplementedException(); MessageBox.Show("添加图书信息成功!"); //添加图书后通过重置,使得set被调用,从而激活UI刷新 this.BookItemList = this.BookItemList; /*** * this.dispatcherService.Dispatch(() => * { * ((DelegateCommand)this.RecodeBookLocationAddBookListCommand).RaiseCanExecuteChanged(); * ((DelegateCommand)this.RecodeBookLocationCleanBookListCommand).RaiseCanExecuteChanged(); * * });***/ }
private void onBookLocationServerSaveCommandExecute() { IBookLocationService service = container.Resolve <IBookLocationService>(); service.ServerIp = BookLocationServer.IP; service.ServerUsername = BookLocationServer.Username; service.ServerPassword = BookLocationServer.Password; //保存配置 databaseAndSerialSettingsServices.saveBookLocationServerSettings(BookLocationServer); }
public void OnNavigatedTo(NavigationContext navigationContext) { //throw new NotImplementedException(); //ISerialService serialService = container.Resolve<ISerialService>(); IBookInformationService bookInformationService = container.Resolve <IBookInformationService>(); IBookLocationService bookLocationService = container.Resolve <IBookLocationService>(); IRFIDService rfidService = container.Resolve <IRFIDService>(); //开始读取RFID的信息,并查询数据库 eventAggregator.GetEvent <RFIDNewItemEvent>().Subscribe(handleNewItemFromRFID); //开始订阅RFID服务发出的事件,这个事件是扫描到的条码的信息,在该view非激活时务必取消此事件的订阅 eventAggregator.GetEvent <RFIDHardwareEvent>().Subscribe(handleErrorFromRFID); rfidService.start();//开启rfid的后台扫描线程 }
//该函数能够画出目标书架在书库中的位置 public void drawSelectedShelfLibraryShelfMapByLibraryName(String shelfRfid) { //获取图书位置信息数据库的引用 IBookLocationService bookLocationService = this.container.Resolve <IBookLocationService>(); String shelfLocationString = bookLocationService.getItemPositionStringByShelfRfid(shelfRfid); //把位置字符解析为具体的图形 char[] separator = { ',', ',' }; String[] pointDescInString = shelfLocationString.Split(separator); if (pointDescInString.Length == 4) { double[] pointDescInDouble = new double[] { Convert.ToDouble(pointDescInString[0]), Convert.ToDouble(pointDescInString[1]), Convert.ToDouble(pointDescInString[2]), Convert.ToDouble(pointDescInString[3]) }; Point leftTop = new Point(pointDescInDouble[0], pointDescInDouble[1]); Point rightBottom = new Point(pointDescInDouble[0] + pointDescInDouble[2], pointDescInDouble[1] + pointDescInDouble[3]); //把书库大门的位置信息放入结构体的变量中shelfMapShelfList //在地图上画出选中的书库 this.libraryShelfDrawer.drawSelectedRectangle(leftTop, rightBottom); } }
public TestUserControlViewModelForBookLocation(IUnityContainer container) { this.container = container; bookLocationService = container.Resolve<IBookLocationService>(); this.shelfRfidString = ""; this.bookRfidString = ""; }
public TestUserControlViewModelForBookLocation(IUnityContainer container) { this.container = container; bookLocationService = container.Resolve <IBookLocationService>(); this.shelfRfidString = ""; this.bookRfidString = ""; }
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; }); } } }
//该函数能够画出一个书库的背景图片,包含书架,轮廓和门,参数为该图书馆名称,参数即为Map表中的location字段 public void drawLibraryShelfMapBackgroundByLibraryName(String libraryName) { String libraryNameInTable = this.bookLocationStringToLibraryName(libraryName); //获取图书位置信息数据库的引用 IBookLocationService bookLocationService = this.container.Resolve <IBookLocationService>(); //画出书库的地板,重复画出 /*** * BitmapImage floorTileBitmapImage = new BitmapImage(); * floorTileBitmapImage.BeginInit(); * floorTileBitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/glass.png", UriKind.RelativeOrAbsolute); * floorTileBitmapImage.EndInit(); * this.libraryShelfDrawer.drawFloor(floorTileBitmapImage); ***/ //画出所有的书架 try { //获取某个书库中所有的书架 List <String> shelfPositionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "SHELF"); //从数据库中读到的字符串列表中解析出所有的书架地理位置信息,并加入到this.shelfMapShelfList中 List <ShelfShape> shelfMapShelfList = new List <ShelfShape>(); foreach (String stringItem in shelfPositionStringList) {//stringItem is a string ,such as "13000,1500,1500,1000",startpoint x,y,and width,height char[] separator = { ',', ',' }; String[] pointDescInString = stringItem.Split(separator); if (pointDescInString.Length != 4) { continue; } //如果不为4个数字,则意味着可能出现了解析或者存储错误 double[] pointDescInDouble = new double[] { Convert.ToDouble(pointDescInString[0]), Convert.ToDouble(pointDescInString[1]), Convert.ToDouble(pointDescInString[2]), Convert.ToDouble(pointDescInString[3]) }; Point leftTop = new Point(pointDescInDouble[0], pointDescInDouble[1]); Point rightBottom = new Point(pointDescInDouble[0] + pointDescInDouble[2], pointDescInDouble[1] + pointDescInDouble[3]); //把书架的位置信息放入结构体的变量中shelfMapShelfList shelfMapShelfList.Add(new ShelfShape(leftTop, rightBottom)); } //开始绘制俯视图中的书架 BitmapImage bitmapImage = new BitmapImage(); //Uri uri = new Uri("pack://application:,,,/UI;component/Resource/images/oneShelf.png", UriKind.RelativeOrAbsolute); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/oneShelf.png", UriKind.RelativeOrAbsolute); bitmapImage.EndInit(); //设置旋转效果和阴影效果,开始 RotateTransform rotateTransform = new RotateTransform(0); DropShadowBitmapEffect bitmapEffect = new DropShadowBitmapEffect(); Color ShadowColor = new Color(); ShadowColor.ScA = 1; ShadowColor.ScB = 0; ShadowColor.ScG = 0; ShadowColor.ScR = 0; bitmapEffect.Color = ShadowColor; bitmapEffect.Direction = 320; bitmapEffect.ShadowDepth = 10; bitmapEffect.Softness = 0.1; bitmapEffect.Opacity = 0.1; //设置选择效果和阴影效果,结束 foreach (ShelfShape oneShelf in shelfMapShelfList) { //原始代码是绘制矩形框,现在改为绘制图片 //this.libraryShelfDrawer.drawShelf(oneShelf.topLeft, oneShelf.bottomRight); this.libraryShelfDrawer.drawImage(oneShelf.topLeft, oneShelf.bottomRight, bitmapImage, rotateTransform, bitmapEffect); } } catch (Exception) { this.eventAggregator.GetEvent <DatabaseEvent>().Publish("DrawMapService:从数据库中获取书架信息出错!"); //如果发生错误那发布事件 } //画出某个书库的轮廓 try { List <String> shelfContourPostionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "CONTOUR"); String shelfContourPostionString = ""; ContourShape shelfMapContour; //轮廓信息存放的地点 //如果获得的轮廓个数小于零,则说明数据出现了问题.其实一个书库的轮廓只能有一个 if (shelfContourPostionStringList.Count > 0) { shelfContourPostionString = shelfContourPostionStringList[0]; char[] separator = { ',', ',' }; String[] pointDescInString = shelfContourPostionString.Split(separator); //轮廓点的个数只能是偶数个,如果解析和读取数据的时候出现任何错误,则花图书轮廓的程序终止 if ((pointDescInString.Length % 2 == 0) && (pointDescInString.Length >= 2)) { List <Double> pointXList = new List <Double>(); List <Double> pointYList = new List <Double>(); for (int i = 0; i < pointDescInString.Length; i = i + 2) { pointXList.Add(Convert.ToDouble(pointDescInString[i])); pointYList.Add(Convert.ToDouble(pointDescInString[i + 1])); } if (pointXList.Count == pointYList.Count) { List <Point> contourPointList = new List <Point>(); for (int i = 0; i < pointXList.Count(); i++) { Point onePoint = new Point(pointXList[i], pointYList[i]); contourPointList.Add(onePoint); } shelfMapContour = new ContourShape(contourPointList); this.libraryShelfDrawer.drawContour(shelfMapContour.pointList); } } } }catch (Exception) { this.eventAggregator.GetEvent <DatabaseEvent>().Publish("DrawMapService:从数据库中获取书库轮廓信息出错!"); //如果发生错误那发布事件 } //画出某个书库大门的位置 try { List <String> doorPostionStringList = bookLocationService.getItemPositionStringListByLocationAndType(libraryNameInTable, "DOOR"); DoorShape shelfMapDoor;//入口信息存放的位置 if (doorPostionStringList.Count > 0) { String doorPostionString = doorPostionStringList[0]; char[] separator = { ',', ',' }; String[] pointDescInString = doorPostionString.Split(separator); if (pointDescInString.Length == 4) { double[] pointDescInDouble = new double[] { Convert.ToDouble(pointDescInString[0]), Convert.ToDouble(pointDescInString[1]), Convert.ToDouble(pointDescInString[2]), Convert.ToDouble(pointDescInString[3]) }; Point leftTop = new Point(pointDescInDouble[0], pointDescInDouble[1]); Point rightBottom = new Point(pointDescInDouble[0] + pointDescInDouble[2], pointDescInDouble[1] + pointDescInDouble[3]); //把书库大门的位置信息放入结构体的变量中shelfMapShelfList shelfMapDoor = new DoorShape(leftTop, rightBottom); //载入入口图片 BitmapImage bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.UriSource = new Uri("pack://application:,,,/UI;component/Resource/images/door.png", UriKind.RelativeOrAbsolute); bitmapImage.EndInit(); //设置旋转效果和阴影效果,开始 RotateTransform rotateTransform = new RotateTransform(0); DropShadowBitmapEffect bitmapEffect = new DropShadowBitmapEffect(); //this.libraryShelfDrawer.drawDoor(shelfMapDoor.topLeft, shelfMapDoor.bottomRight); this.libraryShelfDrawer.drawImage(shelfMapDoor.topLeft, shelfMapDoor.bottomRight, bitmapImage, rotateTransform, bitmapEffect); } } } catch (Exception) { this.eventAggregator.GetEvent <DatabaseEvent>().Publish("DrawMapService:从数据库中获取书库大门信息出错!"); //如果发生错误那发布事件 } }
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" }); }