AccountItem.cs 11 KB

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