| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 |
- //----------------------------------------------------------------
- //Module Name: FocusGoodsSelectViewModel
- //Purpose:
- //CopyRight: Muchinfo
- //History:
- //----------------------------------------------------------------
- //DateTime Author Description
- //----------------------------------------------------------------
- //2014-03-26 deng.yinping Create
- //----------------------------------------------------------------
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Ioc;
- using Muchinfo.MTPClient.Data;
- using Muchinfo.MTPClient.Infrastructure.Utilities;
- using Muchinfo.MTPClient.IService;
- using Muchinfo.MTPClient.Resources;
- using Muchinfo.MTPClient.UI.Views;
- using Muchinfo.WPF.Controls.Windows;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows.Controls;
- namespace Muchinfo.MTPClient.UI.ViewModels
- {
- /// <summary>
- /// EditQuoteListHeaderViewModel类
- /// </summary>
- public class FocusGoodsSelectViewModel : ViewModelBase
- {
- #region Fields
- private ObservableCollection<TreeViewEntity> _exchangeList;
- private ObservableCollection<TreeViewEntity> _selectedItems;
- private TreeViewEntity _currentListViewItem;
- /// <summary>
- /// 最多关注数量
- /// </summary>
- private int _maxCount = 3;
- #endregion Fields
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the <see cref="EditQuoteListHeaderViewModel" /> class.
- /// </summary>
- public FocusGoodsSelectViewModel()
- {
- InitializeData();
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- public ObservableCollection<TreeViewEntity> ExchangeList
- {
- get
- {
- return _exchangeList;
- }
- set
- {
- Set(() => ExchangeList, ref _exchangeList, value);
- }
- }
- public ObservableCollection<TreeViewEntity> SelectedItems
- {
- get
- {
- return _selectedItems;
- }
- set
- {
- Set(() => SelectedItems, ref _selectedItems, value);
- }
- }
- public TreeViewEntity CurrentListViewEntity
- {
- get
- {
- return _currentListViewItem;
- }
- set
- {
- Set(() => CurrentListViewEntity, ref _currentListViewItem, value);
- }
- }
- /// <summary>
- /// 获取和设置the OK command
- /// </summary>
- public RelayCommand<FocusGoodsSelectView> OKCommand
- {
- get
- {
- return new RelayCommand<FocusGoodsSelectView>((view) =>
- {
- view.DialogResult = true;
- UserManager.SaveFocusGoodsList(SelectedItems == null ? null : SelectedItems.ToList());
- });
- }
- }
- /// <summary>
- /// 获取和设置the cancel command
- /// </summary>
- public RelayCommand<FocusGoodsSelectView> CancelCommand
- {
- get
- {
- return new RelayCommand<FocusGoodsSelectView>((view) =>
- {
- view.DialogResult = false;
- });
- }
- }
- /// <summary>
- /// 获取和设置the in command
- /// </summary>
- public RelayCommand<TreeViewEntity> InCommand
- {
- get
- {
- return new RelayCommand<TreeViewEntity>((entity) =>
- {
- //有子集,返回
- if (entity == null || (entity.Children != null && entity.Children.Any())) return;
- if (SelectedItems.Count == _maxCount)
- {
- MessageBoxHelper.ShowInfo(string.Format(Muchinfo_Resource.UI2014_CanOnlyAddCentainAmountFocusGoods, _maxCount.ToString()), Muchinfo_Resource.UI2014_FoucusGoodsSettingTips);
- }
- else
- {
- var item = SelectedItems.FirstOrDefault(z => z.Key == entity.Key);
- if (item == null)
- {
- SelectedItems.Add(entity);
- CurrentListViewEntity = entity;
- }
- }
- });
- }
- }
- /// <summary>
- /// 获取和设置the out command
- /// </summary>
- public RelayCommand<TreeViewEntity> OutCommand
- {
- get
- {
- return new RelayCommand<TreeViewEntity>((entity) =>
- {
- if (entity == null) return;
- var item = SelectedItems.FirstOrDefault(z => z.Key == entity.Key);
- if (item == null) return;
- SelectedItems.Remove(item);
- });
- }
- }
- /// <summary>
- /// 获取和设置up command
- /// </summary>
- public RelayCommand<ListBox> UpCommand
- {
- get
- {
- return new RelayCommand<ListBox>((listbox) =>
- {
- if (listbox == null) return;
- var item = listbox.SelectedItem;
- if (item == null) return;
- var index = listbox.SelectedIndex;
- if (index == 0) return;
- _selectedItems.Move(index, index - 1);
- listbox.ScrollIntoView(item);
- });
- }
- }
- /// <summary>
- /// 获取和设置down command
- /// </summary>
- public RelayCommand<ListBox> DownCommand
- {
- get
- {
- return new RelayCommand<ListBox>((view) =>
- {
- if (view == null) return;
- var item = view.SelectedItem;
- if (item == null) return;
- var index = view.SelectedIndex;
- if (index == (_selectedItems.Count - 1)) return;
- _selectedItems.Move(index, index + 1);
- view.ScrollIntoView(item);
- });
- }
- }
- #endregion Public Properties
- #endregion Properties
- /// <summary>
- /// 数据初始化
- /// </summary>
- private void InitializeData()
- {
- var service = SimpleIoc.Default.GetInstance<IGoodsService>();
- ExchangeList = service.GetExchangeTree();
- //todo:获取本地数据初始化关注商品
- var goodsList = UserManager.GetFocusGoodsList();
- var list = new ObservableCollection<TreeViewEntity>();
- if (goodsList != null && goodsList.Any())
- {
- foreach (var goods in goodsList)
- {
- if (goods == null) continue;
- list.Add(new TreeViewEntity() { Key = goods.GoodsCode, Value = string.IsNullOrWhiteSpace(goods.Name) ? goods.GoodsCode : goods.Name });
- }
- }
- SelectedItems = list;
- }
- }
- }
|