Ejemplo n.º 1
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (Valid())
            {
                RefillBl refillBl = new RefillBl();

                //Close  previous refill
                if (Id == 0 && RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())) != null)
                {
                    refillBl.SetClosed(RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())));
                }
                try
                {
                    refillBl.Save(Id, DateTime.Parse(dateTimePicker.Text), int.Parse(vehicleComboBox.SelectedValue.ToString()), decimal.Parse(amountTextBox.Text), double.Parse(litreageTextBox.Text), decimal.Parse(mileageTextBox.Text));

                    dateTimePicker.Text = DateTime.Today.ToString();
                    amountTextBox.Text  = mileageTextBox.Text = litreageTextBox.Text = "";
                    Id = 0;
                }
                catch (Exception ex) { MessageBox.Show("Error occured: " + ex.Message); }

                RefreshGrid();
                NewVehicleCompobox();
            }
        }
Ejemplo n.º 2
0
        private void saveButton_Click(object sender, EventArgs e)
        {
            if (Valid())
            {
                TripBl tripBl = new TripBl();

                try
                {
                    tripBl.Save(Id, DateTime.Parse(startDateDateTimePicker.Text + " " + startTimeDateTimePicker.Text), DateTime.Parse(endDateDateTimePicker.Text + " " + endTimeDateTimePicker.Text), int.Parse(vehicleComboBox.SelectedValue.ToString()), int.Parse(driverComboBox.SelectedValue.ToString()), RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())).Id, decimal.Parse(mileageStartTextBox.Text), decimal.Parse(mileageEndTextBox.Text), tripDetailsRichTextBox.Text, expenseAccountTextBox.Text);

                    startDateDateTimePicker.Text = startTimeDateTimePicker.Text = endDateDateTimePicker.Text = endTimeDateTimePicker.Text = DateTime.Now.ToString();
                    mileageStartTextBox.Text     = mileageEndTextBox.Text = tripDetailsRichTextBox.Text = expenseAccountTextBox.Text = "";
                    Id = 0;
                }
                catch
                {
                    MessageBox.Show("Trip not saved, make sure you add a fuel refill for this vehicle. ");
                }
                RefreshGrid();
                NewDriverCompobox();
                NewVehicleCompobox();
            }
        }
Ejemplo n.º 3
0
        public bool  Valid()
        {
            if (String.IsNullOrEmpty(mileageTextBox.Text) ||
                String.IsNullOrWhiteSpace(mileageTextBox.Text) ||
                !Utility.IsNumber(mileageTextBox.Text)
                )
            {
                MessageBox.Show("Invalid value for mileage");
                mileageTextBox.Focus();
                return(false);
            }

            if (Id == 0 && TripBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())) != null && TripBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())).MileageEnd > decimal.Parse(mileageTextBox.Text))
            {
                MessageBox.Show("This vehicle is already above the mileage given.");
                mileageTextBox.Focus();
                return(false);
            }

            if (Id > 0 && RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString()), Id) != null && RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString()), Id).Mileage > decimal.Parse(mileageTextBox.Text))
            {
                MessageBox.Show("This vehicle was already above the mileage given.");
                mileageTextBox.Focus();
                return(false);
            }

            if (String.IsNullOrEmpty(litreageTextBox.Text) ||
                String.IsNullOrWhiteSpace(litreageTextBox.Text) ||
                !Utility.IsNumber(litreageTextBox.Text)
                )
            {
                MessageBox.Show("Invalid value for litreage");
                litreageTextBox.Focus();
                return(false);
            }

            if (String.IsNullOrEmpty(amountTextBox.Text) ||
                String.IsNullOrWhiteSpace(amountTextBox.Text) ||
                !Utility.IsNumber(amountTextBox.Text)
                )
            {
                MessageBox.Show("Invalid value for amount");
                amountTextBox.Focus();
                return(false);
            }

            if (RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString()), Id) != null && DateTime.Parse(dateTimePicker.Text) < RefillBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString()), Id).DateAndTime)
            {
                MessageBox.Show("Date can not be before the previous refill for this vehicle");
                dateTimePicker.Focus();
                return(false);
            }

            if (TripBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())) != null && DateTime.Parse(dateTimePicker.Text).Date < TripBl.GetPrevious(int.Parse(vehicleComboBox.SelectedValue.ToString())).DateTimeEnd.Date)
            {
                MessageBox.Show("Date can not be before the previous last trip for this vehicle");
                dateTimePicker.Focus();
                return(false);
            }



            return(true);
        }