⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 countmonth.aspx.cs

📁 这是asp.net^和Visual C++Sharp编写的串并口通讯的书籍 源代码
💻 CS
字号:
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Drawing;

public partial class _Default : System.Web.UI.Page 
{
    protected void Page_Load(object sender, EventArgs e)
    {
        int Year = Convert.ToInt32(Request["ShowYear"].ToString());
        this.CreateImage(Year);
    }
    private void CreateImage(int Year)
    {
        int height = 380, width = 570;
        System.Drawing.Bitmap image = new System.Drawing.Bitmap(width,height);
        //创建Graphics类对象
        Graphics g = Graphics.FromImage(image);

        try
        {
            //清空图片背景色
            g.Clear(Color.White);

            Font font = new System.Drawing.Font("Arial", 9,FontStyle.Regular);
            Font font1 = new System.Drawing.Font("宋体", 20, FontStyle.Regular);

            System.Drawing.Drawing2D.LinearGradientBrush brush = new System.Drawing.Drawing2D.LinearGradientBrush(new Rectangle(0, 0, image.Width, image.Height), Color.Blue,Color.Blue, 1.2f, true);
            g.FillRectangle(Brushes.WhiteSmoke, 0, 0, width, height);
            Brush brush1 = new SolidBrush(Color.Blue);

            g.DrawString(""+Year+"年各月份网站流量统计", font1, brush1, new PointF(130, 30));
            //画图片的边框线
            g.DrawRectangle(new Pen(Color.Blue), 0,0, image.Width - 1, image.Height - 1);

            Pen mypen = new Pen(brush,1);
            //绘制线条
            //绘制横向线条
            int x = 100;
            for (int i = 0; i < 11; i++)
            {
                g.DrawLine(mypen,x, 80, x, 340);
                x = x + 40;
            }
            Pen mypen1 = new Pen(Color.Blue,2);
            g.DrawLine(mypen1, x-480, 80, x-480, 340);

            //绘制纵向线条
            int y = 106;
            for (int i = 0; i < 9; i++)
            {
                g.DrawLine(mypen,60, y, 540, y);
                y = y + 26;
            }
            g.DrawLine(mypen1, 60, y, 540, y);

            //x轴
            String[] n = {"  一月", "  二月", "  三月", "  四月", "  五月", "  六月", "  七月",
                     "  八月", "  九月", "  十月", "十一月", "十二月"};
            x = 62;
            for (int i = 0; i < 12; i++)
            {
                g.DrawString(n[i].ToString(),font,Brushes.Red, x, 348); //设置文字内容及输出位置
                x = x + 40;
            }

            //y轴
            String[] m = {"7500", "6750", "6000", "5250", "4500", "3750", "3000",
                     "2250", "1500", "750"};
            y = 72;
            for (int i = 0; i < 10; i++)
            {
                g.DrawString(m[i].ToString(),font, Brushes.Red, 25, y); //设置文字内容及输出位置
                y = y + 26;
            }

            int[] Count = new int[12];
            string cmdtxt2 = "SELECT * FROM 访问量表 WHERE ShowYear=" + Year + "";
            SqlConnection Con = new SqlConnection(ConfigurationManager.AppSettings["ConSql"]);
            Con.Open();
            SqlCommand Com = new SqlCommand(cmdtxt2, Con);
            SqlDataAdapter da = new SqlDataAdapter();
            da.SelectCommand = Com;
            DataSet ds = new DataSet();
            da.Fill(ds);
            int j = 0;
            //int number = SumYear(Year);
            for(j=0;j<12;j++)
            {
                Count[j] = Convert.ToInt32(ds.Tables[0].Rows[0][j+1].ToString());
            }
            //显示柱状效果
            x = 70;
            for (int i = 0; i < 12; i++)
            {
                SolidBrush mybrush = new SolidBrush(Color.Red);
                g.FillRectangle(mybrush, x, 340 - Count[i] * 26 / 750, 20, Count[i] * 26 / 750);
                x = x + 40;
            }

            System.IO.MemoryStream ms = new System.IO.MemoryStream();
            image.Save(ms, System.Drawing.Imaging.ImageFormat.Gif);
            Response.ClearContent();
            Response.ContentType = "image/Gif";
            Response.BinaryWrite(ms.ToArray());
        }
        finally
        {
            g.Dispose();
            image.Dispose();
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -