private void btnCancel_Click(object sender, EventArgs e)
        {
            var manageRentalRecords = new ManageRentalRecords();

            manageRentalRecords.Show();
            this.Close();
        }
예제 #2
0
        private void viewArchiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var manageRentalRecords = new ManageRentalRecords();

            manageRentalRecords.MdiParent = this;
            manageRentalRecords.Show();
        }
예제 #3
0
 public AddEditRentalRecord(ManageRentalRecords manageRentalRecords = null)
 {
     InitializeComponent();
     _db                  = new CarRentalEntities();
     label1.Text          = "Add New Rental Record";
     this.Text            = "Add New Rental";
     isEditMode           = false;
     _manageRentalRecords = manageRentalRecords;
 }
예제 #4
0
 private void viewArchiveToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     if (!Utils.FormIsOpen("ManageVehicleListing"))
     {
         var manageRentalRecords = new ManageRentalRecords();
         manageRentalRecords.MdiParent = this;
         manageRentalRecords.Show();
     }
 }
예제 #5
0
 public AddEditRentalRecord(CarRentalRecord recordToEdit, ManageRentalRecords manageRentalRecords = null)
 {
     InitializeComponent();
     lblTitle.Text = "Edit Rental Record";
     PopulateFields(recordToEdit);
     _manageRentalRecords = manageRentalRecords;
     _db        = new CarRentalEntities();
     isEditMode = true;
 }
예제 #6
0
 public AddEditRentalRecord(CarRentalRecord recordToEdit, ManageRentalRecords manageRentalRecords)
 {
     InitializeComponent();
     label1.Text          = "Edit Vehicle";
     _manageRentalRecords = manageRentalRecords;
     if (recordToEdit == null)
     {
         MessageBox.Show("Please ensure that you selected a valid record");
         Close();
     }
     else
     {
         isEditMode = true;
         _db        = new CarRentalEntities();
         PopulateFields(recordToEdit);
     }
 }
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            try
            {
                string customerName = txtUsername.Text;
                var    dateOut      = dtRented.Value;
                var    dateIn       = dtReturned.Value;
                var    carType      = cboCarType.Text;
                double cost         = Convert.ToDouble(txtCost.Text);
                var    isValid      = true;
                var    errorMessage = "";

                if (string.IsNullOrEmpty(customerName) || string.IsNullOrEmpty(carType))
                {
                    isValid       = false;
                    errorMessage += "Error: Please enter missing data.\n\r";
                }

                if (dateOut > dateIn)
                {
                    isValid       = false;
                    errorMessage += "Error: Illegal Date Selection.\n\r";
                }

                if (isValid)
                {
                    //Declare an object of the record to be added
                    var rentalRecord = new CarRentalRecord();
                    if (isEditMode)
                    {
                        var id = int.Parse(lblRecorId.Text);
                        rentalRecord = db.CarRentalRecords.FirstOrDefault(q => q.id == id);
                    }

                    //populate record object with values from the form
                    rentalRecord.customerName = customerName;
                    rentalRecord.dateRented   = dateOut;
                    rentalRecord.dateReturned = dateIn;
                    rentalRecord.cost         = (decimal)cost;
                    rentalRecord.carID        = (int)cboCarType.SelectedValue;

                    // if not in edit mode, then add the record object to DB
                    if (!isEditMode)
                    {
                        db.CarRentalRecords.Add(rentalRecord);
                    }

                    //Save changes to entity
                    db.SaveChanges();

                    MessageBox.Show("Data Saved Successfully");
                    DialogResult dialogResult = MessageBox.Show("Want to Add new Record?", "New Record", MessageBoxButtons.YesNo);
                    if (dialogResult == DialogResult.Yes)
                    {
                        txtUsername.Text = "";
                        txtUsername.Focus();
                        txtCost.Text = "";
                        var addRentalRecord = new AddEditRentalRecord();
                        addRentalRecord.Show();
                    }
                    else
                    {
                        var manageRentalRecord = new ManageRentalRecords();
                        manageRentalRecord.Show();
                        this.Close();
                    }
                    this.Close();
                }
                else
                {
                    MessageBox.Show(errorMessage);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }