using System;
using System.Collections;
using System.Data;
using System.Data.OleDb;namespace dongleo_v3.Components
{
/// <summary>
/// BlogCalendar 的摘要说明。
///冬雷物语
///http://www.dongleo.com
/// 2004-12-5
/// </summary>
public class BlogCalendar
{
protected Db_Conn myDb_Conn=new Db_Conn();
public BlogCalendar()
{
//
// TODO: 在此处添加构造函数逻辑
// }
public void MakeBlogCalendar()
{
string ca_bg_color = "#c8ccc8";//日历背景即边线颜色
string ca_head_color = "#a8a8a8";//头部颜色
string ca_week_color = "#f0f0f0";//星期栏颜色
string ca_day_color = "#ffffff";//主背景色
string ca_nowday_color = "#f0f0f0";//按日查看时所查看日的颜色
string ca_today_color = "#c8c8c8";//今天的颜色
// string[,] linkdays = new string[2,0];
// int linkcount = 0;
int c_year,c_month,c_day;//日历年月日
System.DateTime moment = System.DateTime.Now;//取得当前时间
//取得QueryString,判断年
if (System.Web.HttpContext.Current.Request.QueryString["l_year"] == null || System.Web.HttpContext.Current.Request.QueryString["l_year"] == "")
c_year = System.Convert .ToInt32 (moment.Year.ToString());
else
c_year = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_year"]);
//取得QueryString,判断月
if (System.Web.HttpContext.Current.Request.QueryString["l_month"] == null || System.Web.HttpContext.Current.Request.QueryString["l_month"] == "")
c_month = System.Convert .ToInt32 (moment.Month.ToString());
else
c_month = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_month"]);
//取得QueryString,判断日
if (System.Web.HttpContext.Current.Request.QueryString["l_day"] == null || System.Web.HttpContext.Current.Request.QueryString["l_day"] == "")
c_day = 0;
else
c_day = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_day"]);
// System.Web.HttpContext.Current.Response.Write(c_year);
// System.Web.HttpContext.Current.Response.Write(c_month);
// System.Web.HttpContext.Current.Response.Write(c_day);
//添加连接
string strSel = "SELECT log_PostDay,log_PostMonth,log_PostYear FROM dl_Content WHERE log_PostYear="+c_year+" and log_PostMonth="+c_month+"";
myDb_Conn.Conn_Open();
OleDbCommand myCommand = new OleDbCommand( strSel, myDb_Conn.Conn );
// OleDbDataAdapter myDbAdapter = new OleDbDataAdapter ();
// myDbAdapter.SelectCommand = myCommand;
// myDbAdapter.Fill (myDb_Conn.myDataSet,"d_detail");
// System.Web.HttpContext.Current.Response.Write(myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostMonth"].ToString());
// if(myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostDay"].ToString() != theday)
// theday = myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostDay"].ToString();
// System.Web.HttpContext.Current.Response.Write(theday);
OleDbDataReader myReader = myCommand.ExecuteReader();
string theday = "0";
// while (myReader.Read())
// {
// if((myReader["log_PostDay"].ToString()) != theday )
// theday = myReader["log_PostDay"].ToString();
// System.Web.HttpContext.Current.Response.Write(theday);
// string[,] linkdays = new string[2,linkcount];
// linkdays[0,linkcount] = myReader["log_PostMonth"].ToString();
// linkdays[1,linkcount] = myReader["log_PostDay"].ToString();
// linkdays[2,linkcount] = "default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"";
// linkcount++;
// }
ArrayList ar2=new ArrayList();
while (myReader.Read ())
{
if((myReader["log_PostDay"].ToString()) != theday )
theday = myReader["log_PostDay"].ToString();
ArrayList ar1=new ArrayList();
ar1.Add(myReader["log_PostMonth"].ToString());
ar1.Add(myReader["log_PostDay"].ToString());
ar1.Add("default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"");
// for(int i=0;i<3;i++)
// {
// ar1.Add(myReader[i]);
// }
ar2.Add(ar1);
// string[] linkcount = new string[3];
// linkcount[0] = myReader["log_PostMonth"].ToString();
// linkcount[1] = myReader["log_PostDay"].ToString();
// linkcount[2] = "default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"";
// for(int i=0;i<3;i++)
// {
// ar2.Add(linkcount[i]);
// }
}
// for(int i=0;i<ar2.Count;i++)
// for(int j=0;j<((ArrayList)ar2[i]).Count;j++)
// {
//
// System.Web.HttpContext.Current.Response.Write(((ArrayList)ar2[i])[j]);
// System.Web.HttpContext.Current.Response.Write("<br>");
// }
myReader.Close();
myDb_Conn.Conn_Close(); ///////////
string[] mname = new string[13];
mname[0] = "";
mname[1]="January ";
mname[2]="February ";
mname[3]="Mar.";
mname[4]="April ";
mname[5]="May ";
mname[6]="June ";
mname[7]="July ";
mname[8]="August ";
mname[9]="September ";
mname[10]="October ";
mname[11]="November ";
mname[12]="December ";
int[] mdays = new int[13];
mdays[0]=0;
mdays[1]=31;
mdays[2]=28;
mdays[3]=31;
mdays[4]=30;
mdays[5]=31;
mdays[6]=30;
mdays[7]=31;
mdays[8]=31;
mdays[9]=30;
mdays[10]=31;
mdays[11]=30;
mdays[12]=31;
using System.Collections;
using System.Data;
using System.Data.OleDb;namespace dongleo_v3.Components
{
/// <summary>
/// BlogCalendar 的摘要说明。
///冬雷物语
///http://www.dongleo.com
/// 2004-12-5
/// </summary>
public class BlogCalendar
{
protected Db_Conn myDb_Conn=new Db_Conn();
public BlogCalendar()
{
//
// TODO: 在此处添加构造函数逻辑
// }
public void MakeBlogCalendar()
{
string ca_bg_color = "#c8ccc8";//日历背景即边线颜色
string ca_head_color = "#a8a8a8";//头部颜色
string ca_week_color = "#f0f0f0";//星期栏颜色
string ca_day_color = "#ffffff";//主背景色
string ca_nowday_color = "#f0f0f0";//按日查看时所查看日的颜色
string ca_today_color = "#c8c8c8";//今天的颜色
// string[,] linkdays = new string[2,0];
// int linkcount = 0;
int c_year,c_month,c_day;//日历年月日
System.DateTime moment = System.DateTime.Now;//取得当前时间
//取得QueryString,判断年
if (System.Web.HttpContext.Current.Request.QueryString["l_year"] == null || System.Web.HttpContext.Current.Request.QueryString["l_year"] == "")
c_year = System.Convert .ToInt32 (moment.Year.ToString());
else
c_year = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_year"]);
//取得QueryString,判断月
if (System.Web.HttpContext.Current.Request.QueryString["l_month"] == null || System.Web.HttpContext.Current.Request.QueryString["l_month"] == "")
c_month = System.Convert .ToInt32 (moment.Month.ToString());
else
c_month = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_month"]);
//取得QueryString,判断日
if (System.Web.HttpContext.Current.Request.QueryString["l_day"] == null || System.Web.HttpContext.Current.Request.QueryString["l_day"] == "")
c_day = 0;
else
c_day = System.Convert .ToInt32 (System.Web.HttpContext.Current.Request.QueryString["l_day"]);
// System.Web.HttpContext.Current.Response.Write(c_year);
// System.Web.HttpContext.Current.Response.Write(c_month);
// System.Web.HttpContext.Current.Response.Write(c_day);
//添加连接
string strSel = "SELECT log_PostDay,log_PostMonth,log_PostYear FROM dl_Content WHERE log_PostYear="+c_year+" and log_PostMonth="+c_month+"";
myDb_Conn.Conn_Open();
OleDbCommand myCommand = new OleDbCommand( strSel, myDb_Conn.Conn );
// OleDbDataAdapter myDbAdapter = new OleDbDataAdapter ();
// myDbAdapter.SelectCommand = myCommand;
// myDbAdapter.Fill (myDb_Conn.myDataSet,"d_detail");
// System.Web.HttpContext.Current.Response.Write(myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostMonth"].ToString());
// if(myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostDay"].ToString() != theday)
// theday = myDb_Conn.myDataSet.Tables["d_detail"].Rows[0]["log_PostDay"].ToString();
// System.Web.HttpContext.Current.Response.Write(theday);
OleDbDataReader myReader = myCommand.ExecuteReader();
string theday = "0";
// while (myReader.Read())
// {
// if((myReader["log_PostDay"].ToString()) != theday )
// theday = myReader["log_PostDay"].ToString();
// System.Web.HttpContext.Current.Response.Write(theday);
// string[,] linkdays = new string[2,linkcount];
// linkdays[0,linkcount] = myReader["log_PostMonth"].ToString();
// linkdays[1,linkcount] = myReader["log_PostDay"].ToString();
// linkdays[2,linkcount] = "default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"";
// linkcount++;
// }
ArrayList ar2=new ArrayList();
while (myReader.Read ())
{
if((myReader["log_PostDay"].ToString()) != theday )
theday = myReader["log_PostDay"].ToString();
ArrayList ar1=new ArrayList();
ar1.Add(myReader["log_PostMonth"].ToString());
ar1.Add(myReader["log_PostDay"].ToString());
ar1.Add("default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"");
// for(int i=0;i<3;i++)
// {
// ar1.Add(myReader[i]);
// }
ar2.Add(ar1);
// string[] linkcount = new string[3];
// linkcount[0] = myReader["log_PostMonth"].ToString();
// linkcount[1] = myReader["log_PostDay"].ToString();
// linkcount[2] = "default.aspx?l_year="+myReader["log_PostYear"].ToString()+"&l_month="+myReader["log_PostMonth"].ToString()+"&l_day="+myReader["log_PostDay"].ToString()+"";
// for(int i=0;i<3;i++)
// {
// ar2.Add(linkcount[i]);
// }
}
// for(int i=0;i<ar2.Count;i++)
// for(int j=0;j<((ArrayList)ar2[i]).Count;j++)
// {
//
// System.Web.HttpContext.Current.Response.Write(((ArrayList)ar2[i])[j]);
// System.Web.HttpContext.Current.Response.Write("<br>");
// }
myReader.Close();
myDb_Conn.Conn_Close(); ///////////
string[] mname = new string[13];
mname[0] = "";
mname[1]="January ";
mname[2]="February ";
mname[3]="Mar.";
mname[4]="April ";
mname[5]="May ";
mname[6]="June ";
mname[7]="July ";
mname[8]="August ";
mname[9]="September ";
mname[10]="October ";
mname[11]="November ";
mname[12]="December ";
int[] mdays = new int[13];
mdays[0]=0;
mdays[1]=31;
mdays[2]=28;
mdays[3]=31;
mdays[4]=30;
mdays[5]=31;
mdays[6]=30;
mdays[7]=31;
mdays[8]=31;
mdays[9]=30;
mdays[10]=31;
mdays[11]=30;
mdays[12]=31;
int today,tomonth,toyear;
today = System.Convert .ToInt32 (moment.Day.ToString());
tomonth = System.Convert .ToInt32 (moment.Month.ToString());
toyear = System.Convert .ToInt32 (moment.Year.ToString());
//指定的年月日及星期
int thismonth = c_month;
int thisdate = c_day;
int thisyear = c_year;
//判断闰年
if(((thisyear%4 == 0)&&(thisyear%100 != 0))||(thisyear%400 == 0))
mdays[2] = 29;
//确定日历1号的星期
int startspace = 0;
try
{
switch (DateTime.Parse(""+thisyear+"-"+thismonth+"-1").DayOfWeek.ToString())
{
case "Monday":
startspace = 1;
break;
case "Tuesday":
startspace = 2;
break;
case "Wednesday":
startspace = 3;
break;
case "Thursday":
startspace = 4;
break;
case "Friday":
startspace = 5;
break;
case "Saturday":
startspace = 6;
break;
case "Sunday":
startspace = 0;
break;
}
}
catch
{
System.Web.HttpContext.Current.Response.Write("你别瞎搞,有这一天吗?");
System.Web.HttpContext.Current.Response.End();
}
string ccode = "<table border='0' width='100%' cellspacing='1' cellpadding='1' bgcolor='"+ca_bg_color+"' class='caBox'>";
ccode = ccode+"<tr><td colspan='7' bgcolor='"+ca_head_color+"' style='color:#ffffff'><b></b></td></tr><tr>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>Su</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>M</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>Tu</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>W</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>Th</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>F</b></td>";
ccode = ccode+"<td align='center' bgcolor='"+ca_week_color+"'><b>Sa</b></td></tr><tr>";
for(int i=0;i<startspace;i++)
ccode = ccode+"<td bgcolor='"+ca_day_color+"'></td>";
int count = 1;
while (count<=mdays[thismonth])
{
for (int b=startspace;b<7;b++)
{
string thisbgcolor = ca_day_color;
if(count==today && thisyear==toyear && thismonth==tomonth)
thisbgcolor = ca_today_color;
if (count==thisdate)
thisbgcolor = ca_nowday_color;
ccode = ccode+"<td align='center' bgcolor='"+thisbgcolor+"'>";
string linktrue="false";
for (int c=0;c<ar2.Count;c++)
{
if (((ArrayList)ar2[c])[0].ToString()!="")
{
if (System.Convert.ToInt32(((ArrayList)ar2[c])[0].ToString())==thismonth&&System.Convert.ToInt32(((ArrayList)ar2[c])[1].ToString())==count)
{
ccode = ccode+"<a href='"+((ArrayList)ar2[c])[2].ToString()+"'><b>";
linktrue="true";
}
}
}
if (count<=mdays[thismonth])
ccode=ccode+count;
if (linktrue=="true")
ccode=ccode+"</a></b>";
ccode=ccode+"</td>"; count=count+1;
}
ccode=ccode+"</tr>";
startspace=0;
}
int nextmonth = c_month+1;
int nextyear = c_year;
if (nextmonth>12)
{
nextmonth=1;
nextyear=nextyear+1;
}
int promonth=c_month-1;
int proyear=c_year;
if (promonth<1)
{
promonth=12;
proyear=proyear-1;
}
ccode=ccode+"<tr><td colspan='7' bgcolor='"+ca_week_color+"' align='center'>";
ccode=ccode+"<a href='default.aspx?l_year="+proyear+"&l_month="+promonth+"'><</a><b> MONTH </b><a href='default.aspx?l_year="+nextyear+"&l_month="+nextmonth+"'>></a> <a href='default.aspx?l_year="+(c_year-1)+"&l_month="+c_month+"'><</a><b> YEAR </b><a href='default.aspx?l_year="+(c_year+1)+"&l_month="+c_month+"'>></a>";
ccode=ccode+"</tr></table>";
System.Web.HttpContext.Current.Response.Write(ccode); }
}
}//////////
好多注释掉的是我测试时的代码:)
参考了DUOLUO(猪飞飞)的ASP代码:)
///////
调用时:)
protected BlogCalendar myBC = new BlogCalendar();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
myBC.MakeBlogCalendar();
}
找找BUG:)
谢谢:)
还有谁愿意做ASP。NET下的BLOG可以与我联系:)
正在进行时:)
using System.Collections;
using System.Data;
using System.Data.OleDb;namespace dongleo_v3.Components
{
/// <summary>
/// Db_Conn 的摘要说明。
/// OLE Db数据库相关操作
/// 最后修改日期:2004-08-15
/// 类库相关版本:Version 0.1
/// </summary>
public class Db_Conn
{
public OleDbConnection Conn;
public DataSet myDataSet;
public Db_Conn()
{
Conn = new OleDbConnection();
myDataSet = new DataSet ();
}
private string GetConnStr()
{
string strConnection = "";
string dbname = ".\\database\\dongleolog.mdb";
strConnection = @"Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " + System.Web.HttpContext.Current.Server.MapPath (dbname) + ";";
return strConnection;
} public void Conn_Open()
{
string ConnStr = GetConnStr();
Conn.ConnectionString = ConnStr;
Conn.Open();
}
public void Conn_Close()
{
if(Conn != null)
Conn.Close();
}
}
}
数据访问层:)
BLOG还没做出来:(
没有下载地址:)