示例#1
0
        private async void BtnAppend_Click(object sender, RoutedEventArgs e)
        {
            // Date to use for string format
            try
            {
                // Validating Date & Report is Picked -- LR
                if (cmbReports.SelectedIndex == -1)
                {
                    MessageBox.Show("Please select a report");
                    return;
                }


                // If In-Progress Orders is checked -- Lr

                if (cmbReports.SelectedIndex == 0)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }

                    startDate      = (DateTime)dateStart.SelectedDate;
                    endDate        = (DateTime)dateEnd.SelectedDate;
                    selectedOrders = await OrderProcessor.ShowAllProgressOrders(currentUser.Privileges, currentUser.Token);

                    if (selectedUser == null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tIn Progress Orders from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tIn Progress Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tIn Progress Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " with " + selectedEmployee.Firstname + " " + selectedEmployee.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }

                    FillListBox();
                }
                // If Completed Orders is checked -- Lr

                if (cmbReports.SelectedIndex == 1)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate      = (DateTime)dateStart.SelectedDate;
                    endDate        = (DateTime)dateEnd.SelectedDate;
                    selectedOrders = await OrderProcessor.ShowAllCompleteOrders(currentUser.Privileges, currentUser.Token);

                    if (selectedUser == null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCompleted Orders from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCompleted Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCompleted Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " with " + selectedEmployee.Firstname + " " + selectedEmployee.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    FillListBox();
                }

                // If Cancelled Orders is checked -- Lr

                if (cmbReports.SelectedIndex == 2)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;

                    selectedOrders = await OrderProcessor.ShowAllCancelledOrders(currentUser.Privileges, currentUser.Token); if (selectedUser == null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCancelled Orders from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee == null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCancelled Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else if (selectedUser != null && selectedEmployee != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\tCancelled Orders for " + selectedUser.Firstname + " " + selectedUser.Lastname + " with " + selectedEmployee.Firstname + " " + selectedEmployee.Lastname + " from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    FillListBox();
                }

                // If Customer's Orders is checked -- Lr

                if (cmbReports.SelectedIndex == 3)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate      = (DateTime)dateStart.SelectedDate;
                    endDate        = (DateTime)dateEnd.SelectedDate;
                    selectedOrders = await OrderProcessor.ShowAllOrders(currentUser.Privileges, currentUser.Token);

                    if (string.IsNullOrEmpty(txtCustomer.Text))
                    {
                        MessageBox.Show("Please select a customer");
                        return;
                    }
                    lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s orders from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    FillListBox();
                }

                // If Pet's By Customer is checked -- Lr

                if (cmbReports.SelectedIndex == 4)
                {
                    if (string.IsNullOrEmpty(txtCustomer.Text))
                    {
                        MessageBox.Show("Please select a customer");
                        return;
                    }


                    lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s Pets");

                    selectedPets = await PetProcessor.ShowPetsByCustomer(selectedUser.UserID, currentUser.Token);

                    foreach (PetModel m in selectedPets)
                    {
                        lstReports.Items.Add(m);
                    }
                }

                // If Employee Assigned Orders is checked -- Lr

                if (cmbReports.SelectedIndex == 5)
                {
                    if (string.IsNullOrEmpty(txtEmployee.Text))
                    {
                        MessageBox.Show("Please select an employee.");
                        return;
                    }
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;
                    lstReports.Items.Add("\t\t\t\t\t" + txtEmployee.Text + "'s schedule from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    selectedOrders = await OrderProcessor.GetAssignedRequest(selectedEmployee.UserID, currentUser.Token);


                    FillListBox();
                }

                // If Paid Invoices is checked -- LR

                if (cmbReports.SelectedIndex == 6)
                {
                    /// Validation
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;

                    /// Header If Statement

                    if (selectedUser != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s paid invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + "Paid Invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }

                    /// Calling API Service for Unpaid Invoices

                    selectedInvoices = await InvoiceProcessor.getPaidinvoices(currentUser.Privileges, currentUser.Token);


                    /// Testing to see if there are any paid invoices for date

                    if (selectedInvoices == null)
                    {
                        MessageBox.Show("There are no invoices to display.");
                        return;
                    }

                    /// Adding invoices in listbox

                    foreach (InvoiceModel m in selectedInvoices)
                    {
                        if (selectedUser != null)
                        {
                            if (m.CustomerID == selectedUser.UserID)
                            {
                                if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                                {
                                    lstReports.Items.Add(m);
                                }
                            }
                        }

                        else
                        {
                            if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                            {
                                lstReports.Items.Add(m);
                            }
                        }
                    }
                }

                // If Unpaid Invoices is checked -- LR

                if (cmbReports.SelectedIndex == 7)
                {
                    /// Validation

                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }
                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;


                    /// Header If Statement

                    if (selectedUser != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s unpaid invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + "Unpaid Invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }

                    /// Calling API Service for Unpaid Invoices

                    selectedInvoices = await InvoiceProcessor.getUnpaidInvoices(currentUser.Privileges, currentUser.Token);

                    /// Testing to see if there are any paid invoices for date

                    if (selectedInvoices == null)
                    {
                        MessageBox.Show("There are no invoices to display.");
                        return;
                    }

                    /// Adding invoices in listbox

                    foreach (InvoiceModel m in selectedInvoices)
                    {
                        if (selectedUser != null)
                        {
                            if (m.CustomerID == selectedUser.UserID)
                            {
                                if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                                {
                                    lstReports.Items.Add(m);
                                }
                            }
                        }

                        else
                        {
                            if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                            {
                                lstReports.Items.Add(m);
                            }
                        }
                    }
                }
                // test comment
                // If overdue invoices is checked -- LR

                if (cmbReports.SelectedIndex == 8)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }


                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;

                    selectedInvoices = await InvoiceProcessor.getOverdueInvoices(currentUser.Privileges, currentUser.Token);

                    if (selectedInvoices == null)
                    {
                        MessageBox.Show("There are no invoices to display.");
                        return;
                    }

                    if (selectedUser != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s overdue invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + "Overdue invoices from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }

                    foreach (InvoiceModel m in selectedInvoices)
                    {
                        if (selectedUser != null)
                        {
                            if (m.CustomerID == selectedUser.UserID)
                            {
                                if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                                {
                                    lstReports.Items.Add(m);
                                }
                            }
                        }

                        else
                        {
                            if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                            {
                                lstReports.Items.Add(m);
                            }
                        }
                    }
                }

                // If due invoices is checked -- LR

                if (cmbReports.SelectedIndex == 9)
                {
                    if (dateStart.SelectedDate == null || dateEnd.SelectedDate == null)
                    {
                        MessageBox.Show("Please select a start and end date");
                        return;
                    }


                    startDate = (DateTime)dateStart.SelectedDate;
                    endDate   = (DateTime)dateEnd.SelectedDate;

                    selectedInvoices = await InvoiceProcessor.getUnderdueInvoices(currentUser.Privileges, currentUser.Token);

                    if (selectedInvoices == null)
                    {
                        MessageBox.Show("There are no invoices to display.");
                        return;
                    }

                    if (selectedUser != null)
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + txtCustomer.Text + "'s due invoices (not overdue) from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }
                    else
                    {
                        lstReports.Items.Add("\t\t\t\t\t" + "Due invoices (not overdue) from " + startDate.ToString("MM/dd/yyyy") + " to " + endDate.ToString("MM/dd/yyyy"));
                    }

                    foreach (InvoiceModel m in selectedInvoices)
                    {
                        if (selectedUser != null)
                        {
                            if (m.CustomerID == selectedUser.UserID)
                            {
                                if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                                {
                                    lstReports.Items.Add(m);
                                }
                            }
                        }

                        else
                        {
                            if (DateTime.Parse(m.InvoiceDate) >= dateStart.SelectedDate && DateTime.Parse(m.InvoiceDate) <= dateEnd.SelectedDate)
                            {
                                lstReports.Items.Add(m);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
示例#2
0
        private async void FillInvoiceListBox(UserModel user)
        {
            lstInvoices.Items.Clear();
            usedInvoices.Clear();
            invoices.Clear();
            lstInvoices.IsEnabled = true;
            if (await InvoiceProcessor.getOverdueInvoices(currentUser.Privileges, currentUser.Token) != null)
            {
                invoices.Add(await InvoiceProcessor.getOverdueInvoices(currentUser.Privileges, currentUser.Token));
            }

            if (await InvoiceProcessor.getUnderdueInvoices(currentUser.Privileges, currentUser.Token) != null)
            {
                invoices.Add(await InvoiceProcessor.getUnderdueInvoices(currentUser.Privileges, currentUser.Token));
            }

            if (await InvoiceProcessor.getUnpaidInvoices(currentUser.Privileges, currentUser.Token) != null)
            {
                invoices.Add(await InvoiceProcessor.getUnpaidInvoices(currentUser.Privileges, currentUser.Token));
            }

            if (await InvoiceProcessor.getPaidinvoices(currentUser.Privileges, currentUser.Token) != null)
            {
                invoices.Add(await InvoiceProcessor.getPaidinvoices(currentUser.Privileges, currentUser.Token));
            }

            if (invoices != null)
            {
                foreach (List <InvoiceModel> i in invoices)
                {
                    foreach (InvoiceModel n in i)
                    {
                        if (n.CustomerID == user.UserID)
                        {
                            if (usedInvoices.Count == 0)
                            {
                                usedInvoices.Add(n);
                            }
                            else
                            {
                                foreach (InvoiceModel invoice in usedInvoices)
                                {
                                    if (n.InvoiceID == invoice.InvoiceID)
                                    {
                                        lstInvoices.Items.Add(n);
                                    }
                                }
                                usedInvoices.Add(n);
                            }
                        }
                    }
                }
                if (lstInvoices.Items.IsEmpty)
                {
                    lstInvoices.Items.Add("NO INVOICES FOR THIS CUSTOMER");
                }
            }
            else
            {
                lstInvoices.Items.Add("NO INVOICES FOR THIS CUSTOMER");
            }
        }