예제 #1
0
        ///Search Combo Box
        private void ComboBoxFields_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            AppointList newFilterList = new AppointList();

            switch (comboBoxFields.SelectedIndex)
            {
            case 0: {
                var customer = from appointment in appointList
                               orderby appointment.CustData.CustType descending
                               select appointment;

                foreach (Appointment appt in customer)
                {
                    newFilterList.Add(appt);
                }
                Grid.ItemsSource = newFilterList;
                break;
            }

            case 1: {
                var Name = from appointment in appointList
                           orderby appointment.CustData.CustName descending
                           select appointment;
                foreach (Appointment appt in Name)
                {
                    newFilterList.Add(appt);
                }
                Grid.ItemsSource = newFilterList;
                break;
            }
            }
        }
예제 #2
0
        private void Addbutton_Click(object sender, RoutedEventArgs e)
        {
            ErrorLabel.Content    = "";
            ErrorLabel.Foreground = Brushes.Black;
            AppointBox.ClearValue(TextBox.BorderBrushProperty);
            CustomerNameText.ClearValue(TextBox.BorderBrushProperty);
            CustomerNumberText.ClearValue(TextBox.BorderBrushProperty);
            comboBoxTypeOfCustomer.ClearValue(TextBox.BorderBrushProperty);

            Time       = AppointBox.Text.ToString();
            custName   = CustomerNameText.Text;
            contNumber = CustomerNumberText.Text;
            custType   = comboBoxTypeOfCustomer.Text;
            Age        = txtAge.Text;

            ///validation for appointment combo box
            do
            {
                if (AppointBox.SelectedIndex == -1)
                {
                    result = false;
                    MessageBox.Show("Please select Appointment");
                    break;
                }
                else
                {
                    AppointBox.BorderBrush = Brushes.Black;
                    break;
                }
            } while (true);


            //Validation for Name
            do
            {
                if (custName.Trim().Length != 0)
                {
                    CustomerNameText.Foreground = Brushes.Black;
                    char[] customerNameChar = custName.ToArray();
                    foreach (char index in customerNameChar)
                    {
                        if (!char.IsLetter(index))
                        {
                            result                      = false;
                            ErrorLabel.Content          = "Please enter valid customer name";
                            ErrorLabel.Foreground       = Brushes.Red;
                            CustomerNameText.Foreground = Brushes.Red;
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    result                      = false;
                    ErrorLabel.Content          = "Please enter valid customer name";
                    ErrorLabel.Foreground       = Brushes.Red;
                    CustomerNameText.Foreground = Brushes.Red;
                    break;
                }
            } while (true);

            ///validation for Number
            do
            {
                if (contNumber.Trim().Length != 0)
                {
                    CustomerNumberText.Foreground = Brushes.Black;
                    char[] contactNumberChar = contNumber.ToArray();
                    foreach (char index in contactNumberChar)
                    {
                        if (!char.IsNumber(index))
                        {
                            result                        = false;
                            ErrorLabel.Content            = "Please enter valid contact name";
                            ErrorLabel.Foreground         = Brushes.Red;
                            CustomerNumberText.Foreground = Brushes.Red;
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    result                        = false;
                    ErrorLabel.Content            = "Please enter valid contact name";
                    ErrorLabel.Foreground         = Brushes.Red;
                    CustomerNumberText.Foreground = Brushes.Red;
                    break;
                }
            } while (true);

            ///validation for the Age
            do
            {
                if (Age.Trim().Length == 0)
                {
                    result            = false;
                    txtAge.Foreground = Brushes.Red;
                    break;
                }
                else if (int.TryParse(Age, out ageint) && ageint > 1 && ageint < 100)
                {
                    ErrorLabel.Content = "";

                    txtAge.Foreground = Brushes.Black;
                    break;
                }
                else
                {
                    result                = false;
                    ErrorLabel.Content    = "Please enter valid age [1-100]";
                    ErrorLabel.Foreground = Brushes.Red;
                    txtAge.Foreground     = Brushes.Red;
                    break;
                }
            } while (true);

            custType = comboBoxTypeOfCustomer.Text.ToString();

            if (result)
            {
                try
                {
                    Time = (string)Data[AppointBox.SelectedIndex];
                    Data.Remove(AppointBox.SelectedIndex);
                    AppointBox.Items.Clear();
                    ArrayList arrayList = new ArrayList(Data.Keys);
                    for (int i = 0; i < arrayList.Count; i++)
                    {
                        AppointBox.Items.Add(Data[i]);
                    }


                    ///input fields will be cleared
                    CustomerNameText.Text   = "";
                    CustomerNumberText.Text = "";
                    txtAge.Text             = "";
                    comboBoxTypeOfCustomer.SelectedIndex = 0;

                    //Saving data
                    Customer type = null;
                    switch (comboBoxTypeOfCustomer.SelectedIndex)
                    {
                    case 0:
                    {
                        type = new Ladies()
                        {
                            CustName     = custName,
                            ContNum      = contNumber,
                            HomeTreat    = homeTreatment ? "Home treatment is Required" : " Home treatment is Not Required",
                            CustType     = custType,
                            Year         = Age,
                            IsHairColour = requirement
                        };
                        break;
                    }

                    case 1:
                    {
                        type = new Gents()
                        {
                            CustName     = custName,
                            ContNum      = contNumber,
                            HomeTreat    = homeTreatment ? "Home treatment is Required" : "Home treatment is Not Required",
                            CustType     = custType,
                            Year         = Age,
                            IsHairMakeup = requirement
                        };
                        break;
                    }

                    case 2:
                    {
                        type = new Children()
                        {
                            CustName        = custName,
                            ContNum         = contNumber,
                            HomeTreat       = homeTreatment ? "Home treatment is Required" : "Home treatment is Not Required",
                            CustType        = custType,
                            Year            = Age,
                            IsHaircutNeeded = requirement
                        };
                        break;
                    }

                    default:
                    {
                        break;
                    }
                    }
                    Appointment Obj = new Appointment()
                    {
                        AppTime  = Time,
                        CustData = type
                    };

                    appointList.Add(Obj);
                    Insert();
                }
                catch (Exception exc)
                {
                }
            }
        }