| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217 |
- 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<ICommonQueryService>();
- /*废弃,不需要这个逻辑了
- 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<IQuoteDataService>();
- _currentGoods = goods;
- CommandTypes = SimpleIoc.Default.GetInstance<ISystemService>().GetIndicator();
- QueryGoodsReckonPlan(goods);
- InitSetChartColorStyle();
- ChartCycle =(int) ChartCycleType.MinuteTik;
- SetIndecatorEnable(0);
- }
- catch (Exception ex)
- {
- LogHelper.WriteError(typeof(CChartViewModel), ex.ToString());
- }
- }
- /// <summary>
- /// 图表请求数据
- /// </summary>
- /// <param name="lExchangeCode">交易所代码</param>
- /// <param name="strWareCode">商品代码</param>
- /// <param name="strStartDate">开始时间</param>
- /// <param name="strEndDate">结束时间</param>
- /// <param name="lPriceNum">请求数量</param>
- /// <param name="lDataCycle">周期</param>
- 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);
- }
- /// <summary>
- /// 历史数据回应
- /// </summary>
- /// <param name="data"></param>
- 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<SysMenuItem> _commandTypes;
- /// <summary>
- /// 底部菜单列表
- /// </summary>
- public List<SysMenuItem> CommandTypes
- {
- get { return _commandTypes; }
- set { Set(() => CommandTypes, ref _commandTypes, value); }
- }
- private SysMenuItem _currentIndexMenu;
- /// <summary>
- /// 当前选择的指标
- /// </summary>
- public SysMenuItem CurrentIndexMenu
- {
- get { return _currentIndexMenu; }
- set
- {
- Set(() => CurrentIndexMenu, ref _currentIndexMenu, value);
- SetChartIndecator(value);
- }
- }
- /// <summary>
- /// 设置图表指标
- /// </summary>
- /// <param name="menuItem"></param>
- 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());
- }
- /// <summary>
- /// 设置图表的样式
- /// </summary>
- 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;
- }
- }
- /// <summary>
- /// 图表周期
- /// </summary>
- public int ChartCycle { get; set; }
- /// <summary>
- /// 格式化服务器时间
- /// </summary>
- /// <param name="clienttime">客户端时间</param>
- /// <returns></returns>
- 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 "转换商品类型"
- /// <summary>
- /// 商品类型转换
- /// </summary>
- /// <param name="goods"></param>
- /// <returns></returns>
- 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;
- }
- /// <summary>
- /// 转换开收市时间
- /// </summary>
- /// <param name="openCloseDates">开收市时间</param>
- /// <returns></returns>
- private string ConvertTradeHour(List<OpenCloseDate> openCloseDates)
- {
- if (openCloseDates == null || !openCloseDates.Any())
- {
- return string.Empty;
- }
- var dateList = new List<string>();
- foreach (var openCloseDate in openCloseDates)
- {
- dateList.Add(openCloseDate.OpenDate.ToString("HHmm"));
- dateList.Add(openCloseDate.CloseDate.ToString("HHmm"));
- }
- return string.Join(",", dateList);
- }
- #endregion
- /// <summary>
- /// 图表添加商品
- /// </summary>
- /// <param name="goods"></param>
- 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);
- }
- /// <summary>
- /// 更新商品
- /// </summary>
- /// <param name="goods"></param>
- 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);
- }
- /// <summary>
- /// 切换商品
- /// </summary>
- /// <param name="isNext"> true:切换下一个商品,false:切换上一个商品</param>
- public void ChangeGoodsNextFront(bool isNext)
- {
- var goodsList = new List<QuoteGoods>();
- 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<QuoteGoodsDTO>(dto, MessengerTokens.SelectGoodsChange);
- }
- }
- }
- /// <summary>
- /// 选中某个单据触发的图表显示问题
- /// </summary>
- /// <param name="quoteGoods"></param>
- public void SelectGoodsOrder(QuoteGoodsForSelectOrder quoteGoods)
- {
- if (quoteGoods != null && _currentGoods.GoodsId != quoteGoods.QuoteGoods.GoodsId)// 如果是相同的商品,就不要再做任何事情了
- {
- UpdateWare(quoteGoods.QuoteGoods);
- var dto = new QuoteGoodsDTO(quoteGoods.QuoteGoods);
- MessengerHelper.DefaultSend<QuoteGoodsDTO>(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;
- /// <summary>
- /// 是否显示报价牌
- /// </summary>
- public bool IsPriceBoard
- {
- get { return _isPriceBoard; }
- set { Set(() => IsPriceBoard, ref _isPriceBoard, value); }
- }
- private bool isUpdate = false;
- #region "创建图表"
- /// <summary>
- /// 创建图表
- /// </summary>
- /// <param name="quoteChart">控件对象</param>
- 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<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTikQuote);
- MessengerHelper.QuoteRegister<List<QuoteGoods>>(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<string>(this, MessengerTokens.RegisterResourceChange, (e) =>
- {
- InitSetChartColorStyle();
- // RegisterResourceChange(e);
- });
- ////市场开市信号(清盘信号)
- MessengerHelper.DefaultRegister<string>(this, MessengerTokens.Market_OpenToken, (e) =>
- {
- MarketOpenChangeSettle();
- });
- }
- /// <summary>
- /// 注册消息
- /// </summary>
- private void RegiterMsg()
- {
- MessengerHelper.DefaultRegister<bool>(this, MessengerTokens.ChartGoodsChange, ChangeGoodsNextFront);
- MessengerHelper.DefaultRegister<QuoteGoodsForSelectOrder>(this, MessengerTokens.SelectGoodsOrderChange, SelectGoodsOrder);
- }
- private void MarketOpenChangeSettle()
- {
- CacheManager.TradeDayPlan.Clear();
- if (_currentGoods != null)
- {
- ChartInitTradePlan();
- }
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="tradeDays"></param>
- protected override void QueryReckenSuccess(List<QuoteTradePlan> 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<QuoteTradeTime> 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);
- }
- }
- /// <summary>
- /// 查询结算时间失败
- /// </summary>
- /// <param name="errorEntity"></param>
- 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)));
- }
- /// <summary>
- /// 查询结算时间失败使用默认时间(使用8-22)
- /// </summary>
- 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<OpenCloseDate>() { 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<List<QuoteGoods>>(this, MessengerTokens.ReceiveRealTikQuote);
- MessengerHelper.DefaultUnregister<bool>(this, MessengerTokens.ChartGoodsChange);
- this.Cleanup();
- }
- private QuotePriceViewModel _priceViewModel;
- /// <summary>
- /// 报价牌视图模型
- /// </summary>
- public QuotePriceViewModel PriceViewModel
- {
- get { return _priceViewModel; }
- set { Set(() => PriceViewModel, ref _priceViewModel, value); }
- }
- private ICommand _enterCommand;
- public RelayCommand<int> EnterCommand
- {
- get
- {
- return new RelayCommand<int>((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);
- }
- }
- /// <summary>
- /// 指标是否可用
- /// </summary>
- 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);
- // });
- // }
- //}
-
- }
- }
|