| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218 |
- 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.ToUpper();
- war.Type = "0";
- war.HqKind = "1";
- war.Rate = (double)1;
- war.SellPoint = (double)0;
- war.PriceDigit = 7;
- war.PriceType = "1";
- war.HqWare = goods.GoodsCode.ToUpper();
- 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);
- _financeChart.UpdateWareOfView2(_controlHandle, goods.GoodsCode.ToUpper(), 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.ToUpper() == item.Symbol.ToUpper() && 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.ToUpper();
- //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);
- // });
- // }
- //}
-
- }
- }
|