using FINANCEPRICELib; using GalaSoft.MvvmLight; using GalaSoft.MvvmLight.Command; using GalaSoft.MvvmLight.Ioc; using Muchinfo.MTPClient.Data; using Muchinfo.MTPClient.Data.Chart; using Muchinfo.MTPClient.Data.DTO; using Muchinfo.MTPClient.Data.Enums; using Muchinfo.MTPClient.Data.Model; using Muchinfo.MTPClient.Data.Quote; using Muchinfo.MTPClient.Infrastructure.Cache; using Muchinfo.MTPClient.Infrastructure.Helpers; using Muchinfo.MTPClient.Infrastructure.MessageBox; using Muchinfo.MTPClient.Infrastructure.Utilities; using Muchinfo.MTPClient.IService; using Muchinfo.PC.Common.Helpers; using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Runtime.InteropServices; using System.Text; //---------------------------------------------------------------- //Module Name: $safeprojectname$ //Purpose: //CopyRight: Muchinfo //History: //---------------------------------------------------------------- //DateTime 2017/2/4 10:25:33 //Author //Description Create //---------------------------------------------------------------- using System.Windows.Input; using Muchinfo.MTPClient.Data.Model.Account; namespace Muchinfo.MTPClient.Analysis.ViewModels { public class CChartViewModel : ChartViewModelBase, IDisposable { private ICommonQueryService _commonQueryService; static CChartViewModel() { Init(); } public static void Init() { //关于图表管理静态类初始化问题 以后考虑放到外面同意初始化 //Exception ex=null; string SysteFile = System.IO.Path.Combine(UserManager.SysConfigFolderPath, "SystemFile.dat"); string UserFile = System.IO.Path.Combine(UserManager.SysConfigFolderPath, "UserFile.dat"); try { FinanceGlobal = new GlobalAttribClass(); FinanceGlobal.SetDllType((int)DLLEDITIONTYPE.DllEditionType_MUCHINFO_MTP); FinanceGlobal.SetUseVirtualVolume(1); FinanceGlobal.SetUserFileName(UserFile); FinanceGlobal.SetSystemFileName(SysteFile); //FinanceChart.FilePath(UserIniFile); // FinanceChart.FilePath(UserIniFile); //STDMETHOD(SetSystemFileName)(/*[in]*/ BSTR strFileName); //STDMETHOD(SetUserFileName)(/*[in]*/ BSTR strFileName); #if !Futury FinanceGlobal.SetHistoryEdition((int)HistoryEdition.HistoryEdition_Muchinfo_MTP_WITH_SETTLE); #else FinanceGlobal.SetHistoryEdition((int)HistoryEdition.HistoryEdition_Muchinfo_MTP_WITH_SETTLE); //3 #endif FinanceGlobal.SetSystemDateTime(ApplicationParameter.ServerTimeNow.ToString("yyyyMMddHHmmss")); FinanceGlobal.SetUseSingleViewConfig(1); } catch (COMException ex) { MessageBoxHelper.ShowQuestion(string.Format(Resources.Client_Resource.ChartRegisterError, Path.Combine(ChartPathDir, c_chartRegitFile)), Resources.Client_Resource.APP_Tips); LogHelper.WriteError(typeof(CChartViewModel), ex.ToString()); } } private static GlobalAttribClass FinanceGlobal; ////图表配置 private PriceChartClass _financeChart; ////图表对象 private int _controlHandle; private CycleType _cycleType; private const string c_chartRegitFile = "regchart.bat"; ///注册图表控件的文件路径 private ChartCycleType _chartCycleType = ChartCycleType.MinuteTik; ///图表路径目录 public static string ChartPathDir { get { return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "COM"); } } public CChartViewModel(QuoteGoods goods, int handle):base(goods) { try { if (_commonQueryService == null) { _commonQueryService = SimpleIoc.Default.GetInstance(); /*废弃,不需要这个逻辑了 if (CacheManager.QuoteSourceGroupMarketDatas == null || CacheManager.QuoteSourceGroupMarketDatas.Count == 0) { _commonQueryService.QuoteSourceGroupMarketDate((list => { }), entity => { }); }*/ } RegiterMsg(); _controlHandle = handle; string UserIniFile = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "FinancePrice.ini"); _financeChart = new PriceChartClass(); _financeChart.OnMenuMessage += new _IPriceChartEvents_OnMenuMessageEventHandler(Chart_OnMenuMessage); _financeChart.RequestHistoryPrice += new _IPriceChartEvents_RequestHistoryPriceEventHandler(RequestHistoryPrice); PriceViewModel = new QuotePriceViewModel(); _financeChart.FilePath = UserIniFile; _quoteDataService = SimpleIoc.Default.GetInstance(); _currentGoods = goods; CommandTypes = SimpleIoc.Default.GetInstance().GetIndicator(); QueryGoodsReckonPlan(goods); InitSetChartColorStyle(); ChartCycle =(int) ChartCycleType.MinuteTik; SetIndecatorEnable(0); } catch (Exception ex) { LogHelper.WriteError(typeof(CChartViewModel), ex.ToString()); } } /// /// 图表请求数据 /// /// 交易所代码 /// 商品代码 /// 开始时间 /// 结束时间 /// 请求数量 /// 周期 private void RequestHistoryPrice(int lExchangeCode, string strWareCode, string strStartDate, string strEndDate, int lPriceNum, int lDataCycle) { // Console.WriteLine("请求:" + lDataCycle); //var dataCycle = lDataCycle; //格式化开始时间 string strStart = FormatSeverTime(strStartDate); //格式化结束时间 string strEnd = FormatSeverTime(strEndDate); DateTime starTime; //取当前时间之前的 if (string.IsNullOrWhiteSpace(strStart) || !DateTime.TryParse(strStart, out starTime)) { starTime = ApplicationParameter.ServerTimeNow; } DateTime endTime; if (string.IsNullOrWhiteSpace(strEnd) || !DateTime.TryParse(strEnd, out endTime)) { endTime = ApplicationParameter.BasicDateTime; } short count = (short)lPriceNum; _quoteDataService.GetHistoryCycleData(_currentGoods, (CycleType)lDataCycle, starTime, endTime, count, QueryHistorySuccess, ErrorSuccess); SetIndecatorEnable(0); } /// /// 历史数据回应 /// /// private void QueryHistorySuccess(byte[] data) { if (data == null || data.Length == 0) { LogHelper.WriteInfo("历史回应数据为空"); } if (_financeChart != null && data != null) { _financeChart.ResponseHistoryPrice(data, data.Length); } } private List _commandTypes; /// /// 底部菜单列表 /// public List CommandTypes { get { return _commandTypes; } set { Set(() => CommandTypes, ref _commandTypes, value); } } private SysMenuItem _currentIndexMenu; /// /// 当前选择的指标 /// public SysMenuItem CurrentIndexMenu { get { return _currentIndexMenu; } set { Set(() => CurrentIndexMenu, ref _currentIndexMenu, value); SetChartIndecator(value); } } /// /// 设置图表指标 /// /// private void SetChartIndecator(SysMenuItem menuItem) { if (_financeChart != null) { string index1 = string.Empty, index2 = string.Empty; _financeChart.GetFrameMessage2(_controlHandle, (int)UserDefineWindowsMessage.SetAddIndex, ref index1, ref index2); var hasIndex = string.IsNullOrWhiteSpace(index1); INDEX_TYPE indextype = INDEX_TYPE.INDEX_TYPE_MA; switch (menuItem.SysCommandType) { case MenuCommandType.MA: indextype = INDEX_TYPE.INDEX_TYPE_MA; if (!hasIndex && index1.Contains("MA")) { return; ///已存在MA } break; case MenuCommandType.BOLL: indextype = INDEX_TYPE.INDEX_TYPE_BOLL; if (!hasIndex && index1.Contains("BOLL")) { return; ///已存在BOLL } break; case MenuCommandType.MACD: indextype = INDEX_TYPE.INDEX_TYPE_MACD; if (!hasIndex && index1.Contains("MACD")) { return; ///已存在 } break; case MenuCommandType.KDJ: indextype = INDEX_TYPE.INDEX_TYPE_KDJ; if (!hasIndex && index1.Contains("KDJ")) { return; ///已存在 } break; case MenuCommandType.RSI: indextype = INDEX_TYPE.INDEX_TYPE_RSI; if (!hasIndex && index1.Contains("RSI")) { return; ///已存在 } break; case MenuCommandType.PSY: indextype = INDEX_TYPE.INDEX_TYPE_PSY; if (!hasIndex && index1.Contains("PSY")) { return; ///已存在 } break; case MenuCommandType.DMI: indextype = INDEX_TYPE.INDEX_TYPE_DMI; if (!hasIndex && index1.Contains("DMI")) { return; ///已存在 } break; case MenuCommandType.VOL: indextype = INDEX_TYPE.INDEX_TYPE_VOLUME; if (!hasIndex && index1.Contains("VOL")) { return; ///已存在 } break; default: break; } if (!hasIndex) { index1 = index1.Trim(';'); var indexArray= index1.Split(';'); if (indexArray.Any()) { var indicator = indexArray[indexArray.Length - 1]; var formulaArr = indicator.Split(','); if (formulaArr.Any()) { bool isExist = false; var index= ChartIndecator(formulaArr[0],ref isExist); if (isExist) { _financeChart.PostFrameMessage(_controlHandle, (int) UserDefineWindowsMessage.SetDeleteIndex, (int) index, 0); } } } } _financeChart.PostFrameMessage(_controlHandle, (int) UserDefineWindowsMessage.SetAddIndex, (int) indextype, 0); } } private INDEX_TYPE ChartIndecator(string formula,ref bool isExist) { isExist = true; var indextype = INDEX_TYPE.INDEX_TYPE_VOLUME; switch (formula) { case "MA": indextype = INDEX_TYPE.INDEX_TYPE_MA; break; case "BOLL": indextype = INDEX_TYPE.INDEX_TYPE_BOLL; break; case "MACD": indextype = INDEX_TYPE.INDEX_TYPE_MACD; break; case "KDJ": indextype = INDEX_TYPE.INDEX_TYPE_KDJ; break; case "RSI": indextype = INDEX_TYPE.INDEX_TYPE_RSI; break; case "PSY": indextype = INDEX_TYPE.INDEX_TYPE_PSY; break; case "DMI": indextype = INDEX_TYPE.INDEX_TYPE_DMI; break; case "VOL": indextype = INDEX_TYPE.INDEX_TYPE_VOLUME; break; default: isExist = false; break; } return indextype; } private void ErrorSuccess(ErrorEntity errorEntity) { LogHelper.WriteError(typeof(CChartViewModel), errorEntity.ReturnCode.ToString()); } /// /// 设置图表的样式 /// private void InitSetChartColorStyle() { var colorStyle = UserManager.GetCurrentColorStyle(); switch (colorStyle) { case ColorStyle.BlueWhite: FinanceGlobal.SetDefaultColorType((int)KLine_ColorType.KLine_COLOR_LCB_Red_RGB); break; case ColorStyle.DarkBlue: case ColorStyle.CoolBlack: FinanceGlobal.SetDefaultColorType((int)KLine_ColorType.KLine_COLOR_TDX_Red_Black); break; default: break; } } /// /// 图表周期 /// public int ChartCycle { get; set; } /// /// 格式化服务器时间 /// /// 客户端时间 /// public string FormatSeverTime(string clienttime) { if (!string.IsNullOrEmpty(clienttime)) { StringBuilder sb = new StringBuilder(); sb.Append(clienttime.Substring(0, 4)); if (clienttime.Length > 5) { sb.Append("-"); sb.Append(clienttime.Substring(4, 2)); } if (clienttime.Length > 7) { sb.Append("-"); sb.Append(clienttime.Substring(6, 2)); } if (clienttime.Length > 9) { sb.Append(" "); sb.Append(clienttime.Substring(8, 2)); } if (clienttime.Length > 11) { sb.Append(":"); sb.Append(clienttime.Substring(10, 2)); } if (clienttime.Length > 13) { sb.Append(":"); sb.Append(clienttime.Substring(12, 2)); } return sb.ToString(); } return string.Empty; } #region "转换商品类型" /// /// 商品类型转换 /// /// /// private WareAttributeClass ConverWare(QuoteGoods goods) { WareAttributeClass war = new WareAttributeClass(); war.Name = goods.Name; war.Ware = goods.GoodsCode; war.Type = "0"; war.HqKind = "1"; war.Rate = (double)1; war.SellPoint = (double)0; war.PriceDigit = 7; war.PriceType = "1"; war.HqWare = goods.GoodsCode; war.Logo = goods.MarketCode; war.HqDecimal = Math.Pow(10, -goods.DecimalPlaces); //GetWareTailLength(goods.DecimalPlaces.ToString()); war.ShowDecimal = Math.Pow(10, -goods.DecimalPlaces); //GetWareTailLength(goods.DecimalPlaces.ToString()); int exchange = 0; int.TryParse(goods.ExchHqCode, out exchange); war.HqExchangeCode = exchange; war.HqExchange = goods.ExchHqCode; //if (!string.IsNullOrEmpty(Mark)) // war.TradeHour = Mark; //if (goods.Config != null) //{ // //若历史开收盘时段不为空,则图表使用历史开收盘 by yxw 2014-12-01 // if (!goods.Config.IsHistory || string.IsNullOrEmpty(goods.Config.HistoryMark)) // war.TradeHour = goods.Config.Mark; // else // { // war.TradeHour = goods.Config.HistoryMark; // goods.Config.HistoryMark = string.Empty; //更新完后需释放,不影响下一次判定 // } //} #if DEBUG if (CacheManager.TradeDayPlan.ContainsKey(goods.GoodsParameters.GoodsId)) { var tradedates = CacheManager.TradeDayPlan[goods.GoodsParameters.GoodsId]; war.TradeDate = tradedates.TradeDay.ToString("yyyyMMdd"); war.TradeHour = ConvertTradeHour(tradedates.OpenCloseDates); } #else if (CacheManager.TradeDayPlan.ContainsKey(goods.GoodsParameters.GoodsId)) { var tradedates = CacheManager.TradeDayPlan[goods.GoodsParameters.GoodsId]; war.TradeDate = tradedates.TradeDay.ToString("yyyyMMdd"); war.TradeHour = ConvertTradeHour(tradedates.OpenCloseDates); } #endif war.IsHasVolume = goods.TradeMode == eTradeMode.TRADEMODE_MARKETMAKE ? 0 : 1; ////是否是有量商品 war.HighLimit = (double)goods.RaisesPrice; war.LowLimit = (double)goods.FallsPrice; //if (IsKLineMinuteTik) //{ // if (goods.ExchangeCode == Exchange.Sge) // { // war.TradeDayCloseOffset = -1; // } // war.TradeDate = KLineMinuteDate; //} //else //{ // if (goods.Config != null) // { // if (goods.ExchangeCode == Exchange.Sge && goods.Config.TradeDate >= ApplicationParamater.ServerTimeNow.Date) // { // war.TradeDayCloseOffset = -1; // } // war.TradeDate = goods.Config.TradeDate.ToString(FormatHelper.DateFormat2); // } //} //if (goods.ExchangeCode == Exchange.Sse || goods.ExchangeCode == Exchange.Szse) //{ // war.HighLimit = (double)goods.Preclose * 1.1; // war.LowLimit = (double)goods.Preclose * 0.9; //} try { if (CacheManager.TradeDayPlan.ContainsKey(goods.GoodsParameters.GoodsId)) { QuoteTradePlan tradedates = CacheManager.TradeDayPlan[goods.GoodsParameters.GoodsId]; if (tradedates.OpenCloseDates.Count > 0)// 太白说一定会有index 0的值 { OpenCloseDate index0 = tradedates.OpenCloseDates[0]; war.TradeDayCloseOffset = index0.OpenDate.Day - tradedates.TradeDay.Day;// TradeDayCloseOffset -1表示向前偏移,1表示向后偏移。0不偏移 } } } catch (Exception ex) { LogHelper.WriteError(typeof(UserManager), "处理TradeDayCloseOffset偏移量问题失败(CChartViewModel.cs 563行左右):" + ex.ToString()); } return war; } /// /// 转换开收市时间 /// /// 开收市时间 /// private string ConvertTradeHour(List openCloseDates) { if (openCloseDates == null || !openCloseDates.Any()) { return string.Empty; } var dateList = new List(); foreach (var openCloseDate in openCloseDates) { dateList.Add(openCloseDate.OpenDate.ToString("HHmm")); dateList.Add(openCloseDate.CloseDate.ToString("HHmm")); } return string.Join(",", dateList); } #endregion /// /// 图表添加商品 /// /// private void AddWare(QuoteGoods goods) { var war = ConverWare(goods); _financeChart.AddWare(war); _financeChart.SetWareName(war.Ware, war.Name); // SetWareFlag(war.HqExchange.ToString(), war.Ware.ToString(), false); CreateChartView(goods); } /// /// 更新商品 /// /// public void UpdateWare(QuoteGoods goods) { _currentGoods = goods; // var ware = ConverWare(goods); // _financeChart.AddWare(ware); // _financeChart.SetWareName(ware.Ware, ware.Name); QueryGoodsReckonPlan(goods); PriceViewModel.UpdateGoods(goods); // CreateChartView(goods, true); } /// /// 切换商品 /// /// true:切换下一个商品,false:切换上一个商品 public void ChangeGoodsNextFront(bool isNext) { var goodsList = new List(); var currentLayout = UserManager.GetCurrentLayoutStyle(); if (currentLayout == LayoutStyle.PersonalCenter) { goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode == eTradeMode.TRADEMODE_BIDDING) .ToList(); } else { goodsList = CacheManager.CacheGoodsBaseInfos.Where((item) => item.TradeMode != eTradeMode.TRADEMODE_SALE) .ToList(); } if (goodsList.Any()) { QuoteGoods nextGoods; var index = goodsList.FindIndex((goods) => goods.Symbol == _currentGoods.Symbol); if (isNext) { nextGoods = (index == -1 || index == goodsList.Count - 1) ? goodsList[0] : goodsList[index + 1]; } else { nextGoods = (index == -1 || index == 0) ? goodsList[goodsList.Count - 1] : goodsList[index - 1]; } if (nextGoods != null) { UpdateWare(nextGoods); var dto = new QuoteGoodsDTO(nextGoods); MessengerHelper.DefaultSend(dto, MessengerTokens.SelectGoodsChange); } } } /// /// 选中某个单据触发的图表显示问题 /// /// public void SelectGoodsOrder(QuoteGoodsForSelectOrder quoteGoods) { if (quoteGoods != null && _currentGoods.GoodsId != quoteGoods.QuoteGoods.GoodsId)// 如果是相同的商品,就不要再做任何事情了 { UpdateWare(quoteGoods.QuoteGoods); var dto = new QuoteGoodsDTO(quoteGoods.QuoteGoods); MessengerHelper.DefaultSend(dto, MessengerTokens.SelectGoodsChange); } } private void Chart_OnMenuMessage(int lMessageType, int lSubMessageType, int lExchangeCode, string strWare, string strParam) { switch ((UserDefineWindowsMessage) lMessageType) { #region 暂时不使用 case UserDefineWindowsMessage.None: break; case UserDefineWindowsMessage.Start: break; case UserDefineWindowsMessage.ChangeStyleCycle: break; case UserDefineWindowsMessage.DrawLine: break; case UserDefineWindowsMessage.ChangeViewCycle: break; case UserDefineWindowsMessage.ChangeViewFQ: break; case UserDefineWindowsMessage.Set_ShowRect: break; case UserDefineWindowsMessage.SetEnableDraw: break; case UserDefineWindowsMessage.SetDeleteIndex: break; case UserDefineWindowsMessage.SetAddIndex: break; case UserDefineWindowsMessage.SetRemoveAllIndex: break; case UserDefineWindowsMessage.GetCurIndexCount: break; case UserDefineWindowsMessage.SetMouseEvent: break; case UserDefineWindowsMessage.SetTradeDate: break; case UserDefineWindowsMessage.SetPreclose: break; case UserDefineWindowsMessage.SetMouseButtonRightUp: break; case UserDefineWindowsMessage.SetAddWare: break; case UserDefineWindowsMessage.SetSacle: break; case UserDefineWindowsMessage.DelAppendWare: break; case UserDefineWindowsMessage.SetVolumeUnit: break; case UserDefineWindowsMessage.SetOpenPrice: break; case UserDefineWindowsMessage.SetAppendWareClosePrice: break; case UserDefineWindowsMessage.FormulaInfo: break; case UserDefineWindowsMessage.ShowFormula: break; case UserDefineWindowsMessage.TRADEHOURDELAY: break; case UserDefineWindowsMessage.OPENPRICETIME: break; case UserDefineWindowsMessage.SHOWMATIK: break; case UserDefineWindowsMessage.TIKVOLUMEUNIT: break; case UserDefineWindowsMessage.MeanType: break; case UserDefineWindowsMessage.ViewPY: break; case UserDefineWindowsMessage.DrawIsdisplay: break; case UserDefineWindowsMessage.SetAutoScroll: break; case UserDefineWindowsMessage.ClearInvestLog: break; case UserDefineWindowsMessage.SetAxisShow: break; case UserDefineWindowsMessage.ClearInvestLogByViewHandler: break; case UserDefineWindowsMessage.ChartDispose: break; case UserDefineWindowsMessage.CloseStatFrom: break; case UserDefineWindowsMessage.CreateTime: break; case UserDefineWindowsMessage.ClearCache: break; case UserDefineWindowsMessage.OpenOrder: break; case UserDefineWindowsMessage.OpenMine: break; case UserDefineWindowsMessage.OpenDrawTool: break; case UserDefineWindowsMessage.AddToCustomBoard: break; case UserDefineWindowsMessage.OpenChartHide: break; case UserDefineWindowsMessage.OpenMouseOut: break; case UserDefineWindowsMessage.OpenMouseIn: break; case UserDefineWindowsMessage.OpenCycle: ChartCycle = lSubMessageType; SetIndecatorEnable(0); break; case UserDefineWindowsMessage.OpenReceiveHistory: break; case UserDefineWindowsMessage.OpenRequestMine: break; case UserDefineWindowsMessage.OpenKLineNode: break; case UserDefineWindowsMessage.DeleteFromCustomBoard: break; case UserDefineWindowsMessage.OpenAlarmCondition: break; case UserDefineWindowsMessage.OpenMouseEvent: break; case UserDefineWindowsMessage.OpenClickExportData: break; case UserDefineWindowsMessage.UNKNOWN_WARE_INFO: break; #endregion case UserDefineWindowsMessage.View_ZOOM_IN: IsPriceBoard = false; break; case UserDefineWindowsMessage.View_ZOOM_OUT: var currentLayout = UserManager.GetCurrentLayoutStyle(); if (currentLayout != LayoutStyle.PersonalCenter) { IsPriceBoard = true; } break; default: break; } } private bool _isPriceBoard = true; /// /// 是否显示报价牌 /// public bool IsPriceBoard { get { return _isPriceBoard; } set { Set(() => IsPriceBoard, ref _isPriceBoard, value); } } private bool isUpdate = false; #region "创建图表" /// /// 创建图表 /// /// 控件对象 internal void CreateChartView(QuoteGoods goods ) { int exchange = 0; int.TryParse(goods.ExchHqCode, out exchange); if (!isUpdate) { ////图表 参数2是分时图 //_financeChart.CreateChartView2(_controlHandle, goods.GoodsCode, (int)_chartCycleType, exchange); // 要使用的OutGoodsCode查历史数据(暂时大写处理) _financeChart.CreateChartView2(_controlHandle, goods.GoodsCode.ToUpper(), (int)_chartCycleType, exchange); isUpdate = true; RegisterMessage(); _financeChart.PostFrameMessage(_controlHandle, (int)UserDefineWindowsMessage.SetSacle, 60, 0); ////设置分时图刻度 } else { _financeChart.UpdateWareOfView2(_controlHandle, goods.GoodsCode, exchange); } if (CacheManager.TradeDayPlan.ContainsKey(goods.GoodsParameters.GoodsId)) { var tradedates = CacheManager.TradeDayPlan[goods.GoodsParameters.GoodsId]; _financeChart.PostFrameMessage2(_controlHandle, (int) UserDefineWindowsMessage.SetTradeDate, tradedates.TradeDay.ToString("yyyyMMdd"), string.Empty); ////设置交易日 } _financeChart.PostFrameMessage2(_controlHandle, (int)UserDefineWindowsMessage.SetPreclose, goods.LastCloseDisplay, string.Empty); ////设置交易日 var lastCalc = goods.TradeMode == eTradeMode.TRADEMODE_BIDDING ? MA_TIK_CALC_MODE.MA_TIK_CALC_MODE_TURNOVER_VOLUME : MA_TIK_CALC_MODE.MA_TIK_CALC_MODE_PRECLOSE; ////是否是有量商品 // var lastCalc = 2; ////因图表按卖一价来累K线,第一按无量商品计算均线, _financeChart.PostFrameMessage(_controlHandle, (int)UserDefineWindowsMessage.MeanType, (int)lastCalc, 0); ///设置均线计算方式 _financeChart.PostFrameMessage2(_controlHandle, (int)UserDefineWindowsMessage.TIKVOLUMEUNIT, goods.GoodsParameters.AgreeUnit+string.Empty, string.Empty); // FinanceChart.FilePath //FinanceChart.CreateChartView3(quoteChart.ViewHanlde, quoteChart.Goods.GoodsCode.ToString(), (int)quoteChart.CycleType, exchange, 0); // FinanceChart. //鼠标中轴滚动 //FinanceChart.PostFrameMessage(quoteChart.ViewHanlde, (int)FUN_SET_MOUSE_EVENT, WM_MOUSEWHEEL, 0); ////右键事件放开 //FinanceChart.PostFrameMessage(quoteChart.ViewHanlde, (int)FUN_SET_MOUSE_EVENT, WM_RBUTTONUP, 0); //InitDataBaseInfrom(quoteChart); } #endregion private void RegisterMessage() { MessengerHelper.QuoteUnregister>(this, MessengerTokens.ReceiveRealTikQuote); MessengerHelper.QuoteRegister>(this, MessengerTokens.ReceiveRealTikQuote, (quoteList) => { if (quoteList == null || !quoteList.Any()) return; foreach (var item in quoteList) { if (item == null) continue; QuoteTradePlan qp = CacheManager.TradeDayPlan[_currentGoods.GoodsId]; if (qp != null) { if (item.TradeDate != null) { if (!qp.TradeDay.ToString("yyyyMMdd").Equals(item.TradeDate)) // 如果交易日不一样,就重新设置一下交易日 { AddWare(_currentGoods); _financeChart.PostFrameMessage2(_controlHandle, (int)UserDefineWindowsMessage.SetTradeDate, item.TradeDate, string.Empty); ////设置交易日 } } } if (_currentGoods.Symbol.ToLower() == item.Symbol.ToLower() && item.CurrentPrice != 0) { //交易所代码 string exchangeCode = _currentGoods.ExchHqCode; //int divid = 1; //if (exchangeCode == Exchange.Sge) //{ // divid = goods.LotSize; // if (goods.PriceUnit == "千克") // { // divid = divid * 1000 ; // } //} //商品代码 string goodCode = _currentGoods.GoodsCode; //if (goods.HasVolume) //{ // if (goods.Volume <= 0) // return; //} double iVolume = item.CurrentVolume; // *divid; //商品买入价 double dbBid = (double)item.BidPrice; //商品卖价 double dbAsk = (double)item.AskPrice; //行情最高价 double dbHiPr = (double)item.High; //行情最高价 double dbLowPr = (double)item.Low; //现价 double dbPr = (double)item.CurrentPrice; //昨收 double dbPrLast = (double)_currentGoods.LastClose; //今开 double dbOpen = (double)item.Open; ////总额 //double dbTrd = (double)goods.TotalTurnover; //现量 //double dbVolume = (double)goods.Volume * divid; //现额 double dbNowSum = (double)item.TradeTurnover; //持仓量 double dbHolVolm = 0; // (double)item.Positions; --图表有成交量时,不支持持仓量 //买量 double dbBidVolume = (double)item.BidVolume; // *divid; //卖量 double dbAskVolume = (double)item.AskVolume; // *divid; //当前时间 string time = item.Date.ToString("yyyyMMddHHmmss"); _financeChart.UpdateTickPrice3(goodCode, dbBid, dbAsk, dbHiPr, dbLowPr, dbPr, dbPrLast, dbOpen, iVolume, dbHolVolm, dbBidVolume, dbAskVolume, time, int.Parse(exchangeCode), dbNowSum); } } }); MessengerHelper.DefaultRegister(this, MessengerTokens.RegisterResourceChange, (e) => { InitSetChartColorStyle(); // RegisterResourceChange(e); }); ////市场开市信号(清盘信号) MessengerHelper.DefaultRegister(this, MessengerTokens.Market_OpenToken, (e) => { MarketOpenChangeSettle(); }); } /// /// 注册消息 /// private void RegiterMsg() { MessengerHelper.DefaultRegister(this, MessengerTokens.ChartGoodsChange, ChangeGoodsNextFront); MessengerHelper.DefaultRegister(this, MessengerTokens.SelectGoodsOrderChange, SelectGoodsOrder); } private void MarketOpenChangeSettle() { CacheManager.TradeDayPlan.Clear(); if (_currentGoods != null) { ChartInitTradePlan(); } } /// /// /// /// protected override void QueryReckenSuccess(List tradeDays) { base.QueryReckenSuccess(tradeDays); AddWare(_currentGoods); ////添加商品 //tradeDays = tradeDays.OrderBy((item) => item.OpenWeekDay).ToList(); var goodsPlan = tradeDays.FirstOrDefault((item) => item.GoodsId == _currentGoods.GoodsId); if (goodsPlan == null) { goodsPlan = tradeDays.FirstOrDefault((item) => item.GoodsId == 0); } if (PriceViewModel != null) { PriceViewModel.TaskInitQuotePriceView(goodsPlan, _currentGoods); } } protected override void QueryTradeTimeSuccess(List quoteTimes) { base.QueryTradeTimeSuccess(quoteTimes); AddWare(_currentGoods); ////添加商品 //tradeDays = tradeDays.OrderBy((item) => item.OpenWeekDay).ToList(); var tradeDays = SetDefautTradePlan(); if (CacheManager.TradeDayPlan.ContainsKey(_currentGoods.GoodsParameters.GoodsId)) { tradeDays = CacheManager.TradeDayPlan[_currentGoods.GoodsParameters.GoodsId]; } if (PriceViewModel != null) { PriceViewModel.TaskInitQuotePriceView(tradeDays, _currentGoods); } } /// /// 查询结算时间失败 /// /// protected override void QueryReckenError(ErrorEntity errorEntity) { //todo:查询结算时间失败计算 var tradeDays = SetDefautTradePlan(); AddWare(_currentGoods); ////添加商品 if (PriceViewModel != null) { PriceViewModel.TaskInitQuotePriceView(tradeDays, _currentGoods); } LogHelper.WriteError(typeof(CChartViewModel), string.Format(ErrorManager.FormatErrorMsg(errorEntity))); } /// /// 查询结算时间失败使用默认时间(使用8-22) /// private QuoteTradePlan SetDefautTradePlan() { //查询结算时间失败使用默认时间(使用8-22) var goodsOpenCloses = new QuoteTradePlan(); goodsOpenCloses.ExchangeCode = this._currentGoods.ExchHqCode; var openClose = new OpenCloseDate() { CloseDate = ApplicationParameter.ServerTimeNow.Date.AddHours(22), OpenDate = ApplicationParameter.ServerTimeNow.Date.AddHours(8) }; goodsOpenCloses.OpenCloseDates = new List() { openClose }; return goodsOpenCloses; } private void QueryGoodsReckonPlan(QuoteGoods goods) { /*if (CacheManager.TradeDayPlan.ContainsKey(goods.GoodsParameters.GoodsId)) { AddWare(goods); ////添加商品 // SetChartControlCycle(_goodsOpenCloses); if (PriceViewModel != null) { PriceViewModel.TaskInitQuotePriceView(CacheManager.TradeDayPlan[goods.GoodsParameters.GoodsId], goods); } } else {*/ ChartInitTradePlan(); /*}*/ } public void Dispose() { if (_financeChart != null) { _financeChart.Destory(); } MessengerHelper.DefaultUnregister>(this, MessengerTokens.ReceiveRealTikQuote); MessengerHelper.DefaultUnregister(this, MessengerTokens.ChartGoodsChange); this.Cleanup(); } private QuotePriceViewModel _priceViewModel; /// /// 报价牌视图模型 /// public QuotePriceViewModel PriceViewModel { get { return _priceViewModel; } set { Set(() => PriceViewModel, ref _priceViewModel, value); } } private ICommand _enterCommand; public RelayCommand EnterCommand { get { return new RelayCommand((keyV) => { ////分时图与日线切换 if (_financeChart != null) { var pressKey = (Key)keyV; // Console.WriteLine("回车:" + _cycleType); //_chartCycleType = _chartCycleType == ChartCycleType.MinuteTik ? ChartCycleType.Day : ChartCycleType.MinuteTik; //_financeChart.PostFrameMessage(_controlHandle, (int)UserDefineWindowsMessage.ChangeViewCycle, (int)_chartCycleType, 0); switch (pressKey) { case Key.Enter: case Key.F5: _chartCycleType = _chartCycleType == ChartCycleType.MinuteTik ? ChartCycleType.Day : ChartCycleType.MinuteTik; _financeChart.PostFrameMessage(_controlHandle, (int)UserDefineWindowsMessage.ChangeViewCycle, (int)_chartCycleType, 0); break; case Key.PageDown: ChangeGoodsNextFront(true); break; case Key.PageUp: ChangeGoodsNextFront(false); break; } } }, SetIndecatorEnable); } } /// /// 指标是否可用 /// public bool IsIndecatorEnable { get { return ChartCycle != (int)ChartCycleType.MinuteTik; } } public bool SetIndecatorEnable(int paramter) { RaisePropertyChanged(() => IsIndecatorEnable); return true; } //public ICommand EnterCommand //{ // get // { // return new RelayCommand(() => // { // ////分时图与日线切换 // if (_financeChart != null) // { // // Console.WriteLine("回车:" + _cycleType); // _chartCycleType = _chartCycleType == ChartCycleType.MinuteTik ? ChartCycleType.Day : ChartCycleType.MinuteTik; // _financeChart.PostFrameMessage(_controlHandle, (int)UserDefineWindowsMessage.ChangeViewCycle, (int)_chartCycleType, 0); // } // }); // } //} //public ICommand PageDownCommand //{ // get // { // return new RelayCommand(() => // { // ChangeGoodsNextFront(true); // }); // } //} //public ICommand PageUpCommand //{ // get // { // return new RelayCommand(() => // { // ChangeGoodsNextFront(false); // }); // } //} } }