예제 #1
0
        public void CanImportAccountWithTransactions()
        {
            var sample = @"!Clear:AutoSwitch
!Option:AutoSwitch
!Account
NBank Account 1
TBank
^
!Type:Bank 
D01/1/18
U-400.00
T-400.00
CX
NCard
PMr Land Lord
LRent
^";

            QifDom parser = null;

            using (new CultureContext(new CultureInfo("en-GB")))
                using (var reader = new StringReader(sample))
                {
                    parser = QifDom.ImportFile(reader);
                }

            Assert.Equal(1, parser.AccountListTransactions.Count);
            Assert.Equal(1, parser.BankTransactions.Count);
            Assert.Equal("Bank Account 1", parser.BankTransactions[0].AccountName);
        }
예제 #2
0
        public void CanImportCreditCardTransaction()
        {
            var sample = @"!Type:CCard
D31/1/18
U-6.25
T-6.25
CX
PStarbucks
MCoffee & cake
LDining
^";

            QifDom parser = null;

            using (new CultureContext(new CultureInfo("en-GB")))
                using (var reader = new StringReader(sample))
                {
                    parser = QifDom.ImportFile(reader);
                }

            var transaction = parser.CreditCardTransactions[0];

            Assert.Equal(new DateTime(2018, 1, 31), transaction.Date);
            Assert.Equal(-6.25M, transaction.Amount);
            Assert.Equal("X", transaction.ClearedStatus);
            Assert.Equal("Starbucks", transaction.Payee);
            Assert.Equal("Coffee & cake", transaction.Memo);
            Assert.Equal("Dining", transaction.Category);
        }
예제 #3
0
        public void CanImportCategory()
        {
            var sample = @"!Type:Cat
NEmployment
DEmployment income
T
I
^";

            QifDom parser = null;

            using (new CultureContext(new CultureInfo("en-GB")))
                using (var reader = new StringReader(sample))
                {
                    parser = QifDom.ImportFile(reader);
                }

            var category = parser.CategoryListTransactions[0];

            Assert.Equal("Employment", category.CategoryName);
            Assert.Equal("Employment income", category.Description);
            Assert.True(category.IncomeCategory);
            Assert.False(category.ExpenseCategory);
            Assert.True(category.TaxRelated);
        }
예제 #4
0
        public static string ToQifData(this IEnumerable <BasicTransaction> transactions)
        {
            var qifDom = new QifDom(QifConfiguration)
            {
                BankTransactions = transactions.ToList()
            };
            var tempFileName = Path.GetTempFileName();

            try
            {
                using (new TemporaryCulture(_englishCulture))
                {
                    qifDom.Export(tempFileName);
                }

                var qifData = File.ReadAllText(tempFileName);
                return(qifData);
            }
            finally
            {
                if (File.Exists(tempFileName))
                {
                    try
                    {
                        File.Delete(tempFileName);
                    }
                    catch
                    {
                        /* ignored */
                    }
                }
            }
        }
예제 #5
0
파일: MainUI.cs 프로젝트: kaytame/qif
 private void exportButton_Click(object sender, EventArgs e)
 {
     if (saveFileDialog.ShowDialog(this) == DialogResult.OK)
     {
         QifDom.ExportFile((QifDom)qifDomPropertyGrid.SelectedObject, saveFileDialog.FileName);
         MessageBox.Show(this, "The export is complete.", "Complete", MessageBoxButtons.OK, MessageBoxIcon.Information);
     }
 }
예제 #6
0
 public MainUI()
 {
     InitializeComponent();
     using (new SpoofCulture("en-US"))
     {
         qifDomPropertyGrid.SelectedObject = QifDom.ImportFile(Path.GetDirectoryName(Application.ExecutablePath) + Path.DirectorySeparatorChar + "sample.qif");
     }
 }
예제 #7
0
 public static QifDom ParseQifDom(string qifData)
 {
     using (new TemporaryCulture(_englishCulture))
     {
         var ms     = new MemoryStream(Encoding.UTF8.GetBytes(qifData));
         var qifDom = QifDom.ImportFile(new StreamReader(ms), QifConfiguration);
         return(qifDom);
     }
 }
예제 #8
0
파일: MainUI.cs 프로젝트: kaytame/qif
 private void importButton_Click(object sender, EventArgs e)
 {
     if (ConfirmOverwrite())
     {
         if (openFileDialog.ShowDialog(this) == DialogResult.OK)
         {
             qifDomPropertyGrid.SelectedObject = QifDom.ImportFile(openFileDialog.FileName);
         }
     }
 }
예제 #9
0
        public void Cannot_import_sample_qif_when_current_culture_is_ar_SA()
        {
            var sample = File.ReadAllText("sample.qif");

            using (new CultureContext(new CultureInfo("ar-SA")))
                using (var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(sample))))
                {
                    Assert.Throws <InvalidCastException>(() => QifDom.ImportFile(reader));
                }
        }
예제 #10
0
        public void Can_import_sample_qif_when_current_culture_is_en_US()
        {
            var sample = File.ReadAllText("sample.qif");

            using (new CultureContext(new CultureInfo("en-US")))
                using (var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(sample))))
                {
                    var qif = QifDom.ImportFile(reader);
                    Assert.NotEmpty(qif.BankTransactions);
                }
        }
예제 #11
0
        public void Can_import_sample_qif_when_current_culture_is_en_CA_with_CustomReadDateFormat()
        {
            var sample = File.ReadAllText("sample.qif");

            using (new CultureContext(new CultureInfo("en-CA")))
                using (var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(sample))))
                {
                    var qif = QifDom.ImportFile(reader, new Configuration
                    {
                        ReadDateFormatMode   = ReadDateFormatMode.Custom,
                        CustomReadDateFormat = "M/d/yyyy",
                    });
                    Assert.NotEmpty(qif.BankTransactions);
                }
        }
