public override bool ParseScheduleDataToXmlNode(XElement scheduleDataEntry)
        {
            TransferingItem data = new TransferingItem
            {
                FromAccountId = scheduleDataEntry.Attribute("fromAccountId").Value.ToGuid()
            };

            if (data.FromAccountId == System.Guid.Empty)
            {
                return false;
            }

            data.ToAccountId = scheduleDataEntry.TryGet<string, XAttribute>(p => p.Attribute("toAccountId"), p => p.Value).ToGuid();
            if (data.ToAccountId == System.Guid.Empty)
            {
                return false;
            }

            data.TransferingDate = System.DateTime.Now;
            data.Notes = scheduleDataEntry.TryGet<string, XAttribute>(p => p.Attribute("notes"), p => p.Value);

            data.Amount = scheduleDataEntry.TryGet<string, XAttribute>(p => p.Attribute("amount"), p => p.Value).ToDecimal();

            data.TransferingPoundageAmount = scheduleDataEntry.TryGet<string, XAttribute>(p => p.Attribute("transferingPoundageAmount"), p => p.Value).ToDecimal();

            data.AssociatedTaskId = scheduleDataEntry.TryGet<string, XAttribute>(p => p.Attribute("autoTokenId"), p => p.Value).ToGuid();

            this.OnHandlerDataParsed(data);
            return true;
        }
        /// <summary>
        /// return a bool value, indicate that the revert opreation is ok or not. If true, it's ok, otherwise, it's no cause of the 
        /// related accounts do not exist longer.
        /// </summary>
        /// <param name="item"></param>
        /// <returns></returns>
        public bool Revert(TransferingItem item)
        {
            var fromAccount = AccountBookDataContext.Accounts.FirstOrDefault(p => p.Id == item.FromAccountId);
            var toAccount = AccountBookDataContext.Accounts.FirstOrDefault(p => p.Id == item.ToAccountId);

            if (fromAccount != null && toAccount != null)
            {
                //exchange those two account.   
                ViewModelLocator
                    .AccountViewModel.Transfer(toAccount, fromAccount, item.Amount, item.Amount, false);

                //delete this transfering item.
                DeleteItem(item.Id);

                return true;
            }

            return false;
        }
 /// <summary>
 /// Deletes the item.
 /// </summary>
 /// <param name="id">The id.</param>
 public void DeleteItem(TransferingItem item)
 {
     if (item == null) return;
     TransferingItemList.Remove(item);
     TransferingHistoryContext.TransferingItems.DeleteOnSubmit(item);
     TransferingHistoryContext.SubmitChanges();
 }
 public TransferingItem CreateOrUpdateTransferingItem(Account fromAccount, Account toAccount, decimal amount, string transferingPoundageAmountInfo, DateTime transferingDate, string notes, TransferingItem itemToUpdate = null)
 {
     TransferingItem entry = itemToUpdate ?? new TransferingItem();
     entry.Amount = amount;
     entry.AmountInfo = AccountItemMoney.GetMoneyInfoWithCurrency(fromAccount.CurrencyType, amount) + (
         transferingPoundageAmountInfo.IsNullOrEmpty() ? string.Empty : ("(" + transferingPoundageAmountInfo + ")"));
     entry.Currency = fromAccount.CurrencyType;
     entry.FromAccountName = fromAccount.Name;
     entry.ToAccountName = toAccount.Name;
     entry.TransferingDate = transferingDate;
     entry.FromAccountId = fromAccount.Id;
     entry.ToAccountId = toAccount.Id;
     entry.Notes = notes;
     return entry;
 }
        /// <summary>
        /// Adds the specified from account.
        /// </summary>
        /// <param name="fromAccount">From account.</param>
        /// <param name="toAccount">To account.</param>
        /// <param name="amount">The amount.</param>
        public void Add(Account fromAccount, Account toAccount, decimal amount, string transferingPoundageAmountInfo, DateTime transferingDate, string notes)
        {
            TransferingItem entry = new TransferingItem();
            entry.Amount = amount;
            entry.AmountInfo = AccountItemMoney.GetMoneyInfoWithCurrency(fromAccount.CurrencyType, amount) + (
                transferingPoundageAmountInfo.IsNullOrEmpty() ? string.Empty : ("(" + transferingPoundageAmountInfo + ")"));
            entry.Currency = fromAccount.CurrencyType;
            entry.FromAccountName = fromAccount.Name;
            entry.ToAccountName = toAccount.Name;
            entry.TransferingDate = transferingDate;
            entry.FromAccountId = fromAccount.Id;
            entry.ToAccountId = toAccount.Id;
            entry.Notes = notes;

            //TransferingItemRepository.Instance.Add(entry);
            TransferingItemList.Add(entry);

            TransferingHistoryContext.TransferingItems.InsertOnSubmit(entry);

        }
        /// <summary>
        /// Transfers the specified transfering item.
        /// </summary>
        /// <param name="transferingItem">The transfering item.</param>
        public void Transfer(TransferingItem transferingItem)
        {
            var from = this.AccountBookDataContext.Accounts.FirstOrDefault(p => p.Id == transferingItem.FromAccountId);
            var amountFrom = transferingItem.Amount;

            var to = this.AccountBookDataContext.Accounts.FirstOrDefault(p => p.Id == transferingItem.ToAccountId);

            decimal? balance = from.Balance;
            decimal num = amountFrom;

            from.Balance = balance.HasValue ? new decimal?(balance.GetValueOrDefault() - num) : null;
            decimal? nullable3 = to.Balance;

            CurrencyType currencyFrom = from.Currency;
            CurrencyType currency = to.Currency;

            var amountToTo = currencyFrom.GetConversionRateTo(currency) * amountFrom;

            to.Balance = nullable3.HasValue ? new decimal?(nullable3.GetValueOrDefault() + amountToTo) : null;

            AccountBookDataContext.TransferingItems.InsertOnSubmit(transferingItem);

            this.SubmitChanges();
        }
        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();
                }
            }
        }
        private void AddItemToGroup(TransferingItem entry)
        {
            var group = this.GroupItems.FirstOrDefault(p => p.Key == entry.TransferingDate.Date);

            if (group == null)
            {
                group = new DateTimeBasedGroupingViewModel<TransferingItem>(entry.TransferingDate);

                this.GroupItems.AddRange(group);
            }

            group.Add(entry);
        }
 /// <summary>
 /// Updates the assoicated transfering item info.
 /// </summary>
 /// <param name="assoicatedTransferingItem">The assoicated transfering item.</param>
 private void UpdateAssoicatedTransferingItemInfo(TransferingItem transferingItem)
 {
     this.AccountItemTypeAndCategoryInfo.Text = "{0}“{1}”".FormatWith(AppResources.From.ToLower(), transferingItem.FromAccountName);
     this.AccountItemAccountName.Text = "{0}“{1}”".FormatWith(AppResources.To.ToLower(), transferingItem.ToAccountName);
     this.AccountItemAccountAmountInfo.Text = transferingItem.AmountInfo;
     this.scheduleDataInfo.Money = transferingItem.Amount;
 }
 public void BindEditingData(TransferingItem transferingItem)
 {
     this.UpdateAssoicatedTransferingItemInfo(transferingItem);
     this.AccountItemTypeAndCategoryInfo.Style = (Style)base.Resources["PhoneTextNormalStyle"];
     this.SetScheduledItemNameFromDetailsInfo(transferingItem);
 }
        private void AccountItemInfoEditor_Click(object sender, RoutedEventArgs e)
        {
            if (taskType == RecordActionType.CreateTranscationRecord)
            {
                NewOrEditAccountItemPage.IsSelectionMode = true;
                NewOrEditAccountItemPage.SelectionObjectType = ScheduleRecordType.ScheduledRecord;
                NewOrEditAccountItemPage.ScheduledTaskInfo = scheduleDataInfo;
                NewOrEditAccountItemPage.RegisterSelectionMode(this.AssociatedAccountItem, (accountItem) =>
                {
                    NewOrEditAccountItemPage.IsSelectionMode = false;

                    NewOrEditAccountItemPage.SelectionObjectType = ScheduleRecordType.ProfileRecord;
                    this.BindEditingData(accountItem);
                });
                this.NavigateTo("{0}?action=selection", new object[] { "/Pages/NewOrEditAccountItemPage.xaml" });
            }
            else if (taskType == RecordActionType.CreateTransferingRecord)
            {
                AccountTransferingPage.IsSelectionMode = true;
                AccountTransferingPage.RegisterSelectionMode(this.assoicatedTransferingItem, transferingItem =>
                {
                    NewOrEditAccountItemPage.IsSelectionMode = false;
                    this.BindEditingData(transferingItem);
                    this.assoicatedTransferingItem = transferingItem;
                });

                this.NavigateTo("{0}?action=selection", new object[] { "/Pages/AccountTransferingPage.xaml" });
            }
        }
 /// <summary>
 /// Recovers the item processor.
 /// </summary>
 /// <param name="item">The item.</param>
 public static void RecoverItemProcessor(TransferingItem item)
 {
     if (DataRecoverProcessor != null)
     {
         DataRecoverProcessor(item);
     }
 }
        /// <summary>
        /// Deletes the item.
        /// </summary>
        /// <param name="id">The id.</param>
        public void DeleteItem(TransferingItem item)
        {
            if (item == null) return;

            if (this.GroupItems != null)
            {
                var group = this.GroupItems.FirstOrDefault(p => p.Key.Date == item.TransferingDate.Date);
                if (group != null)
                {
                    group.Remove(item);
                }
            }

            AccountBookDataContext.TransferingItems.DeleteOnSubmit(item);
            AccountBookDataContext.SubmitChanges();
        }
 /// <summary>
 /// Creates the or update transfering item.
 /// </summary>
 /// <param name="fromAccount">From account.</param>
 /// <param name="toAccount">To account.</param>
 /// <param name="amount">The amount.</param>
 /// <param name="transferingPoundageAmountInfo">The transfering poundage amount info.</param>
 /// <param name="transferingDate">The transfering date.</param>
 /// <param name="notes">The notes.</param>
 /// <param name="itemToUpdate">The item to update.</param>
 /// <returns></returns>
 public TransferingItem CreateOrUpdateTransferingItem(Account fromAccount, Account toAccount, decimal amount, decimal transferingPoundageAmountInfo, DateTime transferingDate, string notes, TransferingItem itemToUpdate = null)
 {
     itemToUpdate = itemToUpdate ?? new TransferingItem();
     itemToUpdate.Amount = amount;
     itemToUpdate.TransferingPoundageAmount = transferingPoundageAmountInfo;
     itemToUpdate.Currency = fromAccount.CurrencyType;
     itemToUpdate.TransferingDate = transferingDate;
     itemToUpdate.FromAccount = fromAccount;
     itemToUpdate.ToAccount = toAccount;
     itemToUpdate.FromAccountId = fromAccount.Id;
     itemToUpdate.ToAccountId = toAccount.Id;
     itemToUpdate.Notes = notes;
     itemToUpdate.Currency = fromAccount.CurrencyType;
     return itemToUpdate;
 }
        private void TransferButton_Click(object sender, System.EventArgs e)
        {
            decimal amount = this.AmountTextBox.Text.ToDecimal(() => 0.0M);
            if (amount != 0.0M)
            {
                if (!IsSelectionMode && this.transferFrom.Category != AccountCategory.CreditCard)
                {
                    if (!AppSetting.Instance.EnableAllAccountOverdraft)
                    {

                        if (amount > this.transferFrom.Balance)
                        {
                            this.ShowToasteMessage(this.amountOverAccountBalanceMessage.FormatWith(new object[] { this.transferFrom.BalanceInfo }), null);
                            return;
                        }
                    }
                }

                if (IsSelectionMode)
                {
                    _transferingItemForScheduledTask = ViewModelLocator.TransferingHistoryViewModel.CreateOrUpdateTransferingItem(
                          this.transferFrom, this.transferTo, amount, this.TransferingPoundage.Text.ToDecimal(), this.CreateDate.Value.GetValueOrDefault(), this.Description.Text, _transferingItemForScheduledTask);

                    if (AfterCreated != null)
                    {
                        AfterCreated(_transferingItemForScheduledTask);
                    }

                    this.SafeGoBack();
                    return;
                }

                ViewModelLocator.TransferingHistoryViewModel.Add(this.transferFrom, this.transferTo, amount, this.TransferingPoundage.Text.ToDecimal(), this.CreateDate.Value.GetValueOrDefault(), this.Description.Text);

                decimal? balance = this.transferFrom.Balance;
                decimal transferingPoundageAmount = this.transferingPoundageAmount;
                this.transferFrom.Balance = balance.HasValue ? new decimal?(balance.GetValueOrDefault() - transferingPoundageAmount) : null;

                ViewModelLocator.AccountViewModel.Transfer(this.transferFrom, this.transferTo, amount, this.amountToUpdate, true);

                this.ShowToasteMessage(this.operationSuccessfullyMessage, null);

                this.AmountTextBox.Text = "0.0";

                this.Description.Text = string.Empty;
            }
        }
 /// <summary>
 /// Sets the scheduled item name from details info.
 /// </summary>
 /// <param name="transferingItem">The transfering item.</param>
 private void SetScheduledItemNameFromDetailsInfo(TransferingItem transferingItem)
 {
     if (this.action == "edit")
     {
         this.NameBlock.Text = this.scheduleDataInfo.Name;
     }
     else
     {
         if (this.action == "add")
         {
             this.SetExampleName();
         }
         if (transferingItem != null)
         {
             string str = (transferingItem == null) ? string.Empty : transferingItem.AmountInfo;
             string str2 = (transferingItem == null) ? string.Empty : transferingItem.Notes;
             this.NameBlock.Text = AppResources.ScheduleItemNameFormatter.FormatWith(new object[] {
                 this.frequencySelector.Frequency.GetSummary(string.Empty), str, str2 });
             this.scheduleDataInfo.Name = this.NameBlock.Text;
         }
     }
 }
        public static void RegisterSelectionMode(TransferingItem transferingItem, System.Action<TransferingItem> afterCreated)
        {
            if (!IsSelectionMode)
            {
                IsSelectionMode = true;
            }

            _transferingItemForScheduledTask = transferingItem;
            AfterCreated = afterCreated;
        }
        /// <summary>
        /// Adds the specified from account.
        /// </summary>
        /// <param name="fromAccount">From account.</param>
        /// <param name="toAccount">To account.</param>
        /// <param name="amount">The amount.</param>
        public void Add(Account fromAccount, Account toAccount, decimal amount, decimal transferingPoundageAmountInfo, DateTime transferingDate, string notes)
        {
            TransferingItem entry = new TransferingItem();
            entry.Amount = amount;
            entry.TransferingPoundageAmount = transferingPoundageAmountInfo;
            entry.Currency = fromAccount.CurrencyType;
            entry.FromAccount = fromAccount;
            entry.ToAccount = toAccount;
            entry.TransferingDate = transferingDate;
            entry.FromAccountId = fromAccount.Id;
            entry.ToAccountId = toAccount.Id;
            entry.Notes = notes;

            //TransferingItemRepository.Instance.Add(entry);

            AddItemToGroup(entry);

            AccountBookDataContext.TransferingItems.InsertOnSubmit(entry);
        }