AccountItem.cs 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Collections.ObjectModel;
  6. using System.ComponentModel;
  7. using System.ComponentModel.DataAnnotations;
  8. using MECF.Framework.Common.Account.Extends;
  9. using OpenSEMI.ClientBase;
  10. namespace VirgoUI.Client.Models.Utility.AccountPage
  11. {
  12. public class AccountItem : ValidatorBase, INotifyPropertyChanged
  13. {
  14. /// <summary>
  15. /// Account Constructor
  16. /// </summary>
  17. public AccountItem(string strID)
  18. {
  19. m_Account = new AccountEx(strID, string.Empty, string.Empty, string.Empty, string.Empty, string.Empty, new List<string>());
  20. }
  21. /// <summary>
  22. /// Account Constructor
  23. /// </summary>
  24. public AccountItem(AccountEx Acc)
  25. {
  26. m_Account = Acc;
  27. }
  28. private AccountEx m_Account;
  29. public AccountEx Account
  30. {
  31. get { return m_Account; }
  32. set { m_Account = value; }
  33. }
  34. /// <summary>
  35. /// Account ID
  36. /// </summary>
  37. public string AccountID
  38. {
  39. get { return m_Account.UserID; }
  40. set { m_Account.UserID = value; }
  41. }
  42. /// <summary>
  43. /// Account name
  44. /// </summary>
  45. public string AccountName
  46. {
  47. get { return Account.LoginName; }
  48. set
  49. {
  50. Account.LoginName = value;
  51. }
  52. }
  53. /// <summary>
  54. /// Account Password
  55. /// </summary>
  56. public string Password
  57. {
  58. get { return Account.Password; }
  59. set
  60. {
  61. Account.Password = value;
  62. }
  63. }
  64. /// <summary>
  65. /// Account New Password
  66. /// </summary>
  67. private string m_strNewPassword;
  68. public string NewPassword
  69. {
  70. get { return m_strNewPassword; }
  71. set
  72. {
  73. if (value != m_strNewPassword)
  74. {
  75. m_strNewPassword = value;
  76. }
  77. }
  78. }
  79. /// <summary>
  80. /// Account Confirm New Password
  81. /// </summary>
  82. private string m_strConfirmPassword;
  83. public string ConfirmPassword
  84. {
  85. get { return m_strConfirmPassword; }
  86. set
  87. {
  88. if (value != m_strConfirmPassword)
  89. {
  90. m_strConfirmPassword = value;
  91. }
  92. }
  93. }
  94. /// <summary>
  95. /// Account first name
  96. /// </summary>
  97. public string FirstName
  98. {
  99. get { return Account.FirstName; }
  100. set
  101. {
  102. Account.FirstName = value;
  103. }
  104. }
  105. /// <summary>
  106. /// Account last name
  107. /// </summary>
  108. public string LastName
  109. {
  110. get { return Account.LastName; }
  111. set
  112. {
  113. Account.LastName = value;
  114. }
  115. }
  116. /// <summary>
  117. /// Email address
  118. /// </summary>
  119. public string Email
  120. {
  121. get { return Account.Email; }
  122. set
  123. {
  124. Account.Email = value;
  125. }
  126. }
  127. private string _DisplayAccountName;
  128. [Required(ErrorMessage = "AccountName Required")]
  129. public string DisplayAccountName
  130. {
  131. get
  132. {
  133. return _DisplayAccountName;
  134. }
  135. set
  136. {
  137. _DisplayAccountName = value;
  138. this.OnPropertyChanged("DisplayAccountName");
  139. }
  140. }
  141. //[Required(ErrorMessage = "FirstName Required")]
  142. private string _DisplayFirstName = string.Empty;
  143. public string DisplayFirstName
  144. {
  145. get { return _DisplayFirstName; }
  146. set
  147. {
  148. _DisplayFirstName = value;
  149. }
  150. }
  151. //[Required(ErrorMessage = "LastName Required")]
  152. private string _DisplayLastName = string.Empty;
  153. public string DisplayLastName
  154. {
  155. get { return _DisplayLastName; }
  156. set
  157. {
  158. _DisplayLastName = value;
  159. }
  160. }
  161. private string _DisplayEmail = string.Empty;
  162. //[Required(ErrorMessage = "Email Required")]
  163. //[RegularExpression(@"^(\w)+(\.\w+)*@(\w)+((\.\w+)+)$", ErrorMessage = "Email Format Error")]
  164. public string DisplayEmail
  165. {
  166. get { return _DisplayEmail; }
  167. set
  168. {
  169. _DisplayEmail = value;
  170. }
  171. }
  172. private bool _IsSelected = false;
  173. public bool IsSelected
  174. {
  175. get
  176. {
  177. return _IsSelected;
  178. }
  179. set
  180. {
  181. _IsSelected = value;
  182. this.OnPropertyChanged("IsSelected");
  183. }
  184. }
  185. private bool _AccountTextSaved = true;
  186. public bool AccountTextSaved
  187. {
  188. get { return _AccountTextSaved; }
  189. set
  190. {
  191. if (_AccountTextSaved != value)
  192. {
  193. _AccountTextSaved = value;
  194. this.OnPropertyChanged("AccountTextSaved");
  195. }
  196. }
  197. }
  198. private bool _FirstNameTextSaved = true;
  199. public bool FirstNameTextSaved
  200. {
  201. get { return _FirstNameTextSaved; }
  202. set
  203. {
  204. if (_FirstNameTextSaved != value)
  205. {
  206. _FirstNameTextSaved = value;
  207. this.OnPropertyChanged("FirstNameTextSaved");
  208. }
  209. }
  210. }
  211. private bool _LastNameTextSaved = true;
  212. public bool LastNameTextSaved
  213. {
  214. get { return _LastNameTextSaved; }
  215. set
  216. {
  217. if (_LastNameTextSaved != value)
  218. {
  219. _LastNameTextSaved = value;
  220. this.OnPropertyChanged("LastNameTextSaved");
  221. }
  222. }
  223. }
  224. private bool _EmailTextSaved = true;
  225. public bool EmailTextSaved
  226. {
  227. get { return _EmailTextSaved; }
  228. set
  229. {
  230. if (_EmailTextSaved != value)
  231. {
  232. _EmailTextSaved = value;
  233. this.OnPropertyChanged("EmailTextSaved");
  234. }
  235. }
  236. }
  237. private bool _IsEnableChangeAccountName = true;
  238. public bool IsEnableChangeAccountName
  239. {
  240. get
  241. {
  242. return _IsEnableChangeAccountName;
  243. }
  244. set
  245. {
  246. if (_IsEnableChangeAccountName != value)
  247. {
  248. _IsEnableChangeAccountName = value;
  249. this.OnPropertyChanged("IsEnableChangeAccountName");
  250. }
  251. }
  252. }
  253. /// <summary>
  254. /// Store all roles
  255. /// </summary>
  256. private ObservableCollection<RoleStatusItem> m_RoleColleciton = new ObservableCollection<RoleStatusItem>();
  257. public ObservableCollection<RoleStatusItem> RoleColleciton
  258. {
  259. get { return m_RoleColleciton; }
  260. }
  261. /// <summary>
  262. /// Update password
  263. /// </summary>
  264. public bool UpdatePassword()
  265. {
  266. if (NewPassword == null || NewPassword == string.Empty
  267. || ConfirmPassword == null || ConfirmPassword == string.Empty
  268. || NewPassword != ConfirmPassword)
  269. {
  270. return false;
  271. }
  272. Password = NewPassword;
  273. NewPassword = null;
  274. ConfirmPassword = null;
  275. return true;
  276. }
  277. /// <summary>
  278. /// Try update password
  279. /// </summary>
  280. public bool TryUpdatePassword()
  281. {
  282. if (NewPassword == null || NewPassword == string.Empty
  283. || ConfirmPassword == null || ConfirmPassword == string.Empty
  284. || NewPassword != ConfirmPassword)
  285. {
  286. return false;
  287. }
  288. return true;
  289. }
  290. /// <summary>
  291. /// Init role list
  292. /// </summary>
  293. /// <param name="listRole"></param>
  294. public void InitRoleList(List<Role> listRole)
  295. {
  296. m_RoleColleciton.Clear();
  297. foreach (Role role in listRole)
  298. {
  299. RoleStatusItem RoleStatus = new RoleStatusItem()
  300. {
  301. RoleID = role.RoleID,
  302. RoleName = role.RoleName,
  303. RoleStatus = this.Account.RoleIDs.Contains(role.RoleID) ? true : false
  304. };
  305. m_RoleColleciton.Add(RoleStatus);
  306. }
  307. }
  308. public bool IsAccountChanged()
  309. {
  310. if (this.DisplayAccountName != Account.LoginName)
  311. return true;
  312. if (this.DisplayFirstName != Account.FirstName)
  313. return true;
  314. if (this.DisplayLastName != Account.LastName)
  315. return true;
  316. if (this.DisplayEmail != Account.Email)
  317. return true;
  318. foreach (RoleStatusItem item in m_RoleColleciton)
  319. {
  320. if (item.DisplayRoleStatus != item.RoleStatus)
  321. return true;
  322. }
  323. return false;
  324. }
  325. #region INotifyPropertyChanged Members
  326. public event PropertyChangedEventHandler PropertyChanged;
  327. protected virtual void OnPropertyChanged(string propertyName)
  328. {
  329. PropertyChangedEventHandler handler = this.PropertyChanged;
  330. if (handler != null)
  331. handler(this, new PropertyChangedEventArgs(propertyName));
  332. }
  333. #endregion
  334. }
  335. }