Exemplo n.º 1
0
        /// <summary>
        /// Calculate the Sums of the summary columns
        /// </summary>
        private void calcSummaries()
        {
            foreach (ReadOnlyTextBox roTextBox in sumBoxHash.Values)
            {
                if (roTextBox.IsSummary)
                {
                    roTextBox.Tag  = 0;
                    roTextBox.Text = "0";
                    roTextBox.Invalidate();
                }
            }

            if (SummaryColumns != null && SummaryColumns.Length > 0 && sumBoxHash.Count > 0)
            {
                foreach (DataGridViewRow dgvRow in DGV.Rows)
                {
                    foreach (DataGridViewCell dgvCell in dgvRow.Cells)
                    {
                        foreach (DataGridViewColumn dgvColumn in sumBoxHash.Keys)
                        {
                            if (dgvCell.OwningColumn.Equals(dgvColumn))
                            {
                                ReadOnlyTextBox sumBox = (ReadOnlyTextBox)sumBoxHash[dgvColumn];

                                if (sumBox != null && sumBox.IsSummary)
                                {
                                    if (dgvCell.Value != null && !(dgvCell.Value is DBNull))
                                    {
                                        if (IsInteger(dgvCell.Value))
                                        {
                                            sumBox.Tag = Convert.ToInt64(sumBox.Tag) + Convert.ToInt64(dgvCell.Value);
                                        }
                                        else if (IsDecimal(dgvCell.Value))
                                        {
                                            sumBox.Tag = Convert.ToDecimal(sumBox.Tag) + Convert.ToDecimal(dgvCell.Value);
                                        }
                                        sumBox.Text = string.Format("{0}", sumBox.Tag);
                                        if (sumBox.Text == "0" && !ReportShowZero)
                                        {
                                            sumBox.Text = String.Empty;
                                        }
                                        sumBox.Invalidate();
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        private void calcSummaries1()
        {
            if (TotalRow != null)
            {
                foreach (ReadOnlyTextBox roTextBox in sumBoxHash.Values)
                {
                    if (roTextBox.IsSummary)
                    {
                        roTextBox.Tag  = 0;
                        roTextBox.Text = "0";
                        roTextBox.Invalidate();
                    }
                }

                if (SummaryColumns != null && SummaryColumns.Length > 0 && sumBoxHash.Count > 0)
                {
                    foreach (DataGridViewColumn dgvColumn in sumBoxHash.Keys)
                    {
                        ReadOnlyTextBox sumBox = (ReadOnlyTextBox)sumBoxHash[dgvColumn];

                        if (sumBox != null && sumBox.IsSummary)
                        {
                            if (TotalRow is DataRow)
                            {
                                DataRow dataRow = TotalRow as DataRow;
                                sumBox.Tag = dataRow[dgvColumn.DataPropertyName];
                            }
                            else
                            {
                                sumBox.Tag = ReflectionHelper.GetProperty(TotalRow, dgvColumn.DataPropertyName);
                            }

                            sumBox.Text = string.Format("{0}", sumBox.Tag);
                            if (sumBox.Text == "0" && !ReportShowZero)
                            {
                                sumBox.Text = String.Empty;
                            }
                            sumBox.Invalidate();
                        }
                    }
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Resize the summary Boxes depending on the
        /// width of the Columns of the DataGridView
        /// </summary>
        private void resizeSumBoxes()
        {
            try
            {
                this.SuspendLayout();
                if (sumBoxHash != null && sumBoxHash.Count > 0)
                {
                    try
                    {
                        int rowHeaderWidth = DGV.RowHeadersVisible ? DGV.RowHeadersWidth - 1 : 0;
                        int sumLabelWidth  = DGV.RowHeadersVisible ? DGV.RowHeadersWidth - 1 : 0;
                        int curPos         = rowHeaderWidth;

                        if (sumLabelWidth > 0)
                        {
                            sumRowHeaderLabel.Visible = true;
                            sumRowHeaderLabel.Width   = sumLabelWidth;
                            if (DGV.RightToLeft == RightToLeft.Yes)
                            {
                                if (sumRowHeaderLabel.Dock != DockStyle.Right)
                                {
                                    sumRowHeaderLabel.Dock = DockStyle.Right;
                                }
                            }
                            else
                            {
                                if (sumRowHeaderLabel.Dock != DockStyle.Left)
                                {
                                    sumRowHeaderLabel.Dock = DockStyle.Left;
                                }
                            }
                        }
                        else
                        {
                            if (sumRowHeaderLabel.Visible)
                            {
                                sumRowHeaderLabel.Visible = false;
                            }
                        }

                        int       iCnt = 0;
                        Rectangle oldBounds;

                        foreach (DataGridViewColumn dgvColumn in SortedColumns)
                        {
                            ReadOnlyTextBox sumBox = (ReadOnlyTextBox)sumBoxHash[dgvColumn];
                            if (sumBox != null)
                            {
                                oldBounds = sumBox.Bounds;
                                if (!dgvColumn.Visible)
                                {
                                    sumBox.Visible = false;
                                    continue;
                                }

                                int from  = dgvColumn.Frozen ? curPos : curPos - DGV.HorizontalScrollingOffset;
                                int width = dgvColumn.Width + (iCnt == 0 ? 0 : 0);
                                if (from < rowHeaderWidth)
                                {
                                    width -= rowHeaderWidth - from;
                                    from   = rowHeaderWidth;
                                }
                                if (sumBox.IsLastColumn)
                                {
                                    String test = string.Empty;
                                }

                                if (width < 4)
                                {
                                    if (sumBox.Visible)
                                    {
                                        sumBox.Visible = false;
                                    }
                                }
                                else
                                {
                                    if (this.RightToLeft == RightToLeft.Yes)
                                    {
                                        from = this.Width - from - width;
                                    }

                                    if (sumBox.Left != from || sumBox.Width != width)
                                    {
                                        sumBox.SetBounds(from, 0, width, 0, BoundsSpecified.X | BoundsSpecified.Width);
                                    }

                                    if (!sumBox.Visible)
                                    {
                                        sumBox.Visible = true;
                                    }
                                }

                                curPos += dgvColumn.Width + (iCnt == 0 ? 0 : 0);
                                if (oldBounds != sumBox.Bounds)
                                {
                                    sumBox.Invalidate();
                                }
                            }
                            iCnt++;
                        }
                    }
                    finally
                    {
                        this.ResumeLayout();
                    }
                }
            }
#if (DEBUG)
            catch (Exception ee)
            {
                MessageBox.Show(ee.ToString());
                System.Diagnostics.Debug.WriteLine(ee.ToString());
            }
#else
            catch
            { }
#endif
        }