Exemple #1
0
        public ConstructionProgress createNewConstructionProgress(int attractionID, string title, string desc, DateTime?progressDate)
        {
            ConstructionProgressMediator mediator = new ConstructionProgressMediator();
            ConstructionProgress         cp       = new ConstructionProgress();

            cp.progressID   = mediator.getLastID() + 1;
            cp.attractionID = attractionID;
            cp.title        = title;
            cp.description  = desc;
            cp.progressDate = progressDate;

            return(cp);
        }
        private void submitBtn_Click(object sender, RoutedEventArgs e)
        {
            string   attractionIDStr = attractionIDTxt.Text.Trim();
            string   title           = titleTxt.Text.Trim();
            string   desc            = descTxt.Text.Trim();
            DateTime?progressDate    = progressDatePicker.SelectedDate;
            int      attractionID;

            bool success = int.TryParse(attractionIDStr, out attractionID);

            if (!success)
            {
                errorLbl.Text = "TaskID must be a number!";
            }
            else if (title == "" || desc == "" || !progressDate.HasValue)
            {
                errorLbl.Text = "Please input all field!";
            }
            else
            {
                if (new AttractionRideMediator().getAttractionOrRide(attractionID) == null)
                {
                    errorLbl.Text = "Attraction ID invalid!";
                }
                else
                {
                    ConstructionProgressMediator mediator = new ConstructionProgressMediator();
                    ConstructionProgressFactory  factory  = new ConstructionProgressFactory();

                    ConstructionProgress cp = mediator.addConstructionProgress(factory.createNewConstructionProgress(attractionID, title, desc, progressDate));
                    if (cp == null)
                    {
                        MessageBox.Show("Add construction progress failed!");
                    }
                    else
                    {
                        MessageBox.Show("Add construction progress success!");
                    }
                    this.Close();
                }
            }
        }
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            ConstructionProgressMediator mediator = new ConstructionProgressMediator();

            constructionProgressView.ItemsSource = mediator.getAllConstructionProgress();
        }