public void InvoiceSearch(SearchWindow window)
        {
            string name     = window.TxtSearchInvoiceName.Text;
            string statusId = window.CbSearchInvoiceStatus.Text;

            List <Objects.Invoice> invoices = new InvoiceCRUD().GetInvoices();

            if (!String.IsNullOrEmpty(name))
            {
                invoices.RemoveAll(x => x.InvoiceName != name);
            }

            if (!String.IsNullOrEmpty(statusId))
            {
                invoices.RemoveAll(x => x.InvoiceTypeId != Convert.ToInt32(statusId));
            }

            if (invoices.Count > 0)
            {
                BindDataGrid(invoices);
                window.Close();
            }
            else
            {
                MessageBox.Show("There are no results", "Information");
            }
        }
Exemplo n.º 2
0
        private void BtnSubmit_Click(object sender, RoutedEventArgs e)
        {
            int result = 0;

            result = new InvoiceCRUD().Update((Objects.Invoice) this.DataContext);
            if (result > 0)
            {
                this.Close();
                MessageBox.Show("Invoice was updated", "Success");
            }
            else
            {
                MessageBox.Show("Unable to update invoice", "Failure");
            }
        }
        public void BindDataGrid(List <Objects.Invoice> invoices)
        {
            if (invoices == null)
            {
                invoices = new InvoiceCRUD().GetInvoices();
            }

            List <Objects.InvoiceType> invoiceTypes = new InvoiceCRUD().GetInvoiceTypes();
            List <Job> allJobs = new JobCRUD().GetJobs();

            if (invoices.Count > 0)
            {
                foreach (var inv in invoices)
                {
                    if (inv.InvoiceTypeId > 0)
                    {
                        inv.InvoiceTypeName = invoiceTypes.Where(x => x.InvoiceTypeId == inv.InvoiceTypeId).First().InvoiceTypeName;
                    }
                    else
                    {
                        inv.InvoiceTypeName = "None";
                    }

                    try
                    {
                        if (inv.JobId > 0)
                        {
                            inv.JobName = allJobs.Where(x => x.JobId == inv.JobId).First().Name;
                        }
                        else
                        {
                            inv.JobName = "None";
                        }
                    }
                    catch (Exception ex)
                    {
                        inv.JobName = "";
                        continue;
                    }
                }
            }

            this.dgData.ItemsSource = invoices;
        }