/// <summary> /// 获取K线静态数值 /// </summary> /// <param name="div">K线层</param> private void SetCandleStaticValue(SandBoxCandleDiv div) { SecurityData data = div.Data; SpinA spinOpen = GetSpin("txtOpen"); SpinA spinClose = GetSpin("txtClose"); SpinA spinHigh = GetSpin("txtHigh"); SpinA spinLow = GetSpin("txtLow"); SpinA spinVolume = GetSpin("txtVolume"); SpinA spinAmount = GetSpin("txtAmount"); LabelA lblDate = GetLabel("lblDate"); data.m_open = (float)spinOpen.Value; data.m_close = (float)spinClose.Value; data.m_high = (float)spinHigh.Value; data.m_low = (float)spinLow.Value; data.m_volume = spinVolume.Value; data.m_amount = spinAmount.Value; String strDate = lblDate.Text; if (strDate != null && strDate.Length > 0) { data.m_date = m_chart.Chart.ConvertDateToNum(Convert.ToDateTime(strDate)); } div.Data = data; }
/// <summary> /// 控件添加方法 /// </summary> public override void OnAdd() { base.OnAdd(); if (m_layoutDiv == null) { m_layoutDiv = new LayoutDivA(); m_layoutDiv.BorderColor = COLOR.EMPTY; m_layoutDiv.LayoutStyle = LayoutStyleA.LeftToRight; m_layoutDiv.AutoWrap = true; AddControl(m_layoutDiv); } if (m_shrinkBtn == null) { m_shrinkBtn = new RibbonButton2(); m_shrinkBtn.Font = new FONT("微软雅黑", 12, false, false, false); m_clickButtonEvent = new ControlMouseEvent(ClickButton); m_shrinkBtn.RegisterEvent(m_clickButtonEvent, EVENTID.CLICK); AddControl(m_shrinkBtn); } if (m_titleLabel == null) { m_titleLabel = new LabelA(); m_titleLabel.Font = new FONT("微软雅黑", 16, true, false, false); AddControl(m_titleLabel); } }
/// <summary> /// 生成K线的下一个数据 /// </summary> /// <param name="addOrDelete">添加或删除</param> private void CreateNextData(bool addOrDelete) { ChartA chart = m_chart.Chart; CTable dataSource = chart.DataSource; LabelA lblDate = GetLabel("lblDate"); String strDate = lblDate.Text; if (strDate != null && strDate.Length > 0) { double date = 0; if (addOrDelete) { DateTime dateTime = Convert.ToDateTime(strDate); date = chart.ConvertDateToNum(dateTime); } else { int rowsCount = dataSource.RowsCount; if (rowsCount > 0) { date = dataSource.GetXValue(rowsCount - 1); } } date += m_chart.Cycle * 60; SetSpinValue(date); } }
/// <summary> /// 加载XML /// </summary> /// <param name="xmlPath">XML路径</param> public override void Load(String xmlPath) { LoadFile(xmlPath, null); DataCenter.MainUI = this; ControlA control = Native.GetControls()[0]; RegisterEvents(control); control.RegisterEvent(new ControlTimerEvent(CallTimerEvent), EVENTID.TIMER); control.StartTimer(m_timerID, 10); control.RegisterEvent(new ControlPaintEvent(PaintDiv), EVENTID.PAINT); m_barrageDiv = new BarrageDiv(); m_barrageDiv.Dock = DockStyleA.Fill; Native.AddControl(m_barrageDiv); m_sky = new Sky(); m_sky.Dock = DockStyleA.Fill; Native.AddControl(m_sky); m_sky.MainFrame = this; m_txtAnswer = FindControl("txtAnswer") as iTextBox; m_txtAnswer.MainFrame = this; m_txtQuestion = FindControl("txtQuestion") as iTextBox; m_lblAlarm = GetLabel("lblAlarm"); m_lblTime = GetLabel("lblTime"); m_btnStart = GetButton("btnStart"); m_lblType = GetLabel("lblType"); m_lblMode = GetLabel("lblMode"); (m_btnStart as RuningButton).MainFrame = this; }
/// <summary> /// 设置股票账户资金 /// </summary> /// <param name="tradeResult"></param> private void SetSecurityTradingAccount(String stockCaptialResult) { m_securityTradingAccount = null; if (stockCaptialResult == null || stockCaptialResult.Length == 0) { return; } SecurityTradingAccount stockTradingAccount = SecurityTradingAccount.ConvertToStockTradingAccount(stockCaptialResult); if (stockTradingAccount == null) { return; } m_securityTradingAccount = stockTradingAccount; LabelA lblCapitalBalance = m_mainFrame.GetLabel("lblCapitalBalance"); if (lblCapitalBalance != null) { lblCapitalBalance.Text = stockTradingAccount.m_capitalBalance.ToString(); } LabelA lblFrozenCash = m_mainFrame.GetLabel("lblFrozenCash"); if (lblFrozenCash != null) { lblFrozenCash.Text = stockTradingAccount.m_frozenCash.ToString(); } LabelA lblAvailable = m_mainFrame.GetLabel("lblAvailable"); if (lblAvailable != null) { lblAvailable.Text = stockTradingAccount.m_available.ToString(); } LabelA lblWithdrawQuota = m_mainFrame.GetLabel("lblWithdrawQuota"); if (lblWithdrawQuota != null) { lblWithdrawQuota.Text = stockTradingAccount.m_withdrawQuota.ToString(); } LabelA lblStockValue = m_mainFrame.GetLabel("lblStockValue"); if (lblStockValue != null) { lblStockValue.Text = stockTradingAccount.m_stockValue.ToString(); } LabelA lblTotalCapital = m_mainFrame.GetLabel("lblTotalCapital"); if (lblTotalCapital != null) { lblTotalCapital.Text = stockTradingAccount.m_totalCapital.ToString(); } DivA divCapital = m_mainFrame.GetDiv("divCapital"); divCapital.Invalidate(); }
/// <summary> /// 销毁资源 /// </summary> public override void Dispose() { m_titleLabel = null; if (m_shrinkBtn != null) { m_shrinkBtn.UnRegisterEvent(m_clickButtonEvent, EVENTID.CLICK); m_shrinkBtn = null; } m_layoutDiv = null; base.Dispose(); }
/// <summary> /// 获取参数 /// </summary> private void GetParameters() { if (m_indicator != null) { m_window.Text = "参数设置(" + m_indicator.Name + ")"; IndicatorData indicatorData = m_indicator.Tag as IndicatorData; String[] strs = indicatorData.m_parameters.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; //依此创建控件 int addHeight = 0; for (int i = 0; i < strsSize; i++) { String str = strs[i]; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); String name = strs2[0]; String value = strs2[3]; //创建标签 LabelA label = new LabelA(); POINT location = new POINT(50, addHeight + 40); label.Location = location; label.Text = name; m_window.AddControl(label); //创建数值控件 SpinA spin = new SpinA(); location.x = 130; location.y = addHeight + 40; spin.Location = location; spin.Maximum = 10000000; spin.Value = CStrA.ConvertStrToDouble(value); m_window.AddControl(spin); addHeight += 30; } m_window.Height += addHeight; //调整按钮的位置 ButtonA cancelButton = GetButton("btnCancel"); ButtonA submitButton = GetButton("btnSubmit"); cancelButton.Top += addHeight; submitButton.Top += addHeight; } }
/// <summary> /// 把指定日期K线的高开低收数据设置到画面的数值控件上 /// </summary> /// <param name="date">日期</param> private void SetSpinValue(double date) { ChartA chart = m_chart.Chart; CTable dataSource = chart.DataSource; int rowsCount = dataSource.RowsCount; if (rowsCount > 0) { int index = dataSource.GetRowIndex(date); if (index < 1) { index = rowsCount - 1; } SpinA spinOpen = GetSpin("txtOpen"); SpinA spinClose = GetSpin("txtClose"); SpinA spinHigh = GetSpin("txtHigh"); SpinA spinLow = GetSpin("txtLow"); SpinA spinVolume = GetSpin("txtVolume"); SpinA spinAmount = GetSpin("txtAmount"); LabelA lblDate = GetLabel("lblDate"); spinOpen.Value = dataSource.Get2(index, KeyFields.OPEN_INDEX); spinClose.Value = dataSource.Get2(index, KeyFields.CLOSE_INDEX); spinHigh.Value = dataSource.Get2(index, KeyFields.HIGH_INDEX); spinLow.Value = dataSource.Get2(index, KeyFields.LOW_INDEX); spinVolume.Value = dataSource.Get2(index, KeyFields.VOL_INDEX); spinAmount.Value = dataSource.Get2(index, KeyFields.AMOUNT_INDEX); DateTime dateTime = m_chart.Chart.ConvertNumToDate(date); int m_cycle = m_chart.Cycle; if (m_cycle <= 60) { lblDate.Text = dateTime.ToString("yyyy-MM-dd HH:mm:ss"); } else { lblDate.Text = dateTime.ToString("yyyy-MM-dd"); } m_window.Invalidate(); } }
public override int GetHashCode() { int hash = 1; if (IdA != 0) { hash ^= IdA.GetHashCode(); } if (LabelA.Length != 0) { hash ^= LabelA.GetHashCode(); } if (IdB != 0) { hash ^= IdB.GetHashCode(); } if (LabelB.Length != 0) { hash ^= LabelB.GetHashCode(); } hash ^= weight_.GetHashCode(); return(hash); }
/// <summary> /// 设置参数 /// </summary> private void SetParameters() { List <ControlA> controls = m_window.GetControls(); List <LabelA> labels = new List <LabelA>(); List <SpinA> spins = new List <SpinA>(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA control = controls[i]; LabelA label = control as LabelA; SpinA spin = control as SpinA; if (label != null) { labels.Add(label); } else if (spin != null) { spins.Add(spin); } } int labelsSize = labels.Count; String newParameters = ""; for (int i = 0; i < labelsSize; i++) { newParameters += labels[i].Text + ",0,0," + spins[i].Value.ToString(); newParameters += ";"; } labels.Clear(); spins.Clear(); m_indicator.Clear(); m_indicator.SetSourceField(KeyFields.CLOSE, KeyFields.CLOSE_INDEX); m_indicator.SetSourceField(KeyFields.HIGH, KeyFields.HIGH_INDEX); m_indicator.SetSourceField(KeyFields.LOW, KeyFields.LOW_INDEX); m_indicator.SetSourceField(KeyFields.OPEN, KeyFields.OPEN_INDEX); m_indicator.SetSourceField(KeyFields.VOL, KeyFields.VOL_INDEX); m_indicator.SetSourceField(KeyFields.AMOUNT, KeyFields.AMOUNT_INDEX); m_indicator.SetSourceField(KeyFields.CLOSE.Substring(0, 1), KeyFields.CLOSE_INDEX); m_indicator.SetSourceField(KeyFields.HIGH.Substring(0, 1), KeyFields.HIGH_INDEX); m_indicator.SetSourceField(KeyFields.LOW.Substring(0, 1), KeyFields.LOW_INDEX); m_indicator.SetSourceField(KeyFields.OPEN.Substring(0, 1), KeyFields.OPEN_INDEX); m_indicator.SetSourceField(KeyFields.VOL.Substring(0, 1), KeyFields.VOL_INDEX); m_indicator.SetSourceField(KeyFields.AMOUNT.Substring(0, 1), KeyFields.AMOUNT_INDEX); IndicatorData indicatorData = m_indicator.Tag as IndicatorData; indicatorData.m_parameters = newParameters; String constValue = ""; if (newParameters != null && newParameters.Length > 0) { String[] strs = newParameters.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String str = strs[i]; String[] strs2 = str.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); constValue += "const " + strs2[0] + ":" + strs2[3] + ";"; } } m_indicator.Script = constValue + indicatorData.m_script; m_indicator.OnCalculate(0); if (m_indicator.AttachVScale == AttachVScale.Left) { //m_indicator.Div.TitleBar.Text = m_indicator.Title; } m_chart.Chart.Update(); m_chart.Chart.Invalidate(); }