private void Click_SubmitButton(object sender, RoutedEventArgs e)
        {
            //get combobox
            var comboBoxState = boxState as ComboBox;

            //set selected value to string
            string stateSelected = comboBoxState.SelectedItem as string;

            try
            {
                locationModel.NewLocation = new Location()
                {
                    City       = txtCity.Text,
                    CityRating = int.Parse(txtRating.Text),
                    Notes      = txtNotes.Text,
                };
                var stateID = statesModel.AllStates.Where(x => x.State == stateSelected);
                foreach (var item in stateID)
                {
                    locationModel.NewLocation.StateId = item.StateID;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("The rating must be a single, valid number", "Error", MessageBoxButton.OK);
                return;
            }

            if (string.IsNullOrEmpty(txtCity.Text) || string.IsNullOrEmpty(txtRating.Text) || stateSelected is null)
            {
                MessageBox.Show("You must have City, State, and Rating all filled out in order to submit", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }

            SQLConnections sqlConnection = new SQLConnections();

            sqlConnection.AddLocation(locationModel.NewLocation);


            MessageBoxResult result = MessageBox.Show("Location added!", "Success", MessageBoxButton.OKCancel, MessageBoxImage.None);

            if (result == MessageBoxResult.OK)
            {
                //clear text boxes

                canceledMessage.Visibility = Visibility.Hidden;
                txtCity.Clear();
                boxState.SelectedItem = null;
                txtRating.Clear();
                txtNotes.Clear();
                boxState.SelectedItem = null;
            }
            else
            {
                sqlConnection.DeleteLastLocationRecord();
                canceledMessage.Visibility = Visibility.Visible;
            }
        }
예제 #2
0
        private void Click_SubmitButton(object sender, RoutedEventArgs e)
        {
            //get combobox
            var comboBoxState = boxState as ComboBox;

            //set selected value to string
            string stateSelected = comboBoxState.SelectedItem as string;

            //get int value for stateID
            int stateIDValue = GetStateID(stateSelected);

            try
            {
                LocationInfo.City    = txtCity.Text;
                LocationInfo.StateID = stateIDValue;
                LocationInfo.Rating  = int.Parse(txtRating.Text);
                LocationInfo.Notes   = txtNotes.Text;
            }
            catch (FormatException)
            {
                MessageBox.Show("Rating must be a number", "Error", MessageBoxButton.OK, MessageBoxImage.None);
                return;
            }
            if (string.IsNullOrEmpty(txtCity.Text) || string.IsNullOrEmpty(txtNotes.Text) || string.IsNullOrEmpty(txtRating.Text) || stateSelected is null)
            {
                MessageBox.Show("You must have City, State, and Rating all filled out in order to submit", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                return;
            }
            SQLConnections sqlConnection = new SQLConnections();

            sqlConnection.AddLocation();
            MessageBoxResult result = MessageBox.Show("Location added!", "Success", MessageBoxButton.OKCancel, MessageBoxImage.None);

            if (result == MessageBoxResult.OK)
            {
                //clear text boxes
                canceledMessage.Visibility = Visibility.Hidden;
                txtCity.Clear();
                boxState.SelectedItem = null;
                txtRating.Clear();
                txtNotes.Clear();
                boxState.SelectedItem = null;
            }
            else
            {
                sqlConnection.DeleteLastLocationRecord();
                canceledMessage.Visibility = Visibility.Visible;
            }
        }