Esempio n. 1
0
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            var    errorHandler = new ErrorHandler();
            var    lib          = new BankLib(errorHandler);
            var    transactions = new List <Transaction>();
            var    sr           = new StringReader(_input.Text);
            string line;
            var    strings = new List <string>();

            while ((line = sr.ReadLine()) != null)
            {
                strings.Add(line);
            }
            lib.parseTransactions(strings.ToArray(), ref transactions);
            if (errorHandler.getParseErrors().Count > 0)
            {
                var sb = new StringBuilder();
                errorHandler.getParseErrors().ForEach(error =>
                {
                    sb.AppendLine(error.Error + " | " + error.SourceLine);
                });
                MessageBox.Show(sb.ToString(), "Parsing Error");
            }
            if (transactions.Count > 0)
            {
                MessageManager.queueMessage(new InsertTransactionsMessage(transactions.ToArray()));
                MessageManager.queueMessage(new CloseOverlayMessage()
                {
                    Overlay = this
                });
            }
        }
Esempio n. 2
0
        private void onAddToDatabaseMany(object sender, RoutedEventArgs e)
        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "CSV Files (.csv)|*.csv";

            dlg.Multiselect = true;
            dlg.FileOk     += (a, b) =>
            {
                var files        = dlg.FileNames;
                var errorHandler = new ErrorHandler();
                var lib          = new BankLib(errorHandler);
                var transactions = new List <Transaction>();

                foreach (var path in files)
                {
                    var file = new FileInfo(path);
                    if (!file.Exists)
                    {
                        throw new Exception("foo");
                    }

                    var lines = File.ReadAllLines(file.FullName);
                    lib.parseTransactions(lines, ref transactions);
                }

                if (errorHandler.getParseErrors().Count > 0)
                {
                    var sb = new StringBuilder();
                    errorHandler.getParseErrors().ForEach(error =>
                    {
                        sb.AppendLine(error.Error + " | " + error.SourceLine);
                    });
                    MessageBox.Show(sb.ToString(), "Parsing Error");
                }
                if (transactions.Count > 0)
                {
                    MessageManager.queueMessage(new InsertTransactionsMessage(transactions.ToArray()));
                    //MessageManager.queueMessage(new CloseOverlayMessage() { Overlay = this });
                }
            };
            dlg.ShowDialog();
        }