Tutorials to .com

Tutorials to .com » Dotnet » Control-and-components » Blog to your personalized calendar control to create

Blog to your personalized calendar control to create

Print View , by: iSee ,Total views: 10 ,Word Count: 1202 ,Date: Wed, 20 May 2009 Time: 7:01 PM

dotnet calendar control is one of self-control and powerful, in many projects have used for the blog system is essential. If it is good also need to cut and polish jade, in order to make it more beautiful and practical, we need it the second development.

The first step is to set the appearance, this according to your needs, just do it a number of adjustments related to property. The chart below is my revised interface



Property as follows: <asp: calendar id = "Calendar1" CellPadding = "2" Width = "160px" TitleStyle-BackColor = "# 000000" BorderColor = "# aaaaaa"
DayHeaderStyle-BackColor = "# 5e715e" OtherMonthDayStyle-ForeColor = "# cccccc" DayNameFormat = "Full"
runat = "server" TitleStyle-ForeColor = "# ffffff" NextPrevStyle-ForeColor = "# ffffff" CellSpacing = "1"
WeekendDayStyle-BackColor = "# eeeeee" DayHeaderStyle-ForeColor = "# ffffff" SelectionMode = "None"
TodayDayStyle-BorderColor = "# 5e715e" TodayDayStyle-BorderWidth = "1" TodayDayStyle-Font-Bold = "true"
TodayDayStyle-ForeColor = "# 5e715e">

The second step is the adjustment of the internal functions, this work focused on the handling of two events.

PreRender: when the server control that will be presented to include the occurrence of the Page object.

DayRender: When the controls for the Calendar control hierarchy in the creation of every day occurrence.

First definition of the three integer variables and integer array
private int [] arrCurrentDays, arrPreDays, arrNextDays; / / three variables are the current month, previous month and next month
private int intCurrentMonth, intPreMonth, intNextMonth; / / integer array stored comparative three month of the date written on blog
protected System.Web.UI.WebControls.Calendar Calendar1; / / this is our control of the calendar

2. Now I will give the source of these two events, and explained in the following functions to achieve it, if you do not understand, you can look at the following description of

PreRender
private void Calendar1_PreRender (object sender, System.EventArgs e)
(
Thread threadCurrent = Thread.CurrentThread;
CultureInfo ciNew = (CultureInfo) threadCurrent.CurrentCulture.Clone ();
ciNew.DateTimeFormat.DayNames = new string [] ( "date" and "one", "b", "c", "four" and "five", "six");
ciNew.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Sunday;
threadCurrent.CurrentCulture = ciNew;
)

The above code has changed the name of the show week. You just need to change the value of an array of characters will be able to change the name displayed.

DayRender
private void Calendar1_DayRender (object sender, System.Web.UI.WebControls.DayRenderEventArgs e)
(
/ / The control occurred in the creation of each day.

CalendarDay d = ((DayRenderEventArgs) e). Day;
TableCell c = ((DayRenderEventArgs) e). Cell;

/ / Initialize the current month of the date of the array Blog
if (intPreMonth == 0)
(
intPreMonth = d.Date.Month; / / Note: The calendar control is initialized, we do not get the first month of the current month, but the month of the previous month
intCurrentMonth = intPreMonth +1;
if (intCurrentMonth> 12)
intCurrentMonth = 1;
intNextMonth = intCurrentMonth +1;
if (intNextMonth> 12)
intNextMonth = 1;
arrPreDays = getArrayDay (d.Date.Year, intPreMonth); / / get the previous month of the date of the array blog
arrCurrentDays = getArrayDay (d.Date.Year, intCurrentMonth); / / get the date of the month there is an array blog
arrNextDays = getArrayDay (d.Date.Year, intNextMonth); / / get the date of the next month there is an array blog
)

int j = 0;
if (d.Date.Month.Equals (intPreMonth))
(
while (! arrPreDays [j]. Equals (0))
(
if (d.Date.Day.Equals (arrPreDays [j]))
(
c.Controls.Clear ();
c.Controls.Add (new LiteralControl ( "<a href = day.aspx? year =" + d.Date.Year + "& month =" +
d.Date.Month + "& day =" + d.Date.Day +">"+ d.Date.Day + "</ a >"));
)
j + +;
)
)
else if (d.Date.Month.Equals (intCurrentMonth))
(
while (! arrCurrentDays [j]. Equals (0))
(
if (d.Date.Day.Equals (arrCurrentDays [j]))
(
c.Controls.Clear ();
c.Controls.Add (new LiteralControl ( "<a href = day.aspx? year =" + d.Date.Year + "& month =" +
d.Date.Month + "& day =" + d.Date.Day +">"+ d.Date.Day + "</ a >"));
)
j + +;
)
)
else if (d.Date.Month.Equals (intNextMonth))
(
while (! arrNextDays [j]. Equals (0))
(
if (d.Date.Day.Equals (arrNextDays [j]))
(
c.Controls.Clear ();
c.Controls.Add (new LiteralControl ( "<a href = day.aspx? year =" + d.Date.Year + "& month =" +
d.Date.Month + "& day =" + d.Date.Day +">"+ d.Date.Day + "</ a >"));
)
j + +;
)
)
)

The date of a page can control the three month period showed that the current month is complete, the previous month and the next part of the date of January. Initialization event DayRender specific date is displayed here on the blog we have to content with the date hyperlink. So we need to initialize the array to be three, respectively in the storage array for three consecutive months of the date written blog. Followed by comparison with the current date, then add the same link.

DayRender events in the use, you must not forget the date in each of the implementation of an initialization, which means that a calendar control to initialize this event to be performed 42 times, so as far as possible to simplify the operation, not to be judged not to repeat the operation of the database, I did not pay attention to the beginning, in the case, wrote two years time the Treasury statement, the result of serious impact on performance.

The following method is used to obtain the date of my array.
/ / Get the month of the date of the array blog
private int [] getArrayDay (int intYear, int intMonth)
(
int [] intArray = new int [31];
/ / From the database to meet the requirements to select records, the date deposited in the array
string strSql = "select content_time from content where year (content_time) =" + intYear +
"And month (content_time) =" + intMonth;
dr = SqlHandle.GetDr (strSql);
while (dr.Read ())
(
if (i == 0)
(
intArray [i] = dr.GetDateTime (0). Day;
i + +;
)
else if (dr.GetDateTime (0). Day! = intArray [i-1])
(
intArray [i] = dr.GetDateTime (0). Day;
i + +;
)
)
dr.Close ();
return intArray;
)

Specific results can go to my blog to see: www.dever.cn


.Net Control and components Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.