add account

This commit is contained in:
2022-02-26 12:36:32 +08:00
parent fae6d2ce50
commit 4d69bea70b
12 changed files with 192 additions and 23 deletions

View File

@ -3,6 +3,7 @@
xmlns:r="clr-namespace:Billing.Languages"
xmlns:ui="clr-namespace:Billing.UI"
xmlns:v="clr-namespace:Billing.Views"
xmlns:m="clr-namespace:Billing.Models"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="Billing.Views.AccountPage"
x:Name="accountPage"
@ -12,6 +13,7 @@
<ContentPage.Resources>
<ui:MoneyConverter x:Key="moneyConverter"/>
<ui:MoneyConverter x:Key="money2Converter"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
@ -40,6 +42,22 @@
Text="{Binding Liability, Converter={StaticResource moneyConverter}}"/>
</Grid>
</Grid>
<CollectionView VerticalScrollBarVisibility="Never" ItemsSource="{Binding Accounts}">
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="m:Account">
<StackLayout Orientation="Horizontal" Padding="20, 0" HeightRequest="44" Spacing="10">
<Image Source="{Binding Icon}" HeightRequest="20" VerticalOptions="Center"/>
<Label Text="{Binding Name}" TextColor="{DynamicResource TextColor}"
HorizontalOptions="FillAndExpand" VerticalOptions="Center"
FontSize="Default" FontAttributes="Bold"/>
<Label Text="{Binding Balance, Converter={StaticResource money2Converter}}"
TextColor="{DynamicResource SecondaryTextColor}"
VerticalOptions="Center"/>
<ui:TintImage Source="right.png" HeightRequest="20"/>
</StackLayout>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</StackLayout>
</ScrollView>
</ui:BillingPage>

View File

@ -1,3 +1,5 @@
using System.Collections.ObjectModel;
using Billing.Models;
using Billing.UI;
using Xamarin.Forms;
@ -8,16 +10,22 @@ namespace Billing.Views
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty AssetProperty = BindableProperty.Create(nameof(Asset), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty LiabilityProperty = BindableProperty.Create(nameof(Liability), typeof(decimal), typeof(AccountPage));
private static readonly BindableProperty AccountsProperty = BindableProperty.Create(nameof(Accounts), typeof(ObservableCollection<Account>), typeof(AccountPage));
public decimal Balance => (decimal)GetValue(BalanceProperty);
public decimal Asset => (decimal)GetValue(AssetProperty);
public decimal Liability => (decimal)GetValue(LiabilityProperty);
public ObservableCollection<Account> Accounts => (ObservableCollection<Account>)GetValue(AccountsProperty);
public Command AddAccount { get; }
private readonly ObservableCollection<Account> accounts;
public AccountPage()
{
AddAccount = new Command(OnAddAccount);
accounts = new ObservableCollection<Account>();
SetValue(AccountsProperty, accounts);
InitializeComponent();
}
@ -39,6 +47,7 @@ namespace Billing.Views
private void AccountChecked(object sender, AccountEventArgs e)
{
Helper.Debug(e.Account.ToString());
accounts.Add(e.Account);
}
}
}

View File

