public static Category getCategory(Transaction e) { string name = e.businessName; Category category; if (e.category != null) return e.category; if (!categoriesMap.TryGetValue(name, out category)) { return getDefaultCategory(); //category = new Category(); // i should add it to category list.. } return category; }
internal static void updateAllTransactionFilter(Transaction exp) { filterMap.Add(exp.businessName); }
internal static void updateExpenseCategory(Transaction t, Category selectedCategory) { t.category = selectedCategory; }
public static void loadTransactions() { if (!File.Exists(dataFolder + dataTransactionsFilename)) return; StreamReader sr = new StreamReader(dataFolder + dataTransactionsFilename, Encoding.GetEncoding("ISO-8859-8")); using (XmlReader reader = XmlReader.Create(sr)) { Month month = null; DateTime date = new DateTime(); Transaction e = null; while (reader.Read()) { // Get element name and switch on it. switch (reader.Name) { case "Month": if (reader.IsStartElement()) { month = new Month(); reader.ReadToFollowing("Date"); if (reader.Read()) date = stringDateToDateTime(reader.Value.Trim()); } else { month.sortTransactions(); Database.months.Add(date, month); } break; case "Transaction": if (reader.IsStartElement()) { XmlReader inner = reader.ReadSubtree(); e = new Transaction(); while (inner.Read()) { if (inner.IsStartElement()) { switch (inner.Name) { case "HashCode": if (inner.Read()) e.hashCode = Convert.ToInt32(inner.Value.Trim()); break; case "Date": if (inner.Read()) e.date = stringDateToDateTime(inner.Value.Trim()); break; case "BusinessName": if (inner.Read()) e.businessName = inner.Value.Trim(); break; case "TransactionPrice": if (inner.Read()) e.transactionPrice = Double.Parse(inner.Value.Trim()); break; case "BillingPrice": if (inner.Read()) e.billingPrice = Double.Parse(inner.Value.Trim()); break; //case "PaymentID": // if (inner.Read()) // e.creditCardNumber = inner.Value.Trim(); // break; case "PrimaryCategory": string primary = null; string secondary = null; if (inner.Read()) primary = inner.Value.Trim(); if (reader.ReadToFollowing("SecondaryCategory")) if (inner.Read()) { secondary = inner.Value.Trim(); e.category = Database.getCategory(primary, secondary); } break; case "PaymentInfo": string paymentId = null; string paymentTypeString = null; string startDateString = null; string endDateString = null; while (inner.Read()) { if (inner.IsStartElement()) { switch (inner.Name) { case "Id": if (inner.Read()) paymentId = inner.Value.Trim(); break; case "Name": if (inner.Read()) paymentTypeString = inner.Value.Trim(); break; case "StartDate": if (inner.Read()) startDateString = inner.Value.Trim(); break; case "EndDate": if (inner.Read()) endDateString = inner.Value.Trim(); break; } } if (inner.Name.Equals("PaymentInfo")) { DateTime startDate = stringDateToDateTime(startDateString); DateTime endDate = stringDateToDateTime(endDateString); PaymentType paymentType = PaymentInfo.parsePaymentTypeString(paymentTypeString); e.paymentInfo = month.getPaymentInfo(paymentId,paymentType,startDate,endDate); break; } } break; case "ReceiptID": if (inner.Read()) e.receiptId = Convert.ToInt32(inner.Value.Trim()); break; case "Type": if (inner.Read()) e.setType(inner.Value.Trim()); break; case "Details": if (inner.Read()) e.details = inner.Value.Trim(); break; case "Filter": e.filter = true; break; case "Comment": if (inner.Read()) e.comment = inner.Value.Trim(); break; } } } } reader.Skip(); if (e.paymentInfo == null) Console.Write(e.businessName + "\n"); month.addTransaction(e); break; } } } sr.Close(); sr.Dispose(); }
internal static void updateAllExpensesCategory(Transaction t, Category selectedCategory) { categoriesMap.Add(t.businessName, selectedCategory); }
public void addTransaction(Transaction t) { transactions.Add(t); if (!paymentsInfoList.Contains(t.paymentInfo)) paymentsInfoList.Add(t.paymentInfo); }
private Transaction parseInternationalExpense(List<string> row) { Transaction e = new Transaction(); e.date = Database.stringDateToDateTime(row[0]); Database.stringDateToDateTime(row[1]); if (e.date.Equals(new DateTime(1, 1, 1))) throw new Exception(); e.businessName = row[2]; e.transactionPrice = Double.Parse(row[5]); e.billingPrice = Double.Parse(row[5]); e.receiptId = 0;// Convert.ToInt32(row[4]); e.details = row[7]; return e; }
private Transaction parseExpense(List<string> row) { Transaction e = new Transaction(); e.date = Database.stringDateToDateTime(row[0]); if (e.date.Equals(new DateTime(1, 1, 1))) throw new Exception(); e.businessName = row[1]; e.transactionPrice = Double.Parse(row[2]); e.billingPrice = Double.Parse(row[3]); if (e.billingPrice < 0) { e.type = FinancePlus.PersistentLayer.Type.Credit; //e.billingPrice = Math.Abs(e.billingPrice); //e.transactionPrice = Math.Abs(e.transactionPrice); } e.receiptId = Convert.ToInt32(row[4]); e.details = row[5]; return e; }
public static Transaction parseIncome(List<string> row, DateTime date) { Transaction e = new Transaction(); e.date = Database.stringDateToDateTime(row[0] + "/" + date.Year); if (e.date.Equals(new DateTime(1, 1, 1))) throw new Exception(); e.businessName = row[1]; e.receiptId = Convert.ToInt32(row[2]); e.transactionPrice = Double.Parse(row[5]); e.billingPrice = Double.Parse(row[5]); e.type = FinancePlus.PersistentLayer.Type.Income; //e.details = null; return e; }
public static Transaction parseTransaction(List<string> row, DateTime date) { Transaction t = new Transaction(); t.date = Database.stringDateToDateTime(row[0] + "/" + date.Year); if (t.date.Equals(new DateTime(1, 1, 1))) throw new Exception(); t.businessName = row[1]; t.receiptId = Convert.ToInt32(row[2]); try { t.transactionPrice = Double.Parse(row[4]); t.billingPrice = Double.Parse(row[4]); t.type = FinancePlus.PersistentLayer.Type.Expense; } catch { t.transactionPrice = Double.Parse(row[5]); t.billingPrice = Double.Parse(row[5]); t.type = FinancePlus.PersistentLayer.Type.Income; } return t; }