Esempio n. 1
0
        /// <summary>
        /// Method to cancel booking
        /// </summary>
        /// <param name="practitionerID"></param>
        private void CancelBooking(int practitionerID)
        {
            // make sure a booking is selected
            if (dataGridViewPractitionerBookings.SelectedRows.Count != 1)
            {
                MessageBox.Show("One Booking needs to be selected to perform cancellation");
                return;
            }

            // get booking date and time
            string date = (string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[4].Value;
            string time = (string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[3].Value;
            // create date object
            DateTime bookingDate = DateTime.ParseExact(date + " " + time, "yyyy-MM-dd HH:mm", null);

            // if the date is in the past date display error message
            if (DateTime.Now > bookingDate)
            {
                MessageBox.Show("Cannot cancel past bookings!");
                return;
            }

            // get the bookingID
            int bookingID = Convert.ToInt32(dataGridViewPractitionerBookings.SelectedRows[0].Cells[0].Value);

            // if a booking is paid
            if ((string)dataGridViewPractitionerBookings.SelectedRows[0].Cells[6].Value == BookingStatus.PAID.ToString())
            {
                // using unit of work
                using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
                {
                    // find the payment for this booking
                    List <Payment> paymentToRefund = context.Payments.Where(p => p.BookingID == bookingID).ToList();
                    // set payment's status to Refunded
                    foreach (Payment payment in paymentToRefund)
                    {
                        payment.PaymentStatus = PaymentStatus.REFUNDED;
                    }
                    // save changes
                    context.SaveChanges();
                }
            }

            // whether the booking is paid or not - change it to Cancelled
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // find booking by PK
                Booking bookingToChange = context.Bookings.Find(bookingID);
                // set new values
                bookingToChange.BookingStatus = BookingStatus.CANCELLED;
                bookingToChange.BookingPrice  = 0.0m;
                bookingToChange.Date          = null;
                bookingToChange.Time          = null;
                // save changes
                context.SaveChanges();
            }
            // update booking view
            InitializePractitionersBookings(dataGridViewPractitionerBookings, practitionerID);
        }
Esempio n. 2
0
        /// <summary>
        /// Method to create a booking for the customer
        /// </summary>
        /// <param name="customerID"> id of the customer creating a booking</param>
        private void CreateBooking(int customerID)
        {
            // if some controls were not selected- error
            if (dataGridViewPractitioners.SelectedRows.Count != 1 || listBoxServices.SelectedIndex == -1 || listBoxTime.SelectedIndex == -1)
            {
                MessageBox.Show("Booking information is missing or is invalid!");
                return;
            }
            // create new Booking object
            Booking newBooking = new Booking
            {
                CustomerID          = customerID,
                PractitionerID      = Convert.ToInt32(dataGridViewPractitioners.SelectedRows[0].Cells[0].Value),
                Date                = monthCalendarBooking.SelectionRange.Start,
                Time                = (TimeSpan?)listBoxTime.SelectedItem,
                BookingPrice        = decimal.Parse(Regex.Replace(labelPriceAmount.Text, @"[^\d.]", "")),
                BookingStatus       = BookingStatus.NOT_PAID,
                PractitionerComment = ""
            };

            // add all selected services to the booking
            foreach (Service s in listBoxServices.SelectedItems)
            {
                newBooking.Services.Add(s);
            }

            // validate the new booking - error if not valid
            if (newBooking.InfoIsInvalid())
            {
                MessageBox.Show("Booking information is invalid!");
                return;
            }

            // try to add Booking
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // attach services to context to prevent creating new rows in the Services table!
                foreach (Service s in newBooking.Services)
                {
                    context.Services.Attach(s);
                }
                // try to add
                if (context.Bookings.Add(newBooking) == null)
                {
                    MessageBox.Show("Cannot add booking to database"); // error if didn't work
                    return;
                }
                context.SaveChanges(); // save changes
            }

            // clear calendar before quitting
            monthCalendarBooking.SelectionStart = DateTime.Now;

            // if add was successful- set result to OK and close form
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 3
0
        /// <summary>
        /// creates new user and practitioner
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewPractitioner(object sender, EventArgs e)
        {
            string firstName        = textBoxFirstName.Text;
            string lastName         = textBoxLastName.Text;
            string birthdate        = dateTimePickerBirthDate.Value.ToShortDateString();
            string address          = textBoxStreetAddress.Text;
            string city             = textBoxCity.Text;
            string province         = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string phoneNumber      = textBoxPhoneNumber.Text;
            string email            = textBoxEmail.Text;
            string practitionalType = comboBoxPractitionerType.GetItemText(comboBoxPractitionerType.SelectedItem);

            User newUser = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email
            };

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();
                // get selected practitioner type
                Practitioner_Types selectedPractitionalType = context.Practitioner_Types.SingleOrDefault(x => x.Title == practitionalType);
                Practitioner       newPractitioner          = new Practitioner
                {
                    User               = addedUser,
                    UserID             = addedUser.UserID,
                    PractitionerID     = selectedPractitionalType.TypeID,
                    Practitioner_Types = selectedPractitionalType
                };
                context.Practitioners.Add(newPractitioner);
                context.SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            Close();
        }
        private void AddNewPatient(object sender, EventArgs e)
        {
            string firstName   = textBoxFirstName.Text;
            string lastName    = textBoxLastName.Text;
            string birthdate   = dateTimePickerBirthDate.Value.ToShortDateString();
            string address     = textBoxAddress.Text;
            string city        = textBoxCity.Text;
            string province    = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string phoneNumber = textBoxPhoneNumber.Text;
            string email       = textBoxEmail.Text;
            string msp         = textBoxMSP.Text;

            User newUser = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email,
            };

            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();

                Customer newCustomer = new Customer
                {
                    User   = addedUser,
                    UserID = addedUser.UserID,
                };
                context.Customers.Add(newCustomer);
                context.SaveChanges();
            }

            this.DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 5
