Exemple #1
0
        /// <summary>
        /// method to move building displayed on the panel
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void pnlDraw_MouseMove(object sender, MouseEventArgs e)
        {
            // set last position to current position
            lastPosition = currentPosition;
            // set current position to mouse position
            currentPosition = new Point(e.X, e.Y);
            // calculate how far mouse has moved
            int xMove = currentPosition.X - lastPosition.X;
            int yMove = currentPosition.Y - lastPosition.Y;

            if (!dragging) // mouse not down
            {
                // reset variables
                selectBuilding = null;
                bool needsDisplay = false;

                // create arrayList of shaapes from myModel
                ArrayList theBuildingList = myModel.BuildingList;
                // create array of shapes from array list
                Base[] theBuildings = (Base[])theBuildingList.ToArray(typeof(Base));
                // graphics object to draw shapes when required
                Graphics g = this.pnlDraw.CreateGraphics();

                // loop through array checking if mouse is over shape
                foreach (Base b in theBuildings)
                {
                    // check if mouse is over shape
                    if (b.HitTest(new Point(e.X, e.Y)))
                    {
                        // if so make shape topShape
                        selectBuilding = b;
                    }

                    if (b.Highlight == true)
                    {
                        // shape to be redrawn
                        needsDisplay = true;
                        // redraw shape
                        b.Display(g);
                        b.Highlight = false;
                    }
                }

                if (selectBuilding != null)    // if there is a building
                {
                    needsDisplay = true;       // need to redisplay
                    selectBuilding.Display(g); // redisplay topShape
                    selectBuilding.Highlight = true;
                }

                if (needsDisplay)
                {
                    // redisplay model
                    myModel.UpdateViews();
                }
            }
            else // mouse is down
            {
                // reset position of selected shape by value of mouse move
                selectBuilding.X_pos = selectBuilding.X_pos + xMove;
                selectBuilding.Y_pos = selectBuilding.Y_pos + yMove;
                edit();
                myModel.UpdateViews();
            }
        }
Exemple #2
0
        /// <summary>
        /// updates the selected building with new data
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            int    nX, nY;
            string nName;

            if (string.IsNullOrWhiteSpace(txtName.Text) || string.IsNullOrWhiteSpace(txtX.Text) || string.IsNullOrWhiteSpace(txtY.Text))
            {
                MessageBox.Show("Textboxes cannot be empty", "Missing Data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            if (!rbMall.Checked && !rbShop.Checked && !rbTrainStation.Checked)
            {
                MessageBox.Show("Building Type must be selected.", "No Building Type Selected.", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
            else
            {
                Base selectedBuilding = (MVCPseudoGPS.Base)editBuilding;
                if (selectedBuilding.Type == "Shop")
                {
                    if (!Double.TryParse(txtValue.Text, out double parse))
                    {
                        MessageBox.Show("Capacity is limited to Integer's only", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        double nRating = Convert.ToDouble(txtValue.Text);
                        Shop   sB      = (MVCPseudoGPS.Shop)editBuilding;
                        if (nRating > 10.0 || nRating < 0.0)
                        {
                            MessageBox.Show("Rating must be between 0.0 - 10.0", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            sB.Rating = nRating;
                        }
                    }
                }
                else if (selectedBuilding.Type == "Mall")
                {
                    if (!int.TryParse(txtValue.Text, out int parse))
                    {
                        MessageBox.Show("Capacity is limited to Integer's only", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                    else
                    {
                        int  nCapacity = Convert.ToInt32(txtValue.Text);
                        Mall sB        = (MVCPseudoGPS.Mall)editBuilding;
                        if (nCapacity < 0)
                        {
                            MessageBox.Show("Capacity cannot be less than 0", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            sB.Capacity = nCapacity;
                        }
                    }
                }
                else if (selectedBuilding.Type == "Train Station")
                {
                    string       nLine = txtValue.Text;
                    TrainStation sB    = (MVCPseudoGPS.TrainStation)editBuilding;
                    sB.Line = nLine;
                }
                else
                {
                    MessageBox.Show("Wait, What this error shouldn't happen?", "Building Type doesn't Exist", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }

                nX    = Convert.ToInt32(txtX.Text);
                nY    = Convert.ToInt32(txtY.Text);
                nName = txtName.Text;

                if (nX > max_x)
                {
                    MessageBox.Show("X value cannot be greater than " + max_x, "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (nX < 0)
                {
                    MessageBox.Show("X value cannot be less than 0", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (nY > max_y)
                {
                    MessageBox.Show("Y value cannot be greater than " + max_y, "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else if (nY < 0)
                {
                    MessageBox.Show("Y value cannot be less than 0", "Invalid Input", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    selectedBuilding.X_pos = nX;
                    selectedBuilding.Y_pos = nY;
                    selectedBuilding.Name  = nName;
                }
            }

            myModel.UpdateViews();
        }