| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using Muchinfo.MTPClient.Data.Enums;
- using Muchinfo.MTPClient.Data.Model;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using System.Collections.ObjectModel;
- using System.Linq;
- namespace Muchinfo.MTPClient.Account.ViewModels
- {
- public class MessageInfoViewModel : ViewModelBase
- {
- private bool _nextIsEnabled;
- public bool NextIsEnabled
- {
- get { return _nextIsEnabled; }
- set { Set(() => NextIsEnabled, ref _nextIsEnabled, value); }
- }
- private bool _returnIsEnabled;
- public bool ReturnIsEnabled
- {
- get { return _returnIsEnabled; }
- set { Set(() => ReturnIsEnabled, ref _returnIsEnabled, value); }
- }
- private int CurrentListIndex { get; set; }
- private Announcement _currentAnnouncement;
- public Announcement CurrentAnnouncement
- {
- get { return _currentAnnouncement; }
- set
- {
- Set(() => CurrentAnnouncement, ref _currentAnnouncement, value);
- SetCommand();
- UpdatReadStatus();
- }
- }
- private ObservableCollection<Announcement> _messageOrders;
- public ObservableCollection<Announcement> MessageOrders
- {
- get { return _messageOrders; }
- set { Set(() => MessageOrders, ref _messageOrders, value); }
- }
- private MsgTypeEnum _msgTypeEnum;
- /// <summary>
- /// 消息类型
- /// </summary>
- public MsgTypeEnum MsgTypeEnum
- {
- get { return _msgTypeEnum; }
- set
- {
- _msgTypeEnum = value;
- switch (value)
- {
- case MsgTypeEnum.None:
- break;
- case MsgTypeEnum.Bulletin:
- Title = Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Notice;
- break;
- //case MsgTypeEnum.MSG:
- // break;
- case MsgTypeEnum.NTF:
- Title = Muchinfo.MTPClient.Resources.Muchinfo_Resource.Models_Inform;
- break;
- //case MsgTypeEnum.ALL:
- // break;
- default:
- break;
- }
-
- }
- }
- private string _title;
- /// <summary>
- /// 标题
- /// </summary>
- public string Title
- {
- get { return _title; }
- set { Set(() => Title, ref _title, value); }
- }
- public void UpdatReadStatus()
- {
- if (this.CurrentAnnouncement.ReadStatus == 0)
- {
- //修改阅读状态
- var userInfoList = UserManager.GetTradeAccounts();
- if (userInfoList != null)
- {
- var userInfo = userInfoList.FirstOrDefault(z => z.UserName == UserManager.CurrentTradeAccount.LoginCode);
- if (this.MsgTypeEnum == MsgTypeEnum.Bulletin)
- {
- if (userInfo != null && !userInfo.ReadAnnouncementIds.Contains(this.CurrentAnnouncement.MsgID))
- {
- this.CurrentAnnouncement.ReadStatus = 1;
- userInfo.ReadAnnouncementIds.Add(this.CurrentAnnouncement.MsgID);
- UserManager.SaveTradeAccount(userInfo);
- }
- }
- if (this.MsgTypeEnum == MsgTypeEnum.NTF)
- {
- if (userInfo != null && !userInfo.ReadNoticeIds.Contains(this.CurrentAnnouncement.MsgID))
- {
- this.CurrentAnnouncement.ReadStatus = 1;
- userInfo.ReadNoticeIds.Add(this.CurrentAnnouncement.MsgID);
- UserManager.SaveTradeAccount(userInfo);
- }
- }
- }
- }
- }
- public void SetCommand()
- {
- if (MessageOrders != null && MessageOrders.Count > 0)
- {
- //this.CurrentListIndex = 0;
- //Announcement announcement = MessageOrders.FirstOrDefault(m => m.MsgID == this.CurrentAnnouncement.MsgID);
- //if (announcement != null)
- //{
- // if (this.MessageOrders[0].MsgID == this.CurrentAnnouncement.MsgID)
- // this.ReturnIsEnabled = false;
- // else
- // this.ReturnIsEnabled = true;
- // if (this.MessageOrders[MessageOrders.Count - 1].MsgID == this.CurrentAnnouncement.MsgID)
- // NextIsEnabled = false;
- // else
- // NextIsEnabled = true;
- //}
- this.CurrentListIndex = -1;
- var announcement = MessageOrders.FirstOrDefault(m => m.MsgID == this.CurrentAnnouncement.MsgID);
- if (announcement != null)
- {
- this.CurrentListIndex = MessageOrders.IndexOf(announcement);
- if (this.MessageOrders[0].MsgID == this.CurrentAnnouncement.MsgID)
- this.ReturnIsEnabled = false;
- else
- this.ReturnIsEnabled = true;
- if (this.MessageOrders[MessageOrders.Count - 1].MsgID == this.CurrentAnnouncement.MsgID)
- NextIsEnabled = false;
- else
- NextIsEnabled = true;
- }
- }
- }
- /// <summary>
- /// 上一条
- /// </summary>
- public RelayCommand ReturnCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- this.CurrentAnnouncement = MessageOrders[this.CurrentListIndex - 1];
- });
- }
- }
- /// <summary>
- /// 下一条
- /// </summary>
- public RelayCommand NextCommand
- {
- get
- {
- return new RelayCommand(() =>
- {
- this.CurrentAnnouncement = MessageOrders[this.CurrentListIndex + 1];
- });
- }
- }
- }
- }
|