Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="groupIndex"></param>
        /// <param name="position"></param>
        /// <param name="value"></param>
        /// <returns></returns>
        private IOfferBookGridGroup CreateGroup(int groupIndex, int position, double value)
        {
            OfferBookGridRow    row;
            IOfferBookGridGroup groupCur = null;

            groupCur       = (IOfferBookGridGroup)this.GroupingStyle.Clone(); // init
            groupCur.Value = value;

            //TODO: can be optimized and generalized
            groupCur.GroupIndex = groupIndex - 1;
            groupCur.ItemCount  = 1;

            _groups.Insert(groupIndex, groupCur);

            row = (OfferBookGridRow)this.RowTemplate.Clone();

            row.Group      = groupCur;
            row.IsGroupRow = true;
            row.Height     = groupCur.Height;
            row.CreateCells(this, groupCur.Value);

            Rows.Insert(position, row);

            return(groupCur);
        }
Ejemplo n.º 2
0
 public OfferBookGridRow(IOfferBookGridGroup group, bool isGroupRow)
     : base()
 {
     this.group      = group;
     this.isGroupRow = isGroupRow;
 }
Ejemplo n.º 3
0
 public OfferBookGridRow(IOfferBookGridGroup group)
     : this(group, false)
 {
 }
Ejemplo n.º 4
0
        /// <summary>
        ///     the fill grid method fills the grid with the data from the DataSourceManager
        ///     It takes the grouping style into account, if it is set.
        /// </summary>
        /// <param name="groupingStyle"></param>
        private void FillGrid(IOfferBookGridGroup groupingStyle)
        {
            //TODO: efetuar teste e implementar o retorno booleano informando o resultado da operação

            /*
             * if (this.Rows.Count > 0)
             * {
             *  if (this.Type.Equals(GridType.Buy))
             *  {
             *      if (this.Rows[0].Cells[2].ToString().Equals("Abert."))
             *      {
             *          return;
             *      }
             *  }
             *  else
             *  {
             *      if (this.Rows[0].Cells[0].ToString().Equals("Abert."))
             *      {
             *          return;
             *      }
             *  }
             * }
             */

            if (groupingStyle != null)
            {
                this.GroupingStyle = groupingStyle;
            }

            ArrayList        list;
            OfferBookGridRow row;

            this.Rows.Clear();

            // start filling the grid
            if (dataSource == null)
            {
                return;
            }
            else
            {
                list = dataSource.Rows;
            }

            if (list.Count <= 0)
            {
                return;
            }

            // this block is used of grouping is turned off
            // this will simply list all attributes of each object in the list
            if (groupingStyle == null)
            {
                foreach (DataSourceRow r in list)
                {
                    row = (OfferBookGridRow)this.RowTemplate.Clone();
                    foreach (object val in r)
                    {
                        DataGridViewCell cell = new DataGridViewTextBoxCell();
                        cell.Value = val.ToString();
                        row.Cells.Add(cell);
                    }

                    Rows.Add(row);
                }
            }

            // this block is used when grouping is used
            // items in the list must be sorted, and then they will automatically be grouped
            else
            {
                IOfferBookGridGroup groupCur = null;
                //object result = null;
                Double result = 0.0;
                int    idx;

                //TODO: optimization needed
                foreach (DataSourceRow r in list)
                {
                    row = (OfferBookGridRow)this.RowTemplate.Clone();
                    //result = r[groupingStyle.Column.Index];
                    result = Double.Parse(r[groupingStyle.Column.Index].ToString());

                    //if (groupCur != null && groupCur.CompareTo(result) == 0) // item is part of the group
                    if (groupCur != null && groupCur.Value.Equals(result))
                    {
                        row.Group = groupCur;
                        groupCur.ItemCount++;
                    }
                    else // item is not part of the group, so create new group
                    {
                        groupCur      = (IOfferBookGridGroup)groupingStyle.Clone(); // init
                        groupCur.Type = this.Type;

                        if (this.Type.Equals(GridType.Sell))
                        {
                            groupCur.Value = Double.Parse(r[0].ToString());
                        }

                        if (this.Type.Equals(GridType.Buy))
                        {
                            groupCur.Value = Double.Parse(r[2].ToString());
                        }

                        _groups.Add(groupCur);

                        row.Group      = groupCur;
                        row.IsGroupRow = true;
                        row.Height     = groupCur.Height;
                        row.CreateCells(this, groupCur.Value);
                        idx = Rows.Add(row);

                        // add content row after this
                        row                = (OfferBookGridRow)this.RowTemplate.Clone();
                        row.Group          = groupCur;
                        groupCur.ItemCount = 1;
                    }

                    foreach (object obj in r)
                    {
                        DataGridViewCell cell = new DataGridViewTextBoxCell();
                        cell.Value = obj.ToString();
                        row.Cells.Add(cell);
                    }

                    Rows.Add(row);

                    groupCur.Quantidade += Int64.Parse(row.Cells[1].Value.ToString());
                }
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="index"></param>
        /// <param name="dataGrigViewRow"></param>
        /// <returns></returns>
        private int ValidatePosition(int index, ref OfferBookGridRow dataGrigViewRow)
        {
            StringBuilder str = new StringBuilder();

            int _groupsCount = 0;
            int _itemsCount  = 0;
            int _return      = 0;

            foreach (IOfferBookGridGroup _group in _groups)
            {
                lock (this.SyncRoot)
                {
                    _groupsCount++;
                    _itemsCount += _group.ItemCount;

                    if (index <= _itemsCount)
                    {
                        /********************************************************************************************/
                        /***************************************** Buy side *****************************************/
                        /********************************************************************************************/
                        if (this.Type.Equals(GridType.Buy))
                        {
                            /********************************************************************************************/
                            /********** When the row has a valid group, insert it into the corresponding group **********/
                            /********************************************************************************************/

                            /* The row belongs to the previous group and direction are ascending */
                            if (Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()).Equals(Double.Parse(_group.Value.ToString())))
                            {
                                _return = index + _groupsCount;
                                _group.ItemCount++;
                                _group.Quantidade    += Int32.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = _group;
                                break;
                            }

                            /* The row belongs to the previous following */
                            if (_groups.Count > _groupsCount)
                            {
                                if (Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()).Equals(Double.Parse(_groups[_groupsCount].Value.ToString())))
                                {
                                    _return = index + _groupsCount + 1;
                                    _groups[_groupsCount].ItemCount++;
                                    _groups[_groupsCount].Quantidade += Int32.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_QTY].Value.ToString());
                                    dataGrigViewRow.Group             = _groups[_groupsCount];
                                    break;
                                }
                            }


                            /********************************************************************************************/
                            /*********** When the row does not have a valid group, insert it into a new group ***********/
                            /********************************************************************************************/

                            // Before
                            if (Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()) > Double.Parse(_group.Value.ToString()))
                            {
                                //if (index.Equals(0))
                                //{
                                IOfferBookGridGroup grp = CreateGroup(_groupsCount - 1, _groupsCount + index - 1, Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()));
                                _return               = _groupsCount + index;
                                grp.Quantidade       += Int32.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = grp;
                                break;
                                //}
                            }

                            // After
                            if (Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()) < Double.Parse(_group.Value.ToString()))
                            {
                                IOfferBookGridGroup grp = CreateGroup(_groupsCount, _groupsCount + _itemsCount, Double.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_PRC].Value.ToString()));
                                _return               = _groupsCount + _itemsCount + 1;
                                grp.Quantidade       += Int32.Parse(dataGrigViewRow.Cells[BUYSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = grp;
                                break;
                            }
                        }

                        /********************************************************************************************/
                        /***************************************** Sell side ****************************************/
                        /********************************************************************************************/

                        if (this.Type.Equals(GridType.Sell))
                        {
                            /********************************************************************************************/
                            /********** When the row has a valid group, insert it into the corresponding group **********/
                            /********************************************************************************************/

                            /* The row belongs to the previous group and direction are ascending */
                            if (Double.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_PRC].Value.ToString()).Equals(Double.Parse(_group.Value.ToString())))
                            {
                                _return = index + _groupsCount;
                                _group.ItemCount++;
                                _group.Quantidade    += Int32.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = _group;
                                break;
                            }

                            /* The row belongs to the previous following */
                            if (_groups.Count > _groupsCount)
                            {
                                if (Double.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_PRC].Value.ToString()).Equals(Double.Parse(_groups[_groupsCount].Value.ToString())))
                                {
                                    _return = index + _groupsCount + 1;
                                    _groups[_groupsCount].ItemCount++;
                                    _groups[_groupsCount].Quantidade += Int32.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_QTY].Value.ToString());
                                    dataGrigViewRow.Group             = _groups[_groupsCount];
                                    break;
                                }
                            }

                            /********************************************************************************************/
                            /*********** When the row does not have a valid group, insert it into a new group ***********/
                            /********************************************************************************************/

                            // After
                            if (Double.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_PRC].Value.ToString()) > Double.Parse(_group.Value.ToString()))
                            {
                                IOfferBookGridGroup grp = CreateGroup(_groupsCount, _groupsCount + _itemsCount, Double.Parse(dataGrigViewRow.Cells[0].Value.ToString()));
                                _return               = _groupsCount + _itemsCount + 1;
                                grp.Quantidade       += Int32.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = grp;
                                break;
                            }

                            // Before
                            if (Double.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_PRC].Value.ToString()) < Double.Parse(_group.Value.ToString()))
                            {
                                //if (index.Equals(0))
                                //{
                                IOfferBookGridGroup grp = CreateGroup(_groupsCount - 1, _groupsCount + index - 1, Double.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_PRC].Value.ToString()));
                                _return               = _groupsCount + index;
                                grp.Quantidade       += Int32.Parse(dataGrigViewRow.Cells[SELLSIDE_COL_QTY].Value.ToString());
                                dataGrigViewRow.Group = grp;
                                break;
                                //}
                            }
                        }
                    }
                }
            }
            return(_return);
        }