public static SchedulePlanningHandler CreatePlanningHandler(string recordType, TinyMoneyDataContext db = null) { SchedulePlanningHandler handler = null; string str = recordType; if (str != null) { if (!(str == "CrateExpenseRecord")) { if (str == "CreateIncomeRecord") { handler.HandlerType = RecordActionType.CreateIncomeRecord; return new ExpenseOrIncomeScheduleHanlder(db); } if (((str == "CreateTransferingRecord") || (str == "CreateBorrowRecord")) || (str == "CreateLeanRecord")) { } return handler; } handler = new ExpenseOrIncomeScheduleHanlder(db) { HandlerType = RecordActionType.CrateExpenseRecord }; } return handler; }
public MenuItemViewModel() { AccountBookDataContext = new TinyMoneyDataContext(); this.Items = new ObservableCollection<MainPageItemViewModel>(); this.SummaryItemList = new ObservableCollection<AnalyziationSummarization>(); this.InitializeSummaryEntry(); AppSetting.Instance.PropertyChanged += new PropertyChangedEventHandler(this.Instance_PropertyChanged); }
public static SchedulePlanningHandler CreatePlanningHandler(RecordActionType recordType, TinyMoneyDataContext db) { SchedulePlanningHandler handler = null; switch (recordType) { case RecordActionType.CrateExpenseRecord: case RecordActionType.CreateIncomeRecord: return new ExpenseOrIncomeScheduleHanlder(db); case RecordActionType.CreateTransferingRecord: return new TransferingItemTaskHandler(db); case RecordActionType.CreateBorrowRecord: case RecordActionType.CreateLeanRecord: return handler; } return handler; }
public void SaveCurrentMonthBudgetSettleReport(TinyMoneyDataContext db, System.DateTime date) { var month = date.Month; var year = date.Year; if (month == 1) { month = 12; year--; } else { month--; } var lastTimeReportSaved = IsolatedAppSetingsHelper.LastTimeBudgetReportSaved; if (lastTimeReportSaved.Month < DateTime.Now.Month && lastTimeReportSaved.Year <= DateTime.Now.Year) { IsolatedAppSetingsHelper.LastTimeBudgetReportSaved = DateTime.Now; if (db.BudgetMonthlyReports.Count<BudgetMonthlyReport>(p => ((p.Year == year) && (p.Month == month))) == 0) { Table<BudgetProject> budgetProjects = db.BudgetProjects; if (budgetProjects.Count<BudgetProject>() > 0) { foreach (BudgetProject project in budgetProjects) { BudgetMonthlyReport entity = new BudgetMonthlyReport { Month = month, Year = year, Amount = project.GetMoney().GetValueOrDefault(), BudgetProjectId = project.Id, ItemType = project.ItemType }; db.BudgetMonthlyReports.InsertOnSubmit(entity); } db.SubmitChanges(); } } } }
public void SaveCurrentMonthBudgetSettleReport(TinyMoneyDataContext db, System.DateTime date) { BugFixingFor1_8_9(); if (db.BudgetMonthlyReports.Count<BudgetMonthlyReport>(p => ((p.Year == date.Year) && (p.Month == (date.Month - 1)))) == 0) { Table<BudgetProject> budgetProjects = db.BudgetProjects; if (budgetProjects.Count<BudgetProject>() > 0) { foreach (BudgetProject project in budgetProjects) { BudgetMonthlyReport entity = new BudgetMonthlyReport { Month = date.Month - 1, Year = date.Year, Amount = project.GetMoney().GetValueOrDefault(), BudgetProjectId = project.Id, ItemType = project.ItemType }; db.BudgetMonthlyReports.InsertOnSubmit(entity); } db.SubmitChanges(); } } }
/// <summary> /// Initializes a new instance of the <see cref="SchedulePlanningManager" /> class. /// </summary> /// <param name="db">The db.</param> public SchedulePlanningManager(TinyMoneyDataContext db) { this.dataContext = db; this.ScheduleHanlderCache = new System.Collections.Generic.Dictionary<RecordActionType, SchedulePlanningHandler>(); }
/// <summary> /// Updates the table structure at V1_9_8. /// </summary> /// <param name="dataBaseUpdater">The data base updater.</param> /// <param name="updater">The updater.</param> public static void UpdateTableStructureAtV1_9_8(TinyMoneyDataContext db, Action<Repayment> updater) { var itemsToUpdate = db.Repayments.Where(p => p.RepaymentRecordType == RepaymentType.MoneyBorrowOrLeanRepayment).ToList(); itemsToUpdate.ForEach(p => updater((p))); db.SubmitChanges(); }
public ScheduleTaskManagement(TinyMoneyDataContext db) { this.DataContext = db; }
public void Setup(TinyMoneyDataContext db) { this.SaveFullTemplates(db); GenerateAllForOneDay(null); }
public SchedulePlanningHandler(TinyMoneyDataContext db) { this.DataContext = db; }
public TransferingItemTaskHandler(TinyMoneyDataContext db = null) : base(db) { this.HandlerType = RecordActionType.CreateTransferingRecord; }
public void SaveFullTemplates(TinyMoneyDataContext db) { if (!this.HasSaveFull) { System.Collections.Generic.List<TallySchedule> source = (from p in db.TallyScheduleTable where p.ProfileRecordType == ScheduleRecordType.TempleteRecord select p).ToList<TallySchedule>(); using (System.IO.IsolatedStorage.IsolatedStorageFile file = System.IO.IsolatedStorage.IsolatedStorageFile.GetUserStoreForApplication()) { string directoryName = System.IO.Path.GetDirectoryName("templates/tallyTemplates.xml"); if (!file.DirectoryExists(directoryName)) { file.CreateDirectory(directoryName); } System.IO.IsolatedStorage.IsolatedStorageFileStream fileWriteTo = null; if (!file.FileExists("templates/tallyTemplates.xml")) { fileWriteTo = file.CreateFile("templates/tallyTemplates.xml"); } else { fileWriteTo = file.OpenFile("templates/tallyTemplates.xml", System.IO.FileMode.Truncate); } using (fileWriteTo) { fileWriteTo.Position = 0; XmlHelper.SerializeToXmlString<System.Collections.Generic.List<TallySchedule>>(source, fileWriteTo); } } source.Clear(); this.HasSaveFull = true; } }
private static void LoadDefaultPeopleGroups(TinyMoneyDataContext db) { string displayLanguage = AppSetting.Instance.DisplayLanguage; System.Collections.Generic.List<PeopleGroup> peopleGroups = LocalizedFileHelper.LoadDataSourceFromLocalizedFile<PeopleGroup>(displayLanguage, "DefaultPeopleGroup.xml"); ApplicationSafetyService.TrackToRun(delegate { System.Collections.Generic.List<Guid> idsAlreadyExist = (from p in db.PeopleGroups select p.Id).ToList<System.Guid>(); (from p in peopleGroups where idsAlreadyExist.Contains(p.Id) select p).ToList<PeopleGroup>().ForEach(delegate(PeopleGroup p) { peopleGroups.Remove(p); }); if (peopleGroups.Count > 0) { db.PeopleGroups.InsertAllOnSubmit<PeopleGroup>(peopleGroups); db.SubmitChanges(); } }); }
public static void RebuildDatabase() { using (TinyMoneyDataContext context = new TinyMoneyDataContext()) { DatabaseSchemaUpdater dataBaseUpdater = null; if (!context.DatabaseExists()) { context.CreateDatabase(); dataBaseUpdater = context.CreateDatabaseSchemaUpdater(); dataBaseUpdater.DatabaseSchemaVersion = DatabaseVersion.CurrentVersion; dataBaseUpdater.Execute(); } else { dataBaseUpdater = context.CreateDatabaseSchemaUpdater(); int databaseSchemaVersion = dataBaseUpdater.DatabaseSchemaVersion; if (dataBaseUpdater.DatabaseSchemaVersion != DatabaseVersion.CurrentVersion) { try { UpdateStructure(dataBaseUpdater); failedToUpdate = false; } catch (System.Exception exception) { oldVersion = databaseSchemaVersion; failedToUpdate = true; throw exception; } finally { } } } BudgetManager.Current.SaveCurrentMonthBudgetSettleReport(context, System.DateTime.Now); } }
/// <summary> /// Initializes a new instance of the <see cref="TransferingHistoryViewModel"/> class. /// </summary> public TransferingHistoryViewModel() { TransferingHistoryContext = base.AccountBookDataContext; TransferingItemList = new ObservableCollection<TransferingItem>(); this.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(TransferingHistoryViewModel_PropertyChanged); }
public static void ResetOrders(TinyMoneyDataContext db) { try { var accounts = db.Accounts .ToList(); if (accounts.Count > 0) { accounts.ForEach((p, i) => p.Order = i + 1); db.SubmitChanges(); } accounts = null; } catch (Exception) { } }
public static void BugFixingFor1_9_9(TinyMoneyDataContext db) { try { var allDatasToFix = db.BudgetMonthlyReports.Where(p => (p.Month == 11 && p.Year == 2013) || (p.Month == 0 && p.Year == 2012)); allDatasToFix.ToList<BudgetMonthlyReport>() .ForEach((p) => { p.Month = 12; p.Year = 2012; }); db.SubmitChanges(); } catch (Exception) { } }
public ExpenseOrIncomeScheduleHanlder(TinyMoneyDataContext db) : base(db) { this.HandlerType = RecordActionType.CreateTranscationRecord; }
public static void UpdateOldData(TinyMoneyDataContext tinyMoneyDataContext) { ((System.Collections.Generic.IEnumerable<Repayment>)(from p in tinyMoneyDataContext.Repayments where ((int?)p.RepaymentRecordType) == null select p)).ForEach<Repayment>(delegate(Repayment p) { p.RepaymentRecordType = 0; }); tinyMoneyDataContext.SubmitChanges(); }
public void LoadSummary() { this.isStartLoadingSummary = true; if (hasLoadedFromFile) { LoadSummaryFromFile(); return; } AccountBookDataContext.Dispose(); AccountBookDataContext = new TinyMoneyDataContext(); { System.Collections.Generic.IEnumerable<AccountItem> data = null; this.countOfToday = this.AccountBookDataContext.AccountItems.Count<AccountItem>(p => p.CreateTime.Date == System.DateTime.Now.Date); var hasCustomized = AppSetting.Instance.BudgetStatsicSettings.Calculate(); if (hasCustomized) { var startDate = AppSetting.Instance.BudgetStatsicSettings.StartDate; var endDate = AppSetting.Instance.BudgetStatsicSettings.EndDate; data = ViewModelLocator.AccountItemViewModel.GetOneBudgetMonthData(startDate, endDate); } else { data = ViewModelLocator.AccountItemViewModel.GetOneMonthData(DateTime.Now); } this.CalculateMonthlyExpense(data); if (this._needToShowYearInfo) { data = ViewModelLocator.AccountItemViewModel.GetOneYearData(System.DateTime.Now.Year); this.ThisYearSummary.TotalExpenseAmount = this.CountSum(data, p => p.Type == ItemType.Expense); this.ThisYearSummary.TotalIncomeAmount = this.CountSum(data, p => p.Type == ItemType.Income); } this.TodaySummary.TotalExpenseAmount = this.CountToday(data, ItemType.Expense); this.TodaySummary.TotalIncomeAmount = this.CountToday(data, ItemType.Income); this.amountInfoOfToday = this.TodaySummary.TotalExpenseAmountInfo; System.DateTime date = System.DateTime.Now.Date; System.DateTime end = date; date = date.GetDateTimeOfFisrtDayOfWeek(); end = date.AddDays(7.0).Date; this.ThisWeekSummary.TotalExpenseAmount = this.CountThisWeek(data, ItemType.Expense, date, end); this.ThisWeekSummary.TotalIncomeAmount = this.CountThisWeek(data, ItemType.Income, date, end); if (this.isForAgent) { this.IsSummaryListLoaded = true; this.isForAgent = false; } else { this.AccountInfoSummary.MoneyInfo.Currency = AppSetting.Instance.DefaultCurrency; this.AccountInfoSummary.MoneyInfo.Money = this.AccountBookDataContext.Accounts.ToList<Account>().Sum<Account>(p => p.GetMoney()).GetValueOrDefault(); this.SetCashAmountOnAsset(); this.AccountItemRecordsSummary.TotalExpenseAmountInfo = this.CountRecords(ItemType.Expense); this.AccountItemRecordsSummary.TotalIncomeAmountInfo = this.CountRecords(ItemType.Income); BudgetManager.Current.UpdateCurrentMonthBudgetSummary(this.ThisMonthSummary.TotalExpenseAmount); this.IsSummaryListLoaded = true; } this.isStartLoadingSummary = false; } }
public static void LoadDefaultGroups(TinyMoneyDataContext db, System.Collections.Generic.IEnumerable<PeopleGroup> groups) { db.PeopleGroups.InsertAllOnSubmit<PeopleGroup>(groups); db.SubmitChanges(); }
public SecondSchedulePlanningManager(TinyMoneyDataContext db) : base(db) { }
public static void ForceRebuildDatabase() { GlobalIndicator.Instance.BusyForWork(LocalizedStrings.GetLanguageInfoByKey("RebuildingDatabase")); using (TinyMoneyDataContext context = new TinyMoneyDataContext()) { DatabaseSchemaUpdater updater = null; if (context.DatabaseExists()) { context.DeleteDatabase(); context.CreateDatabase(); updater = context.CreateDatabaseSchemaUpdater(); updater.DatabaseSchemaVersion = DatabaseVersion.CurrentVersion; updater.Execute(); } } ApplicationHelper.HasLoadDefaultCategorys = false; ViewModelLocator.instanceLoader.Reset("DataContext_AccountBookDataContext", new TinyMoneyDataContext()); GlobalIndicator.Instance.WorkDone(); }