예제 #1
0
        /// <summary>
        /// Add the station to the data
        /// </summary>
        /// <param name="sender">sender of the event</param>
        /// <param name="e">e of the argument</param>
        private void Add_Station(object sender, RoutedEventArgs e)
        {
            int    code;
            string message = "";

            if (!int.TryParse(CodeTB.Text, out code) || NameTB.Text == "") // when some data is missing / Invalid jumping massage to the user and asking it
            {
                if (!int.TryParse(CodeTB.Text, out code))
                {
                    message = "Please enter station's code!\n";
                }
                if (NameTB.Text == "")
                {
                    message += "Please enter station's name!";
                }
                MessageBox.Show(message, "Invalid input", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                try
                {
                    bl.AddBusStation(
                        new BO.BusStation()
                    {
                        Code           = code,
                        Name           = NameTB.Text,
                        Position       = new GeoCoordinate(Pin.Location.Latitude, Pin.Location.Longitude),
                        LinesInstation = Enumerable.Empty <BO.Line>()
                    }
                        );
                    this.Close();
                }
                catch (BO.StationExists ex) // the Station already exists
                {
                    MessageBox.Show(ex.Message + string.Format(" Please choose different code than {0}", ex.Code), "Object already exists", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }