示例#1
0
        private void UpdateCurrentPage()
        {
            if (m_currentPage >= m_mainDiary.PageCount)
            {
                m_currentPage = m_mainDiary.PageCount - 1;
            }
            lbPageId.Text = "Stránka " + (m_currentPage + 1).ToString() + ".";
            Record[] records = m_mainDiary.GetPage(m_currentPage);
            ClearGrid();
            String [] cells = new String[8];

            for (int i = 0; i < records.Length && records[i] != null; i++)
            {
                /*
                 * gridHistory.Rows[i].Cells[0].Value = records[i].OverallID.ToString();
                 * gridHistory.Rows[i].Cells[1].Value = records[i].Date;
                 * gridHistory.Rows[i].Cells[2].Value = records[i].TypeID.ToString();
                 * gridHistory.Rows[i].Cells[3].Value = records[i].Content;
                 * if (records[i].Type == Record.RecordType.Expense)
                 * {
                 *  gridHistory.Rows[i].Cells[4].Value = "";
                 *  gridHistory.Rows[i].Cells[5].Value = records[i].Cost.ToString();
                 * }
                 * else
                 * {
                 *  gridHistory.Rows[i].Cells[5].Value = "";
                 *  gridHistory.Rows[i].Cells[4].Value = records[i].Cost.ToString();
                 * }
                 * gridHistory.Rows[i].Cells[6].Value = records[i].Remaining.ToString();
                 * gridHistory.Rows[i].Cells[7].Value = records[i].Note;*/
                cells[0] = records[i].OverallID.ToString();
                cells[1] = records[i].Date;
                cells[2] = records[i].TypeID.ToString();
                cells[3] = records[i].Content;
                if (records[i].Type == Record.RecordType.Expense)
                {
                    cells[4] = "";
                    cells[5] = MoneyConvertor.MoneyToStr(records[i].Cost) + ",-";
                }
                else
                {
                    cells[5] = "";
                    cells[4] = MoneyConvertor.MoneyToStr(records[i].Cost) + ",-";
                }
                cells[6] = MoneyConvertor.MoneyToStr(records[i].Remaining) + ",-";
                cells[7] = records[i].Note.Equals("") ? records[i].CustName : records[i].Note;

                //for (int j=0; j<8; j++)
                //    dataSource[i*8+j] = cells[j];
                if (records[i].Remaining > m_mainDiary.RemainLimit)
                {
                    for (int j = 0; j < gridHistory.Rows[i].Cells.Count; j++)
                    {
                        gridHistory.Rows[i].Cells[j].Style.ForeColor = Color.Red;
                    }
                }
                else if (records[i].Remaining > m_mainDiary.RemainWarning)
                {
                    for (int j = 0; j < gridHistory.Rows[i].Cells.Count; j++)
                    {
                        gridHistory.Rows[i].Cells[j].Style.ForeColor = Color.Blue;
                    }
                }
                else
                {
                    for (int j = 0; j < gridHistory.Rows[i].Cells.Count; j++)
                    {
                        gridHistory.Rows[i].Cells[j].Style.ForeColor = Color.Black;
                    }
                }
                gridHistory.Rows[i].SetValues(cells);
            }
            //gridHistory.DataSource = dataSource;
        }
