| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- using GalaSoft.MvvmLight;
- using GalaSoft.MvvmLight.Command;
- using GalaSoft.MvvmLight.Messaging;
- using MuchInfo.Chart.App.Converters;
- using MuchInfo.Chart.App.Services;
- using MuchInfo.Chart.Data.EnumTypes;
- using MuchInfo.Chart.Data.Models;
- using MuchInfo.Chart.Infrastructure.Data;
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.Linq;
- using System.Windows;
- using System.Windows.Input;
- using System.Windows.Media;
- namespace MuchInfo.Chart.App.ViewModels
- {
- /// <summary>
- /// This class contains properties that a View can data bind to.
- /// <para>
- /// See http://www.galasoft.ch/mvvm
- /// </para>
- /// </summary>
- public class MainViewModel : ViewModelBase
- {
- #region Fields
- private readonly IDataService _dataService;
- /// <summary>
- /// AcceleratedWheelFactor
- /// </summary>
- private int _acceleratedWheelFactor;
- /// <summary>
- /// AcceleratedWheelModifierKeys
- /// </summary>
- private ModifierKeys _acceleratedWheelModifierKeys;
- /// <summary>
- /// ChartBackground
- /// </summary>
- private SolidColorBrush _chartBackground;
- /// <summary>
- /// ChartFontSize
- /// </summary>
- private double _chartFontSize;
- /// <summary>
- /// ChartLanguage
- /// </summary>
- private ChartLanguageType _chartLanguage;
- /// <summary>
- /// CycleType
- /// </summary>
- private CycleType _cycleType;
- ///// <summary>
- ///// DataSet
- ///// </summary>
- //private ChartDataSet _dataSet;
- /// <summary>
- /// DrawingToolPosition
- /// </summary>
- private DrawingToolPositionType _drawingToolPosition;
- /// <summary>
- /// CurrentDrawingToolType
- /// </summary>
- private DrawingToolType _drawingToolType;
- /// <summary>
- /// FillComparisonCandle
- /// </summary>
- private KeyValuePair<string, bool> _fillComparisonCandle;
- private GoodsInfo _goodsInfo;
- /// <summary>
- /// GridOpacity
- /// </summary>
- private double _gridOpacity;
- private string _indicatorType;
- /// <summary>
- /// PlotType
- /// </summary>
- private LinePlotType _linePlotType;
- /// <summary>
- /// MaxRecordCount
- /// </summary>
- private int _maxRecordCount;
- /// <summary>
- /// MinRecordCount
- /// </summary>
- private int _minRecordCount;
- /// <summary>
- /// RecordCount
- /// </summary>
- private int _recordCount;
- /// <summary>
- /// ShowDrawingTool
- /// </summary>
- private Visibility _showDrawingTool;
- /// <summary>
- /// ShowHeader
- /// </summary>
- private Visibility _showHeader;
- /// <summary>
- /// SymbolForeground
- /// </summary>
- private Brush _symbolForeground;
- #endregion Fields
- #region Constructors
- /// <summary>
- /// Initializes a new instance of the MainViewModel class.
- /// </summary>
- public MainViewModel(IDataService dataService)
- {
- _dataService = dataService;
- _chartBackground = new SolidColorBrush(Colors.Black);
- _chartFontSize = 12;
- _chartLanguage = ChartLanguageType.SimplifiedChinese;
- _gridOpacity = 0.15;
- _showHeader = Visibility.Visible;
- _showDrawingTool = Visibility.Collapsed;
- _drawingToolPosition = DrawingToolPositionType.Left;
- _drawingToolType = DrawingToolType.Cross;
- _maxRecordCount = 5000;
- _minRecordCount = 50;
- _recordCount = 100;
- _maxLoadRecordCount = 2000;
- _linePlotType = LinePlotType.Candlestick;
- _cycleType = CycleType.Minute;
- _acceleratedWheelModifierKeys = System.Windows.Input.ModifierKeys.Control;
- _acceleratedWheelFactor = 10;
- var openTimes = new List<OpenCloseTime>()
- {
- new OpenCloseTime()
- {
- OpenTime =DateTime.Today.AddHours(-14),
- CloseTime = DateTime.Today.AddHours(18),
- },
- // new OpenCloseTime()
- //{
- // OpenTime =DateTime.Today.AddHours(13),
- // CloseTime = DateTime.Today.AddHours(15),
- //},
- // new OpenCloseTime()
- //{
- // OpenTime =DateTime.Today.AddHours(17),
- // CloseTime = DateTime.Today.AddHours(20),
- //},
- };
- GoodsInfos = new ObservableCollection<GoodsInfo>()
- {
- new GoodsInfo(100,"XAU1", GoodsType.PreciousMetal, 37, openTimes,1),
- new GoodsInfo(100,"XAU10", GoodsType.PreciousMetal, 37, openTimes,1),
- new GoodsInfo(100,"AU100", GoodsType.PreciousMetal, 37, openTimes,1),
- new GoodsInfo(1,"U1000", GoodsType.PreciousMetal, 37, openTimes,1),
- new GoodsInfo(1,"U100", GoodsType.PreciousMetal, 37, openTimes,1),
- new GoodsInfo(91,"AUTD", GoodsType.Futures, 37, openTimes,2),
- new GoodsInfo(100,"XAUUSD", GoodsType.PreciousMetal, 37, openTimes,2),
- new GoodsInfo(100,"XAGUSD", GoodsType.PreciousMetal, 37, openTimes,2)
- };
- _fillComparisonCandle = BoolDictionary.FirstOrDefault();
- Messenger.Default.Register<string>(this, "SetCurrentGoods", (s) =>
- {
- GoodsInfo = GoodsInfos.FirstOrDefault();
- });
- }
- #endregion Constructors
- #region Properties
- #region Public Properties
- /// <summary>
- /// Sets and gets the AcceleratedWheelFactor property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int AcceleratedWheelFactor
- {
- get
- {
- return _acceleratedWheelFactor;
- }
- set
- {
- Set(() => AcceleratedWheelFactor, ref _acceleratedWheelFactor, value);
- }
- }
- private BarDataPoint _TikBarDataPoint;
- public BarDataPoint TikBarDataPoint
- {
- get { return _TikBarDataPoint; }
- set { Set(() => TikBarDataPoint, ref _TikBarDataPoint, value); }
- }
- /// <summary>
- /// Sets and gets the AcceleratedWheelModifierKeys property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public ModifierKeys AcceleratedWheelModifierKeys
- {
- get
- {
- return _acceleratedWheelModifierKeys;
- }
- set
- {
- Set(() => AcceleratedWheelModifierKeys, ref _acceleratedWheelModifierKeys, value);
- }
- }
- public RelayCommand<MuchInfo.Chart.WPF.Chart> AddIndicatorCommand
- {
- get
- {
- return new RelayCommand<WPF.Chart>((chart) => chart.AddIndicator());
- }
- }
- public Dictionary<string, bool> BoolDictionary
- {
- get
- {
- return new Dictionary<string, bool>
- {
- {"否", false},
- {"是", true}
- };
- }
- }
- public RelayCommand<WPF.Chart> CancelComparisonGoodsCommand
- {
- get
- {
- return
- new RelayCommand<WPF.Chart>((c) => c.ClearComparison());
- }
- }
- /// <summary>
- /// MaxLoadRecordCount
- /// </summary>
- private int _maxLoadRecordCount;
- /// <summary>
- /// Sets and gets the MaxLoadRecordCount property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int MaxLoadRecordCount
- {
- get
- {
- return _maxLoadRecordCount;
- }
- set
- {
- Set(() => MaxLoadRecordCount, ref _maxLoadRecordCount, value);
- }
- }
- /// <summary>
- /// Sets and gets the ChartBackground property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public SolidColorBrush ChartBackground
- {
- get
- {
- return _chartBackground;
- }
- set
- {
- Set(() => ChartBackground, ref _chartBackground, value);
- }
- }
- /// <summary>
- /// Sets and gets the ChartFontSize property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public double ChartFontSize
- {
- get
- {
- return _chartFontSize;
- }
- set
- {
- Set(() => ChartFontSize, ref _chartFontSize, value);
- }
- }
- /// <summary>
- /// Sets and gets the ChartLanguage property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public ChartLanguageType ChartLanguage
- {
- get
- {
- return _chartLanguage;
- }
- set
- {
- Set(() => ChartLanguage, ref _chartLanguage, value);
- }
- }
- /// <summary>
- /// Gets the comparison goods command.
- /// </summary>
- /// <value>The comparison goods command.</value>
- public RelayCommand<ComparisonGoodsCommandArgs> ComparisonGoodsCommand
- {
- get
- {
- return new RelayCommand<ComparisonGoodsCommandArgs>(
- (c) =>
- {
- var list = c.ComparisonListBox.SelectedItems.OfType<ComparisonGoods>().ToList();
- c.Chart.SetComparisonGoodsList(list);
- });
- }
- }
- /// <summary>
- /// Gets the comparison goods list.
- /// </summary>
- /// <value>The comparison goods list.</value>
- public List<ComparisonGoods> ComparisonGoodsList
- {
- get
- {
- return new List<ComparisonGoods>()
- {
- new ComparisonGoods(1,"U1000", GoodsType.PreciousMetal, Colors.Green, 0, null,1),
- new ComparisonGoods(1,"U100", GoodsType.PreciousMetal, Colors.Red, 0, null,1),
- new ComparisonGoods(91,"AUTD", GoodsType.PreciousMetal, Colors.Silver, 0, null,1),
- new ComparisonGoods(100,"XAUUSD", GoodsType.PreciousMetal, Colors.Gold, 0, null,1),
- new ComparisonGoods(100,"XAGUSD", GoodsType.PreciousMetal, Colors.LightPink, 0, null,1)
- };
- }
- }
- private List<CycleType> _CycleItems;
- /// <summary>
- /// 图表集合
- /// </summary>
- public List<CycleType> CycleItems
- {
- get
- {
- if (_CycleItems == null || _CycleItems.Count() == 0)
- {
- var items = new List<CycleType>()
- {
- CycleType.TimeSharing,
- CycleType.Minute,
- CycleType.Minute5 ,
- CycleType.Minute15,
- CycleType.Minute30,
- CycleType.Hour,
- CycleType.Day,
- CycleType.Month,
- CycleType.Year,
- };
- Set(() => CycleItems, ref _CycleItems, items);
- }
- return _CycleItems;
- }
- set { Set(() => CycleItems, ref _CycleItems, value); }
- }
- /// <summary>
- /// Sets and gets the CycleType property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public CycleType CycleType
- {
- get
- {
- return _cycleType;
- }
- set
- {
- Set(() => CycleType, ref _cycleType, value);
- }
- }
- public List<CycleType> CycleTypes
- {
- get
- {
- if (_dataService != null) return _dataService.GetCycleTypes();
- return null;
- }
- }
- ///// <summary>
- ///// Sets and gets the DataSet property.
- ///// Changes to that property's value raise the PropertyChanged event.
- ///// </summary>
- //public ChartDataSet DataSet
- //{
- // get
- // {
- // return _dataSet;
- // }
- // set
- // {
- // //对象必需实现INotificationChanged才能通知改变
- // _dataSet = value;
- // //Set(() => DataSet, ref _dataSet, value);
- // }
- //}
- /// <summary>
- /// Sets and gets the DrawingToolPosition property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public DrawingToolPositionType DrawingToolPosition
- {
- get
- {
- return _drawingToolPosition;
- }
- set
- {
- Set(() => DrawingToolPosition, ref _drawingToolPosition, value);
- //显示画线工具
- ShowDrawingTool = Visibility.Visible;
- }
- }
- public List<DrawingToolPositionType> DrawingToolPositions
- {
- get
- {
- if (_dataService != null) return _dataService.GetDrawingToolPositions();
- return null;
- }
- }
- /// <summary>
- /// Sets and gets the CurrentDrawingToolType property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public DrawingToolType DrawingToolType
- {
- get
- {
- return _drawingToolType;
- }
- set
- {
- Set(() => DrawingToolType, ref _drawingToolType, value);
- }
- }
- public List<DrawingToolType> DrawingToolTypes
- {
- get
- {
- if (_dataService != null) return _dataService.GetDrawingToolTypes();
- return null;
- }
- }
- /// <summary>
- /// Sets and gets the FillComparisonCandle property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- /// <value>The fill comparison candle.</value>
- public KeyValuePair<string, bool> FillComparisonCandle
- {
- get
- {
- return _fillComparisonCandle;
- }
- set
- {
- Set(() => FillComparisonCandle, ref _fillComparisonCandle, value);
- }
- }
- /// <summary>
- /// Sets and gets the MyProperty property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public GoodsInfo GoodsInfo
- {
- get
- {
- return _goodsInfo;
- }
- set
- {
- Set(() => GoodsInfo, ref _goodsInfo, value);
- }
- }
- public static ObservableCollection<GoodsInfo> GoodsInfos
- {
- get;
- private set;
- }
- /// <summary>
- /// Sets and gets the GridOpacity property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public double GridOpacity
- {
- get
- {
- return _gridOpacity;
- }
- set
- {
- Set(() => GridOpacity, ref _gridOpacity, value);
- }
- }
- /// <summary>
- /// Sets and gets the MyProperty property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public string IndicatorType
- {
- get
- {
- return _indicatorType;
- }
- set
- {
- Set(() => IndicatorType, ref _indicatorType, value);
- }
- }
- public List<string> IndicatorTypes
- {
- get
- {
- if (_dataService != null) return _dataService.GetIndicatorTypes();
- return null;
- }
- }
- public Dictionary<ChartLanguageType, string> Languages
- {
- get
- {
- if (_dataService != null) return _dataService.GetLanguages();
- return null;
- }
- }
- /// <summary>
- /// Sets and gets the PlotType property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public LinePlotType LinePlotType
- {
- get
- {
- return _linePlotType;
- }
- set
- {
- Set(() => LinePlotType, ref _linePlotType, value);
- }
- }
- public List<LinePlotType> LinePlotTypes
- {
- get
- {
- if (_dataService != null) return _dataService.GetLinePlotTypes();
- return null;
- }
- }
- /// <summary>
- /// Sets and gets the MaxRecordCount property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int MaxRecordCount
- {
- get
- {
- return _maxRecordCount;
- }
- set
- {
- Set(() => MaxRecordCount, ref _maxRecordCount, value);
- }
- }
- /// <summary>
- /// Sets and gets the MinRecordCount property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int MinRecordCount
- {
- get
- {
- return _minRecordCount;
- }
- set
- {
- Set(() => MinRecordCount, ref _minRecordCount, value);
- }
- }
- public List<ModifierKeys> ModifierKeys
- {
- get
- {
- if (_dataService != null) return _dataService.GetModifierKeys();
- return null;
- }
- }
- /// <summary>
- /// Sets and gets the RecordCount property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public int RecordCount
- {
- get
- {
- return _recordCount;
- }
- set
- {
- Set(() => RecordCount, ref _recordCount, value);
- }
- }
- /// <summary>
- /// Sets and gets the ShowDrawingTool property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility ShowDrawingTool
- {
- get
- {
- return _showDrawingTool;
- }
- set
- {
- Set(() => ShowDrawingTool, ref _showDrawingTool, value);
- }
- }
- /// <summary>
- /// Sets and gets the ShowHeader property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Visibility ShowHeader
- {
- get
- {
- return _showHeader;
- }
- set
- {
- Set(() => ShowHeader, ref _showHeader, value);
- }
- }
- /// <summary>
- /// Sets and gets the SymbolForeground property.
- /// Changes to that property's value raise the PropertyChanged event.
- /// </summary>
- public Brush SymbolForeground
- {
- get
- {
- return _symbolForeground;
- }
- set
- {
- Set(() => SymbolForeground, ref _symbolForeground, value);
- }
- }
- public List<Visibility> Visibilities
- {
- get
- {
- if (_dataService != null) return _dataService.GetVisibilities();
- return null;
- }
- }
- public RelayCommand<WPF.Chart> ExportToExcel
- {
- get
- {
- return new RelayCommand<WPF.Chart>((chart) => chart.ExportToExcel());
- }
- }
- #endregion Public Properties
- #endregion Properties
- }
- }
|