Exemplo n.º 1
0
        private void GenerateMapZoom1Khu(int khu = 1, 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> > >();
            khu--;
            {
                // Khởi tạo các biến số khu hàng, wrapPanel
                KhuHang   khuHang   = khoHang.getKhu(khu);
                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(khu + 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;

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

                stackPanel.Children.Add(wrapPanel);
                stackPanel.HorizontalAlignment = HorizontalAlignment.Center;
                stackPanel.VerticalAlignment   = VerticalAlignment.Center;
                buttonList.Add(button_list);
                currentWrapPanel = wrapPanel;
                currentAngle     = khuHang.getAngle();
                sldZoom.Value    = 50;
                wrapPanel.Children.Add(khuHangName);
            }
            drawArea.Content = stackPanel;
            drawArea.Loaded += Page_Loaded;
        }