Public DateInput ()
{
/ / This call is required for the Windows.Forms Form Designer.
InitializationComponent ();
TBMONTH.CONTEXTMENU = MNU;
Tbyear.ContextMenu = MNU;
TBDAY.CONTEXTMENU = MNU;
THISHEIGHT = 21;
THIS.VALUE = DATETIME.NOW;
This.dateFormat = "YYYY-MM-DD";
IF (! this.designmode)
Createcalendar ();
This.Updown.width = 16;
THIS.REFRESH ();
}
Private void createcalendar ()
{
Calendar = new monthcalendar ();
Calendar.visible = true;
Calendar.dateelected = new dayeeventhandler (Calendar_Dateseled);
FRMCALENDAR = New form ();
FRMCALENDAR.FORMBORDERSTYLE = formborderstyle.none;
FRMCALENDAR.TOPMOST = TRUE;
FRMCALENDAR.WIDTH = 270;
FRMCALENDAR.HEIGHT = 145;
FRMCALENDAR.CONTROLS.ADD (Calendar);
Calendar.dock = dockstyle.fill;
FRMCALENDAR.STARTPSITION = formstartPosition.man;
FRMCALENDAR.DEACTIVATE = New EventHandler (Calendar_leave);
FRMCALENDAR.SHOWINTASKBAR = FALSE;
}
Private void Calendar_dateseled (Object Sender, System.Windows.Forms.Dateeeventargs E)
{
This.frmcalendar.hide ();
THIS.VALUE = this.calendar.SelectionStart;
THIS.TBDAY.FOCUS ();
}
Private Void Calendar_leave (Object Sender, System.EventArgs E)
{
This.frmcalendar.hide ();
//this.value = this.calendar.selectionStart;
THIS.TBDAY.FOCUS ();
}
Private void refreshDisplay ()
{
Bool BLGB = false;
String strchar = "";
IF (strdateformat == "YYYY-MM-DD")
Strchar = "-";
Else IF (strdateformat == "yyyy.mm.dd")
Strchar = "."
Else IF (strdateformat == "yyyy / mm / dd")
Strchar = "/";
Else if (strdateformat == "YYYY MM Moon DD Day) BLGB = true;
Else
Strchar = strfomatchar;
IF (BLGB)
{
LBSEP1.TEXT = "year";
LBSEP2.TEXT = "Month";
LBSEP3.TEXT = "Japan";
}
Else
{
LBSEP1.TEXT = STRCHAR;
LBSEP2.TEXT = STRCHAR;
LBSEP3.TEXT = ""
}
THIS.REFRESH ();
}
///
/// Is it null value?
/// summary>
Public bool isnull ()
{
String stringear = tbyear.text;
String strmonth = tbmonth.text;
String strday = tbday.text;
IF (strMonth == "|| strMonth ==" "| STRDAY ==" ")
Return True;
Else
Return False;
}
///
/// Set value is empty (actually the minimum value)
/// summary>
Public void setValuenull ()
{
THIS.VALUE = DateTime.minvalue;
}
///
/// Empty input value
/// summary>
Private void EmptyInput ()
{
Tbyear.Text = "";
TBMONTH.TEXT = ""
TBDAY.TEXT = "";
}
Private int getthismonthmaxday ()
{
Int year = int.parse (tbyear.text);
INT MONTH = Int.Parse (TBMONTH.TEXT);
Switch (Month)
{
Case 2:
IF (DateTime.isleApyear (Year)) // Leap Year
Return 29;
Else
Return 28;
Case 1:
Case 3:
Case 5:
Case 7:
Case 8:
Case 10:
Case 12:
Return 31;
Case 4:
Case 6:
Case 9:
Case 11:
Return 30;
DEFAULT:
Return 31;
}
}
Private void setrightfmt ()
{
IF (isnull ())
EmptyInput ();
Else
{
Setrightmonthday ();
}
THIS.REFRESH ();
}
Private void setRightMonthday ()
{
Int maxday = getthismonthmaxday ();
INT day = int.parse (tbday.text);
IF (day> maxday)
TBDAY.TEXT = MAXDAY.TOSTRING ();
}
Private void incdecdate (int isign)
{
String stringear = tbyear.text; if (strYear == "")
Stryear = DATETIME.NOW.Year.tostring ();
String strmonth = tbmonth.text;
IF (strMonth == "")
Strmonth = datetime.now.month.toString ();
String strday = tbday.text;
IF (strDay == "")
STRDAY = datetime.now.day.tostring ();
String strdate = strdate = stryear "-" strmonth "-" strday;
DateTime Dtold = DateTime.Parse (strdate);
IF (TBYEAR.FOCUSED)
{
this.Value = dtold.addyears (1 * ISIGN);
}
Else IF (tbmonth.focused)
{
THIS.Value = dtold.addmonths (1 * isign);
}
Else
{
THIS.VALUE = DTOLD.ADDDAYS (1 * ISIGN);
}
}
Private form getWindow ()
{
Control con = THIS;
While (! (! (!
CON = con.parent;
Return (form) con.parent;
}
///
/// Clean all the resources being used.
/// summary>
Protected Override Void Dispose (Bool Disposing)
{
IF (Disposing)
{
IF (Components! = NULL)
{
Components.dispose ();
}
}
Base.dispose (Disposing);
}