Пример #1
0
        private void addRentalRecordToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var addRentalRecord = new AddEditRentalRecord();

            addRentalRecord.ShowDialog();
            addRentalRecord.MdiParent = this;
        }
Пример #2
0
        private void addRecord_btn_Click(object sender, EventArgs e)
        {
            var addRentalRecord = new AddEditRentalRecord();

            addRentalRecord.MdiParent = this.MdiParent;
            addRentalRecord.Show();
        }
Пример #3
0
        private void btn_EditCar_Click(object sender, EventArgs e)
        {
            try
            {
                if (!Utils.FormIsOpen("AddEditRentalRecord"))
                {
                    // get id
                    //We expect Int here (data type from database column). otherwise use var./ need casting
                    int id = (int)dGV_RecordList.SelectedRows[0].Cells["Id"].Value;
                    //query
                    var record = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);

                    // launch addeditvehicle window with data

                    var addEditRentalRecord = new AddEditRentalRecord(record, this)
                    {
                        MdiParent = this.MdiParent
                    };
                    addEditRentalRecord.Show();
                }
            }
            catch (Exception)
            {
                MessageBox.Show("You Have to select a whole row in order to edit", "Error");
            }
        }
Пример #4
0
        private void btnAddRecord_Click(object sender, EventArgs e)
        {
            var form = new AddEditRentalRecord(this);

            form.MdiParent = this.MdiParent;
            form.Show();
        }
Пример #5
0
 private void addRentalRecordToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (!Utils.FormIsOpen("AddEditRentalRecord"))
     {
         var addRentalRecord = new AddEditRentalRecord();
         addRentalRecord.MdiParent = this;
         addRentalRecord.Show();
     }
 }
Пример #6
0
 private void btnAddRecord_Click(object sender, EventArgs e)
 {
     if (!Utils.FormIsOpen("AddEditRentalRecord"))
     {
         var addRentalRecord = new AddEditRentalRecord(this);
         addRentalRecord.MdiParent = this.MdiParent;
         addRentalRecord.Show();
     }
 }
Пример #7
0
        //Launching Window Once Add Rental Tab is Clicked.
        private void addRentalRecordToolStripMenuItem_Click_1(object sender, EventArgs e)
        {
            var addRentalRecord = new AddEditRentalRecord();

            addRentalRecord.ShowDialog();
            //this = class being referred to "addrentalrecords class"
            addRentalRecord.MdiParent = this;
            //launches ford after click
        }
        private void btnAddRecord_Click(object sender, EventArgs e)
        {
            var addRentalRecord = new AddEditRentalRecord
            {
                MdiParent = this.MdiParent
            };

            addRentalRecord.Show();
            this.Close();
        }
Пример #9
0
        private void btn_AddCar_Click(object sender, EventArgs e)
        {
            var  OpenForms = Application.OpenForms.Cast <Form>();
            bool isOpen    = OpenForms.Any(q => q.Name == "AddEditRentalRecord");

            if (!Utils.FormIsOpen("AddEditRentalRecord"))
            {
                AddEditRentalRecord addEditRentalRecord = new AddEditRentalRecord(this);
                addEditRentalRecord.MdiParent = this.MdiParent;
                addEditRentalRecord.Show();
            }
        }
Пример #10
0
 private void btnEditRecord_Click(object sender, EventArgs e)
 {
     try
     {
         var id     = (int)dgvRentalRecords.SelectedRows[0].Cells["id"].Value;
         var record = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);
         var form   = new AddEditRentalRecord(record, this);
         form.MdiParent = this.MdiParent;
         form.Show();
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
        private void btnEditRecord_Click(object sender, EventArgs e)
        {
            try
            {
                //get ID of selected Row
                var id = (int)dgvRecordList.SelectedRows[0].Cells["Id"].Value;

                //query database for record
                var record = db.CarRentalRecords.FirstOrDefault(q => q.id == id);

                //launch AddEditVehicle window with data
                var addEditRentalRecord = new AddEditRentalRecord(record);
                addEditRentalRecord.MdiParent = this.MdiParent;
                addEditRentalRecord.Show();
                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }
Пример #12
0
        private void editRecord_btn_Click(object sender, EventArgs e)
        {
            try
            {
                //Obtain id for row to be edited
                //Cast to integer
                var Id = (int)RecordList_gv.SelectedRows[0].Cells["id"].Value;

                //Query database for records
                var record
                    = carRentalEntities.CarRentalRecords.FirstOrDefault(q => q.ID == Id);

                //Launch window to edit data retrieved
                var addEditRentalRecord = new AddEditRentalRecord(record);
                addEditRentalRecord.MdiParent = this.MdiParent;
                addEditRentalRecord.Show();
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }
Пример #13
0
        private void btnEditRecord_Click(object sender, EventArgs e)
        {
            try
            {
                // get Id of selected row
                var id = (int)gvRecordList.SelectedRows[0].Cells["Id"].Value;

                //query database for record
                var record = _db.CarRentalRecords.FirstOrDefault(q => q.id == id);

                if (!Utils.FormIsOpen("AddEditRentalRecord"))
                {
                    var addEditRentalRecord = new AddEditRentalRecord(record, this);
                    addEditRentalRecord.MdiParent = this.MdiParent;
                    addEditRentalRecord.Show();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Error: {ex.Message}");
            }
        }
        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);
            }
        }