/// <summary> /// Method to Initialize and populate the invoice with all the data /// </summary> public void InitializeGUI() { lblInvoiceNumber.Content = documentInvoice.InvoiceNumber; lblCustomerAddress.Content = documentInvoice.DebtorAddress; lblAddress.Content = "Address: " + Environment.NewLine + documentInvoice.CompanyAddress; lblPhone.Content = "Phone: " + Environment.NewLine + documentInvoice.PhoneNumber; lblHomePage.Content = "Home Page: " + Environment.NewLine + documentInvoice.HomePageURL; PopulateListArticles(); lblTotal.Content = documentInvoice.TotalInvoice().ToString("F"); txtDiscount.Text = documentInvoice.Discount.ToString(); daPDueDate.BorderBrush = Brushes.White; daPCreatedDate.BorderBrush = Brushes.White; daPCreatedDate.SelectedDate = documentInvoice.CreateDate; daPDueDate.SelectedDate = documentInvoice.DueDate; txtDiscount.MaxLength = 2; imgLogo.Source = documentInvoice.Logo; }
/// <summary> /// Method to update list view /// </summary> public void UpdateListViewInvoices() { lstInvoices.Items.Clear(); //clear list view for (int index = 0; index < addInvoiceToLibrary.ElementCount; index++) //loop the list view { //New invoice object get assigned the different objects from manager Invoice allInvoices = addInvoiceToLibrary.RetrieveElementAtPosition(index); // method to retrieve objects form the list lstInvoices.Items.Add(new MyItem { ID = allInvoices.InvoiceNumber.ToString(), Company = allInvoices.CompanyDebtorName, NumberOfItems = allInvoices.NumberOfItems.ToString(), ContactPerson = allInvoices.DebtorContactPerson, DueDate = allInvoices.DueDate.ToString("yyyy-MM-dd"), TotalAmount = allInvoices.TotalInvoice().ToString("F") }); } //focus in the last item in the list view lstInvoices.ScrollIntoView(lstInvoices.Items[lstInvoices.Items.Count - 1]); }
/// <summary> /// Method to import a text file and generate list view row /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnImport_Click(object sender, RoutedEventArgs e) { string fileName; // local variable OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Filter = "Text documents (.txt)|*.txt"; // Filter files by extension Nullable <bool> result = openFileDialog1.ShowDialog(); try { if (result == true) //Dialog box to open the xml file { fileName = openFileDialog1.FileName; //retrieve filename and path Invoice newInvoice = new Invoice(); //initiate object InvoiceReader newDocument = new InvoiceReader(fileName, newInvoice); newDocument.ReadInvoice(); newInvoice.NumberOfItems = newDocument.TotalNumberItems(); lstInvoices.Items.Add(new MyItem { ID = newInvoice.InvoiceNumber.ToString(), Company = newInvoice.CompanyDebtorName, NumberOfItems = newInvoice.NumberOfItems.ToString(), ContactPerson = newInvoice.DebtorContactPerson, DueDate = newInvoice.DueDate.ToString("yyyy-MM-dd"), TotalAmount = newInvoice.TotalInvoice().ToString("F") }); lstInvoices.ScrollIntoView(lstInvoices.Items[lstInvoices.Items.Count - 1]); addInvoiceToLibrary.AddElement(newInvoice); } } catch (Exception error) { MessageBox.Show(error.Message + "Environment.NewLine" + error.StackTrace, "Error"); } finally { } }