/// <summary> /// 获取模板信息 /// </summary> /// <param name="template">模板信息</param> public void GetTemplate(ref SecurityFilterTemplate template) { TextBoxA txtName = GetTextBox("txtName"); TextBoxA txtIndicator = GetTextBox("txtIndicator"); TextBoxA txtParameters = GetTextBox("txtParameters"); ComboBoxA cbCycle = GetComboBox("cbCycle"); ComboBoxA cbSubscription = GetComboBox("cbSubscription"); TextBoxA txtFilter = GetTextBox("txtFilter"); if (m_template.m_templateID != null && m_template.m_templateID.Length > 0) { template.m_templateID = m_template.m_templateID; } template.m_name = txtName.Text; template.m_indicator = txtIndicator.Text; template.m_parameters = txtParameters.Text; if (cbCycle.SelectedValue != null) { template.m_cycle = CStrA.ConvertStrToInt(cbCycle.SelectedValue); } else { template.m_cycle = 1440; } template.m_subscription = cbSubscription.SelectedIndex; template.m_filter = txtFilter.Text; template.m_codes = m_codes; template.m_userID = DataCenter.UserID; }
/// <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 = CStrA.ConvertDateToNum(dateTime); } else { int rowsCount = dataSource.RowsCount; if (rowsCount > 0) { date = dataSource.GetXValue(rowsCount - 1); } } date += m_chart.Cycle * 60; SetSpinValue(date); } }
/// <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 = CStrA.ConvertDateToNum(Convert.ToDateTime(strDate)); } div.Data = data; }
/// <summary> /// 更新服务器信息 /// </summary> /// <param name="serverInfo">服务器信息</param> /// <returns>状态</returns> public void UpdateServer(ServerInfo serverInfo) { String sql = String.Format("UPDATE SERVERS SET IP = '{0}', PORT = {1}, TYPE = '{2}' WHERE ID = '{3}'", CStrA.GetDBString(serverInfo.m_ip), serverInfo.m_port, CStrA.GetDBString(serverInfo.m_type), CStrA.GetDBString(serverInfo.m_id)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); }
/// <summary> /// 由字符串转化为对象 /// </summary> /// <param name="str">字符串</param> public void CodesFromString(String str) { m_codes.Clear(); String[] strs = str.Split(new String[] { ";" }, StringSplitOptions.RemoveEmptyEntries); int strsSize = strs.Length; for (int i = 0; i < strsSize; i++) { String[] subStrs = strs[i].Split(new String[] { ":" }, StringSplitOptions.RemoveEmptyEntries); m_codes[subStrs[0]] = CStrA.ConvertStrToInt(subStrs[1]); } }
/// <summary> /// 更新会话 /// </summary> /// <param name="cookie">会话</param> /// <returns>状态</returns> public int UpdateCookie(UserCookie cookie) { String sql = String.Format("UPDATE USERCOOKIE SET VALUE = '{0}' WHERE USERID = {1} AND KEY = '{2}'", CStrA.GetDBString(cookie.m_value), m_userID, CStrA.GetDBString(cookie.m_key)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 更新连接信息 /// </summary> /// <param name="connectInfo">连接信息</param> /// <returns>状态</returns> public int UpdateConnect(ConnectInfo connectInfo) { String sql = String.Format("UPDATE CONNECTS SET IP = '{0}', PORT = {1}, TYPE = '{2}' WHERE ID = '{3}'", CStrA.GetDBString(connectInfo.m_ip), connectInfo.m_port, CStrA.GetDBString(connectInfo.m_type), CStrA.GetDBString(connectInfo.m_id)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 更新代理信息 /// </summary> /// <param name="proxyInfo">代理信息</param> /// <returns>状态</returns> public int UpdateConnect(ProxyInfo proxyInfo) { String sql = String.Format("UPDATE PROXYINFOS SET IP = '{0}', PORT = {1}, NAME = '{2}', PASSWORD = '******', DOMAIN='{4}', USE = {5} WHERE TYPE = {6}", CStrA.GetDBString(proxyInfo.m_ip), proxyInfo.m_port, CStrA.GetDBString(proxyInfo.m_name), CStrA.GetDBString(proxyInfo.m_pwd), CStrA.GetDBString(proxyInfo.m_domain), proxyInfo.m_use ? 1 : 0, proxyInfo.m_type); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 添加服务器 /// </summary> /// <param name="serverInfo">服务器信息</param> /// <returns>状态</returns> public int AddServer(ServerInfo serverInfo) { String sql = String.Format("INSERT INTO SERVERS(ID, IP, PORT, TYPE) values ('{0}','{1}', {2}, '{3}')", CStrA.GetDBString(serverInfo.m_id), CStrA.GetDBString(serverInfo.m_ip), serverInfo.m_port, CStrA.GetDBString(serverInfo.m_type)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 添加代理信息 /// </summary> /// <param name="proxyInfo">代理信息</param> /// <returns>状态</returns> public int AddProxyInfo(ProxyInfo proxyInfo) { String sql = String.Format("INSERT INTO PROXYINFOS(TYPE, IP, PORT, NAME, PASSWORD, DOMAIN, USE) values ({0},'{1}',{2},'{3}','{4}','{5}',{6})", proxyInfo.m_type, CStrA.GetDBString(proxyInfo.m_ip), proxyInfo.m_port, CStrA.GetDBString(proxyInfo.m_name), CStrA.GetDBString(proxyInfo.m_pwd), CStrA.GetDBString(proxyInfo.m_domain), proxyInfo.m_use ? 1 : 0); SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 添加用户Cookie /// </summary> /// <param name="cookie">消息</param> /// <returns>状态</returns> public int AddCookie(UserCookie cookie) { UserCookie oldCookie = new UserCookie(); if (GetCookie(cookie.m_key, ref oldCookie) > 0) { UpdateCookie(cookie); } else { String sql = String.Format("INSERT INTO USERCOOKIE(USERID, KEY, VALUE, MODIFYTIME, CREATETIME) values ({0}, '{1}', '{2}','1970-1-1','1970-1-1')", m_userID, CStrA.GetDBString(cookie.m_key), CStrA.GetDBString(cookie.m_value)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); conn.Close(); } return(1); }
/// <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 = CStrA.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(); } }
/// <summary> /// 删除服务 /// </summary> /// <param name="id">编号</param> /// <returns>状态</returns> public int DeleteServer(String id) { String sql = String.Format("DELETE FROM SERVERS WHERE ID = '{0}'", CStrA.GetDBString(id)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); conn.Open(); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 重绘背景方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="clipRect">裁剪区域</param> public override void OnPaintBackground(CPaint paint, RECT clipRect) { int width = Width; int height = Height; if (width > 0 && height > 0) { ChartA chart = m_chart.Chart; //十字线出现时进行绘制 if (chart.ShowCrossLine) { CTable dataSource = chart.DataSource; //获取鼠标停留索引 int crossStopIndex = chart.CrossStopIndex; if (dataSource.RowsCount > 0) { if (crossStopIndex < 0) { crossStopIndex = chart.FirstVisibleIndex; } if (crossStopIndex > chart.LastVisibleIndex) { crossStopIndex = chart.LastVisibleIndex; } } else { crossStopIndex = -1; } //获取K线和成交量 RECT rectangle = new RECT(0, 0, width, height); long win32Color = COLOR.EMPTY; paint.FillRect(GetPaintingBackColor(), rectangle); paint.DrawRect(GetPaintingBorderColor(), 1, 0, rectangle); //画关闭按钮 long lineColor = CDraw.PCOLORS_LINECOLOR; paint.DrawLine(lineColor, 2, 0, width - 6, 4, width - 14, 12); paint.DrawLine(lineColor, 2, 0, width - 6, 12, width - 14, 4); //创建字体 FONT font = new FONT("SimSun", 14, false, false, false); FONT lfont = new FONT("Arial", 12, false, false, false); FONT nfont = new FONT("Arial", 14, true, false, false); //画日期 CDraw.DrawText(paint, "时 间", CDraw.PCOLORS_FORECOLOR, font, rectangle.left + 25, rectangle.top + 2); DateTime date = DateTime.Now; if (crossStopIndex >= 0) { double dateNum = dataSource.GetXValue(crossStopIndex); if (dateNum != 0) { date = CStrA.ConvertNumToDate(dateNum); } String dateStr = ""; int cycle = m_chart.Cycle; if (cycle <= 1) { dateStr = date.ToString("hh:mm"); } else if (cycle >= 5 && cycle <= 60) { dateStr = date.ToString("MM-dd hh:mm"); } else { dateStr = date.ToString("yyyy-MM-dd"); } SIZE dtSize = paint.TextSize(dateStr, lfont); CDraw.DrawText(paint, dateStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - dtSize.cx / 2, rectangle.top + 20); //获取值 double close = 0, high = 0, low = 0, open = 0, amount = 0; if (crossStopIndex >= 0) { close = dataSource.Get2(crossStopIndex, KeyFields.CLOSE_INDEX); high = dataSource.Get2(crossStopIndex, KeyFields.HIGH_INDEX); low = dataSource.Get2(crossStopIndex, KeyFields.LOW_INDEX); open = dataSource.Get2(crossStopIndex, KeyFields.OPEN_INDEX); amount = dataSource.Get2(crossStopIndex, KeyFields.AMOUNT_INDEX); } if (double.IsNaN(close)) { close = 0; } if (double.IsNaN(high)) { high = 0; } if (double.IsNaN(low)) { low = 0; } if (double.IsNaN(open)) { open = 0; } if (double.IsNaN(amount)) { amount = 0; } double rate = 1; double lastClose = 0; if (crossStopIndex > 1) { lastClose = dataSource.Get2(crossStopIndex - 1, KeyFields.CLOSE_INDEX); if (cycle == 0) { lastClose = m_chart.LatestData.m_lastClose; } if (!double.IsNaN(lastClose)) { if (lastClose != 0) { rate = (close - lastClose) / lastClose; } } } //开盘价 String openStr = double.IsNaN(open) ? "" : CStr.GetValueByDigit(open, m_digit).ToString(); SIZE tSize = paint.TextSize(openStr, nfont); CDraw.DrawText(paint, openStr, CDraw.GetPriceColor(open, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 60); //最高价 String highStr = double.IsNaN(high) ? "" : CStr.GetValueByDigit(high, m_digit).ToString(); tSize = paint.TextSize(highStr, nfont); CDraw.DrawText(paint, highStr, CDraw.GetPriceColor(high, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 100); //最低价 String lowStr = double.IsNaN(low) ? "" : CStr.GetValueByDigit(low, m_digit).ToString(); tSize = paint.TextSize(lowStr, nfont); CDraw.DrawText(paint, lowStr, CDraw.GetPriceColor(low, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 140); //最低价 String closeStr = double.IsNaN(close) ? "" : CStr.GetValueByDigit(close, m_digit).ToString(); tSize = paint.TextSize(closeStr, nfont); CDraw.DrawText(paint, closeStr, CDraw.GetPriceColor(close, lastClose), nfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 180); //成交量 String unit = ""; if (amount > 100000000) { amount /= 100000000; unit = "亿"; } else if (amount > 10000) { amount /= 10000; unit = "万"; } String amountStr = CStr.GetValueByDigit(amount, 2) + unit; tSize = paint.TextSize(amountStr, lfont); CDraw.DrawText(paint, amountStr, CDraw.PCOLORS_FORECOLOR3, lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 220); //涨幅 String rangeStr = double.IsNaN(rate) ? "0.00%" : rate.ToString("0.00%"); tSize = paint.TextSize(rangeStr, nfont); CDraw.DrawText(paint, rangeStr, CDraw.GetPriceColor(close, lastClose), lfont, rectangle.left + width / 2 - tSize.cx / 2, rectangle.top + 260); } long whiteColor = CDraw.PCOLORS_FORECOLOR; CDraw.DrawText(paint, "开 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 40); CDraw.DrawText(paint, "最 高", whiteColor, font, rectangle.left + 25, rectangle.top + 80); CDraw.DrawText(paint, "最 低", whiteColor, font, rectangle.left + 25, rectangle.top + 120); CDraw.DrawText(paint, "收 盘", whiteColor, font, rectangle.left + 25, rectangle.top + 160); CDraw.DrawText(paint, "金 额", whiteColor, font, rectangle.left + 25, rectangle.top + 200); CDraw.DrawText(paint, "涨 幅", whiteColor, font, rectangle.left + 25, rectangle.top + 240); } } }
/// <summary> /// 获取用户Cookie /// </summary> /// <param name="key">键</param> /// <param name="cookie">会话</param> /// <returns>状态</returns> public int GetCookie(String key, ref UserCookie cookie) { int state = 0; String sql = String.Format("SELECT * FROM USERCOOKIE WHERE USERID = {0} AND KEY = '{1}'", m_userID, CStrA.GetDBString(key)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); SQLiteDataReader reader = cmd.ExecuteReader(); while (reader.Read()) { cookie.m_userID = reader.GetInt32(0); cookie.m_key = reader.GetString(1); cookie.m_value = reader.GetString(2); state = 1; } reader.Close(); conn.Close(); return(state); }
/// <summary> /// 删除用户Cookie /// </summary> /// <param name="key">键</param> /// <returns>状态</returns> public int DeleteCookie(String key) { String sql = String.Format("DELETE FROM USERCOOKIE WHERE USERID = {0} AND KEY = '{1}'", m_userID, CStrA.GetDBString(key)); SQLiteConnection conn = new SQLiteConnection(m_connectStr); SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandText = sql; conn.Open(); cmd.ExecuteNonQuery(); conn.Close(); return(1); }
/// <summary> /// 调用控件线程方法 /// </summary> /// <param name="args">参数</param> public override void OnInvoke(object args) { base.OnInvoke(args); if (args != null) { CMessage message = (CMessage)args; if (message.m_requestID == m_requestID) { //分时数据 if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATA) { LatestDataInfo dataInfo = new LatestDataInfo(); List <SecurityLatestData> datas = new List <SecurityLatestData>(); QuoteService.GetLatestDatas(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestData latestData = datas[0]; if (latestData != null && latestData.m_securityCode == m_securityCode && !latestData.Equal(m_latestData)) { m_latestData = latestData; //设置保留小数的位数 int digit = 2; if (m_latestData.m_securityCode.StartsWith("1") || m_latestData.m_securityCode.StartsWith("5")) { digit = 3; } m_chart.Digit = digit; m_chart.RefreshData(); } } //LV2分时数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHLATESTDATALV2) { LatestDataInfoLV2 dataInfo = new LatestDataInfoLV2(); List <SecurityLatestDataLV2> datas = new List <SecurityLatestDataLV2>(); QuoteService.GetLatestDatasLV2(ref dataInfo, datas, message.m_body, message.m_bodyLength); SecurityLatestDataLV2 latestDataLV2 = datas[0]; if (latestDataLV2 != null && latestDataLV2.m_securityCode == m_securityCode && !latestDataLV2.Equal(m_latestDataLV2)) { m_latestDataLV2 = latestDataLV2; } } //成交数据 else if (message.m_functionID == QuoteService.FUNCTIONID_QUOTE_PUSHTRANSACTIONDATA) { String securityCode = ""; List <TransactionData> transactionDatas = new List <TransactionData>(); QuoteService.GetTransactionDatas(ref securityCode, transactionDatas, message.m_body, message.m_bodyLength); int transactionDatasSize = transactionDatas.Count; for (int i = 0; i < transactionDatasSize; i++) { TransactionData transactionData = transactionDatas[i]; DateTime date = CStrA.ConvertNumToDate(transactionData.m_date); GridRow row = new GridRow(); m_gridTransaction.InsertRow(0, row); TransactionDateCell dateCell = new TransactionDateCell(); dateCell.Text = date.ToString("HH:mm:ss"); row.AddCell(0, dateCell); GridCellStyle dateCellStyle = new GridCellStyle(); dateCellStyle.BackColor = COLOR.EMPTY; dateCellStyle.Font = new FONT("SimSun", 14, true, false, false); dateCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR2; dateCell.Style = dateCellStyle; TransactionDataDoubleCell priceCell = new TransactionDataDoubleCell(); priceCell.Digit = 2; priceCell.SetDouble(transactionData.m_price); row.AddCell(1, priceCell); GridCellStyle priceCellStyle = new GridCellStyle(); priceCellStyle.BackColor = COLOR.EMPTY; priceCellStyle.Font = new FONT("SimSun", 14, true, false, false); priceCellStyle.ForeColor = CDraw.GetPriceColor(transactionData.m_price, m_latestData.m_lastClose); priceCell.Style = priceCellStyle; TransactionDataDoubleCell volumeCell = new TransactionDataDoubleCell(); volumeCell.SetDouble(transactionData.m_volume); row.AddCell(2, volumeCell); GridCellStyle volumeCellStyle = new GridCellStyle(); volumeCellStyle.BackColor = COLOR.EMPTY; volumeCellStyle.Font = new FONT("SimSun", 14, true, false, false); if (transactionData.m_type == 0) { volumeCellStyle.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (transactionData.m_type == 1) { volumeCellStyle.ForeColor = CDraw.PCOLORS_UPCOLOR; } else { volumeCellStyle.ForeColor = CDraw.PCOLORS_DOWNCOLOR; } volumeCell.Style = volumeCellStyle; } m_gridTransaction.Update(); } } Invalidate(); } }