Exemplo n.º 1
0
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            string firstName   = tbFirstName.Text;
            string lastName    = tbLastName.Text;
            string phoneNumber = tbPhoneNumber.Text;
            string email       = tbEmail.Text;
            string address     = tbAddress.Text;

            //Validate values
            if (string.IsNullOrWhiteSpace(firstName) || string.IsNullOrWhiteSpace(lastName) || string.IsNullOrWhiteSpace(phoneNumber))
            {
                MessageHelper.ShowWarningMessage("First Name, Last Name and Phone Number are mandatory!", "Information Error");
                return;
            }
            //If ok

            // Create new employee object
            Employee employee = new Employee(firstName, lastName, phoneNumber, email, address);
            string   newID    = UtilsHelper.GenerateID(employee);

            employee.ID = newID;

            // Store employee into DAO
            XMLHelpers.Instance().Employees.Add(employee);
            DialogResult = true;
            this.Close();
        }
        /// <summary>
        /// Get Data from window
        /// Create new customer and appointment
        /// Save into DAO layer
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            string firstName   = tbFirstName.Text;
            string lastName    = tbLastName.Text;
            string phoneNumber = tbPhoneNumber.Text;
            string email       = tbEmail.Text;
            string address     = tbAddress.Text;

            Customer customer = new Customer(firstName, lastName, phoneNumber, email, address);

            customer.ID = UtilsHelper.GenerateID(customer);
            //Add new customer into DAO
            XMLHelpers.Instance().Customers.Add(customer);

            if (string.IsNullOrWhiteSpace(firstName) ||
                string.IsNullOrWhiteSpace(lastName) ||
                string.IsNullOrWhiteSpace(phoneNumber))
            {
                MessageHelper.ShowWarningMessage("First Name, Last Name and Phone Number are mandatory!", "Error");
                return;
            }

            DateTime date = dpCurrentDate.SelectedDate.Value.Date;

            if (cbTime.SelectedItem == null || cbService.SelectedItem == null || cbNailTechnician.SelectedItem == null)
            {
                MessageHelper.ShowWarningMessage("Date , Time, Service and Employee are mandatory!", "Error");
                return;
            }

            TimeSpan selectedTime = TimeSpan.FromHours(((DateTime)cbTime.SelectedItem).Hour);

            date = date.Date + selectedTime;
            Service  service  = (Service)cbService.SelectedItem;
            Employee employee = (Employee)cbNailTechnician.SelectedItem;


            Appointment newAppointment = new  Appointment(date, customer, service, employee);

            newAppointment.ID = UtilsHelper.GenerateID(newAppointment);

            if (StateHelper.IsEditedAppointmentMode)
            {
                newAppointment.ID = StateHelper.EditedAppointment.ID;
            }

            //Check is valid appointment
            if (!UtilsHelper.IsEmployeeAvailableOn(date, employee, newAppointment))
            {
                MessageHelper.ShowWarningMessage(String.Format("Technician {0} is not available on that time\nPlease choose another time!", employee.FullName), "Appointment");
                return;
            }

            //Update Appointment into DAO when open this windom for editing
            if (StateHelper.IsEditedAppointmentMode)
            {
                //Check is valid appointment

                int index = XMLHelpers.Instance().Appointments.FindIndex(appointment => appointment.ID == StateHelper.EditedAppointment.ID);
                XMLHelpers.Instance().Appointments[index] = newAppointment;
            }
            else
            {
                // Add new appointment into DAO
                XMLHelpers.Instance().Appointments.Add(newAppointment);
            }



            DialogResult = true;

            //Reset Selected Appointment for updating
            ResetState();
            this.Close();
        }