BranchViewModel.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using GalaSoft.MvvmLight;
  6. using GalaSoft.MvvmLight.Command;
  7. using GalaSoft.MvvmLight.Ioc;
  8. using Muchinfo.MTPClient.Bank.Views;
  9. using Muchinfo.MTPClient.Data.Model.Bank;
  10. using Muchinfo.MTPClient.Infrastructure.Utilities;
  11. using Muchinfo.MTPClient.IService;
  12. namespace Muchinfo.MTPClient.Bank.ViewModels
  13. {
  14. public class BranchViewModel : ViewModelBase
  15. {
  16. #region 变量成员
  17. private IBankService _bankService;
  18. private string _searchText;
  19. /// <summary>
  20. ///搜索内容
  21. /// </summary>
  22. public string SearchText
  23. {
  24. get { return _searchText; }
  25. set { Set(() => SearchText, ref _searchText, value); }
  26. }
  27. /// <summary>
  28. /// 省份列表
  29. /// </summary>
  30. private List<KeyValuePair<string, string>> _provinceList;
  31. public List<KeyValuePair<string, string>> ProvinceList
  32. {
  33. get { return _provinceList; }
  34. set { _provinceList = value; }
  35. }
  36. private string _selectProvinceId;
  37. /// <summary>
  38. /// 选择省份Id
  39. /// </summary>
  40. public string SelectProvinceId
  41. {
  42. get
  43. {
  44. return _selectProvinceId;
  45. }
  46. set
  47. {
  48. _selectProvinceId = value;
  49. CityList = _bankService.GetCitys(value, UserManager.CurrentTradeAccount);
  50. SelectCityName = CityList[0];
  51. }
  52. }
  53. /// <summary>
  54. /// 城市列表
  55. /// </summary>
  56. private List<string> _cityList;
  57. public List<string> CityList
  58. {
  59. get { return _cityList; }
  60. set { Set(() => CityList, ref _cityList, value); }
  61. }
  62. private string _selectCityName;
  63. /// <summary>
  64. /// 选择城市Id
  65. /// </summary>
  66. public string SelectCityName
  67. {
  68. get
  69. {
  70. return _selectCityName;
  71. }
  72. set
  73. {
  74. Set(() => SelectCityName, ref _selectCityName, value);
  75. _selectCityName = value;
  76. LoadBranchBanks();
  77. }
  78. }
  79. private List<Branchs> _branchList;
  80. /// <summary>
  81. /// 支行列表
  82. /// </summary>
  83. public List<Branchs> BranchList
  84. {
  85. get
  86. {
  87. return _branchList;
  88. }
  89. set
  90. {
  91. _branchList = value;
  92. BranchSource = value;
  93. }
  94. }
  95. private List<Branchs> _branchSource;
  96. /// <summary>
  97. /// 支行绑定数据源
  98. /// </summary>
  99. /// <value>The bank branch dictionary.</value>
  100. public List<Branchs> BranchSource
  101. {
  102. get { return _branchSource; }
  103. set { Set(() => BranchSource, ref _branchSource, value); }
  104. }
  105. private Branchs _selectBranch = new Branchs();
  106. /// <summary>
  107. /// 当前选择支行
  108. /// </summary>
  109. public Branchs SelectBranch
  110. {
  111. get { return _selectBranch; }
  112. set { _selectBranch = value; }
  113. }
  114. /// <summary>
  115. /// 当前签约银行
  116. /// </summary>
  117. private SigningBank CurrentSigningBank;
  118. #endregion
  119. #region 构造函数
  120. public BranchViewModel(BranchView win_BranchView, SigningBank currentSigningBank, string ProvinceName, string CityName)
  121. {
  122. win_BranchView.Closing += win_BranchView_Closing;
  123. this.CurrentSigningBank = currentSigningBank;
  124. _bankService = SimpleIoc.Default.GetInstance<IBankService>();
  125. ProvinceList = _bankService.GetProvinces(UserManager.CurrentTradeAccount);
  126. if (!string.IsNullOrWhiteSpace(ProvinceName))
  127. {
  128. SelectProvinceId = ProvinceList.Where(x => x.Value == ProvinceName).First().Key;
  129. }
  130. if (!string.IsNullOrWhiteSpace(CityName))
  131. {
  132. SelectCityName = CityList.Where(x => x == "CityName").First();
  133. }
  134. }
  135. #endregion
  136. #region 公共方法
  137. /// <summary>
  138. /// 查询支行
  139. /// </summary>
  140. public void LoadBranchBanks()
  141. {
  142. // this.BranchList = _bankService.GetBranchBanks(this.CurrentSigningBank.Id, this.SelectCityName, UserManager.CurrentTradeAccount);
  143. }
  144. /// <summary>
  145. /// 搜索
  146. /// </summary>
  147. public RelayCommand SearchCommand
  148. {
  149. get
  150. {
  151. return new RelayCommand(() =>
  152. {
  153. ShowBranchBanks();
  154. });
  155. }
  156. }
  157. /// <summary>
  158. /// 点击RadioButton
  159. /// </summary>
  160. public RelayCommand<System.Collections.IList> SelectionChangeCommand
  161. {
  162. get
  163. {
  164. return new RelayCommand<System.Collections.IList>((dg_Branch) =>
  165. {
  166. if (dg_Branch != null && dg_Branch.Count > 0)
  167. {
  168. SelectBranch = dg_Branch[0] as Branchs;
  169. SelectBranch.IsSelected = true;
  170. }
  171. });
  172. }
  173. }
  174. /// <summary>
  175. /// 完成
  176. /// </summary>
  177. public RelayCommand<BranchView> OkCommand
  178. {
  179. get
  180. {
  181. return new RelayCommand<BranchView>((win_BranchView) =>
  182. {
  183. this.CurrentSigningBank.BranchId = SelectBranch.FullBankId;
  184. this.CurrentSigningBank.BranchBankName = SelectBranch.BankName;
  185. win_BranchView.Visibility = System.Windows.Visibility.Collapsed;
  186. });
  187. }
  188. }
  189. /// <summary>
  190. /// 取消
  191. /// </summary>
  192. public RelayCommand<BranchView> CancelCommand
  193. {
  194. get
  195. {
  196. return new RelayCommand<BranchView>((win_BranchView) =>
  197. {
  198. win_BranchView.Visibility = System.Windows.Visibility.Collapsed;
  199. });
  200. }
  201. }
  202. #endregion
  203. #region 私有方法
  204. /// <summary>
  205. /// 显示列表
  206. /// </summary>
  207. private void ShowBranchBanks()
  208. {
  209. try
  210. {
  211. //省份,城市,搜索关键字
  212. if (string.IsNullOrEmpty(SearchText))
  213. {
  214. this.BranchSource = this.BranchList;
  215. }
  216. else
  217. {
  218. this.BranchSource = this.BranchList.Where(p => p.BankName.Contains(SearchText.Trim())).ToList();
  219. }
  220. Branchs branchs = this.BranchSource.FirstOrDefault(c => c.FullBankId == this.SelectBranch.FullBankId);
  221. if (branchs != null)
  222. {
  223. branchs.IsSelected = true;
  224. }
  225. }
  226. catch (Exception ex)
  227. {
  228. }
  229. }
  230. //点击窗体自带关闭按钮时使用
  231. void win_BranchView_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  232. {
  233. BranchView branchView = sender as BranchView;
  234. branchView.Visibility = System.Windows.Visibility.Collapsed;
  235. e.Cancel = true;
  236. }
  237. #endregion
  238. }
  239. }