Asp.net traffic statistics Image Display

Source: Internet
Author: User

<% @ 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">

<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head runat = "server">
<Title> No title page </title>
</Head>
<Body>
<Form id = "form1" runat = "server">
<Div>
</div>
</Form>
</Body>
</Html>

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)
{
// Total number of opened
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 <#" + 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. tow.datestring (). toString () + "','" + Request ["u"]. trim () + "','" + dt + "')");
String j = Judge_Repeat ("select Count (id) As id from tongji Where userid = '" + Request ["u"]. trim () + "'and sj ='" + dt. tow.datestring (). 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 shows the counter
System. Drawing. Bitmap bmp = new Bitmap (Bitmap. FromFile (Server. MapPath ("2.gif"); // load the image
System. Drawing. Graphics g = Graphics. FromImage (bmp );
G. DrawString ("" + j + "Times", new Font ("", 9), new SolidBrush (Color. Red), 65, 9 );
G. DrawString ("" + z + "Times", new Font ("", 9), new SolidBrush (Color. Red), 65, 26 );
G. DrawString ("" + tongji + "", new Font ("", 9), new SolidBrush (Color. Red), 67, 42 );
// Select the text font color
G. Dispose ();
// Output GIF. You can change it if you want other formats.
Response. ContentType = "image/gif ";
Bmp. Save (Response. OutputStream, System. Drawing. Imaging. ImageFormat. Gif );
}
# Use this function when adding, deleting, and updating region
/// <Summary>
/// Run add, delete, and update operations.
/// </Summary>
Public void DoSql (string SQL) // used for adding, deleting, and updating operations
{
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 (); // closes the database tutorial
OldCon. Dispose ();
}
# Endregion
# Region returns a SqlDataReader type data
Public OleDbDataReader ExceRead (string strCom) // This 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 sdr;
OldCon. Close (); // Close the database
OldCon. Dispose ();
}
# Endregion
# Region execution database returns a value
Public string Judge_Repeat (string SQL _str)
{// Determine the number returned from 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 the 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.