예제 #12
0
        public void Cannot_import_sample_qif_when_explicitly_using_ar_SA()
        {
            var sample = File.ReadAllText("sample.qif");

            using (new CultureContext(new CultureInfo("en-US")))
                using (var reader = new StreamReader(new MemoryStream(Encoding.UTF8.GetBytes(sample))))
                {
                    Assert.Throws <InvalidCastException>(() =>
                    {
                        QifDom.ImportFile(reader, new Configuration
                        {
                            CustomReadCultureInfo = new CultureInfo("ar-SA")
                        });
                    });
                }
        }
예제 #13
0
        public void Does_not_change_income_category()
        {
            var sample = new QifDom();

            sample.CategoryListTransactions.Add(new Transactions.CategoryListTransaction()
            {
                IncomeCategory = true,
            });

            var file = Path.GetTempFileName();

            sample.Export(file);

            var test = QifDom.ImportFile(file);

            Assert.AreEqual(sample.CategoryListTransactions.Count, test.CategoryListTransactions.Count);
            Assert.AreEqual(sample.CategoryListTransactions[0].IncomeCategory, test.CategoryListTransactions[0].IncomeCategory);
        }
예제 #14
0
        public void Does_not_change_tax_related()
        {
            var sample = new QifDom();

            sample.CategoryListTransactions.Add(new Transactions.CategoryListTransaction()
            {
                TaxRelated = true,
            });

            var file = Path.GetTempFileName();

            sample.Export(file);

            var test = QifDom.ImportFile(file);

            Assert.AreEqual(sample.CategoryListTransactions.Count, test.CategoryListTransactions.Count);
            Assert.AreEqual(sample.CategoryListTransactions[0].TaxRelated, test.CategoryListTransactions[0].TaxRelated);
        }
예제 #15
0
        public void CanImportCreditCardSplit()
        {
            var sample = @"!Type:CCard
D31/1/18
U-6.25
T-6.25
CX
PCaffe Nero
LDining
SDining
ECoffee
$-2.75
SDining
ECake
$-3.50
^";

            QifDom parser = null;

            using (new CultureContext(new CultureInfo("en-GB")))
                using (var reader = new StringReader(sample))
                {
                    parser = QifDom.ImportFile(reader);
                }

            var transaction = parser.CreditCardTransactions[0];

            // Transaction values.
            Assert.Equal(new DateTime(2018, 1, 31), transaction.Date);
            Assert.Equal(-6.25M, transaction.Amount);
            Assert.Equal("X", transaction.ClearedStatus);
            Assert.Equal("Caffe Nero", transaction.Payee);
            Assert.Equal("Dining", transaction.Category);

            // Split 1.
            Assert.Equal("Dining", transaction.SplitCategories[0]);
            Assert.Equal("Coffee", transaction.SplitMemos[0]);
            Assert.Equal(-2.75M, transaction.SplitAmounts[0]);

            // Split 2.
            Assert.Equal("Dining", transaction.SplitCategories[1]);
            Assert.Equal("Cake", transaction.SplitMemos[1]);
            Assert.Equal(-3.50M, transaction.SplitAmounts[1]);
        }
예제 #16
0
        public void ExportTransactions(string filename)
        {
            var transactions = GetTransactions();
            var wrapper = new QifDomComWrapper();
            var qd = new QifDom();

            foreach (var t in transactions)
            {
                // todo: proper conversion
                var transaction = new BasicTransaction();
                transaction.Amount = (decimal)t.Amount;
                transaction.Date = t.Timestamp;
                transaction.Payee = t.FromAddress;
                transaction.Memo = t.ToAddress;
                qd.CashTransactions.Add(transaction);
            }

            qd.Export(filename);
        }
예제 #17
0
        private void LoadQifFile_Click(object sender, RoutedEventArgs e)
        {
            // Create OpenFileDialog

            Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();



            // Set filter for file extension and default file extension

            dlg.DefaultExt = ".qif";

            dlg.Filter = "QIF Files (.qif)|*.qif";



            // Display OpenFileDialog by calling ShowDialog method

            Nullable <bool> result = dlg.ShowDialog();



            // Get the selected file name and display in a TextBox

            if (result == true)
            {
                // Open document

                string filename = dlg.FileName;

                FileNameTextBox.Text = filename;

                String LoadedMessage = "Loaded";
                QifDom Qd            = new QifDom();
                //Qd.Import("C:\\Users\\Mike\\Documents\\AccountingDatabase\\010544496_20140817.qif");
                Qd.Import(filename);
                LoadMessage.Text = LoadedMessage;
                Qt = new QifTransaction(Qd);
                Dt = Qt.GetTransactionCollection();
                TransactionGrid.ItemsSource = Dt.DefaultView;
            }
        }
예제 #18
0
        public void CanImportClass()
        {
            var sample = @"!Type:Class
NMyClassName
DMyClassDescription
^";

            QifDom parser = null;

            using (new CultureContext(new CultureInfo("en-GB")))
                using (var reader = new StringReader(sample))
                {
                    parser = QifDom.ImportFile(reader);
                }

            var @class = parser.ClassListTransactions[0];

            Assert.Equal("MyClassName", @class.ClassName);
            Assert.Equal("MyClassDescription", @class.Description);
        }
예제 #19
0
 public QifTransaction(QifDom qd)
 {
     QT_Dom = qd;
 }
예제 #20
0
파일: MainUI.cs 프로젝트: tolbxela/qif
 public MainUI()
 {
     InitializeComponent();
     qifDomPropertyGrid.SelectedObject = QifDom.ImportFile(Path.GetDirectoryName(Application.ExecutablePath) + "\\sample.qif");
 }