예제 #1
0
        /// <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);
        }
예제 #2
0
        /// <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();
        }
예제 #3
0
        /// <summary>
        /// 秒表方法
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void timer_Tick(object sender, EventArgs e)
        {
            List <String> refreshCodes = new List <string>();

            lock (newDataCodes) {
                if (newDataCodes.Count > 0)
                {
                    foreach (String key in newDataCodes.Keys)
                    {
                        refreshCodes.Add(key);
                    }
                    newDataCodes.Clear();
                }
            }
            int refreshCodesSize = refreshCodes.Count;

            if (refreshCodes.Count > 0)
            {
                if (updateCells.Count > 0)
                {
                    if (updateCells.Count > 10)
                    {
                        for (int i = 0; i < updateCells.Count; i++)
                        {
                            GridCell updateCell = updateCells[i];
                            updateCell.Style.BackColor = Color.Empty;
                        }
                    }
                    else
                    {
                        for (int i = 0; i < updateCells.Count; i++)
                        {
                            GridCell updateCell = updateCells[i];
                            updateCell.Style.BackColor = Color.Empty;
                        }
                    }
                    updateCells.Clear();
                }
                for (int i = 0; i < refreshCodesSize; i++)
                {
                    GridRow row  = null;
                    String  code = refreshCodes[i];
                    if (rowsMap.ContainsKey(code))
                    {
                        row = rowsMap[code];
                        SecurityLatestData lastestData = new SecurityLatestData();
                        SecurityService.GetLatestData(code, ref lastestData);
                        double lastClose = lastestData.m_lastClose;
                        double diff = 0, diffRange = 0;
                        diff = lastestData.m_close - lastestData.m_lastClose;
                        if (lastestData.m_lastClose != 0)
                        {
                            diffRange = diff / lastestData.m_lastClose;
                        }
                        GridCell cell3 = row.GetCell("colP3");
                        if (lastestData.m_close != cell3.GetDouble())
                        {
                            cell3.SetDouble(lastestData.m_close);
                            cell3.Style.TextColor = GetPriceColor(lastestData.m_close, lastClose);
                            updateCells.Add(cell3);
                        }

                        GridCell cell4 = row.GetCell("colP4");
                        if (diff != cell4.GetDouble())
                        {
                            cell4.SetDouble(Convert.ToDouble(LbCommon.GetValueByDigit(diff, 2, true)));
                            cell4.Style.TextColor = GetPriceColor(lastestData.m_close, lastClose);
                            updateCells.Add(cell4);
                        }

                        GridCell cell5 = row.GetCell("colP5");
                        if (diffRange != cell5.GetDouble())
                        {
                            cell5.SetDouble(diffRange);
                            cell5.Style.TextColor = GetPriceColor(lastestData.m_close, lastClose);
                            updateCells.Add(cell5);
                        }

                        GridCell cell6 = row.GetCell("colP6");
                        if (lastestData.m_high != cell6.GetDouble())
                        {
                            cell6.SetDouble(lastestData.m_high);
                            cell6.Style.TextColor = GetPriceColor(lastestData.m_high, lastClose);
                            updateCells.Add(cell6);
                        }

                        GridCell cell7 = row.GetCell("colP7");
                        if (lastestData.m_low != cell7.GetDouble())
                        {
                            cell7.SetDouble(lastestData.m_low);
                            cell7.Style.TextColor = GetPriceColor(lastestData.m_low, lastClose);
                            updateCells.Add(cell7);
                        }

                        GridCell cell8 = row.GetCell("colP8");
                        if (lastestData.m_open != cell8.GetDouble())
                        {
                            cell8.SetDouble(lastestData.m_open);
                            cell8.Style.TextColor = GetPriceColor(lastestData.m_open, lastClose);
                            updateCells.Add(cell8);
                        }

                        GridCell cell9 = row.GetCell("colP9");
                        if (lastestData.m_volume != cell9.GetDouble())
                        {
                            cell9.SetDouble(lastestData.m_volume);
                            updateCells.Add(cell9);
                        }

                        GridCell cell10 = row.GetCell("colP10");
                        if (lastestData.m_amount != cell10.GetDouble())
                        {
                            cell10.SetDouble(lastestData.m_amount);
                            updateCells.Add(cell10);
                        }

                        GridCell cell11 = row.GetCell("colP11");
                        if (lastestData.m_buyPrice1 != cell11.GetDouble())
                        {
                            cell11.SetDouble(lastestData.m_buyPrice1);
                            cell11.Style.TextColor = GetPriceColor(lastestData.m_buyPrice1, lastClose);
                            updateCells.Add(cell11);
                        }

                        GridCell cell12 = row.GetCell("colP12");
                        if (lastestData.m_buyVolume1 != cell12.GetDouble())
                        {
                            cell12.SetDouble(lastestData.m_buyVolume1);
                            updateCells.Add(cell12);
                        }

                        GridCell cell13 = row.GetCell("colP13");
                        if (lastestData.m_sellPrice1 != cell13.GetDouble())
                        {
                            cell13.SetDouble(lastestData.m_sellPrice1);
                            cell13.Style.TextColor = GetPriceColor(lastestData.m_sellPrice1, lastClose);
                            updateCells.Add(cell13);
                        }

                        GridCell cell14 = row.GetCell("colP14");
                        if (lastestData.m_sellVolume1 != cell14.GetDouble())
                        {
                            cell14.SetDouble(lastestData.m_sellVolume1);
                            updateCells.Add(cell14);
                        }
                    }
                }
                if (updateCells.Count > 0)
                {
                    for (int i = 0; i < updateCells.Count; i++)
                    {
                        updateCells[i].Style.BackColor = Color.FromArgb(50, 255, 255, 255);
                    }
                    UpdateGrid();
                    Invalidate();
                }
            }
        }