@ -8,7 +8,13 @@
x:Name="addAccountPage"
x:DataType="v:AddAccountPage"
Title="{r:Text AddAccount}"
BindingContext="{x:Reference addAccountPage}">
BindingContext="{x:Reference addAccountPage}"
NavigationPage.BackButtonTitle="">
<ContentPage.Resources>
<ui:AccountCategoryConverter x:Key="categoryConverter"/>
<ui:MoneyConverter x:Key="moneyConverter" MarkVisible="False"/>
</ContentPage.Resources>
<ContentPage.ToolbarItems>
<ToolbarItem Order="Primary" IconImageSource="check.png" Command="{Binding CheckAccount}"/>
@ -21,17 +27,19 @@
Icon="pencil.png"
Text="{Binding AccountName, Mode=TwoWay}"
Keyboard="Text" Placeholder="{r:Text AccountNamePlaceholder}"/>
<ui:OptionSelectCell Title="{r:Text Icon}" Height="44" Icon="face.png"
Detail="{Binding AccountIcon}"/>
<ui:OptionImageCell Title="{r:Text Icon}" Height="44" Icon="face.png"
ImageSource="{Binding AccountIcon}"
Command="{Binding SelectIcon}"/>
<ui:OptionSelectCell Title="{r:Text Category}" Height="44" Icon="project.png"
Detail="{Binding Category}"/>
Detail="{Binding Category, Converter={StaticResource categoryConverter}}"
Command="{Binding SelectCategory}"/>
</TableSection>
<TableSection>
<TableSection.Title>
<OnPlatform x:TypeArguments="x:String" Android=" "/>
</TableSection.Title>
<ui:OptionEntryCell Title="{r:Text Balance}" Height="44" Icon="sackdollar.png"
Text="{Binding Balance, Mode=TwoWay}"
Text="{Binding Balance, Mode=TwoWay, Converter={StaticResource moneyConverter}}"
Keyboard="Numeric" Placeholder="{r:Text BalancePlaceholder}"/>
<ui:OptionTextCell Title="{r:Text Currency}" Height="44" Icon="dollar.png"
Detail="{r:Text CNY}"/>

View File

@ -9,7 +9,7 @@ namespace Billing.Views
{
private static readonly BindableProperty AccountNameProperty = BindableProperty.Create(nameof(AccountName), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty AccountIconProperty = BindableProperty.Create(nameof(AccountIcon), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty CategoryProperty = BindableProperty.Create(nameof(Category), typeof(string), typeof(AddAccountPage));
private static readonly BindableProperty CategoryProperty = BindableProperty.Create(nameof(Category), typeof(AccountCategory), typeof(AddAccountPage));
private static readonly BindableProperty BalanceProperty = BindableProperty.Create(nameof(Balance), typeof(decimal), typeof(AddAccountPage));
private static readonly BindableProperty MemoProperty = BindableProperty.Create(nameof(Memo), typeof(string), typeof(AddAccountPage));
@ -23,9 +23,9 @@ namespace Billing.Views
get => (string)GetValue(AccountIconProperty);
set => SetValue(AccountIconProperty, value);
}
public string Category
public AccountCategory Category
{
get => (string)GetValue(CategoryProperty);
get => (AccountCategory)GetValue(CategoryProperty);
set => SetValue(CategoryProperty, value);
}
public decimal Balance
@ -52,6 +52,8 @@ namespace Billing.Views
CheckAccount = new Command(OnCheckAccount);
SelectIcon = new Command(OnSelectIcon);
SelectCategory = new Command(OnSelectCategory);
AccountIcon = BaseModel.ICON_DEFAULT;
Category = AccountCategory.Cash;
InitializeComponent();
}
@ -60,27 +62,35 @@ namespace Billing.Views
this.account = account;
AccountName = account.Name;
AccountIcon = account.Icon;
Category = account.Category.ToString();
Category = account.Category;
Balance = account.Balance;
Memo = account.Memo;
CheckAccount = new Command(OnCheckAccount);
InitializeComponent();
}
private void OnCheckAccount()
private async void OnCheckAccount()
{
AccountChecked?.Invoke(this, new AccountEventArgs
if (Tap.IsBusy)
{
Account = new Account
return;
}
using (Tap.Start())
{
await Navigation.PopAsync();
AccountChecked?.Invoke(this, new AccountEventArgs
{
Id = account?.Id ?? -1,
Name = AccountName,
Icon = AccountIcon,
//Category = Category,
Balance = Balance,
Memo = Memo
}
});
Account = new Account
{
Id = account?.Id ?? -1,
Name = AccountName,
Icon = AccountIcon,
Category = Category,
Balance = Balance,
Memo = Memo
}
});
}
}
private void OnSelectIcon()

View File

@ -39,7 +39,14 @@ namespace Billing.Views
private async void OnAddBilling()
{
await Navigation.PushAsync(new AddBillPage());
if (Tap.IsBusy)
{
return;
}
using (Tap.Start())
{
await Navigation.PushAsync(new AddBillPage());
}
}
}
}