0
        /// <summary>
        /// Method to complete payment for a particular patient on a selected booking
        /// </summary>
        /// <param name="patientID"> id of a customer that is paying</param>
        private void CompletePayment(int patientID)
        {
            // make sure 1 booking is selected
            if (dataGridViewBookings.SelectedRows.Count != 1)
            {
                MessageBox.Show("One Booking needs to be selected to complete payment");
                return;
            }

            // create new payment object
            Payment newPayment = new Payment
            {
                CustomerID      = patientID,
                TotalAmountPaid = decimal.Parse(Regex.Replace(labelTotalAmountNumber.Text, @"[^\d.]", "")),
                BookingID       = Convert.ToInt32(dataGridViewBookings.SelectedRows[0].Cells[0].Value),
                PaymentTypeID   = (comboBoxPaymentType.SelectedItem as Payment_Types).PaymentTypeID,
                PaymentStatus   = PaymentStatus.APPROVED,
                Date            = DateTime.Now.Date,
                Time            = DateTime.Now.TimeOfDay,
            };

            // validate payment
            if (newPayment.InfoIsInvalid())
            {
                MessageBox.Show("Payment information is not valid!");
                return;
            }

            // try to add payment to db
            if (Controller <MedicalCentreManagementEntities, Payment> .AddEntity(newPayment) == null)
            {
                MessageBox.Show("Payment was not added to the database!");
                return;
            }
            // update that booking's status to Paid
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                context.Bookings.Find(newPayment.BookingID).BookingStatus = BookingStatus.PAID;
                context.SaveChanges();
            }
            // if successful- set result to OK and close form
            DialogResult = DialogResult.OK;
            Close();
        }
