/// <summary> /// 注册事件 /// </summary> /// <param name="control">控件</param> private void RegisterEvents(ControlA control) { ControlMouseEvent clickButtonEvent = new ControlMouseEvent(ClickButton); List <ControlA> controls = control.GetControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA subControl = controls[i]; ButtonA button = subControl as ButtonA; GridA grid = subControl as GridA; if (button != null) { button.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } else if (grid != null) { GridRowStyle rowStyle = new GridRowStyle(); grid.RowStyle = rowStyle; rowStyle.BackColor = COLOR.EMPTY; rowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; rowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; } RegisterEvents(controls[i]); } }
/// <summary> /// 销毁方法 /// </summary> public override void Dispose() { if (!IsDisposed) { m_chart = null; if (m_gridIcons != null) { m_gridIcons.UnRegisterEvent(m_gridCellClickEvent, EVENTID.GRIDCELLCLICK); m_gridCellClickEvent = null; m_gridIcons = null; } if (m_gridMacros != null) { m_gridMacros.UnRegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); m_gridSelectedRowsChangedEvent = null; m_gridMacros = null; } if (m_macroService != null) { m_macroService.UnRegisterListener(m_macroService.OperatorRequestID, m_macroDataCallBack); m_macroDataCallBack = null; m_macroService = null; } if (m_window != null) { m_window.UnRegisterEvent(m_invokeEvent, EVENTID.INVOKE); m_invokeEvent = null; m_window.Close(); m_window.Dispose(); m_window = null; } base.Dispose(); } }
/// <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]; control.BackColor = COLOR.CONTROL; RegisterEvents(control); m_jiras.Clear(); //从服务端拿取数据 m_jiras = XmlHandle.GetJiras(); this.m_gridDgvTable = GetGrid("dgvTable"); //注册事件,这样可以在一个自定义方法里监听 m_gridDgvTable.RegisterEvent(new ControlTimerEvent(TimerEvent), EVENTID.TIMER); m_timerID = ControlA.GetNewTimerID(); m_gridDgvTable.StartTimer(m_timerID, 1000); int size = m_jiras.Count; for (int i = 0; i < size; i++) { Jira jira = m_jiras[i]; AddOrUpdate(jira);//添加一行 } //刷新界面 m_gridDgvTable.Invalidate(); }
/// <summary> /// 销毁方法 /// </summary> public override void Dispose() { if (!IsDisposed) { m_chart = null; if (m_gridLayouts != null) { m_gridLayouts.UnRegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); m_gridSelectedRowsChangedEvent = null; m_gridLayouts = null; } if (m_indicatorLayoutService != null) { m_indicatorLayoutService.UnRegisterListener(m_indicatorLayoutService.OperatorRequestID, m_indicatorLayoutDataCallBack); m_indicatorLayoutDataCallBack = null; m_indicatorLayoutService = null; } if (m_window != null) { m_window.UnRegisterEvent(m_invokeEvent, EVENTID.INVOKE); m_invokeEvent = null; m_window.Close(); m_window.Dispose(); m_window = null; } base.Dispose(); } }
/// <summary> /// 获取表格 /// </summary> /// <param name="message"></param> /// <returns></returns> public int Excute(CMessage message) { GridA grid = GetGrid(message.m_body, m_native); Send(message, grid); return(1); }
public OrderTrade(MainFrame mainFrame) { m_mainFrame = mainFrame; // 委托表格 m_gridCommissionAccount = m_mainFrame.GetGrid("gridOrderAccount"); // 持仓表格 m_gridPositionAccount = m_mainFrame.GetGrid("gridPositionAccount"); // 成交表格 m_gridTradeAccount = m_mainFrame.GetGrid("gridTradeAccount"); List <GridA> grids = new List <GridA>(); grids.Add(m_gridCommissionAccount); grids.Add(m_gridPositionAccount); grids.Add(m_gridTradeAccount); int gridsSize = grids.Count; for (int i = 0; i < gridsSize; i++) { GridA grid = grids[i]; grid.GridLineColor = COLOR.CONTROLBORDER; grid.RowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; grid.RowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; grid.RowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; grid.RowStyle.Font = new FONT("微软雅黑", 12, false, false, false); GridRowStyle alternateRowStyle = new GridRowStyle(); alternateRowStyle.BackColor = CDraw.PCOLORS_ALTERNATEROWCOLOR; alternateRowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; alternateRowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; alternateRowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; alternateRowStyle.Font = new FONT("微软雅黑", 12, false, false, false); grid.AlternateRowStyle = alternateRowStyle; } }
/// <summary> /// 发送消息 /// </summary> /// <param name="functionID">方法ID</param> /// <param name="requestID">请求ID</param> /// <param name="grid">事件集合</param> /// <returns>状态</returns> public int Send(int functionID, int requestID, GridA grid) { byte[] bytes = GetBytes(grid); int ret = Send(new CMessage(GroupID, ServiceID, functionID, SessionID, requestID, m_socketID, 0, CompressType, bytes.Length, bytes)); return(ret); }
/// <summary> /// 绑定新股名称表格 /// </summary> private void BindNewStockCalendar() { GridA gridNewStockCalendar = m_mainFrame.GetGrid("gridNewStockCalendar"); gridNewStockCalendar.GridLineColor = COLOR.EMPTY; gridNewStockCalendar.BackColor = COLOR.ARGB(0, 0, 0); gridNewStockCalendar.RowStyle = new GridRowStyle(); gridNewStockCalendar.RowStyle.BackColor = COLOR.ARGB(0, 0, 0); DataSet ds = NewStockDataHelper.GetNewStockCalendar(0); StringBuilder sb = new StringBuilder(); foreach (DataRow dr in ds.Tables[0].Rows) { GridRow row = new GridRow(); gridNewStockCalendar.AddRow(row); row.AddCell("colN1", new GridStringCell(dr[1].ToString())); row.AddCell("colN2", new GridStringCell(dr[2].ToString())); row.AddCell("colN3", new GridStringCell(dr[3].ToString())); row.AddCell("colN4", new GridStringCell(dr[4].ToString())); row.GetCell("colN1").Style = new GridCellStyle(); row.GetCell("colN1").Style.ForeColor = COLOR.ARGB(255, 80, 80); row.GetCell("colN2").Style = new GridCellStyle(); row.GetCell("colN2").Style.ForeColor = COLOR.ARGB(80, 255, 255); row.GetCell("colN3").Style = new GridCellStyle(); row.GetCell("colN3").Style.ForeColor = COLOR.ARGB(255, 80, 255); row.GetCell("colN4").Style = new GridCellStyle(); row.GetCell("colN4").Style.ForeColor = COLOR.ARGB(255, 255, 80); if (dr[3].ToString().IndexOf("网上申购日") != -1) { m_newStockList.Add(Convert.ToDateTime(dr[4]).ToString("yyyy-MM-dd") + " " + dr[2].ToString() + " " + dr[1].ToString() + "\r\n"); } } }
/// <summary> /// 销毁方法 /// </summary> public override void Dispose() { if (!IsDisposed) { m_chart = null; if (m_gridTemplate != null) { m_gridTemplate.UnRegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); m_gridSelectedRowsChangedEvent = null; m_gridTemplate = null; } if (m_securityFilterService != null) { m_securityFilterService.UnRegisterListener(m_securityFilterService.OperatorRequestID, m_securityFilterDataCallBackEvent); m_securityFilterDataCallBackEvent = null; m_securityFilterService = null; } if (m_window != null) { m_window.UnRegisterEvent(m_invokeEvent, EVENTID.INVOKE); m_invokeEvent = null; m_window.StopTimer(m_timerID); m_window.UnRegisterEvent(m_timerEvent, EVENTID.TIMER); m_timerEvent = null; m_window.Close(); m_window.Dispose(); m_window = null; } base.Dispose(); } }
/// <summary> /// 控件添加方法 /// </summary> public override void OnAdd() { base.OnAdd(); if (m_gridTransaction == null) { m_latestData = new SecurityLatestData(); m_latestDataLV2 = new SecurityLatestDataLV2(); m_gridTransaction = new GridA(); m_gridTransaction.BackColor = COLOR.EMPTY; m_gridTransaction.BorderColor = COLOR.EMPTY; m_gridTransaction.GridLineColor = COLOR.EMPTY; m_gridTransaction.HeaderVisible = false; m_gridTransaction.SelectionMode = GridSelectionMode.SelectNone; AddControl(m_gridTransaction); GridColumn dateColumn = new GridColumn(); dateColumn.Width = 80; m_gridTransaction.AddColumn(dateColumn); GridColumn priceColumn = new GridColumn(); priceColumn.Width = 70; m_gridTransaction.AddColumn(priceColumn); GridColumn volumeColumn = new GridColumn(); volumeColumn.Width = 100; m_gridTransaction.AddColumn(volumeColumn); m_gridTransaction.Update(); } }
/// <summary> /// 销毁方法 /// </summary> public void Dispose() { if (!m_isDisposed) { m_chart = null; if (m_gridFilterResult != null) { m_gridFilterResult.UnRegisterEvent(m_gridCellClick, EVENTID.GRIDCELLCLICK); m_gridCellClick = null; m_gridFilterResult = null; } if (m_window != null) { m_window.StopTimer(m_timerID); m_window.UnRegisterEvent(m_timerEvent, EVENTID.TIMER); m_timerEvent = null; m_window.Close(); m_window.Dispose(); m_window = null; } if (m_xml != null) { m_xml.Dispose(); m_xml = null; } m_isDisposed = true; } }
/// <summary> /// 导出到Txt /// </summary> /// <param name="fileName">文件名</param> /// <param name="grid">表格控件</param> public static void ExportToTxt(String fileName, GridA grid) { StringBuilder sb = new StringBuilder(); List <GridColumn> columns = grid.m_columns; int columnsSize = columns.Count; List <GridColumn> visibleColumns = new List <GridColumn>(); for (int i = 0; i < columnsSize; i++) { if (columns[i].Visible) { visibleColumns.Add(columns[i]); } } columnsSize = visibleColumns.Count; for (int i = 0; i < columnsSize; i++) { sb.Append(visibleColumns[i].Text); if (i != columnsSize - 1) { sb.Append(","); } } List <GridRow> rows = grid.m_rows; int rowsSize = rows.Count; List <GridRow> visibleRows = new List <GridRow>(); for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { visibleRows.Add(rows[i]); } } int visibleRowsSize = visibleRows.Count; if (visibleRowsSize > 0) { sb.Append("\r\n"); for (int i = 0; i < visibleRowsSize; i++) { for (int j = 0; j < columnsSize; j++) { GridCell cell = visibleRows[i].GetCell(visibleColumns[j].Index); String cellValue = cell.GetString(); sb.Append(cellValue); if (j != columnsSize - 1) { sb.Append(","); } } if (i != visibleRowsSize - 1) { sb.Append("\r\n"); } } } DataCenter.ExportService.ExportHtmlToTxt(fileName, sb.ToString()); }
/// <summary> /// 加载XML /// </summary> /// <param name="xmlPath">XML路径</param> public override void Load(String xmlPath) { LoadFile(xmlPath, null); m_gridPlan = GetGrid("gridPlan"); RegisterEvents(Native.GetControls()[0]); //CalendarWindow calendarWindow = new CalendarWindow(Native); //calendarWindow.ShowDialog(); }
/// <summary> /// 发送消息 /// </summary> /// <param name="message">消息</param> /// <param name="grid">集合</param> public int Send(CMessage message, GridA grid) { byte[] bytes = GetBytes(grid); message.m_bodyLength = bytes.Length; message.m_body = bytes; int ret = Send(message); return(ret); }
/// <summary> /// 获取表格数据 /// </summary> /// <param name="grid">表格</param> /// <returns>流</returns> public byte[] GetBytes(GridA grid) { Binary br = new Binary(); br.WriteString(grid.Name); List <GridColumn> columns = grid.GetColumns(); int columnsSize = columns.Count; br.WriteInt(columnsSize); for (int i = 0; i < columnsSize; i++) { GridColumn column = columns[i]; br.WriteString(column.Name); br.WriteString(column.ColumnType); } List <GridRow> rows = grid.GetRows(); int rowsCount = rows.Count; br.WriteInt(rowsCount); for (int i = 0; i < rowsCount; i++) { GridRow row = rows[i]; for (int j = 0; j < columnsSize; j++) { GridColumn column = columns[j]; String columnType = column.ColumnType.ToLower(); GridCell cell = row.GetCell(j); if (columnType == "bool") { br.WriteBool(cell.GetBool()); } else if (columnType == "double") { br.WriteDouble(cell.GetDouble()); } else if (columnType == "float") { br.WriteFloat(cell.GetFloat()); } else if (columnType == "int") { br.WriteInt(cell.GetInt()); } else if (columnType == "long") { br.WriteDouble(cell.GetLong()); } else if (columnType == "string") { br.WriteString(cell.GetString()); } } } byte[] bytes = br.GetBytes(); br.Close(); return(bytes); }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">矩形</param> /// <param name="clipRect">裁剪矩形</param> /// <param name="isAlternate">是否交替行</param> public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate) { int clipW = clipRect.right - clipRect.left; int clipH = clipRect.bottom - clipRect.top; if (clipW > 0 && clipH > 0) { GridA grid = Grid; GridRow row = Row; GridColumn column = Column; if (grid != null && row != null && column != null) { //判断选中 String text = Text; bool selected = false; List <GridRow> selectedRows = grid.SelectedRows; int selectedRowsSize = selectedRows.Count; for (int i = 0; i < selectedRowsSize; i++) { if (selectedRows[i] == row) { selected = true; break; } } //获取颜色 FONT font = null; long foreColor = COLOR.EMPTY; GridCellStyle style = Style; if (style != null) { if (style.Font != null) { font = style.Font; } foreColor = style.ForeColor; } SecurityFilterInfo info = (row as SecurityFilterResultRow).Info; if (info.GetValue("FILTER") != 1) { foreColor = CDraw.PCOLORS_FORECOLOR8; } SIZE tSize = paint.TextSize(text, font); POINT tPoint = new POINT(rect.left + 1, rect.top + clipH / 2 - tSize.cy / 2); if (column.Name == "colCode") { tPoint.x = rect.right - tSize.cx; } RECT tRect = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy); paint.DrawText(text, foreColor, font, tRect); if (selected) { paint.DrawLine(CDraw.PCOLORS_LINECOLOR, 2, 0, rect.left, rect.bottom - 1, rect.right, rect.bottom - 1); } } } }
public static extern bool SetForegroundWindow(IntPtr hWnd);//设置此窗体为活动窗体 /// <summary> /// 加载XML /// </summary> /// <param name="xmlPath">XML路径</param> public override void Load(String xmlPath) { LoadFile(xmlPath, null); DataCenter.MainUI = this; m_mainDiv = Native.GetControls()[0] as DivA; m_mainDiv.BackColor = COLOR.CONTROL; ControlPaintEvent paintLayoutEvent = new ControlPaintEvent(PaintLayoutDiv); m_mainDiv.RegisterEvent(paintLayoutEvent, EVENTID.PAINT); m_mainDiv.RegisterEvent(new ControlInvokeEvent(Invoke), EVENTID.INVOKE); DataCenter.ServerChatService.RegisterListener(DataCenter.ChatRequestID, new ListenerMessageCallBack(ChatMessageCallBack)); m_gridHosts = GetGrid("gridHosts"); m_gridHosts.GridLineColor = COLOR.CONTROLBORDER; GridRowStyle rowStyle = new GridRowStyle(); rowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; rowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; rowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; rowStyle.Font = new FONT("微软雅黑", 12, false, false, false); m_gridHosts.RowStyle = rowStyle; GridRowStyle alternateRowStyle = new GridRowStyle(); alternateRowStyle.BackColor = CDraw.PCOLORS_ALTERNATEROWCOLOR; alternateRowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; alternateRowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; alternateRowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; alternateRowStyle.Font = new FONT("微软雅黑", 12, false, false, false); m_gridHosts.AlternateRowStyle = alternateRowStyle; m_gridGroups = GetGrid("gridGroups"); m_gridGroups.RowStyle = rowStyle; m_gridGroups.AlternateRowStyle = alternateRowStyle; m_gridGroups.RegisterEvent(new GridCellMouseEvent(GridCellClick), EVENTID.GRIDCELLCLICK); RegisterEvents(m_mainDiv); //全节点服务器 if (DataCenter.IsFull) { DataCenter.UserID = DataCenter.HostInfo.m_localHost + ":" + CStr.ConvertIntToStr(DataCenter.HostInfo.m_localPort); DataCenter.UserName = DataCenter.UserID; Thread thread = new Thread(new ThreadStart(StartConnect)); thread.Start(); } else { UserCookie cookie = new UserCookie(); if (DataCenter.UserCookieService.GetCookie("USERINFO2", ref cookie) > 0) { String[] strs = cookie.m_value.Split(new String[] { "," }, StringSplitOptions.RemoveEmptyEntries); GetTextBox("txtPhone").Text = strs[0]; GetTextBox("txtUserName").Text = strs[1]; GetTextBox("txtPort").Text = strs[2]; } } m_chatGroups = ChatGroup.ReadGroups(); BindGroups(); }
/// 注册事件 /// </summary> /// <param name="control">控件</param> private void RegisterEvents(ControlA control) { ControlMouseEvent clickButtonEvent = new ControlMouseEvent(ClickEvent); List <ControlA> controls = control.GetControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA subControl = controls[i]; ButtonA button = subControl as ButtonA; GridColumn column = subControl as GridColumn; GridA grid = subControl as GridA; CheckBoxA checkBox = subControl as CheckBoxA; if (column != null) { column.AllowResize = true; column.BackColor = CDraw.PCOLORS_BACKCOLOR; column.BorderColor = CDraw.PCOLORS_LINECOLOR2; column.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (checkBox != null) { checkBox.ButtonBackColor = CDraw.PCOLORS_BACKCOLOR; } else if (button != null) { button.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } else if (grid != null) { grid.BackColor = COLOR.EMPTY; grid.GridLineColor = CDraw.PCOLORS_LINECOLOR2; GridRowStyle rowStyle = new GridRowStyle(); grid.RowStyle = rowStyle; rowStyle.BackColor = COLOR.EMPTY; rowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; rowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; grid.HorizontalOffset = grid.Width; grid.UseAnimation = true; } else { if (subControl.GetControlType() == "Div" || subControl.GetControlType() == "TabControl" || subControl.GetControlType() == "TabPage" || subControl.GetControlType() == "SplitLayoutDiv") { subControl.BackColor = COLOR.EMPTY; } } RegisterEvents(controls[i]); } }
/// <summary> /// 销毁方法 /// </summary> public override void Dispose() { if (!IsDisposed) { if (m_gridServers != null) { m_gridServers.UnRegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); m_gridSelectedRowsChangedEvent = null; m_gridServers = null; } base.Dispose(); } }
/// <summary> /// 销毁方法 /// </summary> public override void Dispose() { if (!IsDisposed) { if (m_gridCategory != null) { m_gridCategory.UnRegisterEvent(m_gridSelectedRowsChangedEvent, EVENTID.GRIDSELECTEDROWSCHANGED); m_gridSelectedRowsChangedEvent = null; m_gridCategory.UnRegisterEvent(m_gridCellEditEndEvent, EVENTID.GRIDCELLEDITEND); m_gridCellEditEndEvent = null; m_gridCategory = null; } if (m_gridSecurities != null) { m_gridSecurities.UnRegisterEvent(m_gridCellClick, EVENTID.GRIDCELLCLICK); m_gridCellClick = null; m_gridSecurities = null; } if (m_quoteService != null) { m_quoteService.UnRegisterListener(m_latestDataRequestID, m_latestDataCallBack); m_latestDataCallBack = null; m_quoteService = null; } m_latestDatas.Clear(); if (m_txtSearch != null) { m_txtSearch.UnRegisterEvent(m_searchTextBoxGotFocus, EVENTID.GOTFOCUS); m_searchTextBoxGotFocus = null; m_txtSearch = null; } if (m_userSecurityService != null) { m_userSecurityService.UnRegisterListener(m_userSecurityService.OperatorRequestID, m_userSecurityDataCallBack); m_userSecurityDataCallBack = null; m_userSecurityService = null; } if (m_window != null) { m_window.UnRegisterEvent(m_invokeEvent, EVENTID.INVOKE); m_invokeEvent = null; m_window.UnRegisterEvent(m_timerEvent, EVENTID.TIMER); m_timerEvent = null; m_window.Close(); m_window.Dispose(); m_window = null; } base.Dispose(); } }
/// 注册事件 /// </summary> /// <param name="control">控件</param> private void RegisterEvents(ControlA control) { ControlMouseEvent clickButtonEvent = new ControlMouseEvent(ClickButton); List <ControlA> controls = control.GetControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA subControl = controls[i]; ButtonA button = controls[i] as ButtonA; LinkLabelA linkLabel = subControl as LinkLabelA; GridColumn column = subControl as GridColumn; GridA grid = subControl as GridA; CheckBoxA checkBox = subControl as CheckBoxA; if (column != null) { column.AllowDrag = true; column.AllowResize = true; column.BackColor = CDraw.PCOLORS_BACKCOLOR; column.Font = new FONT("微软雅黑", 12, false, false, false); column.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (button != null) { button.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } else if (linkLabel != null) { linkLabel.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } else if (grid != null) { grid.GridLineColor = COLOR.CONTROLBORDER; grid.RowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; grid.RowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; grid.RowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; grid.RowStyle.Font = new FONT("微软雅黑", 12, false, false, false); GridRowStyle alternateRowStyle = new GridRowStyle(); alternateRowStyle.BackColor = CDraw.PCOLORS_ALTERNATEROWCOLOR; alternateRowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; alternateRowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; alternateRowStyle.SelectedForeColor = CDraw.PCOLORS_FORECOLOR4; alternateRowStyle.Font = new FONT("微软雅黑", 12, false, false, false); grid.AlternateRowStyle = alternateRowStyle; grid.UseAnimation = true; } RegisterEvents(controls[i]); } }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">区域</param> /// <param name="clipRect">裁剪区域</param> /// <param name="isAlternate">是否交替</param> public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate) { GridA grid = Grid; GridRow row = Row; float opacity = grid.Opacity; float oldOpacity = opacity; if (grid.HoveredRow == row) { POINT mp = grid.MousePoint; if (mp.x >= clipRect.left && mp.x <= clipRect.right && mp.y >= clipRect.top && mp.y <= clipRect.bottom) { if (m_id != null && m_id.Length > 0) { opacity = 1; } } } else if (m_keyPress) { opacity = 1; } if (m_id != null && m_id.Length > 0) { grid.Opacity = opacity; paint.SetOpacity(opacity); } String image = GetString(); if (image != null && image.Length > 0) { paint.DrawImage(GetString(), rect); } else { paint.DrawRect(CDraw.PCOLORS_LINECOLOR, 1, 0, rect); } if (m_id != null && m_id.Length > 0) { grid.Opacity = oldOpacity; paint.SetOpacity(oldOpacity); } }
/// <summary> /// 添加控件方法 /// </summary> public override void OnLoad() { base.OnLoad(); if (m_grid == null) { m_grid = new GridA(); m_grid.AutoEllipsis = true; m_grid.GridLineColor = COLOR.EMPTY; m_grid.Size = new SIZE(240, 200); m_grid.RegisterEvent(m_gridCellClickEvent, EVENTID.GRIDCELLCLICK); m_grid.RegisterEvent(m_gridKeyDownEvent, EVENTID.KEYDOWN); AddControl(m_grid); m_grid.BeginUpdate(); //添加列 GridColumn securityCodeColumn = new GridColumn("股票代码"); securityCodeColumn.BackColor = CDraw.PCOLORS_BACKCOLOR; securityCodeColumn.BorderColor = COLOR.EMPTY; securityCodeColumn.Font = new FONT("Simsun", 14, true, false, false); securityCodeColumn.ForeColor = CDraw.PCOLORS_FORECOLOR; securityCodeColumn.TextAlign = ContentAlignmentA.MiddleLeft; securityCodeColumn.Width = 120; m_grid.AddColumn(securityCodeColumn); GridColumn securityNameColumn = new GridColumn("股票名称"); securityNameColumn.BackColor = CDraw.PCOLORS_BACKCOLOR; securityNameColumn.BorderColor = COLOR.EMPTY; securityNameColumn.Font = new FONT("Simsun", 14, true, false, false); securityNameColumn.ForeColor = CDraw.PCOLORS_FORECOLOR; securityNameColumn.TextAlign = ContentAlignmentA.MiddleLeft; securityNameColumn.Width = 110; m_grid.AddColumn(securityNameColumn); m_grid.EndUpdate(); } if (m_searchTextBox == null) { m_searchTextBox = new TextBoxA(); m_searchTextBox.Location = new POINT(0, 200); m_searchTextBox.Size = new SIZE(240, 20); m_searchTextBox.Font = new FONT("SimSun", 16, true, false, false); m_searchTextBox.RegisterEvent(m_textBoxInputChangedEvent, EVENTID.TEXTCHANGED); m_searchTextBox.RegisterEvent(m_textBoxKeyDownEvent, EVENTID.KEYDOWN); AddControl(m_searchTextBox); } }
/// <summary> /// 导出到Excel /// </summary> /// <param name="path">路径</param> public static void ExportToExcel(String fileName, GridA grid) { DataTable dataTable = new DataTable(); List <GridColumn> visibleColumns = new List <GridColumn>(); List <GridColumn> columns = grid.m_columns; int columnsSize = columns.Count; for (int i = 0; i < columnsSize; i++) { if (columns[i].Visible) { dataTable.Columns.Add(new DataColumn(columns[i].Text)); visibleColumns.Add(columns[i]); } } columnsSize = visibleColumns.Count; List <GridRow> rows = grid.m_rows; int rowsSize = rows.Count; for (int i = 0; i < rowsSize; i++) { if (rows[i].Visible) { DataRow dr = dataTable.NewRow(); for (int j = 0; j < columnsSize; j++) { GridCell cell = grid.m_rows[i].GetCell(visibleColumns[j].Index); if (cell is GridStringCell) { dr[j] = cell.GetString(); } else { dr[j] = cell.GetDouble(); } } dataTable.Rows.Add(dr); } } DataCenter.ExportService.ExportDataTableToExcel(dataTable, fileName); dataTable.Dispose(); }
/// <summary> /// 注册事件 /// </summary> /// <param name="control">控件</param> private void RegisterEvents(ControlA control) { ControlMouseEvent clickButtonEvent = new ControlMouseEvent(ClickButton); ControlEvent selectedIndexChangedEvent = new ControlEvent(ComboBoxSelectedIndexChanged); List <ControlA> controls = control.GetControls(); int controlsSize = controls.Count; for (int i = 0; i < controlsSize; i++) { ControlA subControl = controls[i]; GridColumn column = subControl as GridColumn; ButtonA button = subControl as ButtonA; GridA grid = subControl as GridA; ComboBoxA comboBox = subControl as ComboBoxA; if (column != null) { column.AllowResize = true; column.BackColor = CDraw.PCOLORS_BACKCOLOR; column.BorderColor = COLOR.CONTROLBORDER; column.ForeColor = CDraw.PCOLORS_FORECOLOR; } else if (button != null) { button.RegisterEvent(clickButtonEvent, EVENTID.CLICK); } else if (comboBox != null) { comboBox.RegisterEvent(selectedIndexChangedEvent, EVENTID.SELECTEDINDEXCHANGED); } else if (grid != null) { grid.GridLineColor = COLOR.EMPTY; GridRowStyle rowStyle = new GridRowStyle(); grid.RowStyle = rowStyle; rowStyle.BackColor = COLOR.EMPTY; rowStyle.SelectedBackColor = CDraw.PCOLORS_SELECTEDROWCOLOR; rowStyle.HoveredBackColor = CDraw.PCOLORS_HOVEREDROWCOLOR; } RegisterEvents(subControl); } }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">矩形</param> /// <param name="clipRect">裁剪矩形</param> /// <param name="isAlternate">是否交替行</param> public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate) { int clipW = clipRect.right - clipRect.left; int clipH = clipRect.bottom - clipRect.top; if (clipW > 0 && clipH > 0) { GridA grid = Grid; GridRow row = Row; GridColumn column = Column; if (grid != null && row != null && column != null) { double value = GetDouble(); String text = " "; GridCellStyle style = Style; FONT font = style.Font; long foreColor = style.ForeColor; SIZE tSize = paint.TextSize(text, font); POINT tPoint = new POINT(rect.left, rect.top + clipH / 2 - tSize.cy / 2); CDraw.DrawUnderLineNum(paint, value, m_digit, font, foreColor, false, tPoint.x, tPoint.y); } } }
/// <summary> /// 重绘方法 /// </summary> /// <param name="paint">绘图对象</param> /// <param name="rect">矩形</param> /// <param name="clipRect">裁剪矩形</param> /// <param name="isAlternate">是否交替行</param> public override void OnPaint(CPaint paint, RECT rect, RECT clipRect, bool isAlternate) { int clipW = clipRect.right - clipRect.left; int clipH = clipRect.bottom - clipRect.top; if (clipW > 0 && clipH > 0) { GridA grid = Grid; GridRow row = Row; GridColumn column = Column; if (grid != null && row != null && column != null) { //判断选中 String text = "-"; //绘制背景 bool selected = false; List <GridRow> selectedRows = grid.SelectedRows; int selectedRowsSize = selectedRows.Count; for (int i = 0; i < selectedRowsSize; i++) { if (selectedRows[i] == row) { selected = true; break; } } long backColor = COLOR.EMPTY; GridRowStyle rowStyle = grid.RowStyle; if (selected) { backColor = rowStyle.SelectedBackColor; } else if (row == grid.HoveredRow) { backColor = rowStyle.HoveredBackColor; } else { backColor = rowStyle.BackColor; } paint.FillRect(backColor, clipRect); //获取颜色 FONT font = null; long foreColor = COLOR.EMPTY; GridCellStyle style = Style; if (style != null) { foreColor = style.ForeColor; if (style.Font != null) { font = style.Font; } } double value = GetDouble(); if (!double.IsNaN(value)) { SecurityLatestData data = new SecurityLatestData(); String securityCode = row.GetCell(0).Text; if (m_userSecurityList.m_latestDatas.ContainsKey(securityCode)) { data = m_userSecurityList.m_latestDatas[securityCode]; } String columnName = column.Name; int dataSize = data != null ? data.m_securityCode.Length : 0; if (columnName == "colNo") { foreColor = CDraw.PCOLORS_FORECOLOR7; text = ((int)value + 1).ToString(); } else if (columnName == "colDiff") { if (dataSize > 0) { foreColor = GetPriceColor(value, 0); text = value.ToString("0.00"); } } else if (columnName == "colDiffRange") { if (dataSize > 0) { foreColor = GetPriceColor(data.m_close, data.m_lastClose); text = value.ToString("0.00") + "%"; } } else { if (dataSize > 0) { foreColor = GetPriceColor(value, data.m_lastClose); text = value.ToString("0.00"); } } } SIZE tSize = paint.TextSize(text, font); POINT tPoint = new POINT(rect.right - tSize.cx - 3, rect.top + clipH / 2 - tSize.cy / 2); RECT tRect = new RECT(tPoint.x, tPoint.y, tPoint.x + tSize.cx, tPoint.y + tSize.cy); paint.DrawText(text, foreColor, font, tRect); } } }
/// <summary> /// 获取表格 /// </summary> /// <param name="bytes">流</param> /// <param name="native">方法库</param> /// <returns>表格</returns> public GridA GetGrid(byte[] bytes, INativeBase native) { Binary br = new Binary(); br.Write(bytes, bytes.Length); GridA grid = new GridA(); grid.Native = native; grid.Name = br.ReadString(); int columnsSize = br.ReadInt(); for (int i = 0; i < columnsSize; i++) { GridColumn column = new GridColumn(); column.Name = br.ReadString(); column.ColumnType = br.ReadString(); grid.AddColumn(column); } grid.Update(); List <GridColumn> columns = grid.GetColumns(); int rowsCount = br.ReadInt(); for (int i = 0; i < rowsCount; i++) { GridRow row = new GridRow(); grid.AddRow(row); for (int j = 0; j < columnsSize; j++) { GridColumn column = columns[j]; string columnType = column.ColumnType.ToLower(); GridCell cell = null; if (columnType == "bool") { cell = new GridBoolCell(); row.AddCell(j, cell); cell.SetBool(br.ReadBool()); } else if (columnType == "double") { cell = new GridDoubleCell(); row.AddCell(j, cell); cell.SetDouble(br.ReadDouble()); } else if (columnType == "float") { cell = new GridFloatCell(); row.AddCell(j, cell); cell.SetFloat(br.ReadFloat()); } else if (columnType == "int") { cell = new GridIntCell(); row.AddCell(j, cell); cell.SetInt(br.ReadInt()); } else if (columnType == "long") { cell = new GridLongCell(); row.AddCell(j, cell); cell.SetLong((long)br.ReadDouble()); } else if (columnType == "string") { cell = new GridStringCell(); row.AddCell(j, cell); cell.SetString(br.ReadString()); } else { cell = new GridStringCell(); row.AddCell(j, cell); cell.SetString(br.ReadString()); } } } br.Close(); return(grid); }
/// <summary> /// 获取表格 /// </summary> /// <param name="requestID"></param> /// <param name="grid"></param> /// <returns></returns> public int Excute(int requestID, GridA grid) { int ret = Send(FUNCTIONID_EXCUTEID, requestID, grid); return(ret > 0 ? 1 : 0); }
/// <summary> /// 创建内部控件 /// </summary> /// <param name="parent">父控件</param> /// <param name="clsid">控件标识</param> /// <returns>内部控件</returns> public override ControlA CreateInternalControl(ControlA parent, String clsid) { //日历控件 CalendarA calendar = parent as CalendarA; if (calendar != null) { if (clsid == "datetitle") { return(new DateTitle(calendar)); } else if (clsid == "headdiv") { HeadDiv headDiv = new HeadDiv(calendar); headDiv.Width = parent.Width; headDiv.Dock = DockStyleA.Top; return(headDiv); } else if (clsid == "lastbutton") { return(new ArrowButton(calendar)); } else if (clsid == "nextbutton") { ArrowButton nextBtn = new ArrowButton(calendar); nextBtn.ToLast = false; return(nextBtn); } } //分割层 SplitLayoutDivA splitLayoutDiv = parent as SplitLayoutDivA; if (splitLayoutDiv != null) { if (clsid == "splitter") { ButtonA splitter = new ButtonA(); splitter.BackColor = CDraw.PCOLORS_BACKCOLOR; splitter.Size = new SIZE(5, 5); return(splitter); } } //滚动条 ScrollBarA scrollBar = parent as ScrollBarA; if (scrollBar != null) { scrollBar.BackColor = COLOR.EMPTY; if (clsid == "addbutton") { RibbonButton addButton = new RibbonButton(); addButton.Size = new SIZE(15, 15); if (scrollBar is HScrollBarA) { addButton.ArrowType = 2; } else if (scrollBar is VScrollBarA) { addButton.ArrowType = 4; } return(addButton); } else if (clsid == "backbutton") { ButtonA backButton = new ButtonA(); return(backButton); } else if (clsid == "scrollbutton") { ButtonA scrollButton = new ButtonA(); scrollButton.AllowDrag = true; scrollButton.BackColor = CDraw.PCOLORS_BACKCOLOR; scrollButton.BorderColor = CDraw.PCOLORS_LINECOLOR3; return(scrollButton); } else if (clsid == "reducebutton") { RibbonButton reduceButton = new RibbonButton(); reduceButton.Size = new SIZE(15, 15); if (scrollBar is HScrollBarA) { reduceButton.ArrowType = 1; } else if (scrollBar is VScrollBarA) { reduceButton.ArrowType = 3; } return(reduceButton); } } //页夹 TabPageA tabPage = parent as TabPageA; if (tabPage != null) { if (clsid == "headerbutton") { RibbonButton button = new RibbonButton(); button.AllowDrag = true; SIZE size = new SIZE(100, 20); button.Size = size; return(button); } } //下拉列表 ComboBoxA comboBox = parent as ComboBoxA; if (comboBox != null) { if (clsid == "dropdownbutton") { RibbonButton dropDownButton = new RibbonButton(); dropDownButton.ArrowType = 4; dropDownButton.DisplayOffset = false; int width = comboBox.Width; int height = comboBox.Height; POINT location = new POINT(width - 20, 0); dropDownButton.Location = location; SIZE size = new SIZE(20, height); dropDownButton.Size = size; return(dropDownButton); } else if (clsid == "dropdownmenu") { ComboBoxMenu comboBoxMenu = new ComboBoxMenu(); comboBoxMenu.ComboBox = comboBox; comboBoxMenu.Popup = true; SIZE size = new SIZE(100, 200); comboBoxMenu.Size = size; return(comboBoxMenu); } } //日期选择 DatePickerA datePicker = parent as DatePickerA; if (datePicker != null) { if (clsid == "dropdownbutton") { RibbonButton dropDownButton = new RibbonButton(); dropDownButton.ArrowType = 4; dropDownButton.DisplayOffset = false; int width = datePicker.Width; int height = datePicker.Height; POINT location = new POINT(width - 16, 0); dropDownButton.Location = location; SIZE size = new SIZE(16, height); dropDownButton.Size = size; return(dropDownButton); } else if (clsid == "dropdownmenu") { MenuA dropDownMenu = new MenuA(); dropDownMenu.Padding = new PADDING(1); dropDownMenu.Popup = true; SIZE size = new SIZE(200, 200); dropDownMenu.Size = size; return(dropDownMenu); } } //数字选择 SpinA spin = parent as SpinA; if (spin != null) { if (clsid == "downbutton") { RibbonButton downButton = new RibbonButton(); downButton.ArrowType = 4; downButton.DisplayOffset = false; SIZE size = new SIZE(16, 16); downButton.Size = size; return(downButton); } else if (clsid == "upbutton") { RibbonButton upButton = new RibbonButton(); upButton.ArrowType = 3; upButton.DisplayOffset = false; SIZE size = new SIZE(16, 16); upButton.Size = size; return(upButton); } } //容器层 DivA div = parent as DivA; if (div != null) { if (clsid == "hscrollbar") { HScrollBarA hScrollBar = new HScrollBarA(); hScrollBar.Visible = false; hScrollBar.Size = new SIZE(15, 15); return(hScrollBar); } else if (clsid == "vscrollbar") { VScrollBarA vScrollBar = new VScrollBarA(); vScrollBar.Visible = false; vScrollBar.Size = new SIZE(15, 15); return(vScrollBar); } } //表格 GridA grid = parent as GridA; if (grid != null) { if (clsid == "edittextbox") { TextBoxA textBox = new TextBoxA(); textBox.BackColor = CDraw.PCOLORS_BACKCOLOR; return(textBox); } } return(null); }