Пример #1
0
        public void Draw(Graphics g, Rectangle rectClient)
        {
            Brush brushBack = new SolidBrush(BackColor);
            Brush brushFore = new SolidBrush(ForeColor);

            Brush brushHeading = new SolidBrush(m_colorHeading);
            Brush brushWeekend = new SolidBrush(m_colorWeekend);
            Brush brushBlank   = new SolidBrush(m_colorBlank);

            Font fontHeading = new Font(this.Font.FontFamily, this.Font.Size, FontStyle.Bold);

            fontTitle = new Font(this.Font.FontFamily, this.Font.Size + 5, FontStyle.Bold);

            //  Wipe the whole background.
            g.FillRectangle(brushBack, rectClient);

            //  Get the size of the Title and headings.
            sizeTitle = g.MeasureString(model.Title, fontTitle);
            sizeDOW   = new SizeF(1, 1);

            for (int i = 0; i < model.NumberOfRows; i++)
            {
                SizeF s = g.MeasureString(model.Cells[0, i].text, fontHeading);

                if (sizeDOW == null || s.Width > sizeDOW.Width)
                {
                    sizeDOW = s;
                }
            }

            //  Don't do anything more if the title won't fit!
            if ((sizeTitle.Height < rectClient.Height) &&
                (sizeTitle.Width < rectClient.Width) &&
                (sizeDOW.Width < rectClient.Width))
            {
                calculateGrid(rectClient);

                //	Draw the title bar.
                drawTitleArea(g, rectClient);

                StringFormat format = new StringFormat();
                format.Alignment     = StringAlignment.Near;
                format.LineAlignment = StringAlignment.Center;

                //	Fill in the Cells
                for (int row = 0; row < model.NumberOfRows; row++)
                {
                    for (int col = 0; col < model.NumberOfColumns; col++)
                    {
                        Rectangle rect = Rectangle.FromLTRB(xCoords[col], yCoords[row],
                                                            xCoords[col + 1], yCoords[row + 1]);

                        YearChartCell day = model.Cells[col, row];
                        if (day == null || day.type == CellType.Blank)
                        {
                            g.FillRectangle(brushBlank, rect);
                        }
                        else if (day.type == CellType.Heading)
                        {
                            g.FillRectangle(brushHeading, rect);
                            g.DrawString(day.text, fontHeading, brushFore, rect, format);
                        }
                        else if (day.type == CellType.Weekday)
                        {
                            //e.Graphics.FillRectangle( brushBack, rect );
                            g.DrawString(day.text, Font, brushFore, rect, format);
                        }
                        else if (day.type == CellType.Weekend)
                        {
                            g.FillRectangle(brushWeekend, rect);
                            g.DrawString(day.text, Font, brushFore, rect, format);
                        }
                    }
                }

                drawGrid(g);

                Debug.WriteLine("");
            }

            g.Flush();
        }
Пример #2
0
        /// <summary>
        /// Write the model as HTML to the output stream.
        /// </summary>
        /// <param name="stream">The output stream where the HTML will be written.</param>
        public void Write(Stream stream)
        {
            //  28592              iso-8859-2                   Central European (ISO)
            //  28591              iso-8859-1                   Western European (ISO)
            //  65001              utf-8                        Unicode (UTF-8)
            //  from http://msdn.microsoft.com/en-us/library/system.text.encodinginfo.getencoding.aspx

            //  Create a writer to output to a UTF-8 encoding (code page 65001).
            using (StreamWriter writer = new StreamWriter(stream, System.Text.Encoding.GetEncoding(65001)))
            {
                //TODO: Internationalise this part.
                writer.WriteLine("<html lang=\"en-GB\">");
                writer.WriteLine("<head>");
                writer.WriteLine("	<meta charset=\"UTF-8\">");
                writer.WriteLine("	<title>"+ model.Title + " | www.kajabity.com</title>");
                writer.WriteLine("	<meta name=\"generator\" content=\"Kajabity "+ Application.ProductName + " version " + Application.ProductVersion + "\">");
                writer.WriteLine("	<style type=\"text/css\">");
                writer.WriteLine("	body { font-family: Arial, Helvetica, sans-serif; }");
                writer.WriteLine("	#header { height: 40px; }");
                writer.WriteLine("	#link { float: left; vertical-align:bottom; }");
                writer.WriteLine("	#year { float: right;  clear:none;}");
                writer.WriteLine("	#title { text-align:center; clear:none; width: 50%; }");
                writer.WriteLine("	table { background-color:black; border: 2px solid; width: 100%; }");
                int cellWidthPercent = 100 / model.NumberOfColumns;
                //TODO: correct for rounding errors - for left headings, calculate by subtracting width of n-1 columns.
                writer.WriteLine("	th { text-align:left; background-color:yellow; padding: 0; width: "+ cellWidthPercent + "%; }");
                writer.WriteLine("	.thick-left { border-left:2px solid; }");
                writer.WriteLine("	.thick-right { border-right: 2px solid; }");
                writer.WriteLine("	.thick-top { border-top:2px solid; }");
                writer.WriteLine("	.thick-bottom { border-bottom: 2px solid; }");
                writer.WriteLine("	td { background-color:white; padding: 1; width: "+ cellWidthPercent + "%; }");
                writer.WriteLine("	.empty { background-color:silver; }");
                writer.WriteLine("	.weekend { background-color:orange; }");
                writer.WriteLine("	</style>");
                writer.WriteLine("</head>");

                writer.WriteLine("<body>");

                writer.WriteLine("<div id=\"header\">");
                writer.WriteLine("	<div id=\"link\"><a href=\"http://www.kajabity.com\">www.kajabity.com</a></div>");
                writer.WriteLine("	<div id=\"title\"><h1>"+ model.Title + "</h1></div>");

                //TODO: This is common code - need to extract into a shared class.
                string year = model.Year.ToString();
                if (model.EndDate.Year > model.StartDate.Year)
                {
                    year = year + "-" + model.EndDate.Year;
                }

                writer.WriteLine("	<div id=\"year\">"+ year + "</div>");
                writer.WriteLine("</div>");
                writer.WriteLine("<table>");

                //	Fill in the Cells
                for (int row = 0; row < model.NumberOfRows; row++)
                {
                    writer.WriteLine("	<tr>");
                    for (int col = 0; col < model.NumberOfColumns; col++)
                    {
                        YearChartCell day = model.Cells[col, row];
                        //TODO: Internationalise this part.
                        //TODO: Calculate day text with excaped HTML syntax.
                        //TODO: Calculate cell style - perhaps use Table level style instead.  Or row/column level style...  Specifically the border thicknesses.
                        if (day == null || day.type == CellType.Blank)
                        {
                            writer.WriteLine("		<td class=\"empty\"></td>");
                        }
                        else if (day.type == CellType.Heading)
                        {
                            writer.WriteLine("		<th class=\"\">"+ day.text + "</th>");
                        }
                        else if (day.type == CellType.Weekday)
                        {
                            writer.WriteLine("		<td class=\"\">"+ day.text + "</td>");
                        }
                        else if (day.type == CellType.Weekend)
                        {
                            writer.WriteLine("		<td class=\"weekend\">"+ day.text + "</td>");
                        }
                        else if (day.type == CellType.Extra)
                        {
                            writer.WriteLine("		<td class=\"\">"+ day.text + "</td>");
                        }
                    }

                    writer.WriteLine("	</tr>");
                }

                writer.WriteLine("</table>");
                writer.WriteLine("</body>");

                writer.WriteLine("</html>");
                writer.Close();
            }
        }