| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Bank.Views;
- using Muchinfo.MTPClient.Data.Model.Bank;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- namespace Muchinfo.MTPClient.Bank.ViewModels
- {
- public class BranchViewModel : ViewModelBase
- {
- #region 变量成员
- private IBankService _bankService;
- private string _searchText;
- /// <summary>
- ///搜索内容
- /// </summary>
- public string SearchText
- {
- get { return _searchText; }
- set { Set(() => SearchText, ref _searchText, value); }
- }
- /// <summary>
- /// 省份列表
- /// </summary>
- private List<KeyValuePair<string, string>> _provinceList;
- public List<KeyValuePair<string, string>> ProvinceList
- {
- get { return _provinceList; }
- set { _provinceList = value; }
- }
- private string _selectProvinceId;
- /// <summary>
- /// 选择省份Id
- /// </summary>
- public string SelectProvinceId
- {
- get
- {
- return _selectProvinceId;
- }
- set
- {
- _selectProvinceId = value;
- CityList = _bankService.GetCitys(value, UserManager.CurrentTradeAccount);
- SelectCityName = CityList[0];
- }
- }
- /// <summary>
- /// 城市列表
- /// </summary>
- private List<string> _cityList;
- public List<string> CityList
- {
- get { return _cityList; }
- set { Set(() => CityList, ref _cityList, value); }
- }
- private string _selectCityName;
- /// <summary>
- /// 选择城市Id
- /// </summary>
- public string SelectCityName
- {
- get
- {
- return _selectCityName;
- }
- set
- {
- Set(() => SelectCityName, ref _selectCityName, value);
- _selectCityName = value;
- LoadBranchBanks();
- }
- }
- private List<Branchs> _branchList;
- /// <summary>
- /// 支行列表
- /// </summary>
- public List<Branchs> BranchList
- {
- get
- {
- return _branchList;
- }
- set
- {
- _branchList = value;
- BranchSource = value;
- }
- }
- private List<Branchs> _branchSource;
- /// <summary>
- /// 支行绑定数据源
- /// </summary>
- /// <value>The bank branch dictionary.</value>
- public List<Branchs> BranchSource
- {
- get { return _branchSource; }
- set { Set(() => BranchSource, ref _branchSource, value); }
- }
- private Branchs _selectBranch = new Branchs();
- /// <summary>
- /// 当前选择支行
- /// </summary>
- public Branchs SelectBranch
- {
- get { return _selectBranch; }
- set { _selectBranch = value; }
- }
- /// <summary>
- /// 当前签约银行
- /// </summary>
- private SigningBank CurrentSigningBank;
- #endregion
- #region 构造函数
- public BranchViewModel(BranchView win_BranchView, SigningBank currentSigningBank, string ProvinceName, string CityName)
- {
- win_BranchView.Closing += win_BranchView_Closing;
- this.CurrentSigningBank = currentSigningBank;
- _bankService = SimpleIoc.Default.GetInstance<IBankService>();
- ProvinceList = _bankService.GetProvinces(UserManager.CurrentTradeAccount);
- if (!string.IsNullOrWhiteSpace(ProvinceName))
- {
- SelectProvinceId = ProvinceList.Where(x => x.Value == ProvinceName).First().Key;
- }
- if (!string.IsNullOrWhiteSpace(CityName))
- {
- SelectCityName = CityList.Where(x => x == "CityName").First();
- }
- }
- #endregion
- #region 公共方法
- /// <summary>
- /// 查询支行
- /// </summary>
- public void LoadBranchBanks()
- {
- // this.BranchList = _bankService.GetBranchBanks(this.CurrentSigningBank.Id, this.SelectCityName, UserManager.CurrentTradeAccount);
- }
- /// <summary>
- /// 搜索
- /// </summary>
- public RelayCommand SearchCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- ShowBranchBanks();
- });
- }
- }
- /// <summary>
- /// 点击RadioButton
- /// </summary>
- public RelayCommand<System.Collections.IList> SelectionChangeCommand
- {
- get
- {
- return new RelayCommand<System.Collections.IList>((dg_Branch) =>
- {
- if (dg_Branch != null && dg_Branch.Count > 0)
- {
- SelectBranch = dg_Branch[0] as Branchs;
- SelectBranch.IsSelected = true;
- }
- });
- }
- }
- /// <summary>
- /// 完成
- /// </summary>
- public RelayCommand<BranchView> OkCommand
- {
- get
- {
- return new RelayCommand<BranchView>((win_BranchView) =>
- {
- this.CurrentSigningBank.BranchId = SelectBranch.FullBankId;
- this.CurrentSigningBank.BranchBankName = SelectBranch.BankName;
- win_BranchView.Visibility = System.Windows.Visibility.Collapsed;
- });
- }
- }
- /// <summary>
- /// 取消
- /// </summary>
- public RelayCommand<BranchView> CancelCommand
- {
- get
- {
- return new RelayCommand<BranchView>((win_BranchView) =>
- {
- win_BranchView.Visibility = System.Windows.Visibility.Collapsed;
- });
- }
- }
- #endregion
- #region 私有方法
- /// <summary>
- /// 显示列表
- /// </summary>
- private void ShowBranchBanks()
- {
- try
- {
- //省份,城市,搜索关键字
- if (string.IsNullOrEmpty(SearchText))
- {
- this.BranchSource = this.BranchList;
- }
- else
- {
- this.BranchSource = this.BranchList.Where(p => p.BankName.Contains(SearchText.Trim())).ToList();
- }
- Branchs branchs = this.BranchSource.FirstOrDefault(c => c.FullBankId == this.SelectBranch.FullBankId);
- if (branchs != null)
- {
- branchs.IsSelected = true;
- }
- }
- catch (Exception ex)
- {
- }
- }
- //点击窗体自带关闭按钮时使用
- void win_BranchView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
- {
- BranchView branchView = sender as BranchView;
- branchView.Visibility = System.Windows.Visibility.Collapsed;
- e.Cancel = true;
- }
- #endregion
- }
- }
|