Exemplo n.º 1
0
        private void Main_Load(object sender, EventArgs e)
        {
            mGen.MarketUpdate += r_MarketUpdate;
            mGen.Start();
            // data structure will be needed to get access to all of the data within the market.
            ds = (ByteDs)BytesToObject(ref dBytes, typeof(ByteDs));
            DataGridViewCellStyle hStyle = dataGridView1.ColumnHeadersDefaultCellStyle.Clone();

            dataGridView1.ColumnHeadersDefaultCellStyle.BackColor = Color.Red;

            foreach (DataGridViewColumn item in dataGridView1.Columns)
            {
                item.HeaderCell.Style = hStyle;
            }
            FormClosed += Main_Closed;
        }
Exemplo n.º 2
0
        /* This method binds the date from the byte[] into a datastructure, and updates the
         * datagridview accordingly. So, as long as something is stored in the Byte it will run.
         * It will also highlight the proper cells, based on change from the previous data stored
         * to the current data. If no changes occur, it will unhighlight that data.
         */
        private void BindData()
        {
            ByteDs ds = (ByteDs)BytesToObject(ref dBytes, typeof(ByteDs));

            if (ds != null)
            {
                var dList = new List <ByteDs>()
                {
                    new ByteDs()
                    {
                        ID         = ds.ID,
                        TradePrice = ds.TradePrice,
                        TradeQty   = ds.TradeQty,
                        BidPrice   = ds.BidPrice,
                        BidQty     = ds.BidQty,
                        AskPrice   = ds.AskPrice,
                        AskQty     = ds.AskQty
                    }
                };

                foreach (var item in dList)
                {
                    Boolean exists = false;
                    foreach (DataGridViewRow row in dataGridView1.Rows)
                    {
                        row.DefaultCellStyle.BackColor = Color.Black;
                        row.DefaultCellStyle.ForeColor = Color.White;

                        if (row.Cells["ID"].Value != null && item.ID != null)
                        {
                            if (row.Cells["ID"].Value.ToString() == item.ID.ToString())
                            {
                                exists = true;
                                foreach (DataGridViewColumn col in dataGridView1.Columns)
                                {
                                    var cell = row.Cells[col.Index].Style;
                                    switch (col.Index)
                                    {
                                    case 1:
                                        if (row.Cells[col.Index].Value.ToString() != item.TradePrice.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;

                                    case 2:
                                        if (row.Cells[col.Index].Value.ToString() != item.TradeQty.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;

                                    case 3:
                                        if (row.Cells[col.Index].Value.ToString() != item.BidPrice.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;

                                    case 4:
                                        if (row.Cells[col.Index].Value.ToString() != item.BidQty.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;

                                    case 5:
                                        if (row.Cells[col.Index].Value.ToString() != item.AskPrice.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;

                                    case 6:
                                        if (row.Cells[col.Index].Value.ToString() != item.AskQty.ToString())
                                        {
                                            cell.BackColor = Color.DarkRed;
                                        }
                                        else
                                        {
                                            cell.BackColor = Color.Black;
                                        }
                                        break;
                                    }
                                }
                                // Update the row data
                                row.SetValues(item.ID,
                                              item.TradePrice,
                                              item.TradeQty,
                                              item.BidPrice,
                                              item.BidQty,
                                              item.AskPrice,
                                              item.AskQty);
                            }
                        }
                    }
                    // if there are no instances of this data, by ID, it will create a new row, and add the
                    // new values.
                    if (!exists)
                    {
                        dataGridView1.DefaultCellStyle.BackColor = Color.Black;
                        dataGridView1.DefaultCellStyle.ForeColor = Color.White;
                        dataGridView1.Rows.Add(item.ID,
                                               item.TradePrice,
                                               item.TradeQty,
                                               item.BidPrice,
                                               item.BidQty,
                                               item.AskPrice,
                                               item.AskQty);
                    }
                }
            }
        }