Source code of datechooser-datachooserdesigner. CS

Source: Internet
Author: User

Using system;
Using system. Web. UI;
Using system. Web. UI. webcontrols;
Using system. Web. UI. design;
Using system. componentmodel. design;
Using system. componentmodel;

Namespace cnblogs. DCT. Thin. Design
{
/// <Summary>
/// Summary of datachooserdesigner.
/// </Summary>
Public class datachooserdesigner: controldesigner
{
Public datachooserdesigner ()
{
This. bfirsttime = true;
This. isdroppeddown = false;

This. showhidedropdown = new designerverb ("show/hide drop-down date box"), new eventhandler (this. onshowhidedropdownclick ));
This. About = new designerverb ("about", new eventhandler (this. onabloutclick ));
This. verbs = new designerverbcollection ();
}
Public override string getdesigntimehtml ()
{
String text1 = NULL;
If (base. Component = NULL) |! (Base. component is datechooser ))
{
Return base. getdesigntimehtml ();
}
Try
{
Datechooser chooser1 = (datechooser) base. component;
Controlcollection cc = chooser1.controls;
Text1 = base. getdesigntimehtml ();
If (chooser1.enableclientscript)
{
This. showhidedropdown. Visible = true;
If (this. isdroppeddown)
{
String lightcolor = chooser1.ccs (chooser1.lightcolor );
String midcolor = chooser1.ccs (chooser1.midcolor );
String darkcolor = chooser1.ccs (chooser1.darkcolor );
String bordercolor = chooser1.ccs (chooser1.bordercolor );
String currentback = chooser1.ccs (chooser1.currentbackcolor );
String currentfore = chooser1.ccs (chooser1.currentforecolor );
String todayback = chooser1.ccs (chooser1.todaybackcolor );
String todayfore = chooser1.ccs (chooser1.todayforecolor );
String otherback = chooser1.ccs (chooser1.otherbackcolor );
String otherfore = chooser1.ccs (chooser1.otherforecolor );
String monthback = chooser1.ccs (chooser1.monthbackcolor );
String monthfore = chooser1.ccs (chooser1.monthforecolor );
Bool showbtn = chooser1.showbutton;
Datetime selected;
Selected = (chooser1.selecteddate = "")? Datetime. Today: datetime. parse (chooser1.selecteddate );
If (selected = datetime. minvalue)
Selected = datetime. today;
Bool culturecn = chooser1.culture = culture. cn;
Bool allownull = chooser1.allownull;
Text1 = "<Table cellpadding = 0 cellspacing = 0 border = 0> <tr> <TD>" + text1 + "</TD> </tr> <TD> ";
Text1 + = getdropstring (lightcolor, midcolor, darkcolor, bordercolor, currentback, currentfore,
Todayback, todayfore, otherback, otherfore, monthfore, monthback, culturecn, selected, allownull) + "</TD> </tr> </table> ";
Return text1;
}
}
Else
{
This. showhidedropdown. Visible = false;
}
}
Catch (exception exception1)
{
Text1 = This. geterrordesigntimehtml (exception1 );
}
Return text1;
}
Private string getdropstring (string lightcolor, string midcolor, string darkcolor, string bordercolor, string currentback, string currentfore
, String todayback, string todayfore, string otherback, string otherfore, string monthfore, string monthback
, Bool culturecn, datetime selected, bool allownull)
{
String v = string. Format (@"
<Table Style = "" border-Right: {3} 1px solid; border-top: {3} 1px solid; display: block; font-size: 9pt; border-left: {3} 1px solid; cursor: default; border-bottom: {3} 1px solid; Height: 200px; Background-color: {0} "" border = 0> <tbody>
<Tr Height = 16>
<TD width = "" 100% "">
<Table cellspacing = 0 cellpadding = 0 width = "" 100% "" border = 0>
<Tbody>
<Tr>
<TD style = "" font-size: 9pt; cursor: hand; color: {2}; font-family: webdings "" width = "10%" "> 9 </TD>
<TD style = "" font-size: 9pt; cursor: hand; color: {2}; font-family: webdings "" width = "10%" "> 7 </TD>
<TD width = "" 30% ""> <SELECT> <option> 2000 </option> </SELECT> </TD>
<TD width = "" 30% ""> <SELECT> <option> Jan </option> </SELECT> </TD>
<TD style = "" font-size: 9pt; cursor: hand; color: {2}; font-family: webdings "" width = "10%" "> 8 </TD>
<TD style = "" font-size: 9pt; cursor: hand; color: {2}; font-family: webdings "" width = "" 10% "">: </TD> </tr> </tbody> </table> </TD> </tr>
<Tr Height = 2>
<TD align = middle colspan = 3>
<Div id = datachooser_separator style = "" font-size: 0px; border-bottom: {2} 1px solid ""> & nbsp; </div>
<Div style = "" border-top: # eeeeeeee 1px solid; font-size: 0px ""> & nbsp; </div> </TD> </tr>
<Tr>
<TD colspan = 3>
<Table id = datachooser_tabledays style = "" border-Right: {3} 1px solid; border-top: {3} 1px solid; border-left: {3} 1px solid; border-bottom: {3} 1px solid; border-collapse: collapse "" bordercolor = {3} Height = 124 width = 202 border = 1>
<Tbody>
<Tr style = "" font-weight: bold; color: {2}; font-family: fixedsys; Background-color: {1} ">
<TD align = middle> sun </TD>
<TD align = middle> mon </TD>
<TD align = middle> Tue </TD>
<TD align = middle> wed </TD>
<TD align = middle> Thu </TD>
<TD align = middle> Fri </TD>
<TD align = middle> sat </TD> </tr>
Createdays </tbody> </table> </TD> </tr>
<Tr>
<TD align = middle> <button id = datachooser_btntd hidefocus style = "" border-Right: {3} 1px outset; border-top: {3} 1px outset; font-size: 9pt; border-left: {3} 1px outset; width: 62px; cursor: hand; padding-top: 2px; border-bottom: {3} 1px outset; Background-color: {2} "" onfocus = blur ()> today </button> & nbsp; <button id = datachooser_btnbl hidefocus style = "" border-Right: {3} 1px outset; border-top: {3} 1px outset; font-size: 9pt; border-left: {3} 1px outset; width: 62px; cursor: hand; padding-top: 2px; border-bottom: {3} 1px outset; Background-color: {2} "" onfocus = blur ()> clear </button> & nbsp; <button id = datachooser_btnok hidefocus style = "" border-Right: {3} 1px outset; border-top: {3} 1px outset; font-size: 9pt; border-left: {3} 1px outset; width: 62px; cursor: hand; padding-top: 2px; border-bottom: {3} 1px outset; Background-color: {2} "" onfocus = blur ()> close </button> & nbsp; </TD> </tr> </tbody> </table> ", lightcolor, midcolor, darkcolor, bordercolor, currentback, todayback, otherfore, monthfore, culturecn );
If (! Allownull)
V = v. replace ("<button id = datachooser_btnbl hidefocus style = \" border-Right: "," <button id = datachooser_btnbl hidefocus style = \ "display: none; border-right: ");

If (culturecn)
{
V = V. Replace (@ "<TD align = middle> sun </TD>
<TD align = middle> mon </TD>
<TD align = middle> Tue </TD>
<TD align = middle> wed </TD>
<TD align = middle> Thu </TD>
<TD align = middle> Fri </TD>
<TD align = middle> sat </TD> ", @" <TD align = middle> day </TD>
<TD align = middle> 1 </TD>
<TD align = middle> 2 </TD>
<TD align = middle> 3 </TD>
<TD align = middle> 4 </TD>
<TD align = middle> 5 </TD>
<TD align = middle> 6 </TD> "). replace ("> today <", "> today <"). replace ("> clear <", "> clear <"). replace ("> close <", "> close <");
String month = "";
Switch (selected. month)
{
Case 1:
Month = "January"; break;
Case 2:
Month = "February"; break;
Case 3:
Month = "March"; break;
Case 4:
Month = "April"; break;
Case 5:
Month = "May"; break;
Case 6:
Month = "June"; break;
Case 7:
Month = "July"; break;
Case 8:
Month = "August"; break;
Case 9:
Month = "September"; break;
Case 10:
Month = "October"; break;
Case 11:
Month = "November"; break;
Case 12:
Month = "December"; break;
}
V = V. Replace ("<option> Jan </option>", "<option>" + month + "</option> ");
}
Else
{
String month = "";
Switch (selected. month)
{
Case 1:
Month = "Jan"; break;
Case 2:
Month = "FEB"; break;
Case 3:
Month = "Mar"; break;
Case 4:
Month = "APR"; break;
Case 5:
Month = "may"; break;
Case 6:
Month = "Jun"; break;
Case 7:
Month = "Jul"; break;
Case 8:
Month = "Aug"; break;
Case 9:
Month = "Sep"; break;
Case 10:
Month = "Oct"; break;
Case 11:
Month = "Nov"; break;
Case 12:
Month = "dec"; break;
}
V = V. Replace ("<option> Jan </option>", "<option>" + month + "</option> ");
}
V = V. Replace ("<option> 2000 </option>", "<option>" + selected. year. tostring () + "</option> ");
V = V. Replace ("createdays", createdays (selected, currentback, currentfore, todayback, todayfore, otherback, otherfore, monthback, monthfore ));
Return V;
}
Protected override string geterrordesigntimehtml (exception E)
{
String text1 = "designtimeerrormessage" + E. message;
If (E. innerexception! = NULL)
{
Text1 = text1 + "<br> contact me if you have any questions or suggestions regarding the use of thin (www.cnblogs.com/team/dotnetcontrols.htm, the team is very happy to create controls based on users' suggestions <br> <span style = 'background: yellow'> "+ E. innerexception. message + "</span> ";
}
Return base. createplaceholderdesigntimehtml (text1 );
}
Public override void initialize (icomponent component)
{
Base. initialize (component );
}

Public void onshowhidedropdownclick (Object o, eventargs E)
{
This. isdroppeddown =! This. isdroppeddown;
Base. isdirty = true;
This. updatedesigntimehtml ();
}
Public void onabloutclick (Object o, eventargs E)
{
Help help = new help ();
Help. showdialog ();
}
Private bool bfirsttime;
Private bool isdroppeddown = false;
Public override designerverbcollection Verbs
{
Get
{
If (this. bfirsttime & (base. Component! = NULL ))
{
This. verbs = base. verbs;
This. verbs. Add (this. showhidedropdown );
This. verbs. Add (this. About );
This. bfirsttime = false;
}
This. showhidedropdown. Visible = true;
This. About. Visible = true;
Return this. verbs;
}
}
Private string createdays (datetime selected,
String currentback, string currentfore,
String todayback, string todayfore,
String otherback, string otherfore,
String monthback, string monthfore)
{
Datetime dtfirst = new datetime (selected. Year, selected. month, 1 );
Datetime dtend = new datetime (selected. Year, selected. Month + 1, 1 );
If (! (Dtfirst. Year = 1 & dtfirst. month = 1 ))
Dtfirst = dtfirst. adddays (-1 * (INT) dtfirst. dayofweek ));
If (dtend. dayofweek! = Dayofweek. Sunday)
Dtend = dtend. adddays (7-(INT) dtend. dayofweek ));
String v = "";
For (datetime dt = dtfirst; dt <dtend; dt = DT. adddays (1 ))
{
String TD;
If (Dt. dayofweek = dayofweek. Sunday)
V + = "<tr> ";
TD = "<TD style = \" font-size: 9pt; cursor: hand; color: "+ otherfore +"; Background-color: "+ otherback + "; font-family: fixedsys; \ "align = center width = 16 Height = 16>" + dt. day. tostring () + "</TD> ";
If (Dt. month = selected. month)
TD = "<TD style = \" font-size: 9pt; cursor: hand; color: "+ monthfore +"; Background-color: "+ monthback + "; font-family: fixedsys; \ "align = center width = 16 Height = 16>" + dt. day. tostring () + "</TD> ";
If (Dt. month = datetime. Today. month & DT. Day = datetime. Today. Day)
TD = "<TD style = \" font-size: 9pt; cursor: hand; color: "+ todayfore +"; font-family: fixedsys; Background-color: "+ todayback +"; \ "align = center width = 16 Height = 16>" + dt. day. tostring () + "</TD> ";
If (Dt. month = selected. month & DT. Day = selected. Day)
TD = "<TD style = \" font-weight: bold; font-size: 9pt; cursor: hand; color: "+ currentfore +"; font-family: fixedsys; background-color: "+ currentback +"; \ "align = center width = 16 Height = 16>" + dt. day. tostring () + "</TD> ";
V + = TD;
If (Dt. dayofweek = dayofweek. Saturday)
V + = "<tr> ";
}
Return V;
}

Private designerverb showhidedropdown;
Private designerverb about;
Private designerverbcollection verbs;

}
}

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.