Example #1
0
        internal static TransactionCollectionViewModel Parse(string path)
        {
            TransactionCollectionViewModel vm = new TransactionCollectionViewModel();
            var cult    = CultureInfo.CurrentCulture;
            var swedish = CultureInfo.GetCultureInfo(1053);

            CultureInfo.CurrentCulture = swedish;
            try
            {
                var uri = new Uri(path);
                var fi  = new FileInfo(uri.LocalPath);

                using (var reader = new PdfReader(fi))
                    using (var doc = new PdfDocument(reader))
                        using (var blockE = new TransactionBlockEnumerator(doc))
                        {
                            while (blockE.MoveNext())
                            {
                                var block = blockE.Current;

                                foreach (var item in block)
                                {
                                    // Get the parts
                                    var match  = WellKnownData.Regex_TransactionItem.Match(item);
                                    int year   = int.Parse(match.Groups["year"].Value);
                                    int month  = int.Parse(match.Groups["month"].Value);
                                    int day    = int.Parse(match.Groups["day"].Value);
                                    var date   = new DateTime(year, month, day);
                                    var amount = ParseDouble(match.Groups["amount"].Value);
                                    var shop   = match.Groups["shop"].Value;
                                    var city   = match.Groups["city"].Value;

                                    vm.Add(new TransactionViewModel(date, shop, city, amount, 0, 0, null, false));
                                }
                            }
                        }
            }
            catch (Exception ex)
            {
                vm.Error = ex.ToString();
            }
            finally
            {
                CultureInfo.CurrentCulture = cult;
            }
            return(vm);
        }
Example #2
0
        private void Parse(object o)
        {
            var path = FilePath;

            Unbind();
            if (string.IsNullOrEmpty(path))
            {
                m_collection = new TransactionCollectionViewModel();
            }
            else
            {
                m_collection = TransactionCollectionViewModel.Parse(path);
            }
            Bind();
            TriggerPropertyChanged("Transactions");
            TriggerPropertyChanged("Sum");
            TriggerPropertyChanged("SharedSum");
        }
Example #3
0
 public ViewModel()
 {
     m_collection = new TransactionCollectionViewModel();
     m_parse      = new RelayCommand(o => true, Parse);
 }