private void CalcutingAmountOfAlready(Account currentOfAccount, Account accountOfOld, decimal currentOfAmount)
 {
     this.BusyForWork(AppResources.CalculatingAmountInfoMessage);
     System.Threading.ThreadPool.QueueUserWorkItem(delegate(object callBack)
     {
         System.Func<Repayment, decimal> selector = null;
         Account account1 = currentOfAccount;
         CurrencyType newCurrency = account1.Currency;
         decimal decimal2 = 0.0M;
         if (selector == null)
         {
             selector = p => p.GetMoneyForRepayOrReceive(new CurrencyType?(newCurrency));
         }
         this.alreadyAmountInOriginalCurrency = new decimal?(this.currentObject.RepayToOrGetBackFrom.RepayToOrGetBackFromItems.ToList<Repayment>().AsEnumerable<Repayment>().Select<Repayment, decimal>(selector).Sum());
         decimal2 = currentOfAmount;
         decimal conversionRateTo = this.currentObject.BorrowLoanCurrency.GetConversionRateTo(newCurrency);
         decimal totalExchanged = conversionRateTo * this.currentObject.RepayToOrGetBackFrom.Amount;
         decimal decimal1 = conversionRateTo * decimal2;
         string symBol = account1.CurrencyTypeSymbol;
         decimal alreadyExchanged = this.alreadyAmountInOriginalCurrency.GetValueOrDefault();
         decimal rangeEnding = totalExchanged - alreadyExchanged;
         this.Dispatcher.BeginInvoke(delegate
         {
             this.TotalNeedRepayOrReceieveAmount.Text = newCurrency.GetAmountInfoWithCurrencySymbol(symBol, totalExchanged.ToMoneyF2());
             this.AlreadyRepayOrReceieveAmount.Text = newCurrency.GetAmountInfoWithCurrencySymbol(symBol, alreadyExchanged.ToMoneyF2());
             this.RangeOfThisTimeAmount.Text = "{0}1.00 ~ {1}".FormatWith(new object[] { symBol, newCurrency.GetAmountInfoWithCurrencySymbol(symBol, rangeEnding.ToMoneyF2()) });
             this.MaxAmount = totalExchanged;
             this.WorkDone();
         });
     });
 }
 public bool ExistAccount(PageActionType action, Account accountToCompare)
 {
     if (action == PageActionType.Add)
     {
         return (this.Accounts.Count<Account>(p => (p.Name == accountToCompare.Name)) > 0);
     }
     return (this.Accounts.Count<Account>(p => ((p.Name == accountToCompare.Name) && (p.Id != accountToCompare.Id))) > 0);
 }
 public static string GetBalanceInfo(Account account)
 {
     if (currentBalance.Length == 0)
     {
         currentBalance = LocalizedObjectHelper.GetLocalizedStringFrom("CurrentBalance");
     }
     string str = "{0}{1}".FormatWith(new object[] { account.CurrencyTypeSymbol, account.Balance.GetValueOrDefault().ToMoneyF2() });
     return foratter.FormatWith(new object[] { currentBalance, str });
 }
        public void WithdrawlOrDeposit(Account account, decimal amount)
        {
            decimal? balance = account.Balance;
            decimal num = amount;
            account.Balance = balance.HasValue ? new decimal?(balance.GetValueOrDefault() + num) : num;

            //Account account2 = this.Accounts.FirstOrDefault<Account>(p => p.Id == account.Id);
            //if (account2 != null)
            //{
            //    account2.Balance = account.Balance;
            //}
            this.SubmitChanges();
        }
        /// <summary>
        /// Handles the account item editing.
        /// </summary>
        /// <param name="currentEditObject">The current edit object.</param>
        /// <param name="oldAccount">The old account.</param>
        /// <param name="oldMoney">The old money.</param>
        /// <param name="oldBalance">The old balance.</param>
        public void HandleAccountItemEditing(AccountItem currentEditObject, Account oldAccount, decimal oldMoney, decimal oldBalance)
        {
            if (oldAccount == null) { return; }

            if (oldAccount.Id == currentEditObject.Account.Id)
            {
                if (oldBalance != 0.0M)
                {
                    oldBalance = (currentEditObject.Type == ItemType.Expense) ? -oldBalance : oldBalance;
                    this.WithdrawlOrDeposit(currentEditObject.Account, oldBalance);
                }
            }
            else
            {
                decimal amount = oldMoney;
                if (currentEditObject.Type == ItemType.Expense)
                {
                    this.WithdrawlOrDeposit(oldAccount, amount);
                    this.WithdrawlOrDeposit(currentEditObject.Account, -amount);
                }
                else if (currentEditObject.Type == ItemType.Income)
                {
                    this.WithdrawlOrDeposit(oldAccount, -amount);
                    this.WithdrawlOrDeposit(currentEditObject.Account, amount);
                }
            }
            ViewModelLocator.AccountItemViewModel.Update(currentEditObject);
            ViewModelLocator.MainPageViewModel.IsSummaryListLoaded = false;
        }
 public void DeleteItem(Account accountForDelete)
 {
     this.Accounts.Remove(accountForDelete);
     this.AccountBookDataContext.Accounts.DeleteOnSubmit(accountForDelete);
     this.SubmitChanges();
 }
 public AccountViewModel UpdateOnSubmit(Account accountForEdit)
 {
     this.SubmitChanges();
     return this;
 }
