Пример #1
0
        private void SearchButton_Click(object sender, EventArgs e)
        {
            if (ValidateForm() == false)
            {
                MessageBox.Show("Please enter at least 1 search criteria.");
                return;
            }

            ResultGrid.Rows.Clear();

            Dictionary<TicketRepository.TicketProperty, object> searchArguments = new Dictionary<TicketRepository.TicketProperty, object>();
            if (TicketIdTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.TicketId, TicketIdTextBox.Text);
            }
            if (FirstNameTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.FirstName, FirstNameTextBox.Text);
            }
            if (MiddleNameTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.MiddleName, MiddleNameTextBox.Text);
            }
            if (LastNameTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.LastName, LastNameTextBox.Text);
            }
            if (AddressTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.Address, AddressTextBox.Text);
            }
            if (CityTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.City, CityTextBox.Text);
            }
            if (StateTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.State, StateTextBox.Text);
            }
            if (ZipTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.Zip, ZipTextBox.Text);
            }
            if (TelephoneTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.Telephone, TelephoneTextBox.Text);
            }
            if (EmailTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.Email, EmailTextBox.Text);
            }
            if (PickedUpComboBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.PickedUp, PickedUpComboBox.Text);
            }
            if (StatusComboBox.Text != "")
            {
                if (StatusComboBox.Text == "Active")
                {
                    searchArguments.Add(TicketRepository.TicketProperty.Status, "a");
                }
                else if (StatusComboBox.Text == "Done")
                {
                    searchArguments.Add(TicketRepository.TicketProperty.Status, "d");
                }
                else if (StatusComboBox.Text == "Cancelled")
                {
                    searchArguments.Add(TicketRepository.TicketProperty.Status, "c");
                }
                else if (StatusComboBox.Text == "In Progress")
                {
                    searchArguments.Add(TicketRepository.TicketProperty.Status, "i");
                }
            }
            if (TailorComboBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.TailorName, TailorComboBox.Text);
            }
            if (OrderIdTextBox.Text != "")
            {
                searchArguments.Add(TicketRepository.TicketProperty.OrderId, OrderIdTextBox.Text);
            }

            try
            {
                TicketRepository ticketRepo = new TicketRepository();
                List<TicketResource> searchResults = ticketRepo.GetTicketsByArguments(searchArguments);

                if (searchResults.Count == 0)
                {
                    MessageBox.Show("I couldn't find any matching tickets. Please check the search criteria and try again.");
                }
                else
                {
                    for(int i=0; i<searchResults.Count; i++)
                    {
                        String status = "";
                        if (searchResults[i].Status == "a")
                        {
                            status = "Active";
                        }
                        else if (searchResults[i].Status == "d")
                        {
                            status = "Done";
                        }
                        else if (searchResults[i].Status == "c")
                        {
                            status = "Cancelled";
                        }
                        else if (searchResults[i].Status == "i")
                        {
                            status = "In Progress";
                        }
                        ResultGrid.Rows.Add(searchResults[i].TicketId, searchResults[i].FirstName, searchResults[i].LastName,searchResults[i].DateIn, searchResults[i].DateReady, status, searchResults[i].TailorName, String.Format("{0:C}", searchResults[i].TotalPrice), String.Format("{0:C}", searchResults[i].Deposit), String.Format("{0:C}",searchResults[i].TotalPrice - searchResults[i].Deposit));
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was an error. Please contact Jay with this message: " + ex.Message);
            }
            EnableButtonsBasedOnGrid();
        }