Beispiel #1
0
 // Tạo menu phóng to gồm các khu hàng và gán sự kiện cho các menu
 public void GenerateZoomMenu()
 {
     for (int i = 0; i < khoHang.getSoLuongKhu(); i++)
     {
         MenuItem zoom_khu_i = new MenuItem();
         zoom_khu_i.Header = "Khu hàng " + (i + 1);
         zoom_khu_i.Click += zoom_1kho;
         zoom_Menu.Items.Add(zoom_khu_i);
     }
 }
Beispiel #2
0
        private void GenerateMap(string fileName = "../../../Resources/input.txt")
        {
            // Khởi tạo các biến số kho hàng, stackPanel, buttonList và drawArea
            drawArea.HorizontalScrollBarVisibility = ScrollBarVisibility.Auto;
            drawArea.VerticalScrollBarVisibility   = ScrollBarVisibility.Auto;
            drawArea.Padding       = new Thickness(drawAreaPaddingX, drawAreaPaddingY, drawAreaPaddingX, drawAreaPaddingY);
            khoHang                = new KhoHang(fileName);
            stackPanel             = new StackPanel();
            stackPanel.Orientation = Orientation.Horizontal;
            if (buttonList != null)
            {
                buttonList.Clear();
            }
            buttonList = new List <List <List <KButton> > >();
            int currentPosX = 0;

            for (int k = 0; k < khoHang.getSoLuongKhu(); k++)
            {
                // Khởi tạo các biến số khu hàng, wrapPanel
                KhuHang   khuHang   = khoHang.getKhu(k);
                WrapPanel wrapPanel = new WrapPanel();
                int       row       = khuHang.getNRow();
                int       col       = khuHang.getNCol();
                wrapPanel.Height            = buttonHeight * (row + 1);
                wrapPanel.Width             = buttonWidth * col;
                wrapPanel.VerticalAlignment = VerticalAlignment.Top;
                List <List <KButton> > button_list;

                button_list = new List <List <KButton> >();
                for (int i = 0; i < row; ++i)
                {
                    button_list.Add(new List <KButton>());
                    for (int j = 0; j < col; ++j)
                    {
                        KButton btn = new KButton(k + 1, i, j, khuHang.get(i, j));
                        btn.FontSize         += 10;
                        btn.Height            = buttonHeight;
                        btn.Width             = buttonWidth;
                        btn.Content           = btn.Name;
                        btn.AllowDrop         = true;
                        btn.PreviewMouseMove += Btn_PreviewMouseMove;
                        btn.Drop             += Btn_Drop;
                        btn.MouseDown        += Btn_MouseDown;
                        btn.GotMouseCapture  += Btn_GotMouseCapture;
                        btn.MouseEnter       += Btn_MouseEnter;
                        btn.MouseLeave       += Btn_MouseLeave;
                        btn.upBackGround();
                        button_list[i].Add(btn);
                    }
                }

                // Thiết lập buttonList
                for (int i = 0; i < row; ++i)
                {
                    for (int j = 0; j < col; ++j)
                    {
                        if (j == 0)
                        {
                            button_list[i][j].setLeft(null);
                        }
                        else
                        {
                            button_list[i][j].setLeft(button_list[i][j - 1]);
                        }

                        if (j == col - 1)
                        {
                            button_list[i][j].setRight(null);
                        }
                        else
                        {
                            button_list[i][j].setRight(button_list[i][j + 1]);
                        }
                    }
                }

                for (int i = 0; i < row; i++)
                {
                    for (int j = 0; j < col; j++)
                    {
                        wrapPanel.Children.Add(button_list[i][j]);
                    }
                }

                // Tạo hiệu ứng xoay khu hàng
                RotateTransform rotateTransform = new RotateTransform();
                rotateTransform.Angle     = khuHang.getAngle();
                wrapPanel.LayoutTransform = rotateTransform;

                // Thiết đặt tọa độ cho khu hàng
                wrapPanel.Margin = new Thickness(khuHang.getPosX() * buttonWidth - currentPosX, khuHang.getPosY() * buttonHeight, 0, 0);
                //wrapPanel.Margin = new Thickness(Offset, 0, 0, 0);
                currentPosX = (khuHang.getPosX() + col) * buttonWidth;
                stackPanel.Children.Add(wrapPanel);

                // Thêm tên khu hàng
                Label khuHangName = new Label();
                khuHangName.Height  = buttonHeight;
                khuHangName.Width   = wrapPanel.Width;
                khuHangName.Content = "Khu hàng " + (k + 1).ToString();
                khuHangName.HorizontalContentAlignment = HorizontalAlignment.Center;
                khuHangName.Padding = new Thickness(0);
                wrapPanel.Children.Add(khuHangName);

                buttonList.Add(button_list);
            }
            currentAngle      = 0;
            sldZoom.Value     = 50;
            sldZoom.IsEnabled = true;
            drawArea.Content  = stackPanel;
            drawArea.Loaded  += Page_Loaded;
        }