add account
This commit is contained in:
parent
fae6d2ce50
commit
4d69bea70b
@ -10,6 +10,10 @@ namespace Billing.Languages
|
||||
internal class Resource
|
||||
{
|
||||
public static string TitleDateFormat => Text(nameof(TitleDateFormat));
|
||||
public static string Cash => Text(nameof(Cash));
|
||||
public static string CreditCard => Text(nameof(CreditCard));
|
||||
public static string DebitCard => Text(nameof(DebitCard));
|
||||
public static string ElecAccount => Text(nameof(ElecAccount));
|
||||
|
||||
static readonly Dictionary<string, LanguageResource> dict = new();
|
||||
|
||||
|
@ -27,4 +27,8 @@
|
||||
<CNY>Chinese Yuan (CNY)</CNY>
|
||||
<Memo>Note</Memo>
|
||||
<MemoPlaceholder>Please enter a note</MemoPlaceholder>
|
||||
<Cash>Cash</Cash>
|
||||
<CreditCard>Credit Card</CreditCard>
|
||||
<DebitCard>Debit Card</DebitCard>
|
||||
<ElecAccount>Electronic Account</ElecAccount>
|
||||
</root>
|
@ -27,4 +27,8 @@
|
||||
<CNY>人民币 (CNY)</CNY>
|
||||
<Memo>备注</Memo>
|
||||
<MemoPlaceholder>请输入备注</MemoPlaceholder>
|
||||
<Cash>现金</Cash>
|
||||
<CreditCard>信用卡</CreditCard>
|
||||
<DebitCard>储蓄卡</DebitCard>
|
||||
<ElecAccount>电子账户</ElecAccount>
|
||||
</root>
|
@ -16,7 +16,7 @@ namespace Billing.Models
|
||||
|
||||
public abstract class BaseModel : IModel, IDisposable
|
||||
{
|
||||
protected const string ICON_DEFAULT = "ic_default";
|
||||
public const string ICON_DEFAULT = "ic_default";
|
||||
|
||||
private bool disposed = false;
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using Billing.Languages;
|
||||
using Billing.Models;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using Xamarin.Forms;
|
||||
@ -24,17 +25,36 @@ namespace Billing.UI
|
||||
|
||||
public class MoneyConverter : IValueConverter
|
||||
{
|
||||
public bool MarkVisible { get; set; } = true;
|
||||
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is decimal d)
|
||||
{
|
||||
return "¥ " + d.ToString("n2", CultureInfo.InvariantCulture);
|
||||
var number = d.ToString("n2");
|
||||
if (MarkVisible)
|
||||
{
|
||||
return "¥ " + number;
|
||||
}
|
||||
return number;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is string s)
|
||||
{
|
||||
if (s.StartsWith("¥ "))
|
||||
{
|
||||
s = s[2..];
|
||||
}
|
||||
if (decimal.TryParse(s, out decimal d))
|
||||
{
|
||||
return d;
|
||||
}
|
||||
return 0m;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
@ -51,4 +71,28 @@ namespace Billing.UI
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
public class AccountCategoryConverter : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
if (value is AccountCategory category)
|
||||
{
|
||||
return category switch
|
||||
{
|
||||
AccountCategory.Cash => Resource.Cash,
|
||||
AccountCategory.CreditCard => Resource.CreditCard,
|
||||
AccountCategory.DebitCard => Resource.DebitCard,
|
||||
AccountCategory.ElecAccount => Resource.ElecAccount,
|
||||
_ => category.ToString()
|
||||
};
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
@ -19,6 +19,24 @@ namespace Billing.UI
|
||||
return obj;
|
||||
}
|
||||
|
||||
public static View HorizontalOptions(this View view, LayoutOptions options)
|
||||
{
|
||||
if (view != null)
|
||||
{
|
||||
view.HorizontalOptions = options;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public static View VerticalOptions(this View view, LayoutOptions options)
|
||||
{
|
||||
if (view != null)
|
||||
{
|
||||
view.VerticalOptions = options;
|
||||
}
|
||||
return view;
|
||||
}
|
||||
|
||||
public static View DynamicResource(this View view, BindableProperty property, string key)
|
||||
{
|
||||
view.SetDynamicResource(property, key);
|
||||
|
@ -186,6 +186,49 @@ namespace Billing.UI
|
||||
};
|
||||
}
|
||||
|
||||
public class OptionImageCell : OptionSelectCell
|
||||
{
|
||||
public static readonly BindableProperty ImageSourceProperty = BindableProperty.Create(nameof(ImageSource), typeof(ImageSource), typeof(OptionImageCell));
|
||||
|
||||
[TypeConverter(typeof(ImageSourceConverter))]
|
||||
public ImageSource ImageSource
|
||||
{
|
||||
get => (ImageSource)GetValue(ImageSourceProperty);
|
||||
set => SetValue(ImageSourceProperty, value);
|
||||
}
|
||||
|
||||
protected override View Content => new StackLayout
|
||||
{
|
||||
Orientation = StackOrientation.Horizontal,
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
Children =
|
||||
{
|
||||
new Image
|
||||
{
|
||||
HeightRequest = 20,
|
||||
HorizontalOptions = LayoutOptions.End,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(6, 0)
|
||||
}
|
||||
.Binding(Image.SourceProperty, nameof(ImageSource)),
|
||||
|
||||
new TintImage
|
||||
{
|
||||
HeightRequest = 20,
|
||||
VerticalOptions = LayoutOptions.Center,
|
||||
Margin = new Thickness(6, 0),
|
||||
Source = "right.png"
|
||||
}
|
||||
},
|
||||
GestureRecognizers =
|
||||
{
|
||||
new TapGestureRecognizer()
|
||||
.Binding(TapGestureRecognizer.CommandProperty, nameof(Command))
|
||||
.Binding(TapGestureRecognizer.CommandParameterProperty, nameof(CommandParameter))
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public class OptionSwitchCell : OptionCell
|
||||
{
|
||||
public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(OptionSwitchCell));
|
||||
|
@ -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>
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
@ -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}"/>
|
||||
|
@ -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()
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user