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
{
///
/// This class contains properties that a View can data bind to.
///
/// See http://www.galasoft.ch/mvvm
///
///
public class MainViewModel : ViewModelBase
{
#region Fields
private readonly IDataService _dataService;
///
/// AcceleratedWheelFactor
///
private int _acceleratedWheelFactor;
///
/// AcceleratedWheelModifierKeys
///
private ModifierKeys _acceleratedWheelModifierKeys;
///
/// ChartBackground
///
private SolidColorBrush _chartBackground;
///
/// ChartFontSize
///
private double _chartFontSize;
///
/// ChartLanguage
///
private ChartLanguageType _chartLanguage;
///
/// CycleType
///
private CycleType _cycleType;
/////
///// DataSet
/////
//private ChartDataSet _dataSet;
///
/// DrawingToolPosition
///
private DrawingToolPositionType _drawingToolPosition;
///
/// CurrentDrawingToolType
///
private DrawingToolType _drawingToolType;
///
/// FillComparisonCandle
///
private KeyValuePair _fillComparisonCandle;
private GoodsInfo _goodsInfo;
///
/// GridOpacity
///
private double _gridOpacity;
private string _indicatorType;
///
/// PlotType
///
private LinePlotType _linePlotType;
///
/// MaxRecordCount
///
private int _maxRecordCount;
///
/// MinRecordCount
///
private int _minRecordCount;
///
/// RecordCount
///
private int _recordCount;
///
/// ShowDrawingTool
///
private Visibility _showDrawingTool;
///
/// ShowHeader
///
private Visibility _showHeader;
///
/// SymbolForeground
///
private Brush _symbolForeground;
#endregion Fields
#region Constructors
///
/// Initializes a new instance of the MainViewModel class.
///
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()
{
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()
{
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(this, "SetCurrentGoods", (s) =>
{
GoodsInfo = GoodsInfos.FirstOrDefault();
});
}
#endregion Constructors
#region Properties
#region Public Properties
///
/// Sets and gets the AcceleratedWheelFactor property.
/// Changes to that property's value raise the PropertyChanged event.
///
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); }
}
///
/// Sets and gets the AcceleratedWheelModifierKeys property.
/// Changes to that property's value raise the PropertyChanged event.
///
public ModifierKeys AcceleratedWheelModifierKeys
{
get
{
return _acceleratedWheelModifierKeys;
}
set
{
Set(() => AcceleratedWheelModifierKeys, ref _acceleratedWheelModifierKeys, value);
}
}
public RelayCommand AddIndicatorCommand
{
get
{
return new RelayCommand((chart) => chart.AddIndicator());
}
}
public Dictionary BoolDictionary
{
get
{
return new Dictionary
{
{"否", false},
{"是", true}
};
}
}
public RelayCommand CancelComparisonGoodsCommand
{
get
{
return
new RelayCommand((c) => c.ClearComparison());
}
}
///
/// MaxLoadRecordCount
///
private int _maxLoadRecordCount;
///
/// Sets and gets the MaxLoadRecordCount property.
/// Changes to that property's value raise the PropertyChanged event.
///
public int MaxLoadRecordCount
{
get
{
return _maxLoadRecordCount;
}
set
{
Set(() => MaxLoadRecordCount, ref _maxLoadRecordCount, value);
}
}
///
/// Sets and gets the ChartBackground property.
/// Changes to that property's value raise the PropertyChanged event.
///
public SolidColorBrush ChartBackground
{
get
{
return _chartBackground;
}
set
{
Set(() => ChartBackground, ref _chartBackground, value);
}
}
///
/// Sets and gets the ChartFontSize property.
/// Changes to that property's value raise the PropertyChanged event.
///
public double ChartFontSize
{
get
{
return _chartFontSize;
}
set
{
Set(() => ChartFontSize, ref _chartFontSize, value);
}
}
///
/// Sets and gets the ChartLanguage property.
/// Changes to that property's value raise the PropertyChanged event.
///
public ChartLanguageType ChartLanguage
{
get
{
return _chartLanguage;
}
set
{
Set(() => ChartLanguage, ref _chartLanguage, value);
}
}
///
/// Gets the comparison goods command.
///
/// The comparison goods command.
public RelayCommand ComparisonGoodsCommand
{
get
{
return new RelayCommand(
(c) =>
{
var list = c.ComparisonListBox.SelectedItems.OfType().ToList();
c.Chart.SetComparisonGoodsList(list);
});
}
}
///
/// Gets the comparison goods list.
///
/// The comparison goods list.
public List ComparisonGoodsList
{
get
{
return new List()
{
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 _CycleItems;
///
/// 图表集合
///
public List CycleItems
{
get
{
if (_CycleItems == null || _CycleItems.Count() == 0)
{
var items = new List()
{
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); }
}
///
/// Sets and gets the CycleType property.
/// Changes to that property's value raise the PropertyChanged event.
///
public CycleType CycleType
{
get
{
return _cycleType;
}
set
{
Set(() => CycleType, ref _cycleType, value);
}
}
public List CycleTypes
{
get
{
if (_dataService != null) return _dataService.GetCycleTypes();
return null;
}
}
/////
///// Sets and gets the DataSet property.
///// Changes to that property's value raise the PropertyChanged event.
/////
//public ChartDataSet DataSet
//{
// get
// {
// return _dataSet;
// }
// set
// {
// //对象必需实现INotificationChanged才能通知改变
// _dataSet = value;
// //Set(() => DataSet, ref _dataSet, value);
// }
//}
///
/// Sets and gets the DrawingToolPosition property.
/// Changes to that property's value raise the PropertyChanged event.
///
public DrawingToolPositionType DrawingToolPosition
{
get
{
return _drawingToolPosition;
}
set
{
Set(() => DrawingToolPosition, ref _drawingToolPosition, value);
//显示画线工具
ShowDrawingTool = Visibility.Visible;
}
}
public List DrawingToolPositions
{
get
{
if (_dataService != null) return _dataService.GetDrawingToolPositions();
return null;
}
}
///
/// Sets and gets the CurrentDrawingToolType property.
/// Changes to that property's value raise the PropertyChanged event.
///
public DrawingToolType DrawingToolType
{
get
{
return _drawingToolType;
}
set
{
Set(() => DrawingToolType, ref _drawingToolType, value);
}
}
public List DrawingToolTypes
{
get
{
if (_dataService != null) return _dataService.GetDrawingToolTypes();
return null;
}
}
///
/// Sets and gets the FillComparisonCandle property.
/// Changes to that property's value raise the PropertyChanged event.
///
/// The fill comparison candle.
public KeyValuePair FillComparisonCandle
{
get
{
return _fillComparisonCandle;
}
set
{
Set(() => FillComparisonCandle, ref _fillComparisonCandle, value);
}
}
///
/// Sets and gets the MyProperty property.
/// Changes to that property's value raise the PropertyChanged event.
///
public GoodsInfo GoodsInfo
{
get
{
return _goodsInfo;
}
set
{
Set(() => GoodsInfo, ref _goodsInfo, value);
}
}
public static ObservableCollection GoodsInfos
{
get;
private set;
}
///
/// Sets and gets the GridOpacity property.
/// Changes to that property's value raise the PropertyChanged event.
///
public double GridOpacity
{
get
{
return _gridOpacity;
}
set
{
Set(() => GridOpacity, ref _gridOpacity, value);
}
}
///
/// Sets and gets the MyProperty property.
/// Changes to that property's value raise the PropertyChanged event.
///
public string IndicatorType
{
get
{
return _indicatorType;
}
set
{
Set(() => IndicatorType, ref _indicatorType, value);
}
}
public List IndicatorTypes
{
get
{
if (_dataService != null) return _dataService.GetIndicatorTypes();
return null;
}
}
public Dictionary Languages
{
get
{
if (_dataService != null) return _dataService.GetLanguages();
return null;
}
}
///
/// Sets and gets the PlotType property.
/// Changes to that property's value raise the PropertyChanged event.
///
public LinePlotType LinePlotType
{
get
{
return _linePlotType;
}
set
{
Set(() => LinePlotType, ref _linePlotType, value);
}
}
public List LinePlotTypes
{
get
{
if (_dataService != null) return _dataService.GetLinePlotTypes();
return null;
}
}
///
/// Sets and gets the MaxRecordCount property.
/// Changes to that property's value raise the PropertyChanged event.
///
public int MaxRecordCount
{
get
{
return _maxRecordCount;
}
set
{
Set(() => MaxRecordCount, ref _maxRecordCount, value);
}
}
///
/// Sets and gets the MinRecordCount property.
/// Changes to that property's value raise the PropertyChanged event.
///
public int MinRecordCount
{
get
{
return _minRecordCount;
}
set
{
Set(() => MinRecordCount, ref _minRecordCount, value);
}
}
public List ModifierKeys
{
get
{
if (_dataService != null) return _dataService.GetModifierKeys();
return null;
}
}
///
/// Sets and gets the RecordCount property.
/// Changes to that property's value raise the PropertyChanged event.
///
public int RecordCount
{
get
{
return _recordCount;
}
set
{
Set(() => RecordCount, ref _recordCount, value);
}
}
///
/// Sets and gets the ShowDrawingTool property.
/// Changes to that property's value raise the PropertyChanged event.
///
public Visibility ShowDrawingTool
{
get
{
return _showDrawingTool;
}
set
{
Set(() => ShowDrawingTool, ref _showDrawingTool, value);
}
}
///
/// Sets and gets the ShowHeader property.
/// Changes to that property's value raise the PropertyChanged event.
///
public Visibility ShowHeader
{
get
{
return _showHeader;
}
set
{
Set(() => ShowHeader, ref _showHeader, value);
}
}
///
/// Sets and gets the SymbolForeground property.
/// Changes to that property's value raise the PropertyChanged event.
///
public Brush SymbolForeground
{
get
{
return _symbolForeground;
}
set
{
Set(() => SymbolForeground, ref _symbolForeground, value);
}
}
public List Visibilities
{
get
{
if (_dataService != null) return _dataService.GetVisibilities();
return null;
}
}
public RelayCommand ExportToExcel
{
get
{
return new RelayCommand((chart) => chart.ExportToExcel());
}
}
#endregion Public Properties
#endregion Properties
}
}