예제 #1
0
        private SeatForm()
        {
            _MyImageBrush = SeatFormImageBrush.GetInstance(clientobject.ClientSetting.DeviceSetting.BackImgage);

            InitializeComponent();
            frmResolution    = FromResolution.GetFrmResolution(clientobject.ClientSetting.DeviceSetting.SystemResoultion.WindowSize.Size.X);
            this.DataContext = frmResolution;
            InitialControlBackground();
        }
        void seatLayout()
        {
            this.canvas_Thumbnail.Children.Clear();
            this.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;
            double areaScaleX = SeatWidth / SeatWindow.Width;
            double areaScaleY = SeatHeight / SeatWindow.Height;

            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;
            }
            //scaleX = SeatWidth / canvas_Thumbnail.Width;
            //scaleY = SeatHeight / canvas_Thumbnail.Height;

            try
            {
                Canvas.SetLeft(canvas_Seat, 0);
                Canvas.SetTop(canvas_Seat, 0);
            }
            catch
            { }

            #region 布局座位
            Code.GetSeatNoteImage getImage = new GetSeatNoteImage();
            ReadingRoomInfo       roomInfo = viewModel.clientObject.EnterOutLogData.Student.AtReadingRoom;
            DateTime startTime             = DateTime.Now;
            foreach (Seat seat in viewModel.Layout.Seats.Values)
            {
                seat.ShortSeatNo = SeatComm.SeatNoToShortSeatNo(roomInfo.Setting.SeatNumAmount, seat.SeatNo);
                #region 布局实际图,
                double     canLeft = 24 * (double)seat.PositionX;
                double     canTop  = 24 * (double)seat.PositionY;
                SeatButton seatBtn = new SeatButton();
                seatBtn.Width       = 48;
                seatBtn.Height      = 48;
                seatBtn.ShortSeatNo = seat.ShortSeatNo;
                seatBtn.SeatNo      = seat.SeatNo;
                seatBtn.Background  = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgSeat;
                if (seat.HavePower)
                {
                    seatBtn.PowerImg = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgPower;
                }
                switch (seat.SeatUsedState)
                {
                case SeatManage.EnumType.EnterOutLogType.Leave:
                    if (seat.IsSuspended)
                    {
                        seatBtn.ReaderBackground = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgStopUse;
                        viewModel.AllSeatCount  -= 1;
                    }
                    else
                    {
                        seatBtn.MouseLeftButtonUp   += new MouseButtonEventHandler(seatBtn_MouseLeftButtonUp);
                        viewModel.LastSeatCount     += 1;
                        seatBtn.lblSeatNo.Visibility = System.Windows.Visibility.Visible;
                    }
                    //frmResolution.ViewModel.SeatAmcountFree += 1;//遇到空闲座位,ViewModel空闲座位数+1
                    //seatBtn.MouseLeftButtonUp += new MouseButtonEventHandler(seatBtn_MouseLeftButtonUp);
                    break;

                case SeatManage.EnumType.EnterOutLogType.SelectSeat:
                case SeatManage.EnumType.EnterOutLogType.ReselectSeat:
                case SeatManage.EnumType.EnterOutLogType.ComeBack:
                case SeatManage.EnumType.EnterOutLogType.ContinuedTime:
                case SeatManage.EnumType.EnterOutLogType.BookingConfirmation:
                case SeatManage.EnumType.EnterOutLogType.WaitingSuccess:
                    seatBtn.ReaderBackground = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgReader;
                    if (roomInfo.Setting.NoManagement.Used)
                    {
                        seatBtn.MouseLeftButtonUp += new MouseButtonEventHandler(seatBtn_WaitSeat);
                    }
                    break;

                case SeatManage.EnumType.EnterOutLogType.ShortLeave:
                    seatBtn.ReaderBackground = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgReader;
                    seatBtn.ShowleaveImg     = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgShortLeave;
                    break;

                case SeatManage.EnumType.EnterOutLogType.BespeakWaiting:
                    seatBtn.ReaderBackground = SeatFormImageBrush.GetInstance(viewModel.clientObject.ClientSetting.DeviceSetting.BackImgage).ImgBook;
                    if (roomInfo.Setting.SeatBespeak.SelectBespeakSeat)
                    {
                        seatBtn.MouseLeftButtonUp += new MouseButtonEventHandler(seatBtn_SelectBookingSeat);
                    }
                    break;
                }
                seatBtn.lblSeatNo.RenderTransform       = new RotateTransform(-seat.RotationAngle);
                seatBtn.lblSeatNo.RenderTransformOrigin = new Point(0.5, 0.5);
                seatBtn.RenderTransform       = new RotateTransform(seat.RotationAngle);
                seatBtn.RenderTransformOrigin = new Point(0.5, 0.5);
                this.canvas_Seat.Children.Add(seatBtn);
                Canvas.SetLeft(seatBtn, canLeft);
                Canvas.SetTop(seatBtn, canTop);
                #endregion

                #region 布局缩略图
                Rectangle rec = new Rectangle();
                rec.Width  = 36 / scaleX;
                rec.Height = 36 / scaleY;
                double thumbLeft = (double)(seat.PositionX * (double)24 + 6) / scaleX;
                double thumbTop  = (double)(seat.PositionY * (double)24 + 6) / scaleY;
                switch (seat.SeatUsedState)
                {
                case SeatManage.EnumType.EnterOutLogType.Leave:
                    rec.Fill = new SolidColorBrush(Color.FromRgb(220, 220, 220));
                    if (seat.IsSuspended)
                    {
                        rec.Fill = new SolidColorBrush(Color.FromRgb(234, 38, 52));
                    }
                    break;

                case SeatManage.EnumType.EnterOutLogType.SelectSeat:
                case SeatManage.EnumType.EnterOutLogType.ReselectSeat:
                case SeatManage.EnumType.EnterOutLogType.ComeBack:
                case SeatManage.EnumType.EnterOutLogType.ContinuedTime:
                case SeatManage.EnumType.EnterOutLogType.ShortLeave:
                case SeatManage.EnumType.EnterOutLogType.BespeakWaiting:
                case SeatManage.EnumType.EnterOutLogType.BookingConfirmation:
                case SeatManage.EnumType.EnterOutLogType.WaitingSuccess:
                    rec.Fill = new SolidColorBrush(Color.FromRgb(234, 38, 52));
                    break;
                }
                rec.RenderTransformOrigin = new Point(0.5, 0.5);
                rec.RenderTransform       = new RotateTransform(seat.RotationAngle);
                this.canvas_Thumbnail.Children.Add(rec);
                Canvas.SetZIndex(rec, 0);
                Canvas.SetLeft(rec, thumbLeft + moveX);
                Canvas.SetTop(rec, thumbTop + moveY);
                #endregion
            }
            TimeSpan ts = DateTime.Now - startTime;
            Console.WriteLine("执行时间:" + ts.TotalSeconds);
            //frmResolution.ViewModel.SeatAmcountUsed = frmResolution.ViewModel.SeatAmcountAll - frmResolution.ViewModel.SeatAmcountFree;
            #endregion

            #region 布局备注
            foreach (Note note in viewModel.Layout.Notes)
            {
                #region 实际图

                NoteElement element = new NoteElement();
                if (note.Type == SeatManage.EnumType.OrnamentType.Table)
                {
                    element.BorderThickness = new Thickness(1);
                    element.BorderBrush     = new SolidColorBrush(Colors.Black);
                }
                //element.BorderThickness = new Thickness(1);
                //element.BorderBrush = new SolidColorBrush(Colors.Yellow);
                element.Width  = note.BaseWidth * 24;
                element.Height = note.BaseHeight * 24;
                element.Notes  = note.Remark;
                element.RenderTransformOrigin = new Point(0.5, 0.5);
                element.RenderTransform       = new RotateTransform(note.RotationAngle);
                element.NoteType = note.Type;
                Canvas.SetLeft(element.lbRemark, element.Width / 2 - element.lbRemark.Width / 2);
                this.canvas_Seat.Children.Add(element);
                double canLeft = 24 * (double)note.PositionX;
                double canTop  = 24 * (double)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 * (double)12 / scaleX);
                    br.BorderThickness = new Thickness(note.BaseWidth * (double)12 / scaleX);
                    br.BorderBrush     = new SolidColorBrush(Color.FromRgb(231, 186, 100));
                    double thumbLeft = (double)(24 / scaleX) * (double)note.PositionX;
                    double thumbTop  = (double)(24 / scaleY) * (double)note.PositionY;
                    this.canvas_Thumbnail.Children.Add(br);
                    Canvas.SetLeft(br, thumbLeft + moveX);
                    Canvas.SetTop(br, thumbTop + moveY);
                }
                break;

                default:
                {
                    Rectangle rec = new Rectangle();
                    rec.Width  = (double)24 * note.BaseWidth / scaleX;
                    rec.Height = (double)24 * note.BaseHeight / scaleY;
                    double thumbLeft = (double)(24 / scaleX) * (double)note.PositionX;
                    double thumbTop  = (double)(24 / scaleY) * (double)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));
                    this.canvas_Thumbnail.Children.Add(rec);
                    Canvas.SetLeft(rec, thumbLeft + moveX);
                    Canvas.SetTop(rec, thumbTop + moveY);
                }
                break;
                }

                #endregion
            }
            #endregion


            areaSimle      = new System.Windows.Shapes.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;

            this.canvas_Thumbnail.Children.Add(areaSimle);
            Canvas.SetZIndex(areaSimle, 1000);
            Canvas.SetTop(areaSimle, moveY);
            Canvas.SetLeft(areaSimle, moveX);
            //小的范围层。最后创建,防止被遮盖
        }