asp.net flow statistics picture display

Source: Internet
Author: User
Tags datetime trim

<%@ Page language= "C #" autoeventwireup= "true" codefile= "default2.asp tutorial X.cs" inherits= "DEFAULT2"%>

<! DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 transitional//en" "Http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">

<title> Untitled Page </title>
<body>
<form id= "Form1" runat= "Server" >
<div>
</div>
</form>
</body>

Pic.aspx.cs file

Using System;
Using System.Collections;
Using System.Configuration;
Using System.Data;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.HtmlControls;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Drawing;
Using System.Drawing.Drawing2D;
Using System.Drawing.Imaging;
Using System.IO;
Using System.Data.OleDb;

public partial class _default:system.web.ui.page


{


protected void Page_Load (object sender, EventArgs e)


{


Open Total Count


string Tongji = null;


String strcmd = "Select Tongji from Tong Where userid= ' + request[" U "]. Trim () + "'";


OleDbDataReader SDR = Exceread (strcmd);


if (SDR). Read ())


{


Tongji = sdr["Tongji"]. ToString ();


}


Sdr. Close ();


Sdr. Dispose ();


Statistics and updates


DateTime dt = DateTime.Now;


Dosql ("Delete from Tongji where DSJ &lt; #" + DateTime.Now.AddDays (-3). ToString () + "#");


Dosql ("Update tong set tongji=tongji+1 where userid= '" + request["U"]. Trim () + "'");


Dosql ("INSERT into Tongji (IP,SJ,USERID,DSJ) VALUES (' + request.userhostaddress +" ', ' "+ dt.) ToShortDateString (). ToString () + "', '" + request["U"]. Trim () + "', '" + dt + "')";


String j = Judge_repeat ("Select Count (ID) as ID" from Tongji Where userid= ' "+ request[" U "). Trim () + "' and sj= '" + dt. ToShortDateString (). ToString () + "'");


String z = Judge_repeat ("Select Count (ID) as ID" from Tongji Where userid= ' "+ request[" U "). Trim () + "' and sj= '" + DateTime.Now.AddDays (-1). ToShortDateString () + "'");


The following is the display counter


System.Drawing.Bitmap bmp = new Bitmap (bitmap.fromfile server.mappath ("2.gif"))/Load Picture


System.Drawing.Graphics g = graphics.fromimage (BMP);


g.DrawString ("" + j + "Times", New Font ("Song Body", 9), New SolidBrush (color.red), 65, 9);


g.DrawString ("" + z + "Times", New Font ("Song Body", 9), New SolidBrush (color.red), 65, 26);


g.DrawString ("" + Tongji + "Times", New Font ("Song Body", 9), New SolidBrush (color.red), 67, 42);


Select text Font color here


G.dispose ();


Output GIF, you want other formats can also change their own


Response.ContentType = "Image/gif";


Bmp. Save (Response.outputstream, System.Drawing.Imaging.ImageFormat.Gif);


}


Use #region Add, delete, update


&lt;summary&gt;


Use when performing additions, deletions, updates


&lt;/summary&gt;


public void Dosql (String sql)//is used when performing add, delete, update


{


String constring = Server.MapPath ("app_data/panpao.accdb");


constring = "Provider=microsoft.ace.oledb.12.0;data source=" + constring;


OleDbConnection oldcon = new OleDbConnection (constring);


Oldcon.open ();


OleDbCommand cmd = new OleDbCommand (sql, Oldcon);

        cmd. ExecuteNonQuery ();//
        oldcon.close ();//Close Database tutorial
         Oldcon.dispose ();
   }
    #endregion
    #region Returns a SqlDataReader type data
    public OleDbDataReader exceread (String strcom)//The method returns a SqlDataReader type
    {
         string constring = Server.MapPath ("app_data/panpao.accdb");
        constring = "Provider=microsoft.ace.oledb.12.0;data source=" + constring;
        OleDbConnection oldcon = new OleDbConnection (constring);
        Oldcon.open ();
        OleDbCommand sqlCmd = new OleDbCommand (strcom, Oldcon);

OleDbDataReader SDR = Sqlcmd.executereader (commandbehavior.closeconnection);


Return to SDR;


Oldcon.close ()//Close Database


Oldcon.dispose ();


}


#endregion


Returns a value #region the execution database


public string Judge_repeat (string sql_str)


{//The number returned in the table


String constring = Server.MapPath ("app_data/panpao.accdb");


constring = "Provider=microsoft.ace.oledb.12.0;data source=" + constring;


OleDbConnection oldcon = new OleDbConnection (constring);


Oldcon.open ();


OleDbCommand Command = new OleDbCommand (SQL_STR, Oldcon);


OleDbDataReader Dr = Command.ExecuteReader (commandbehavior.closeconnection);


Try


{


Dr.read ();


Return dr[0]. ToString ();


}


catch (Exception err)


{


Return "";


}


Finally


{


Dr.close ();


Dr.dispose ();


Oldcon.close ()//Close Database


Oldcon.dispose ();


}


}


#endregion


}

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.