Esempio n. 6
0
        /// <summary>
        /// Check whether msp was changed
        /// Adjust future booking prices accordingly
        /// </summary>
        /// <param name="oldMSP"> previous msp </param>
        /// <param name="newMSP"> newly inputted msp </param>
        /// <param name="customerID"> customer id </param>
        private void CheckMSPChange(string oldMSP, string newMSP, int customerID)
        {
            if (oldMSP == newMSP)
            {
                return;
            }

            // if Customer lost their MSP - adjust price for unpaid booking in the future!
            if (newMSP == "")
            {
                using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
                {
                    // get list of unpaid bookings for the customer
                    var listOfUnpaidBookings = context.Bookings.Where(b => (b.CustomerID == customerID && b.BookingStatus == BookingStatus.NOT_PAID)).ToList();

                    // for each check if past or present
                    foreach (Booking booking in listOfUnpaidBookings)
                    {
                        // if in the future (greater than today)
                        if (DateTime.Now < booking.Date)
                        {
                            // recalculate new price
                            // by adding service prices
                            decimal newPrice = 0.0m;
                            foreach (Service s in booking.Services)
                            {
                                newPrice += s.ServicePrice;
                            }
                            booking.BookingPrice = newPrice;// set new price
                        }
                    }
                    // save changes
                    context.SaveChanges();
                }
            }
            // else if user got MSP - recalculate prices for future unpaid  bookings to include discount
            else if (oldMSP == "")
            {
                using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
                {
                    // get list of unpaid bookings for the customer
                    var listOfUnpaidBookings = context.Bookings.Where(b => (b.CustomerID == customerID && b.BookingStatus == BookingStatus.NOT_PAID)).ToList();

                    // for each check if past or present
                    foreach (Booking booking in listOfUnpaidBookings)
                    {
                        // if in the future (greater than today)
                        if (DateTime.Now < booking.Date)
                        {
                            // recalculate new price
                            // by adding service prices
                            decimal newPrice = 0.0m;
                            foreach (Service s in booking.Services)
                            {
                                newPrice += (s.ServicePrice * (1 - s.MSPCoverage));
                            }
                            booking.BookingPrice = newPrice;// set new price
                        }
                    }
                    // save changes
                    context.SaveChanges();
                }
            }
        }
        /// <summary>
        /// Adding a new patient
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewPatient(object sender, EventArgs e)
        {
            // get all values from input controls
            string   firstName   = textBoxFirstName.Text;
            string   lastName    = textBoxLastName.Text;
            DateTime birthdate   = dateTimePickerBirthDate.Value;
            string   address     = textBoxAddress.Text;
            string   city        = textBoxCity.Text;
            string   province    = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string   phoneNumber = textBoxPhoneNumber.Text;
            string   email       = textBoxEmail.Text;
            string   msp         = textBoxMSP.Text;

            // build a new user object
            User newUser = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email,
            };

            // validate user information
            if (newUser.InfoIsInvalid())
            {
                // error if invalid
                MessageBox.Show("Patient information is not valid!");
                return;
            }
            // using a unit-of-work context
            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                // add to Users table and save changes
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();

                // make sure it was added
                if (addedUser == null)
                {
                    MessageBox.Show("User was not added into a database!");
                    return;
                }
                // create a new Customer
                Customer newCustomer = new Customer
                {
                    User   = addedUser,
                    UserID = addedUser.UserID,
                    MSP    = msp
                };

                // validate Customer information
                if (!newCustomer.IsValidCustomer())
                {
                    MessageBox.Show("MSP must be unique or blank!");
                    return;
                }
                // add a new customer to DB
                context.Customers.Add(newCustomer);
                context.SaveChanges();// save changes

                // make sure it was added- error if not
                if (newCustomer == null)
                {
                    MessageBox.Show("Customer was not added into a database!");
                    return;
                }

                BaseFormMethods.ClearAllControls(this);
            }
            // If successful- set result to OK and close form
            DialogResult = DialogResult.OK;
            Close();
        }
        /// <summary>
        /// creates new user and practitioner
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void AddNewPractitioner(object sender, EventArgs e)
        {
            string   firstName   = textBoxFirstName.Text;
            string   lastName    = textBoxLastName.Text;
            DateTime birthdate   = dateTimePickerBirthDate.Value;
            string   address     = textBoxStreetAddress.Text;
            string   city        = textBoxCity.Text;
            string   province    = comboBoxProvince.GetItemText(comboBoxProvince.SelectedItem);
            string   phoneNumber = textBoxPhoneNumber.Text;
            string   email       = textBoxEmail.Text;
            int      typeId      = (comboBoxPractitionerType.SelectedItem as Practitioner_Types).TypeID;
            User     newUser     = new User
            {
                FirstName   = firstName,
                LastName    = lastName,
                Birthdate   = birthdate,
                Address     = address,
                City        = city,
                Province    = province,
                PhoneNumber = phoneNumber,
                Email       = email
            };

            // validate user
            if (newUser.InfoIsInvalid())
            {
                MessageBox.Show("Please fill practitioner's information");
                return;
            }



            // check practitionalType is selected
            if (comboBoxPractitionerType.SelectedIndex == -1)
            {
                MessageBox.Show("Please select a Pracitioner Type");
                return;
            }


            using (MedicalCentreManagementEntities context = new MedicalCentreManagementEntities())
            {
                User addedUser = context.Users.Add(newUser);
                context.SaveChanges();
                // get selected practitioner type

                Practitioner newPractitioner = new Practitioner
                {
                    UserID = addedUser.UserID,
                    TypeID = typeId,
                };

                // validate practitioner
                if (!newPractitioner.IsValidPractitioner())
                {
                    MessageBox.Show("Practitioner must picked from User");
                    return;
                }

                context.Practitioners.Add(newPractitioner);
                context.SaveChanges();
            }
            BaseFormMethods.ClearAllControls(this);
            this.DialogResult = DialogResult.OK;
            Close();
        }