//will not be called if action is cancelled -- only if a save occurs
        private void closeForm()
        {
            VehiclesForm vehiclesForm = (VehiclesForm)parentForm;

            vehiclesForm.ReloadVehicles();

            this.Close();
        }
Esempio n. 2
0
        public TransactionForm(Vehicle vehicle, VehiclesForm parentForm)
        {
            InitializeComponent();

            this.parentForm     = parentForm;
            this.currentVehicle = vehicle;
            initializePromotions();

            //when promotion changes, final price should be re-evaluated
            this.promotionComboBox.SelectedValueChanged += new System.EventHandler(applyPromotion);

            //save the default x position and num of digits of the price labels. we'll be moving them back and forth
            defaultLabelPosition = fullPriceValueLabel.Location.X;

            fullPriceValueLabel.Text = "$" + currentVehicle.price.ToString();
            applyPromotion();
        }
        //confirm that we're ready to save the Vehicle we're editing/adding
        private void confirmButton_Click(object sender, EventArgs e)
        {
            decimal price;

            try
            {
                price = Decimal.Parse(priceTextBox.Text.ToString());

                if (price > 0)
                {
                    //if adding
                    if (mode == ADD_VEHICLE)
                    {
                        //create the Vehicle object
                        Vehicle vehicle = new Vehicle();
                        vehicle.Model = (Model)modelDropDown.SelectedItem;
                        vehicle.sold  = soldCheckBox.Checked;
                        vehicle.used  = usedCheckBox.Checked;
                        vehicle.year  = DateUtil.HandleYearString(yearTextBox.Text.ToString());
                        vehicle.price = price;

                        //check that the user hasn't entered an invalid year
                        if (vehicle.year != DateUtil.INVALID_YEAR)
                        {
                            //save the vehicle
                            VehicleDAO.AddVehicle(vehicle);

                            //add the new vehicle to the list so it shows when the user goes back to the VehiclesForm
                            VehiclesForm vehiclesForm = (VehiclesForm)parentForm;
                            vehiclesForm.vehicles.Add(vehicle);

                            closeForm();
                        }
                        else
                        {
                            //if the date is invalid, ask the user to enter it again without saving the vehicle
                            MessageBox.Show("Please enter a valid year", "Invalid Year Value", MessageBoxButtons.OK);
                        }
                    }
                    else if (mode == EDIT_VEHICLE)
                    {
                        //reassign all of the fields of the current Vehicle object with the information the user entered
                        CurrentVehicle.Model = (Model)modelDropDown.SelectedItem;
                        CurrentVehicle.sold  = soldCheckBox.Checked;
                        CurrentVehicle.used  = usedCheckBox.Checked;
                        CurrentVehicle.year  = DateUtil.HandleYearString(yearTextBox.Text.ToString());
                        CurrentVehicle.price = price;

                        //make sure an invalid year isn't entered
                        if (CurrentVehicle.year != DateUtil.INVALID_YEAR)
                        {
                            //update the vehicle in the database
                            VehicleDAO.EditVehicle(CurrentVehicle);
                            closeForm();
                        }
                        else
                        {
                            //if the date is invalid, ask the user to enter it again without saving the vehicle
                            MessageBox.Show("Please enter a valid year", "Invalid Year Value", MessageBoxButtons.OK);
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid Price", "Invalid Price", MessageBoxButtons.OK);
                }
            }
            catch
            {
                MessageBox.Show("Invalid Input", "Invalid Input", MessageBoxButtons.OK);
            }
        }
Esempio n. 4
0
        //load the vehicles form
        private void vehiclesButton_Click(object sender, EventArgs e)
        {
            VehiclesForm vehiclesForm = new VehiclesForm();

            vehiclesForm.Show();
        }