提交 a389d9bf authored 作者: Mitch Capper's avatar Mitch Capper

Ensure default account gets reset when removing an account, and also ensure we…

Ensure default account gets reset when removing an account, and also ensure we update the status of accounts after possible total changes
上级 4c8cc972
...@@ -130,6 +130,7 @@ namespace FSClient { ...@@ -130,6 +130,7 @@ namespace FSClient {
} }
public static void RemoveAccount(Account account) { public static void RemoveAccount(Account account) {
account.KillGateway(); account.KillGateway();
account.is_default_account = false;
accounts.Remove(account); accounts.Remove(account);
ReloadSofia(); ReloadSofia();
} }
......
...@@ -44,24 +44,35 @@ namespace FSClient { ...@@ -44,24 +44,35 @@ namespace FSClient {
gridCalls.Items.SortDescriptions.Add(new SortDescription("sort_order", ListSortDirection.Descending)); gridCalls.Items.SortDescriptions.Add(new SortDescription("sort_order", ListSortDirection.Descending));
} }
void accounts_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) { void accounts_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) {
if (e.OldItems != null){
RefreshStatusDefaultAccount();
RefreshStatusAccountTotals();
}
if (e.NewItems == null) if (e.NewItems == null)
return; return;
foreach (Account acct in e.NewItems) { foreach (Account acct in e.NewItems) {
acct.PropertyChanged += acct_PropertyChanged; acct.PropertyChanged += acct_PropertyChanged;
} }
RefreshStatusDefaultAccount();
RefreshStatusAccountTotals();
}
private void RefreshStatusAccountTotals(){
account_status.total_accounts = (from a in Account.accounts where a.enabled == true select a).Count();
account_status.active_accounts = (from a in Account.accounts where a.state == "REGED" select a).Count();
}
private void RefreshStatusDefaultAccount(){
Account primary = (from a in Account.accounts where a.is_default_account == true select a).FirstOrDefault();
account_status.primary_account = primary == null ? "" : primary.ToString();
} }
void acct_PropertyChanged(object sender, PropertyChangedEventArgs e) { void acct_PropertyChanged(object sender, PropertyChangedEventArgs e) {
if (e.PropertyName == "gateway_id") { if (e.PropertyName == "gateway_id") {
gridAccounts.Items.SortDescriptions.Clear(); gridAccounts.Items.SortDescriptions.Clear();
gridAccounts.Items.SortDescriptions.Add(new SortDescription("gateway_id", ListSortDirection.Ascending)); gridAccounts.Items.SortDescriptions.Add(new SortDescription("gateway_id", ListSortDirection.Ascending));
} }
else if (e.PropertyName == "is_default_account"){ else if (e.PropertyName == "is_default_account"){
Account primary = (from a in Account.accounts where a.is_default_account == true select a).FirstOrDefault(); RefreshStatusDefaultAccount();
account_status.primary_account = primary == null ? "" : primary.ToString(); }else if (e.PropertyName == "state" || e.PropertyName=="enabled"){
}else if (e.PropertyName == "state"){ RefreshStatusAccountTotals();
account_status.total_accounts = (from a in Account.accounts where a.enabled == true select a).Count();
account_status.active_accounts = (from a in Account.accounts where a.state == "REGED" select a).Count();
} }
} }
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论