Create Page Counter
counter.ascx
<table class="gridview">
<tr>
<th colspan="3">
Internal Customer Count
</th>
<th colspan="3">
External Customer Count
</th>
<th colspan="3">
Total Customer Count
</th>
</tr>
<tr>
<td>
This Year
</td>
<td>
This Month
</td>
<td>
This Day
</td>
<td>
This Year
</td>
<td>
This Month
</td>
<td>
This Day
</td>
<td>
Internal Total
</td>
<td>
External Total
</td>
<td>
Total
</td>
</tr>
<tr>
<td>
<asp:Label ID="lbliyear"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblimonth"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbliday"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbleyear"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblemonth"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbleday"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lblitotal"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbletotal"
runat="server"></asp:Label>
</td>
<td>
<asp:Label ID="lbltotal"
runat="server"></asp:Label>
</td>
</tr>
</table>
counter.ascx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Net.Sockets;
using System.Data;
using DAL;
string UserIP = string.Empty;
public partial class counter :
System.Web.UI.UserControl
{
string visitorIPAddress = "";
DataTable objdt = new
DataTable();
DbManager
odal = new DbManager();
protected void
Page_Load(object sender, EventArgs e)
{
try
{
objdt = odal.Selectdt("Select * from
counter");
UserIP =
Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (UserIP == ""
|| UserIP == null)
{
UserIP = Request.ServerVariables["REMOTE_ADDR"];
}
bool ip = IsInRange("10.*.*.*",
"10.*.*.*", UserIP);
if (ip)
{
odal.IUD("update counter set
Int_Cust_Visit_Count=Int_Cust_Visit_Count+1 Where Param_Id='total'");
if (objdt.Rows[1]["Param_Value"].ToString() == DateTime.Now.Year.ToString())
{
odal.IUD("update counter set Int_Cust_Visit_Count=Int_Cust_Visit_Count+1
where Param_Value='" + DateTime.Now.Year
+ "'");
}
else
{
odal.IUD("update counter set
Int_Cust_Visit_Count=1,value ='" + DateTime.Now.Year
+ "' where Param_Id='year'");
}
if (objdt.Rows[2]["Param_Value"].ToString() == DateTime.Now.Month.ToString())
{
odal.IUD("update counter set
Int_Cust_Visit_Count=Int_Cust_Visit_Count+1 where Param_Value='" + DateTime.Now.Month + "'");
}
else
{
odal.IUD("update counter set
Int_Cust_Visit_Count=1,value ='" + DateTime.Now.Month
+ "' where Param_Id='month'");
}
if (objdt.Rows[3]["Param_Value"].ToString() == DateTime.Now.Day.ToString())
{
odal.IUD("update counter set
Int_Cust_Visit_Count=Int_Cust_Visit_Count+1 where Param_Value='" + DateTime.Now.Day + "'");
}
else
{
odal.IUD("update counter set
Int_Cust_Visit_Count=1,value ='" + DateTime.Now.Day
+ "' where Param_Id='day'");
}
}
else
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=Ext_Cust_Visit_Count+1 Where Param_Id='total'");
if (objdt.Rows[1]["Param_Value"].ToString() == DateTime.Now.Year.ToString())
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=Ext_Cust_Visit_Count+1 where Param_Value='" + DateTime.Now.Year + "'");
}
else
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=1,value ='" + DateTime.Now.Year
+ "' where Param_Id='year'");
}
if (objdt.Rows[2]["Param_Value"].ToString() == DateTime.Now.Month.ToString())
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=Ext_Cust_Visit_Count+1 where Param_Value='" + DateTime.Now.Month + "'");
}
else
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=1,value ='" + DateTime.Now.Month
+ "' where Param_Id='month'");
}
if (objdt.Rows[3]["Param_Value"].ToString() == DateTime.Now.Day.ToString())
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=Ext_Cust_Visit_Count+1 where Param_Value='" + DateTime.Now.Day + "'");
}
else
{
odal.IUD("update counter set
Ext_Cust_Visit_Count=1,value ='" + DateTime.Now.Day
+ "' where Param_Id='day'");
}
}
bind();
}
catch (Exception
ex)
{
}
}
//For Check The Range Of IP Address
public static bool IsInRange(string
startIpAddr, string endIpAddr, string address)
{
long ipStart = BitConverter.ToInt32(IPAddress.Parse(startIpAddr).GetAddressBytes().Reverse().ToArray(),
0);
long ipEnd = BitConverter.ToInt32(IPAddress.Parse(endIpAddr).GetAddressBytes().Reverse().ToArray(),
0);
long ip = BitConverter.ToInt32(IPAddress.Parse(address).GetAddressBytes().Reverse().ToArray(),
0);
return ip >= ipStart && ip <= ipEnd; //edited
}
public void bind()
{
objdt
= odal.Selectdt("Select * from counter");
lbleday.Text = objdt.Rows[3]["Ext_Cust_Visit_Count"].ToString();
lblemonth.Text = objdt.Rows[2]["Ext_Cust_Visit_Count"].ToString();
lbleyear.Text = objdt.Rows[1]["Ext_Cust_Visit_Count"].ToString();
lbliday.Text = objdt.Rows[3]["Int_Cust_Visit_Count"].ToString();
lblimonth.Text = objdt.Rows[2]["Int_Cust_Visit_Count"].ToString();
lbliyear.Text = objdt.Rows[1]["Int_Cust_Visit_Count"].ToString();
lblitotal.Text = objdt.Rows[0]["Int_Cust_Visit_Count"].ToString();
lbletotal.Text = objdt.Rows[0]["Ext_Cust_Visit_Count"].ToString();
lbltotal.Text = (Convert.ToInt32(lblitotal.Text)
+ Convert.ToInt32(lbletotal.Text)).ToString();
}
}
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Default.aspx.cs"
Inherits="_Default"
%>
<%@ Register
src="counter.ascx"
tagname="counter"
tagprefix="uc1"
%>
<body>
<form id="form1" runat="server">
<div>
<uc1:counter ID="counter1"
runat="server"
/>
</div>
</form>
</body>
</html>
Comments
Post a Comment