/// <summary> /// Recovers the item processor. /// </summary> /// <param name="item">The item.</param> public static void RecoverItemProcessor(AccountItem item, TallySchedule taskInfo) { if (DataRecoverProcessor != null) { DataRecoverProcessor(item, taskInfo); } }
public virtual void ParseScheduleDataToXmlNode(XElement node, TallySchedule scheduleDataEntry) { node.SetAttributeValue("frequency", scheduleDataEntry.Frequency); node.SetAttributeValue("dayOfWeek", scheduleDataEntry.DayofWeek); node.SetAttributeValue("date", scheduleDataEntry.StartDate); var lastExecutedDate = node.TryGet(p => p.Attribute("lastExecutedDate"), p => p.Value); node.SetAttributeValue("lastExecutedDate", lastExecutedDate); var hasExecuted = node.TryGet(p => p.Attribute("hasExecuted"), p => p.Value).ToBoolean(false); if (scheduleDataEntry.HasExecuteChanged) { hasExecuted = false; } node.SetAttributeValue("hasExecuted", hasExecuted); node.SetAttributeValue("action", scheduleDataEntry.ActionType); node.SetAttributeValue("fromAccountId", scheduleDataEntry.FromAccountId); node.SetAttributeValue("toAccountId", scheduleDataEntry.ToAccountId); node.SetAttributeValue("categoryId", scheduleDataEntry.CategoryId); node.SetAttributeValue("amount", scheduleDataEntry.Money); node.SetAttributeValue("currency", scheduleDataEntry.Currency); node.SetAttributeValue("notes", scheduleDataEntry.Notes); node.SetAttributeValue("itemType", (int)scheduleDataEntry.RecordType); node.SetAttributeValue("isClaim", scheduleDataEntry.IsClaim); node.SetAttributeValue("active", scheduleDataEntry.IsActive); node.SetAttributeValue("transferingPoundageAmount", scheduleDataEntry.TransferingPoundageAmount); node.SetAttributeValue("dataProvider", scheduleDataEntry.DataProvider); node.SetAttributeValue("actionHandlerType", scheduleDataEntry.ActionHandlerType); node.SetAttributeValue("actionHandlerType", scheduleDataEntry.ActionHandlerType); node.SetAttributeValue("pictureIds", scheduleDataEntry.PictureIds); node.SetAttributeValue("peopleIds", scheduleDataEntry.PeopleIds); }
public void CreateAccountItemScheduleItem(TallySchedule scheduleInfo) { this.AccountBookDataContext.TallyScheduleTable.InsertOnSubmit(scheduleInfo); this.Tasks.Add(scheduleInfo); this.AccountBookDataContext.SubmitChanges(); this.manager.AddTask(scheduleInfo); }
public void Delete(TallySchedule obj) { this.AccountBookDataContext.TallyScheduleTable.DeleteOnSubmit(obj); this.Tasks.Remove(obj); this.AccountBookDataContext.SubmitChanges(); this.manager.DeleteTask(obj); }
public System.Collections.Generic.IEnumerable<GroupByCreateTimeAccountItemViewModel> GetGroupedRelatedItems(TallySchedule itemCompareTo, bool searchingOnlyCurrentMonthData = true, System.Action<AccountItem> itemAdded = null) { System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> list = new System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel>(); IOrderedEnumerable<AccountItem> source = from p in this.GetRelatedItems(itemCompareTo, searchingOnlyCurrentMonthData) orderby p.CreateTime descending select p; if (itemAdded == null) { itemAdded = (ai) => { }; } foreach (var item in (from p in source select p.CreateTime.Date).Distinct<System.DateTime>()) { GroupByCreateTimeAccountItemViewModel agvm = new GroupByCreateTimeAccountItemViewModel(item); (from p in source.Where<AccountItem>(p => p.CreateTime.Date == item.Date) orderby p.Money select p) .ToList<AccountItem>() .ForEach((x) => { agvm.Add(x); itemAdded(x); }); list.Add(agvm); } this.HasLoadAssociatedItemsForCurrentViewAccount = true; return list; }
public void ExecuteTask(TallySchedule scheduleItem) { if (this.manager.ExecuteOnePlan(scheduleItem)) { ViewModelLocator.AccountItemViewModel.IsDataLoaded = false; ViewModelLocator.AccountViewModel.IsDataLoaded = false; ViewModelLocator.AccountViewModel.HasLoadAssociatedItemsForCurrentViewAccount = false; ViewModelLocator.MainPageViewModel.IsSummaryListLoaded = false; CommonExtensions.AlertNotification(null, AppResources.TaskCompletedMessageFormatter.FormatWith(new object[] { 1 }), null); } }
public EditExpenseOrIncomeSchedule() { this.InitializeComponent(); this.manager = new SecondSchedulePlanningManager(ViewModelLocator.AccountBookDataContext); TiltEffect.SetIsTiltEnabled(this, true); base.ApplicationBar.GetIconButtonFrom(0).Text = AppResources.Save; base.ApplicationBar.GetIconButtonFrom(1).Text = AppResources.Cancel; this.SetExampleName(); this.scheduleManagerViewModel = ViewModelLocator.ScheduleManagerViewModel; this.scheduleDataInfo = new TallySchedule(); this.manager = this.scheduleManagerViewModel.ScheduleManager; this.InitializedFrequencySelector(); base.DataContext = this.scheduleManagerViewModel; }
/// <summary> /// Adds the notification. /// </summary> /// <param name="notification">The notification.</param> public void AddNotification(TallySchedule notification) { notification.ProfileRecordType = ScheduleRecordType.Notification; if (notification.IsActive.GetValueOrDefault()) { AlarmManager.AddNotification(notification); } this.Notifications.Add(notification); this.AccountBookDataContext.TallyScheduleTable.InsertOnSubmit(notification); this.AccountBookDataContext.SubmitChanges(); }
/// <summary> /// Adds the task. /// </summary> /// <param name="task">The task.</param> public virtual void AddTask(TallySchedule task) { try { XDocument providerInfo = this.Load(false); XElement element = providerInfo.Element("ScheduleTasks").Element("Tasks"); System.Guid id = task.Id; XElement content = this.CreateScheduleDataInfoNode(task, id, null); element.Add(content); this.SaveBackPlannings(providerInfo); } catch (System.Exception exception) { this.SaveErrorsTo("HandlingScheduleTaskErrors.log", new string[] { exception.Message }); } }
void EditExpenseOrIncomeSchedule_Loaded(object sender, RoutedEventArgs e) { if (!this.hasInitializedBinding) { this.action = this.GetNavigatingParameter("action", null); this.InitializedApplicationBar(); if (ViewModelLocator.AccountViewModel.Accounts.Count == 0) { ViewModelLocator.AccountViewModel.QuickLoadData(); } hasInitializedBinding = true; if (this.action == "edit") { System.Guid id = this.GetNavigatingParameter("id", null).ToGuid(); this.scheduleDataInfo = this.scheduleManagerViewModel.Tasks.FirstOrDefault<TallySchedule>(p => p.Id == id); this.scheduleManagerViewModel.Current = this.scheduleDataInfo; this.taskType = this.scheduleDataInfo.ActionHandlerType; if (this.taskType == RecordActionType.CreateTranscationRecord) { this.associatedAccountItem = this.scheduleManagerViewModel.ReBuildAccountItem(this.scheduleDataInfo); if (this.associatedAccountItem != null) { this.associatedAccountItem.PropertyChanged += associatedAccountItem_PropertyChanged; } } else { this.assoicatedTransferingItem = this.scheduleManagerViewModel.ReBuildTransferingItem(this.scheduleDataInfo); } this.BindingDataToEdit(); } else { this.scheduleDataInfo = new TallySchedule(); } } }
public static bool EnsureToRun(TallySchedule tallySchedule, System.DateTime executingDate) { if (!tallySchedule.IsActive.GetValueOrDefault()) { return false; } bool flag = false; string str = tallySchedule.Frequency.ToString().ToLowerInvariant(); string str2 = tallySchedule.DayofWeek.GetValueOrDefault().ToString().ToLowerInvariant(); string str3 = executingDate.DayOfWeek.ToString().ToLowerInvariant(); if (str == "everymonth") { if (tallySchedule.StartDate.GetValueOrDefault() == executingDate.Day) { flag = true; } return flag; } if ((str == "everyweek") && (str3 == str2)) { return true; } if (str == "everyday") { return true; } if ((str == "workday") && !AppSetting.Weekends.Contains<string>(str3)) { return true; } if ((str == "weekend") && AppSetting.Weekends.Contains<string>(str3)) { return true; } bool flag1 = str == "specificdate"; return flag; }
public System.Collections.Generic.IEnumerable<GroupByCreateTimeAccountItemViewModel> GetGroupedRelatedItems(TallySchedule itemCompareTo, bool searchingOnlyCurrentMonthData = true, System.Action<AccountItem> itemAdded = null) { System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> list = new System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel>(); IOrderedEnumerable<AccountItem> source = from p in this.GetRelatedItems(itemCompareTo, searchingOnlyCurrentMonthData) orderby p.CreateTime descending select p; if (itemAdded == null) { itemAdded = delegate(AccountItem ai) { }; } using (System.Collections.Generic.IEnumerator<DateTime> enumerator = (from p in source select p.CreateTime.Date).Distinct<System.DateTime>().GetEnumerator()) { System.Func<AccountItem, Boolean> predicate = null; System.DateTime item; while (enumerator.MoveNext()) { item = enumerator.Current; GroupByCreateTimeAccountItemViewModel agvm = new GroupByCreateTimeAccountItemViewModel(item); if (predicate == null) { predicate = p => p.CreateTime.Date == item.Date; } (from p in source.Where<AccountItem>(predicate) orderby p.Money select p).ToList<AccountItem>().ForEach(delegate(AccountItem x) { agvm.Add(x); itemAdded(x); }); list.Add(agvm); } } this.HasLoadAssociatedItemsForCurrentViewAccount = true; return list; }
public override bool ProcessingExecute(TallySchedule scheduleData) { AccountItem entity = new AccountItem { Account = scheduleData.FromAccount, AccountId = scheduleData.FromAccountId, CategoryId = scheduleData.CategoryId, CreateTime = System.DateTime.Now.Date, Description = scheduleData.Notes, IsClaim = new bool?((scheduleData.RecordType == ItemType.Income) ? false : scheduleData.IsClaim), Money = scheduleData.Money, State = AccountItemState.Active, Type = scheduleData.RecordType, AutoTokenId = scheduleData.Id }; Account account = entity.Account; decimal num = (entity.Type == ItemType.Expense) ? -entity.Money : entity.Money; decimal? balance = account.Balance; decimal num2 = num; account.Balance = balance.HasValue ? new decimal?(balance.GetValueOrDefault() + num2) : null; base.DataContext.AccountItems.InsertOnSubmit(entity); base.DataContext.SubmitChanges(); return true; }
/// <summary> /// Adds the repayment alarm notification. /// </summary> /// <param name="notification">The notification.</param> public static void AddNotification(TallySchedule notification) { string name = notification.Id.ToString(); if (ScheduledActionService.GetActions<ScheduledNotification>().FirstOrDefault<ScheduledNotification>(p => (p.Name == name)) != null) { try { ScheduledActionService.Remove(name); } catch (System.Exception) { } } ScheduledNotification action = null; Reminder reminder = new Reminder(name) { NavigationUri = new Uri("/Pages/NotificationCenter/NotificationDetailsViewer.xaml?id={0}".FormatWith(new object[] { notification.Id }), UriKind.RelativeOrAbsolute), Title = AppResources.Notification.ToLower(), }; action = reminder; action.RecurrenceType = notification.RecurrenceInterval.GetValueOrDefault().ToEnum<RecurrenceInterval>(); action.BeginTime = notification.StartTime; action.ExpirationTime = notification.EndTime; action.Content = notification.Name; try { ScheduledActionService.Add(action); } catch (System.Exception) { } }
private void RecoverPeoples(AccountItem accountItem, TallySchedule taskInfo) { if (taskInfo.Peoples != null && taskInfo.Peoples.Length > 0) { var ids = taskInfo.Peoples; var originalData = AccountBookDataContext.PeopleAssociationDatas .Where(p => ids.Contains(p.PeopleId) && p.AttachedId == accountItem.AutoTokenId) .ToList() .Select(p => new PeopleAssociationData() { PeopleId = p.PeopleId, Comments = p.Comments, AttachedId = accountItem.Id, CreateAt = DateTime.Now }).ToList(); foreach (var pic in originalData) { AccountBookDataContext.PeopleAssociationDatas.InsertOnSubmit(pic); } } }
private void GoToEditTallyScheduleItem(TallySchedule scheduleItem) { this.NavigateTo(ViewPath.ScheduleEditorPage, new object[] { "edit", scheduleItem.Id }); this.ScheduledItems.SelectedItem = null; }
public static void NavigateTo(PhoneApplicationPage fromPage, TallySchedule template, PageActionType pageAction) { EditingItemGetter = () => template; fromPage.NavigateTo("/Pages/CustomizedTally/CustomizedTallyItemEditorPage.xaml?action={0}", new object[] { pageAction }); }
public void Update(TallySchedule scheduleInfo) { this.AccountBookDataContext.SubmitChanges(); this.manager.UpdateTaskInfo(scheduleInfo); }
protected override void OnNavigatedTo(NavigationEventArgs e) { if (e.NavigationMode != NavigationMode.Back) { this._id = e.GetNavigatingParameter("id").ToGuid(); this._action = e.GetNavigatingParameter("action").ToEnum<PageActionType>(); System.Threading.ThreadPool.QueueUserWorkItem((o) => { if (_action == PageActionType.Edit) { var item = ViewModelLocator.NotificationsViewModel.Notifications.FirstOrDefault(p => p.Id == _id); if (item != null) { Current = item; } } this.Dispatcher.BeginInvoke(() => { if (_action == PageActionType.Add) { Current = new TallySchedule(); Current.StartTime = DateTime.Now.AddSeconds(20); Current.EndTime = DateTime.Now.AddYears(1); } else { this.EnableAlarmNotification.IsEnabled = false; this.PageTitle.Text = AppResources.Edit.ToLower(); } this.DataContext = Current; }); }); } base.OnNavigatedTo(e); }
public AccountItem ReBuildAccountItem(TallySchedule scheduleDataInfo) { var data = new AccountItem { Account = scheduleDataInfo.FromAccount, AccountId = scheduleDataInfo.FromAccountId, AutoTokenId = scheduleDataInfo.Id, Category = scheduleDataInfo.AssociatedCategory, CategoryId = scheduleDataInfo.CategoryId, Description = scheduleDataInfo.Notes, IsClaim = new bool?(scheduleDataInfo.IsClaim), Money = scheduleDataInfo.Money, State = AccountItemState.Active, Type = scheduleDataInfo.RecordType, IsInDeattchedFromDatabaseMode = true, }; RebuildPicture(data, scheduleDataInfo.Pictures); RebuildPeople(data, scheduleDataInfo.Peoples); return data; }
public TransferingItem ReBuildTransferingItem(TallySchedule tallySchedule) { return new TransferingItem() { FromAccount = tallySchedule.FromAccount, ToAccount = tallySchedule.ToAccount, AssociatedTaskId = tallySchedule.Id, Currency = tallySchedule.Currency, Notes = tallySchedule.Notes, Amount = tallySchedule.Money, TransferingPoundageAmount = tallySchedule.TransferingPoundageAmount, }; }
/// <summary> /// Updates the task info node. /// </summary> /// <param name="task">The task.</param> /// <param name="taskInfoNode">The task info node.</param> /// <returns></returns> public virtual XElement UpdateTaskInfoNode(TallySchedule task, XElement taskInfoNode = null) { taskInfoNode = taskInfoNode ?? new XElement("Task"); System.Guid id = task.Id; taskInfoNode.SetAttributeValue("frequency", task.Frequency); taskInfoNode.SetAttributeValue("dayOfWeek", task.DayofWeek); taskInfoNode.SetAttributeValue("date", task.StartDate); return taskInfoNode; }
public System.Collections.Generic.IEnumerable<AccountItem> GetRelatedItems(TallySchedule itemCompareTo, bool searchingOnlyCurrentMonth = true) { System.Func<AccountItem, Boolean> predicate = null; System.Collections.Generic.IEnumerable<AccountItem> source = null; if (itemCompareTo.ActionHandlerType == RecordActionType.CreateTranscationRecord) { source = from p in this.AccountBookDataContext.AccountItems where ((((int)p.Type) == ((int)itemCompareTo.RecordType)) && (p.AutoTokenId == itemCompareTo.Id)) && (p.AutoTokenId != System.Guid.Empty) select p; } else if (itemCompareTo.ActionHandlerType == RecordActionType.CreateTransferingRecord) { // load Transfering list. var transfering = ViewModelLocator.TransferingHistoryViewModel .AccountBookDataContext.TransferingItems.Where(p => p.AssociatedTaskId == itemCompareTo.Id); transfering = transfering.OrderByDescending(p => p.TransferingDate.Date); var exchange = AppResources.TransferingAccount; var dates = transfering.Select(p => p.TransferingDate.Date).Distinct().ToList(); source = transfering.ToList().Select(x => new AccountItem() { Account = x.FromAccount, TypeInfo = exchange, Money = x.Amount, SecondInfo = "{0}“{1}”{2}“{3}”".FormatWith(AppResources.From, x.FromAccountName, AppResources.To, x.ToAccountName), ThirdInfo = x.Notes, }); } if (!searchingOnlyCurrentMonth) { return source; } if (predicate == null) { predicate = p => (p.CreateTime.Date >= this.SearchingCondition.StartDate.GetValueOrDefault().Date) && (p.CreateTime.Date <= this.SearchingCondition.EndDate.GetValueOrDefault().Date); } return source.Where<AccountItem>(predicate); }
public abstract bool ProcessingExecute(TallySchedule scheduleData);
/// <summary> /// Updates the task info. /// </summary> /// <param name="task">The task.</param> public virtual void UpdateTaskInfo(TallySchedule task) { System.Func<XElement, Boolean> predicate = null; try { XDocument providerInfo = this.Load(false); if (predicate == null) { predicate = p => p.TryGet<string, XAttribute>(x => x.Attribute("autoTokenId"), x => x.Value).ToGuid() == task.Id; } XElement element = providerInfo.Element("ScheduleTasks").Element("Tasks").Descendants("ScheduleData").Where<XElement>(predicate).FirstOrDefault<XElement>(); if (element != null) { System.Guid taskId = element.TryGet<string, XAttribute>(p => p.Attribute("taskId"), p => p.Value).ToGuid(); this.CreateScheduleDataInfoNode(task, taskId, element); this.SaveBackPlannings(providerInfo); } } catch (System.Exception exception) { this.SaveErrorsTo("HandlingScheduleTaskErrors.log", new string[] { exception.Message }); } }
/// <summary> /// Executes the one plan. /// </summary> /// <param name="planToExecute">The plan to execute.</param> /// <returns></returns> public virtual bool ExecuteOnePlan(TallySchedule planToExecute) { TallySchedule scheduleData = planToExecute; if (scheduleData == null) { return false; } SchedulePlanningHandler handler = null; this.ScheduleHanlderCache.TryGetValue(planToExecute.ActionType, out handler); if (handler == null) { handler = SchedulePlanningHandler.CreatePlanningHandler(planToExecute.ActionType, this.dataContext); this.ScheduleHanlderCache[planToExecute.ActionType] = handler; } return handler.ProcessingExecute(scheduleData); }
/// <summary> /// Deletes the task. /// </summary> /// <param name="obj">The obj.</param> public virtual void DeleteTask(TallySchedule obj) { System.Func<XElement, Boolean> predicate = null; try { XDocument providerInfo = this.Load(false); if (predicate == null) { predicate = p => p.Attribute("autoTokenId").Value.ToGuid() == obj.Id; } XElement element = providerInfo.Element("ScheduleTasks").Element("Tasks").Descendants("ScheduleData").Where<XElement>(predicate).FirstOrDefault<XElement>(); if (element != null) { element.Remove(); this.SaveBackPlannings(providerInfo); } } catch (System.Exception exception) { this.SaveErrorsTo("HandlingScheduleTaskErrors.log", new string[] { exception.Message }); } }
/// <summary> /// Creates the schedule data info node. /// </summary> /// <param name="scheduleDataEntry">The schedule data entry.</param> /// <param name="taskId">The task id.</param> /// <param name="scheduleDataNode">The schedule data node.</param> /// <returns></returns> protected virtual XElement CreateScheduleDataInfoNode(TallySchedule scheduleDataEntry, System.Guid taskId, XElement scheduleDataNode = null) { scheduleDataNode = scheduleDataNode ?? new XElement("ScheduleData"); scheduleDataNode.SetAttributeValue("taskId", taskId); scheduleDataNode.SetAttributeValue("autoTokenId", scheduleDataEntry.Id); SchedulePlanningHandler handler = GetHandler(scheduleDataEntry.ActionType); handler.ParseScheduleDataToXmlNode(scheduleDataNode, scheduleDataEntry); return scheduleDataNode; }
/// <summary> /// Recovers the picutres. /// </summary> /// <param name="accountItem">The account item.</param> /// <param name="taskInfo">The task info.</param> private void RecoverPicutres(AccountItem accountItem, TallySchedule taskInfo) { if (taskInfo.Pictures != null && taskInfo.Pictures.Length > 0) { var ids = taskInfo.Pictures; var originalPictures = AccountBookDataContext.PictureInfos .Where(p => ids.Contains(p.PictureId) && p.Tag == PictureInfo.ScheduledAccountItemsTag) .ToList() .Select(p => new PictureInfo() { PictureId = p.PictureId, AttachedId = accountItem.Id, Comments = p.Comments, CreateAt = DateTime.Now, FullPath = p.FullPath, FileName = p.FileName, Tag = PictureInfo.AccountItemsTag }).ToList(); ViewModelLocator.PicturesViewModel.SavePicturesFrom(originalPictures, PictureInfo.ScheduledAccountItemsTag); foreach (var pic in originalPictures) { //accountItem.Pictures.Add(pic); AccountBookDataContext.PictureInfos.InsertOnSubmit(pic); //accountItem.Pictures.Add(pic); } } }
/// <summary> /// Handles the account item adding for task. /// </summary> /// <param name="accountItem">The account item.</param> /// <param name="taskInfo">The task info.</param> public void HandleAccountItemAddingForTask(AccountItem accountItem, TallySchedule taskInfo) { if (taskInfo != null) { if (!taskInfo.PeopleIds.IsNullOrEmpty()) { // RecoverPeoples(accountItem, taskInfo); } if (!taskInfo.PictureIds.IsNullOrEmpty()) { // RecoverPicutres(accountItem, taskInfo); } } ViewModelLocator.AccountItemViewModel.AddItem(accountItem); ViewModelLocator.AccountViewModel.WithdrawlOrDeposit(accountItem.Account, (accountItem.Type == ItemType.Expense) ? -accountItem.Money : accountItem.Money); }