示例#2
0
        private void PrintDiaryPage(Graphics g, int page)
        {
            Debug.Assert(page <= m_diaryToPrint.PageCount);
            if (page > m_diaryToPrint.PageCount)
            {
                return;
            }

            Record[] records = m_diaryToPrint.GetPage(page);
            Debug.Assert(records.Length >= 0);
            if (records.Length < 0)
            {
                return;
            }

            g.TextRenderingHint = System.Drawing.Text.TextRenderingHint.ClearTypeGridFit;
            //g.TextRenderingHin
            Font defaultTextFont = new Font("Times New Roman", 12, FontStyle.Bold);
            Font mainTextFont    = new Font("Times New Roman", 18, FontStyle.Bold);

            //Tisk razitka
            printStamp(g, 130, 6);

            g.ResetTransform();
            g.ScaleTransform((g.VisibleClipBounds.Width - 8) / 827,
                             (g.VisibleClipBounds.Height - 8) / 1169);
            float width = (float)827;

            int[]    colBorders      = { 32, 50, 57, 266, 83, 83, 101, 138 };
            string[] colDescriptions = { "Poř.\nčíslo", "Datum",    "Obsah zápisu", "Příjmy",
                                         "Výdaje",      "Zůstatek", "Poznámka" };

            Rectangle tableRect   = new Rectangle(5, 80, 817, 1064);
            int       tableHeader = 40;

            //g.ScaleTransform(g.VisibleClipBounds.Width/width , g.VisibleClipBounds.Height/height);

            g.DrawString(m_diaryToPrint.Name, mainTextFont, TextBrush, width / 2, 35, CenterCenterAlign);
            if (records.Length > 0)
            {
                g.DrawString("Od: " + records[0].DateDiary + "   Do: " + records[records.Length - 1].DateDiary,
                             defaultTextFont, TextBrush, width / 2, 60, CenterCenterAlign);
            }
            g.DrawString("Stránka: " + (page + 1).ToString() + ".  ",
                         defaultTextFont, TextBrush, tableRect.Right - 20, 35, RightCenterAlign);


            Brush borderBrush = new SolidBrush(Color.Black);
            Pen   borderPen   = new Pen(borderBrush, 3);
            Pen   normalPen   = new Pen(borderBrush, 1);

            g.DrawRectangle(borderPen, tableRect);
            g.DrawLine(borderPen, tableRect.Left, tableRect.Top + tableHeader, tableRect.Right, tableRect.Top + tableHeader);

            float rowHeight = (tableRect.Height - tableHeader) / (float)m_diaryToPrint.PageSize;
            int   tableTop  = tableHeader + tableRect.Top;

            for (int row = 1; row <= m_diaryToPrint.PageSize; row++)
            {
                g.DrawLine(normalPen, tableRect.Left, row * rowHeight + tableTop, tableRect.Right,
                           row * rowHeight + tableTop);
            }
            int sumCol = tableRect.Left;

            Font tableHeaderFont = new Font("Times New Roman", 10, FontStyle.Bold);

            for (int colId = 1; colId < colBorders.Length; colId++)
            {
                if (colId == colBorders.Length - 1)
                {
                    colBorders[colId] = tableRect.Right - sumCol;
                    sumCol            = tableRect.Right;
                }
                else
                {
                    sumCol += colBorders[colId];
                }
                g.DrawLine(normalPen, sumCol, tableRect.Top, sumCol, tableRect.Bottom);
                g.DrawString(colDescriptions[colId - 1], tableHeaderFont, TextBrush,
                             new RectangleF(sumCol - colBorders[colId], tableRect.Top, colBorders[colId], tableHeader),
                             CenterCenterAlign);
            }

            Font tableBodyFont = new Font("Courier New", 9, FontStyle.Bold);

            for (int row = 0; row < records.Length; row++)
            {
                Record         record    = records[row];
                string         costIn    = (record.Type == Record.RecordType.Income)?(MoneyConvertor.MoneyToStr(record.Cost) + ",-"):("");
                string         costOut   = (record.Type == Record.RecordType.Expense) ? (MoneyConvertor.MoneyToStr(record.Cost) + ",-") : ("");
                string         remaining = MoneyConvertor.MoneyToStr(record.Remaining) + ",-";
                string         note      = record.Note.Equals("") ? record.CustName : record.Note;
                string[]       rowVals   = { record.OverallID.ToString(), record.DateDiary.ToString(),
                                             record.Content,                      costIn,                     costOut,remaining, note };
                StringFormat[] colFormats = { RightCenterAlign, RightCenterAlign, LeftCenterAlign, RightCenterAlign, RightCenterAlign, RightCenterAlign, LeftCenterAlign, LeftCenterAlign };

                sumCol = tableRect.Left;
                float rowTop = tableRect.Top + tableHeader + row * rowHeight;
                for (int colId = 1; colId < colBorders.Length; colId++)
                {
                    if (colId == colBorders.Length - 1)
                    {
                        colBorders[colId] = tableRect.Right - sumCol;
                        sumCol            = tableRect.Right;
                    }
                    else
                    {
                        sumCol += colBorders[colId];
                    }
                    // g.DrawLine(normalPen, sumCol, tableRect.Top, sumCol, tableRect.Bottom);
                    g.DrawString(rowVals[colId - 1], tableBodyFont, TextBrush,
                                 new RectangleF(sumCol - colBorders[colId] + 2, rowTop + 2, colBorders[colId] - 5, rowHeight),
                                 colFormats[colId - 1]);
                }
            }

            g.DrawString(footerText, m_footerFont, TextBrush, (float)tableRect.Right - 10, (float)tableRect.Bottom + 15, RightCenterAlign);
        }