Example #1
0
        private void viewArchiveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var manageRentalRecords = new ManageRentalRecords();

            manageRentalRecords.MdiParent = this;
            manageRentalRecords.Show();
        }
        private void btnCancel_Click(object sender, EventArgs e)
        {
            var manageRentalRecords = new ManageRentalRecords();

            manageRentalRecords.Show();
            this.Close();
        }
Example #3
0
 private void viewArchiveToolStripMenuItem_Click_1(object sender, EventArgs e)
 {
     if (!Utils.FormIsOpen("ManageVehicleListing"))
     {
         var manageRentalRecords = new ManageRentalRecords();
         manageRentalRecords.MdiParent = this;
         manageRentalRecords.Show();
     }
 }
        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);
            }
        }