MessageInfoViewModel.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. using GalaSoft.MvvmLight;
  2. using GalaSoft.MvvmLight.Command;
  3. using Muchinfo.MTPClient.Data.Enums;
  4. using Muchinfo.MTPClient.Data.Model;
  5. using Muchinfo.MTPClient.Infrastructure.Utilities;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. namespace Muchinfo.MTPClient.Account.ViewModels
  9. {
  10. public class MessageInfoViewModel : ViewModelBase
  11. {
  12. private bool _nextIsEnabled;
  13. public bool NextIsEnabled
  14. {
  15. get { return _nextIsEnabled; }
  16. set { Set(() => NextIsEnabled, ref _nextIsEnabled, value); }
  17. }
  18. private bool _returnIsEnabled;
  19. public bool ReturnIsEnabled
  20. {
  21. get { return _returnIsEnabled; }
  22. set { Set(() => ReturnIsEnabled, ref _returnIsEnabled, value); }
  23. }
  24. private int CurrentListIndex { get; set; }
  25. private Announcement _currentAnnouncement;
  26. public Announcement CurrentAnnouncement
  27. {
  28. get { return _currentAnnouncement; }
  29. set
  30. {
  31. Set(() => CurrentAnnouncement, ref _currentAnnouncement, value);
  32. SetCommand();
  33. UpdatReadStatus();
  34. }
  35. }
  36. private ObservableCollection<Announcement> _messageOrders;
  37. public ObservableCollection<Announcement> MessageOrders
  38. {
  39. get { return _messageOrders; }
  40. set { Set(() => MessageOrders, ref _messageOrders, value); }
  41. }
  42. private MsgTypeEnum _msgTypeEnum;
  43. /// <summary>
  44. /// 消息类型
  45. /// </summary>
  46. public MsgTypeEnum MsgTypeEnum
  47. {
  48. get { return _msgTypeEnum; }
  49. set
  50. {
  51. _msgTypeEnum = value;
  52. switch (value)
  53. {
  54. case MsgTypeEnum.None:
  55. break;
  56. case MsgTypeEnum.Bulletin:
  57. Title = Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Notice;
  58. break;
  59. //case MsgTypeEnum.MSG:
  60. // break;
  61. case MsgTypeEnum.NTF:
  62. Title = Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Inform;
  63. break;
  64. //case MsgTypeEnum.ALL:
  65. // break;
  66. default:
  67. break;
  68. }
  69. }
  70. }
  71. private string _title;
  72. /// <summary>
  73. /// 标题
  74. /// </summary>
  75. public string Title
  76. {
  77. get { return _title; }
  78. set { Set(() => Title, ref _title, value); }
  79. }
  80. public void UpdatReadStatus()
  81. {
  82. if (this.CurrentAnnouncement.ReadStatus == 0)
  83. {
  84. //修改阅读状态
  85. var userInfoList = UserManager.GetTradeAccounts();
  86. if (userInfoList != null)
  87. {
  88. var userInfo = userInfoList.FirstOrDefault(z => z.UserName == UserManager.CurrentTradeAccount.LoginCode);
  89. if (this.MsgTypeEnum == MsgTypeEnum.Bulletin)
  90. {
  91. if (userInfo != null && !userInfo.ReadAnnouncementIds.Contains(this.CurrentAnnouncement.MsgID))
  92. {
  93. this.CurrentAnnouncement.ReadStatus = 1;
  94. userInfo.ReadAnnouncementIds.Add(this.CurrentAnnouncement.MsgID);
  95. UserManager.SaveTradeAccount(userInfo);
  96. }
  97. }
  98. if (this.MsgTypeEnum == MsgTypeEnum.NTF)
  99. {
  100. if (userInfo != null && !userInfo.ReadNoticeIds.Contains(this.CurrentAnnouncement.MsgID))
  101. {
  102. this.CurrentAnnouncement.ReadStatus = 1;
  103. userInfo.ReadNoticeIds.Add(this.CurrentAnnouncement.MsgID);
  104. UserManager.SaveTradeAccount(userInfo);
  105. }
  106. }
  107. }
  108. }
  109. }
  110. public void SetCommand()
  111. {
  112. if (MessageOrders != null && MessageOrders.Count > 0)
  113. {
  114. //this.CurrentListIndex = 0;
  115. //Announcement announcement = MessageOrders.FirstOrDefault(m => m.MsgID == this.CurrentAnnouncement.MsgID);
  116. //if (announcement != null)
  117. //{
  118. // if (this.MessageOrders[0].MsgID == this.CurrentAnnouncement.MsgID)
  119. // this.ReturnIsEnabled = false;
  120. // else
  121. // this.ReturnIsEnabled = true;
  122. // if (this.MessageOrders[MessageOrders.Count - 1].MsgID == this.CurrentAnnouncement.MsgID)
  123. // NextIsEnabled = false;
  124. // else
  125. // NextIsEnabled = true;
  126. //}
  127. this.CurrentListIndex = -1;
  128. var announcement = MessageOrders.FirstOrDefault(m => m.MsgID == this.CurrentAnnouncement.MsgID);
  129. if (announcement != null)
  130. {
  131. this.CurrentListIndex = MessageOrders.IndexOf(announcement);
  132. if (this.MessageOrders[0].MsgID == this.CurrentAnnouncement.MsgID)
  133. this.ReturnIsEnabled = false;
  134. else
  135. this.ReturnIsEnabled = true;
  136. if (this.MessageOrders[MessageOrders.Count - 1].MsgID == this.CurrentAnnouncement.MsgID)
  137. NextIsEnabled = false;
  138. else
  139. NextIsEnabled = true;
  140. }
  141. }
  142. }
  143. /// <summary>
  144. /// 上一条
  145. /// </summary>
  146. public RelayCommand ReturnCommand
  147. {
  148. get
  149. {
  150. return new RelayCommand(() =>
  151. {
  152. this.CurrentAnnouncement = MessageOrders[this.CurrentListIndex - 1];
  153. });
  154. }
  155. }
  156. /// <summary>
  157. /// 下一条
  158. /// </summary>
  159. public RelayCommand NextCommand
  160. {
  161. get
  162. {
  163. return new RelayCommand(() =>
  164. {
  165. this.CurrentAnnouncement = MessageOrders[this.CurrentListIndex + 1];
  166. });
  167. }
  168. }
  169. }
  170. }