Пример #8
0
 public void RestoreFrom(Account fromAccount)
 {
     this.Balance = fromAccount.balance;
     this.CanBeDeleted = fromAccount.CanBeDeleted;
     this.CanChangeCategory = fromAccount.CanChangeCategory;
     this.Color = fromAccount.Color;
     this.Category = fromAccount.Category;
     this.CurrencyType = fromAccount.CurrencyType;
     this.InitialBalance = fromAccount.initialBlance;
     this.Poundage = fromAccount.Poundage;
     this.initialDateTime = fromAccount.initialDateTime;
     this.Name = fromAccount.name;
     this.StasticsBlance = fromAccount.StasticsBlance;
 }
        public void Transfer(Account from, Account to, decimal amountFromFrom, decimal amountToTo, bool addTransferingHistory = true)
        {
            decimal? balance = from.Balance;
            decimal num = amountFromFrom;

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

            decimal num2 = amountToTo;
            to.Balance = nullable3.HasValue ? new decimal?(nullable3.GetValueOrDefault() + num2) : null;
            this.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;
 }
 private void ExchangeAccountButton_Click(object sender, RoutedEventArgs e)
 {
     if (this.rollInAccountIndex != this.rollOutAccountIndex)
     {
         int rollOutAccountIndex = this.rollOutAccountIndex;
         this.rollOutAccountIndex = this.rollInAccountIndex;
         this.rollInAccountIndex = rollOutAccountIndex;
         this.transferFrom = ViewModelLocator.AccountViewModel.Accounts[this.rollOutAccountIndex];
         this.SelectRollOutAccountButton.DataContext = this.transferFrom;
         this.transferTo = ViewModelLocator.AccountViewModel.Accounts[this.rollInAccountIndex];
         this.SelectRollInAccountButton.DataContext = this.transferTo;
         this.transerButton.IsEnabled = this.CheckIsTransferEnable();
         this.MoneyCurrency.Text = this.transferFrom.CurrencyType.GetCurrentString();
         this.SetTransferingInfo();
     }
 }
        private void BindData(AccountItem item)
        {
            this.CategoryType.SelectedIndex = (item.Type == ItemType.Expense) ? 0 : 1;
            this.CategoryNameButton.DataContext = item.NameInfo;
            this.tempCategory = item.Category;
            this.oldAccount = item.Account;

            if (item.Type == ItemType.Expense)
            {
                this.IsClaim.IsChecked = new bool?(item.IsClaim.GetValueOrDefault());
            }

            this.MoneyCurrency.Text = item.Account.CurrencyType.GetCurrentString();
            this.TotalMoneyBox.Text = item.Money.ToMoneyF2();

            if (item.Account != null)
            {
                this.AccountName.SelectedItem = item.Account;
                this.PaymentByInstalmentsSettingPanel.Visibility = item.Account.IsCreditCard ? Visibility.Visible : System.Windows.Visibility.Collapsed;
            }

            this.CreateDate.Value = new System.DateTime?(item.CreateTime);

            this.CreateTime.Value = item.CreateTime;

            this.DescriptionTextBox.Text = item.Description;
        }
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            if (e.NavigationMode != NavigationMode.Back)
            {
                string id = e.GetNavigatingParameter("id", null);
                this.pageAction = e.GetNavigatingParameter("action", null).ToEnum<PageActionType>();
                if (this.pageAction == PageActionType.Add)
                {
                    this.Current = new Account();
                    this.CategoryManagementPageTitle.Text = LocalizedStrings.GetCombinedText(AppResources.Create, AppResources.AccountName, false).ToUpperInvariant();
                }
                else
                {
                    this.Current = this.accountViewModel.Accounts.FirstOrDefault<Account>(p => p.Id == id.ToGuid());
                    this.CategoryManagementPageTitle.Text = LocalizedStrings.GetCombinedText(AppResources.Edit, AppResources.AccountInfo, false).ToUpperInvariant();
                    this.LoadEditing();
                }

                this.DataContext = this;
            }
        }
        private void AccountName_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Account selectedItem = this.AccountName.SelectedItem as Account;
            if (selectedItem != null)
            {
                this.MoneyCurrency.Text = selectedItem.CurrencyType.GetCurrentString();

                this._newAccount = selectedItem;

                this.PaymentByInstalmentsSettingPanel.Visibility = selectedItem.IsCreditCard ? Visibility.Visible : System.Windows.Visibility.Collapsed;

                if (!selectedItem.IsCreditCard)
                {
                    this.PaymentByInstalmentsSettingCheckBox.IsChecked = false;
                }
            }
        }
 private void AccountTransferingPage_Loaded(object sender, RoutedEventArgs e)
 {
     System.Action a = null;
     if (!this.hasInitializedTransfering)
     {
         if (a == null)
         {
             a = delegate
             {
                 this.rollOutAccountIndex = 0;
                 this.rollInAccountIndex = (ViewModelLocator.AccountViewModel.Accounts.Count > 1) ? 1 : 0;
                 this.transferFrom = ViewModelLocator.AccountViewModel.Accounts[this.rollOutAccountIndex];
                 this.SelectRollOutAccountButton.DataContext = this.transferFrom;
                 this.transferTo = ViewModelLocator.AccountViewModel.Accounts[this.rollInAccountIndex];
                 this.SelectRollInAccountButton.DataContext = this.transferTo;
                 this.transerButton.IsEnabled = this.rollInAccountIndex != this.rollOutAccountIndex;
                 this.SetTransferingInfo();
                 this.hasInitializedTransfering = true;
                 this.MoneyCurrency.Text = this.transferFrom.CurrencyType.GetCurrentString();
             };
         }
         base.Dispatcher.BeginInvoke(a);
     }
 }
        public System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> LoadAssociatedItemsForAccount(Account itemCompareToCurrent, ObservableCollection<GroupByCreateTimeAccountItemViewModel> out_container)
        {
            this.HasLoadAssociatedItemsForCurrentViewAccount = true;
            System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> container = new System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel>();
            int recordCount = 0;
            int num = 0;
            System.Action<Int32, String> action = delegate(int count, string name)
            {
                recordCount += count;
                Deployment.Current.Dispatcher.BeginInvoke(delegate
                {
                    GlobalIndicator.Instance.BusyForWork(AppResources.NowLoadingFormatter.FormatWith(new object[] { AppResources.RecordCountTipsFormatter.FormatWith(new object[] { count, name }) }), new object[0]);
                });
            };
            if ((this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All) || (this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.Transcations))
            {
                IQueryable<AccountItem> source = from p in ViewModelLocator.AccountItemViewModel.AccountBookDataContext.AccountItems
                                                 where p.AccountId == itemCompareToCurrent.Id
                                                 select p;
                if (this.searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
                {
                    source = from p in source
                             where (p.CreateTime.Date > this.searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date) && (p.CreateTime.Date <= this.searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date)
                             select p;
                }
                source = from p in source
                         orderby p.Type descending
                         select p into p
                         orderby p.CreateTime.Date descending
                         select p;
                num = source.Count<AccountItem>();
                action(num, AppResources.SelectAccountItemsLabel);
                using (System.Collections.Generic.List<DateTime>.Enumerator enumerator = (from p in source select p.CreateTime.Date).Distinct<System.DateTime>().ToList<System.DateTime>().GetEnumerator())
                {
                    System.DateTime item;
                    while (enumerator.MoveNext())
                    {
                        item = enumerator.Current;
                        GroupByCreateTimeAccountItemViewModel agvm = new GroupByCreateTimeAccountItemViewModel(item);
                        ((System.Collections.Generic.IEnumerable<AccountItem>)(from p in source
                                                                               where p.CreateTime.Date == item.Date
                                                                               select p)).ForEach<AccountItem>(delegate(AccountItem x)
                        {
                            AccountItem item1 = new AccountItem
                            {
                                Account = x.Account,
                                Money = x.Money,
                                CreateTime = x.CreateTime,
                                Category = x.Category,
                                CategoryId = x.CategoryId,
                                Description = x.Description,
                                Id = x.Id,
                                State = x.State,
                                PageNameGetter = "AccountItems",
                                Type = x.Type,
                                TypeInfo = LocalizedStrings.GetLanguageInfoByKey(x.Type.ToString())
                            };
                            if (x.Type == ItemType.Expense)
                            {
                                item1.Money = -x.Money;
                            }
                            item1.SecondInfo = x.NameInfo;
                            item1.ThirdInfo = x.Description;
                            agvm.Add(item1);
                        });
                        container.Add(agvm);
                    }
                }
            }
            if ((this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All) || (this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.TransferingAccount))
            {
                IQueryable<TransferingItem> queryable2 = from p in ViewModelLocator.TransferingHistoryViewModel.AccountBookDataContext.TransferingItems
                                                         where (p.ToAccountId == itemCompareToCurrent.Id) || (p.FromAccountId == itemCompareToCurrent.Id)
                                                         select p;
                if (this.searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
                {
                    queryable2 = from p in queryable2
                                 where (p.TransferingDate.Date > this.searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date) && (p.TransferingDate.Date <= this.searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date)
                                 select p;
                }
                queryable2 = from p in queryable2
                             orderby p.TransferingDate.Date descending
                             select p;
                num = queryable2.Count<TransferingItem>();
                string exchange = AppResources.TransferingAccount;
                action(num, exchange);
                using (System.Collections.Generic.List<DateTime>.Enumerator enumerator2 = (from p in queryable2 select p.TransferingDate.Date).Distinct<System.DateTime>().ToList<System.DateTime>().GetEnumerator())
                {
                    System.Func<GroupByCreateTimeAccountItemViewModel, Boolean> predicate = null;
                    System.DateTime item;
                    while (enumerator2.MoveNext())
                    {
                        item = enumerator2.Current;
                        if (predicate == null)
                        {
                            predicate = p => p.Key.Date == item.Date;
                        }
                        GroupByCreateTimeAccountItemViewModel agvm = container.FirstOrDefault<GroupByCreateTimeAccountItemViewModel>(predicate);
                        bool flag = false;
                        if (agvm == null)
                        {
                            flag = true;
                            agvm = new GroupByCreateTimeAccountItemViewModel(item);
                        }
                        ((System.Collections.Generic.IEnumerable<TransferingItem>)(from p in queryable2
                                                                                   where p.TransferingDate.Date == item.Date
                                                                                   select p)).ForEach<TransferingItem>(delegate(TransferingItem x)
                        {
                            AccountItem item1 = new AccountItem
                            {
                                Account = itemCompareToCurrent,
                                TypeInfo = exchange
                            };
                            flag = x.FromAccountId == itemCompareToCurrent.Id;
                            item1.Money = flag ? -x.Amount : x.Amount;
                            string str = flag ? AppResources.RolloutToSomeAccountName.FormatWith(new object[] { x.ToAccountName }) : AppResources.TransferFromAccountName.FormatWith(new object[] { x.FromAccountName });
                            item1.SecondInfo = str;
                            item1.PageNameGetter = "TransferingItems";
                            item1.ThirdInfo = x.Notes;
                            agvm.Add(item1);
                        });
                        if (flag)
                        {
                            container.Add(agvm);
                        }
                    }
                }
            }
            if ((this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All)
                || (this.searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.BorrowAndLean))
            {
                IQueryable<Repayment> queryable3 = from p in ViewModelLocator.BorrowLeanViewModel.AccountBookDataContext.Repayments
                                                   where (p.FromAccountId == itemCompareToCurrent.Id) && (((int?)p.RepaymentRecordType) == ((int?)RepaymentType.MoneyBorrowOrLeanRepayment))
                                                   select p;
                SearchingScope searchingScope = this.searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope;
                queryable3 = from p in queryable3
                             orderby ((System.DateTime)p.ExecuteDate).Date descending
                             select p;
                num = queryable3.Count<Repayment>();
                string borrowLoanName = AppResources.BorrowAndLean;
                action(num, borrowLoanName);
                using (System.Collections.Generic.List<DateTime>.Enumerator enumerator3 = (from p in queryable3 select p.ExecuteDate.Value.Date).Distinct<System.DateTime>().ToList<System.DateTime>().GetEnumerator())
                {
                    System.Func<GroupByCreateTimeAccountItemViewModel, Boolean> func2 = null;
                    System.DateTime item;
                    while (enumerator3.MoveNext())
                    {
                        item = enumerator3.Current;
                        if (func2 == null)
                        {
                            func2 = p => p.Key.Date == item.Date;
                        }
                        GroupByCreateTimeAccountItemViewModel agvm = container.FirstOrDefault<GroupByCreateTimeAccountItemViewModel>(func2);
                        bool flag2 = false;
                        if (agvm == null)
                        {
                            flag2 = true;
                            agvm = new GroupByCreateTimeAccountItemViewModel(item);
                        }
                        ((System.Collections.Generic.IEnumerable<Repayment>)(from p in queryable3
                                                                             where ((System.DateTime)p.ExecuteDate).Date == item.Date
                                                                             select p)).ForEach<Repayment>(delegate(Repayment x)
                        {
                            LeanType? borrowOrLean = LeanType.BorrowIn;
                            AccountItem item1 = new AccountItem
                            {
                                Id = x.Id,
                                Account = itemCompareToCurrent,
                                TypeInfo = borrowLoanName
                            };

                            if (((LeanType)x.BorrowOrLean) != LeanType.LoanOut)
                            {
                                borrowOrLean = x.BorrowOrLean;
                            }
                            bool flag = (((LeanType)borrowOrLean.GetValueOrDefault()) != LeanType.Repayment) || borrowOrLean.HasValue;
                            item1.Money = flag ? -x.Amount : x.Amount;
                            string borrowLoanInfoWithoutAmountInfo = x.BorrowLoanInfoWithoutAmountInfo;
                            item1.PageNameGetter = x.IsRepaymentOrReceieve ? "RepaymentsTableForReceieveOrPayBack" : "Repayments";
                            item1.SecondInfo = borrowLoanInfoWithoutAmountInfo;
                            item1.ThirdInfo = x.Notes;
                            agvm.Add(item1);
                        });
                        if (flag2)
                        {
                            container.Add(agvm);
                        }
                    }
                }
            }
            Deployment.Current.Dispatcher.BeginInvoke(delegate
            {
                (from p in container
                 orderby p.Key descending
                 select p).ToList<GroupByCreateTimeAccountItemViewModel>().ForEach(new System.Action<GroupByCreateTimeAccountItemViewModel>(out_container.Add));
            });
            return container;
        }
 /// <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;
 }
        /// <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);
        }
        /// <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);

        }
        public System.Collections.Generic.List<GroupByCreateTimeAccountItemViewModel> LoadAssociatedItemsForAccount(
            Account itemCompareToCurrent, ObservableCollection<GroupByCreateTimeAccountItemViewModel> out_container)
        {
            HasLoadAssociatedItemsForCurrentViewAccount = true;

            var container = new List<GroupByCreateTimeAccountItemViewModel>();

            int recordCount = 0;
            var eachCount = 0;

            Action<int, string> showRecordTips = (count, name) =>
            {
                recordCount += count;
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    mangoProgressIndicator.GlobalIndicator.Instance.BusyForWork(AppResources.NowLoadingFormatter.FormatWith(AppResources.RecordCountTipsFormatter.FormatWith(count, name)));
                });

            };


            if (searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All
                || searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.Transcations)
            {
                var accountItemsData = ViewModelLocator.AccountItemViewModel
                    .AccountBookDataContext.AccountItems.Where(p => p.AccountId == itemCompareToCurrent.Id);

                if (searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
                {
                    accountItemsData = accountItemsData.Where(p => p.CreateTime.Date >= searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date
                                           && p.CreateTime.Date <= searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date);
                }

                accountItemsData = accountItemsData.OrderByDescending(p => p.Type)
                .OrderByDescending(p => p.CreateTime.Date);

                eachCount = accountItemsData.Count();

                showRecordTips(eachCount, AppResources.SelectAccountItemsLabel);

                var dates = accountItemsData.Select(p => p.CreateTime.Date).Distinct().ToList();
                foreach (var item in dates)
                {
                    var agvm = new GroupByCreateTimeAccountItemViewModel(item);
                    accountItemsData.Where(p => p.CreateTime.Date == item.Date)
                        .ForEach(x =>
                        {
                            var cx = new AccountItem();
                            cx.Account = x.Account;
                            cx.Money = x.Money;
                            cx.CreateTime = x.CreateTime;
                            cx.Category = x.Category;
                            cx.CategoryId = x.CategoryId;
                            cx.Description = x.Description;
                            cx.Id = x.Id;
                            cx.State = x.State;
                            cx.Type = x.Type;

                            cx.TypeInfo = LocalizedStrings.GetLanguageInfoByKey(x.Type.ToString());
                            if (x.Type == ItemType.Expense)
                                cx.Money = -x.Money;
                            cx.SecondInfo = x.NameInfo;

                            cx.PageNameGetter = PictureInfo.AccountItemsTag;
                            cx.ThirdInfo = x.Description;
                            agvm.Add(cx);
                            //OnItemAdding(x);
                        });

                    container.Add(agvm);
                }
            }

            if (searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All
               || searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.TransferingAccount)
            {
                // load Transfering list.

                var transfering = ViewModelLocator.TransferingHistoryViewModel
                    .AccountBookDataContext.TransferingItems.Where(p => (p.ToAccountId == itemCompareToCurrent.Id || p.FromAccountId == itemCompareToCurrent.Id)
                      );

                if (searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
                {
                    transfering = transfering.Where(p => p.TransferingDate.Date >= searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date
                      && p.TransferingDate.Date <= searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date);
                }

                transfering = transfering.OrderByDescending(p => p.TransferingDate.Date);

                eachCount = transfering.Count();

                var exchange = AppResources.TransferingAccount;
                showRecordTips(eachCount, exchange);

                var dates = transfering.Select(p => p.TransferingDate.Date).Distinct().ToList();

                foreach (var item in dates)
                {
                    var agvm = container.FirstOrDefault(p => p.Key.Date == item.Date);
                    bool hasToAdd = false;
                    if (agvm == null)
                    {
                        hasToAdd = true;
                        agvm = new GroupByCreateTimeAccountItemViewModel(item);
                    }

                    transfering.Where(p => p.TransferingDate.Date == item.Date)
                        .ForEach(x =>
                        {
                            var warp = new AccountItem();
                            warp.Account = itemCompareToCurrent;

                            warp.TypeInfo = exchange;

                            bool isOut = x.FromAccountId == itemCompareToCurrent.Id;
                            warp.Money = isOut ? -x.Amount : x.Amount;

                            var key = isOut ?
                                (AppResources.RolloutToSomeAccountName.FormatWith(x.ToAccountName))
                                : (AppResources.TransferFromAccountName.FormatWith(x.FromAccountName));

                            warp.SecondInfo = key;

                            warp.ThirdInfo = x.Notes;
                            agvm.Add(warp);
                        });

                    if (hasToAdd)
                        container.Add(agvm);
                }
            }

            if (searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.All
               || searchingConditionForAssociatedItemsForCurrentViewAccount.DataType == AssociatedItemType.BorrowAndLean)
            {
                // load Transfering list.

                var borrowLoans = ViewModelLocator.BorrowLeanViewModel
                    .AccountBookDataContext.Repayments.Where(p => (p.FromAccountId == itemCompareToCurrent.Id && p.RepaymentRecordType == RepaymentType.MoneyBorrowOrLeanRepayment));

                if (searchingConditionForAssociatedItemsForCurrentViewAccount.SearchingScope != SearchingScope.All)
                {
                    //borrowLoans = borrowLoans.Where(p => p.ExecuteDate.Value.Date >= searchingConditionForAssociatedItemsForCurrentViewAccount.StartDate.Value.Date
                    //  && ((DateTime)p.ExecuteDate).Date <= searchingConditionForAssociatedItemsForCurrentViewAccount.EndDate.Value.Date);
                }

                borrowLoans = borrowLoans.OrderByDescending(p => ((DateTime)p.ExecuteDate).Date);

                eachCount = borrowLoans.Count();
                var borrowLoanName = AppResources.BorrowAndLean;

                showRecordTips(eachCount, borrowLoanName);


                var dates = borrowLoans.Select(p => p.ExecuteDate.Value.Date).Distinct().ToList();

                foreach (var item in dates)
                {
                    var agvm = container.FirstOrDefault(p => p.Key.Date == item.Date);
                    bool hasToAdd = false;
                    if (agvm == null)
                    {
                        hasToAdd = true;
                        agvm = new GroupByCreateTimeAccountItemViewModel(item);
                    }

                    borrowLoans.Where(p => ((DateTime)p.ExecuteDate).Date == item.Date)
                        .ForEach(x =>
                        {
                            var warp = new AccountItem();
                            warp.Account = itemCompareToCurrent;
                            warp.Id = x.Id;

                            warp.TypeInfo = borrowLoanName;

                            bool isOut = x.BorrowOrLean == LeanType.LoanOut || x.BorrowOrLean == LeanType.Repayment;
                            warp.Money = isOut ? -x.Amount : x.Amount;

                            var key = x.BorrowLoanInfoWithoutAmountInfo;

                            warp.SecondInfo = key;

                            warp.PageNameGetter = x.IsRepaymentOrReceieve ? "RepaymentsTableForReceieveOrPayBack" : "Repayments";
                            warp.ThirdInfo = x.Notes;
                            agvm.Add(warp);
                        });

                    if (hasToAdd)
                        container.Add(agvm);
                }
            }

            Deployment.Current.Dispatcher.BeginInvoke(() =>
            {
                container.OrderByDescending(p => p.Key).ToList()
                    .ForEach(out_container.Add);
            });

            return container;
        }
 private void customDialog_Closed(object sender, System.EventArgs e)
 {
     if (!this.isClosed)
     {
         bool flag = false;
         if (this.chooseRequireSender == 0)
         {
             this.rollOutAccountIndex = this.accountSelectorDialogBox.SelectedIndex;
             this.transferFrom = ViewModelLocator.AccountViewModel.Accounts[this.rollOutAccountIndex];
             this.SelectRollOutAccountButton.DataContext = this.transferFrom;
         }
         else if (this.chooseRequireSender == 1)
         {
             this.rollInAccountIndex = this.accountSelectorDialogBox.SelectedIndex;
             this.transferTo = ViewModelLocator.AccountViewModel.Accounts[this.rollInAccountIndex];
             this.SelectRollInAccountButton.DataContext = this.transferTo;
         }
         this.isClosed = true;
         flag = this.CheckIsTransferEnable();
         this.SetTransferingInfo();
         this.transerButton.IsEnabled = flag;
     }
 }
        public void SetMostOftenAccount(Account account)
        {
            AppSetting.Instance.DefaultAccount = account.Id;

            if (this.DefaultAccountForEditing == null)
            {
                return;
            }

            this.DefaultAccountForEditing.IsDefaultAccount = false;
            this.DefaultAccountForEditing = account;
            account.IsDefaultAccount = true;
            SettingPageViewModel.Update();
        }
        private void AccountTransferingPage_Loaded(object sender, RoutedEventArgs e)
        {
            if (!this.hasInitializedTransfering)
            {
                base.Dispatcher.BeginInvoke(() =>
                {
                    this.rollOutAccountIndex = 0;
                    this.rollInAccountIndex = (ViewModelLocator.AccountViewModel.Accounts.Count > 1) ? 1 : 0;
                    this.transferFrom = ViewModelLocator.AccountViewModel.Accounts[this.rollOutAccountIndex];
                    this.SelectRollOutAccountButton.DataContext = this.transferFrom;
                    this.transferTo = ViewModelLocator.AccountViewModel.Accounts[this.rollInAccountIndex];
                    this.SelectRollInAccountButton.DataContext = this.transferTo;
                    this.transerButton.IsEnabled = this.rollInAccountIndex != this.rollOutAccountIndex;

                    if (IsSelectionMode)
                    {
                        CreateDate.Visibility = System.Windows.Visibility.Collapsed;
                    }

                    this.SetTransferingInfo();
                    this.hasInitializedTransfering = true;
                    this.MoneyCurrency.Text = this.transferFrom.CurrencyType.GetCurrentString();
                });
            }
        }
Пример #24
0
        /// <summary>
        /// Sets the payment due date.
        /// </summary>
        /// <param name="account">The account.</param>
        /// <param name="day">The day.</param>
        public static void SetPaymentDueDate(Account account, int day)
        {
            if (account == null)
                return;

            account.PaymentDueDay = day;
        }