void seatLayout() { canvas_Thumbnail.Children.Clear(); canvas_Seat.Children.Clear();//座位图中移除所有子元素 viewModel.AllSeatCount = viewModel.Layout.Seats.Count; int SeatWidth = 24 * viewModel.Layout.SeatCol; int SeatHeight = 24 * viewModel.Layout.SeatRow; this.canvas_Seat.Width = SeatWidth; this.canvas_Seat.Height = SeatHeight; //设置空间最小尺寸 if (viewModel.WindowWidth <= 1080) { G_bg.Width = 1080; } else { G_bg.Width = viewModel.WindowWidth; } if (viewModel.WindowHeight <= 1000) { G_bg.Height = 1000; } else { G_bg.Height = viewModel.WindowHeight; } if (G_bg.Width == 1080 || G_bg.Height == 1000) { if (G_bg.Height <= G_bg.Width) { G_bg.Width = viewModel.WindowWidth * (G_bg.Height / viewModel.WindowHeight); } else { G_bg.Height = viewModel.WindowHeight * (G_bg.Width / viewModel.WindowWidth); } } double areaScaleX = SeatWidth / (G_bg.Width - SeatWindow.Margin.Left - SeatWindow.Margin.Right); double areaScaleY = SeatHeight / (G_bg.Height - SeatWindow.Margin.Top - SeatWindow.Margin.Bottom); if (SeatWidth >= SeatHeight) { scaleX = SeatWidth / canvas_Thumbnail.Width; scaleY = SeatWidth / canvas_Thumbnail.Height; moveY = (SeatWidth - SeatHeight) / 2 / scaleY; } else { scaleX = SeatHeight / canvas_Thumbnail.Width; scaleY = SeatHeight / canvas_Thumbnail.Height; moveX = (SeatHeight - SeatWidth) / 2 / scaleX; } try { Canvas.SetLeft(canvas_Seat, 0); Canvas.SetTop(canvas_Seat, 0); } catch { PopupWindowsObject.GetInstance().Window.ShowMessage(SeatManage.EnumType.TipType.Exception); WinClosing(); } #region 布局座位 foreach (KeyValuePair <string, Seat> seat in viewModel.Layout.Seats) { #region 布局实际图, double canLeft = 24 * seat.Value.PositionX; double canTop = 24 * seat.Value.PositionY; UC_Seat seatUC = new UC_Seat(viewModel.SeatLayoutList[seat.Key]); seatUC.Width = 48; seatUC.Height = 48; seatUC.LblSeatNo.RenderTransform = new RotateTransform(-seat.Value.RotationAngle); seatUC.LblSeatNo.RenderTransformOrigin = new Point(0.5, 0.5); seatUC.RenderTransform = new RotateTransform(seat.Value.RotationAngle); seatUC.RenderTransformOrigin = new Point(0.5, 0.5); canvas_Seat.Children.Add(seatUC); Canvas.SetLeft(seatUC, canLeft); Canvas.SetTop(seatUC, canTop); #endregion #region 布局缩略图 Rectangle rec = new Rectangle(); rec.Width = 36 / scaleX; rec.Height = 36 / scaleY; double thumbLeft = (seat.Value.PositionX * 24 + 6) / scaleX; double thumbTop = (seat.Value.PositionY * 24 + 6) / scaleY; if (viewModel.SeatLayoutList[seat.Key].IsStop || viewModel.SeatLayoutList[seat.Key].IsUsing) { rec.Fill = new SolidColorBrush(Color.FromRgb(234, 38, 52)); } else { rec.Fill = new SolidColorBrush(Color.FromRgb(220, 220, 220)); } rec.RenderTransformOrigin = new Point(0.5, 0.5); rec.RenderTransform = new RotateTransform(seat.Value.RotationAngle); canvas_Thumbnail.Children.Add(rec); Panel.SetZIndex(rec, 0); Canvas.SetLeft(rec, thumbLeft + moveX); Canvas.SetTop(rec, thumbTop + moveY); #endregion } #endregion #region 布局备注 foreach (Note note in viewModel.Layout.Notes) { #region 实际图 ViewModel.NoteUC_ViewModel noteVM = new ViewModel.NoteUC_ViewModel(); noteVM.Notes = note.Remark; noteVM.NoteType = note.Type; UC_Note element = new UC_Note(noteVM); if (note.Type == SeatManage.EnumType.OrnamentType.Table) { element.BorderThickness = new Thickness(1); element.BorderBrush = new SolidColorBrush(Colors.Black); } element.Width = note.BaseWidth * 24; element.Height = note.BaseHeight * 24; element.RenderTransformOrigin = new Point(0.5, 0.5); element.RenderTransform = new RotateTransform(note.RotationAngle); canvas_Seat.Children.Add(element); double canLeft = 24 * note.PositionX; double canTop = 24 * note.PositionY; Canvas.SetLeft(element, canLeft); Canvas.SetTop(element, canTop); #endregion #region 缩略图 switch (note.Type) { case SeatManage.EnumType.OrnamentType.Door: case SeatManage.EnumType.OrnamentType.Steps: break; case SeatManage.EnumType.OrnamentType.Roundtable: case SeatManage.EnumType.OrnamentType.Plant: { Border br = new Border(); br.CornerRadius = new CornerRadius(note.BaseWidth * 12 / scaleX); br.BorderThickness = new Thickness(note.BaseWidth * 12 / scaleX); br.BorderBrush = new SolidColorBrush(Color.FromRgb(231, 186, 100)); double thumbLeft = 24 / scaleX * note.PositionX; double thumbTop = 24 / scaleY * note.PositionY; canvas_Thumbnail.Children.Add(br); Canvas.SetLeft(br, thumbLeft + moveX); Canvas.SetTop(br, thumbTop + moveY); } break; default: { Rectangle rec = new Rectangle(); rec.Width = 24 * note.BaseWidth / scaleX; rec.Height = 24 * note.BaseHeight / scaleY; double thumbLeft = 24 / scaleX * note.PositionX; double thumbTop = 24 / scaleY * note.PositionY; rec.RenderTransformOrigin = new Point(0.5, 0.5); rec.RenderTransform = new RotateTransform(note.RotationAngle); rec.Fill = new SolidColorBrush(Color.FromRgb(231, 186, 100)); canvas_Thumbnail.Children.Add(rec); Canvas.SetLeft(rec, thumbLeft + moveX); Canvas.SetTop(rec, thumbTop + moveY); } break; } #endregion } #endregion areaSimle = new Rectangle(); areaSimle.Name = "areaSimle"; if (areaScaleX != 0) { areaSimle.Width = (canvas_Thumbnail.Width - moveX * 2) / areaScaleX;//按比例缩小层的宽度 } else { areaSimle.Width = canvas_Thumbnail.Width; } if (areaScaleY != 0) { areaSimle.Height = (canvas_Thumbnail.Height - moveY * 2) / areaScaleY; //按比例缩小层的高度 } else { areaSimle.Height = canvas_Thumbnail.Height; } areaSimle.Fill = new SolidColorBrush(Colors.White); areaSimle.Opacity = 0.5; canvas_Thumbnail.Children.Add(areaSimle); Panel.SetZIndex(areaSimle, 1000); Canvas.SetTop(areaSimle, moveY); Canvas.SetLeft(areaSimle, moveX); //小的范围层。最后创建,防止被遮盖 }
private void seatLayout_note() { if (SeatCache.NoteList == null) { SeatCache.NoteList = new List <NoteElement>(); } var list = SeatCache.NoteList.Where(p => p.ReadingRoomNum == this.RoomNoStr).ToList(); if (list.Count > 0) { foreach (NoteElement noteElement in list) { this.canvas_Seat.Children.Add(noteElement.noteUC); Canvas.SetLeft(noteElement.noteUC, noteElement.noteLeft); Canvas.SetTop(noteElement.noteUC, noteElement.noteTop); switch (noteElement.noteType) { case SeatManage.EnumType.OrnamentType.Door: case SeatManage.EnumType.OrnamentType.Steps: break; case SeatManage.EnumType.OrnamentType.Roundtable: case SeatManage.EnumType.OrnamentType.Plant: { this.canvas_Thumbnail.Children.Add(noteElement.br); Canvas.SetLeft(noteElement.br, noteElement.recLeft); Canvas.SetTop(noteElement.br, noteElement.recTop); } break; default: { this.canvas_Thumbnail.Children.Add(noteElement.rec); Panel.SetZIndex(noteElement.rec, 0); Canvas.SetLeft(noteElement.rec, noteElement.recLeft); Canvas.SetTop(noteElement.rec, noteElement.recTop); } break; } } } else { #region 布局备注 foreach (Note note in viewModel.Layout.Notes) { #region 实际图 ViewModel.NoteUC_ViewModel noteVM = new ViewModel.NoteUC_ViewModel(); noteVM.Notes = note.Remark; noteVM.NoteType = note.Type; UC_Note element = new UC_Note(noteVM); if (note.Type == SeatManage.EnumType.OrnamentType.Table) { element.BorderThickness = new Thickness(1); element.BorderBrush = new SolidColorBrush(Colors.Black); } element.Width = note.BaseWidth * 24; element.Height = note.BaseHeight * 24; element.RenderTransformOrigin = new Point(0.5, 0.5); element.RenderTransform = new RotateTransform(note.RotationAngle); canvas_Seat.Children.Add(element); double canLeft = 24 * note.PositionX; double canTop = 24 * note.PositionY; Canvas.SetLeft(element, canLeft); Canvas.SetTop(element, canTop); #endregion var noteElement = new NoteElement(); #region 缩略图 switch (note.Type) { case SeatManage.EnumType.OrnamentType.Door: case SeatManage.EnumType.OrnamentType.Steps: break; case SeatManage.EnumType.OrnamentType.Roundtable: case SeatManage.EnumType.OrnamentType.Plant: { Border br = new Border(); br.CornerRadius = new CornerRadius(note.BaseWidth * 12 / scaleX); br.BorderThickness = new Thickness(note.BaseWidth * 12 / scaleX); br.BorderBrush = new SolidColorBrush(Color.FromRgb(231, 186, 100)); double thumbLeft = 24 / scaleX * note.PositionX; double thumbTop = 24 / scaleY * note.PositionY; canvas_Thumbnail.Children.Add(br); Canvas.SetLeft(br, thumbLeft + moveX); Canvas.SetTop(br, thumbTop + moveY); noteElement.br = br; noteElement.recLeft = (float)(thumbLeft + moveX); noteElement.recTop = (float)(thumbTop + moveY); } break; default: { Rectangle rec = new Rectangle(); rec.Width = 24 * note.BaseWidth / scaleX; rec.Height = 24 * note.BaseHeight / scaleY; double thumbLeft = 24 / scaleX * note.PositionX; double thumbTop = 24 / scaleY * note.PositionY; rec.RenderTransformOrigin = new Point(0.5, 0.5); rec.RenderTransform = new RotateTransform(note.RotationAngle); rec.Fill = new SolidColorBrush(Color.FromRgb(231, 186, 100)); canvas_Thumbnail.Children.Add(rec); Canvas.SetLeft(rec, thumbLeft + moveX); Canvas.SetTop(rec, thumbTop + moveY); noteElement.rec = rec; noteElement.recLeft = (float)(thumbLeft + moveX); noteElement.recTop = (float)(thumbTop + moveY); } break; } noteElement.noteLeft = (float)canLeft; noteElement.noteTop = (float)canTop; noteElement.noteUC = element; noteElement.ReadingRoomNum = RoomNoStr; SeatCache.NoteList.Add(noteElement); #endregion } #endregion } }