Example #1
0
        /// <summary>
        /// Create the <see cref="MatrixCell"/> controls. Also instantiate the item template if it exists
        /// </summary>
        /// <param name="e"></param>
        protected override void OnInit(EventArgs e)
        {
            MatrixField mf = (MatrixField)this.ContainingField;

            foreach (var dc in mf.DisplayColumns)
            {
                MatrixCell mc = new MatrixCell(dc);
                mc.MergeStyle(this.ContainingField.ItemStyle);
                this.Controls.Add(mc);
            }
            mf.DisplayColumns.CollectionChanged += DisplayColumns_CollectionChanged;
            base.OnInit(e);
        }
Example #2
0
        private void DoRenderSubtotals(MatrixCell mc, int firstRowIndex, int lastRowIndex)
        {
            GridView gv = (GridView)this.NamingContainer.NamingContainer;

            decimal?[] subtotals = new decimal?[mc.CellValues.Length];

            IEnumerable <object[]> query = gv.Rows.Cast <GridViewRow>()
                                           .Skip(firstRowIndex).Take(lastRowIndex - firstRowIndex + 1)
                                           .SelectMany(p => p.Cells.OfType <MatrixRow>())
                                           .SelectMany(p => p.MatrixCells)
                                           .Where(p => object.ReferenceEquals(p.DisplayColumn, mc.DisplayColumn))
                                           .Select(p => p.CellValues);

            /*
             *           foreach (int i in _mf.DataCellFields
             *  .Select((p, i) => _colTotalindexes.Contains(i) ? i : -1)
             *  .Where(p => p >= 0))
             * {
             *  if (values[i] != DBNull.Value)
             *  {
             *      _columnTotals[i] = (_columnTotals[i] ?? 0) + Convert.ToDecimal(values[i]);
             *  }
             *
             * }
             */
            MatrixField mf = (MatrixField)this.ContainingField;

            foreach (var values in query)
            {
                if (values != null)
                {
                    foreach (int i in mf.DataCellFields
                             .Select((p, i) => mc.DisplayColumn.FieldsToTotal.Contains(i) ? i : -1)
                             .Where(p => p >= 0))
                    {
                        if (values[i] != DBNull.Value)
                        {
                            subtotals[i] = (subtotals[i] ?? 0) + Convert.ToDecimal(values[i]);
                        }
                    }
                    //for (int i = 0; i < subtotals.Length; ++i)
                    //{
                    //    if (values[i] != DBNull.Value)
                    //    {
                    //        subtotals[i] = (subtotals[i] ?? 0) + Convert.ToDecimal(values[i]);
                    //    }
                    //}
                }
            }
            mc.Text = string.Format(mc.DisplayColumn.MatrixColumn.ColumnTotalFormatString, subtotals.Cast <object>().ToArray());
        }
Example #3
0
        /// <summary>
        /// Create a <see cref="MatrixCell"/> for each <see cref="MatrixDisplayColumn"/> which is added after <see cref="OnInit"/>
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void DisplayColumns_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
        {
            switch (e.Action)
            {
            case NotifyCollectionChangedAction.Add:
                foreach (MatrixDisplayColumn dc in e.NewItems.Cast <MatrixDisplayColumn>())
                {
                    MatrixCell cell = new MatrixCell(dc);
                    this.Controls.Add(cell);
                }
                break;

            default:
                throw new NotImplementedException();
            }
        }