public MainWindow()
        {
            InvoiceReader reader = new InvoiceReader();

            InitializeComponent();

            edited = new List <Changable>();

            MenuItemDiscount.IsEnabled = false;
            StartDatepicker.IsEnabled  = false;
            DueDatepicker.IsEnabled    = false;
        }
Example #2
0
        /// <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
            {
            }
        }
        /// <summary>
        /// Eventhandler for the BtnOpen in Menu
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void BtnOpen_Click(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.Filter = "Text files (*.txt) | *.txt";
            if (dialog.ShowDialog() == true)
            {
                openFileName = dialog.FileName;
            }

            if (!string.IsNullOrEmpty(openFileName))
            {
                InvoiceReader reader = new InvoiceReader();
                invoice = reader.CreateInvoiceFromFile(openFileName);

                MenuItemDiscount.IsEnabled = true;
                StartDatepicker.IsEnabled  = true;
                DueDatepicker.IsEnabled    = true;
            }

            UpdateGui();
        }