Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for dialogboxes_datetimebox.cs

(view source code of dialogboxes_datetimebox.cs as plain text)

  1. using System.Linq;
  2.  
  3.  
  4. namespace RobvanderWoude
  5. {
  6. 	[System.Runtime.InteropServices.Guid( "BC45108A-B13D-4D27-87C5-4E9A759107C2" )]
  7. 	public interface DateTimeBox_Interface
  8. 	{
  9. 		[System.Runtime.InteropServices.DispId( 1 )]
  10. 		void CheckUpdate( );
  11.  
  12. 		[System.Runtime.InteropServices.DispId( 2 )]
  13. 		string Credits( );
  14.  
  15. 		[System.Runtime.InteropServices.DispId( 3 )]
  16. 		string Help( int html = 0 );
  17.  
  18. 		[System.Runtime.InteropServices.DispId( 4 )]
  19. 		string ListProperties( );
  20.  
  21. 		[System.Runtime.InteropServices.DispId( 5 )]
  22. 		string SampleCode( );
  23.  
  24. 		[System.Runtime.InteropServices.DispId( 6 )]
  25. 		void Show( );
  26. 	}
  27.  
  28.  
  29. 	[System.Runtime.InteropServices.Guid( "1D9EEC0E-41BE-4190-8ADF-F310D081F099" ), System.Runtime.InteropServices.InterfaceType( System.Runtime.InteropServices.ComInterfaceType.InterfaceIsIDispatch )]
  30. 	public interface DateTimeBox_Events
  31. 	{
  32. 	}
  33.  
  34.  
  35. 	[System.Runtime.InteropServices.Guid( "13BFE67A-D92B-4AA9-A9DE-D7A0C109F12E" ), System.Runtime.InteropServices.ClassInterface( System.Runtime.InteropServices.ClassInterfaceType.AutoDual ), System.Runtime.InteropServices.ComSourceInterfaces( typeof( DateTimeBox_Events ) )]
  36. 	public class DateTimeBox : DateTimeBox_Interface
  37. 	{
  38. 		#region Default Values
  39.  
  40. 		const string defaultcaptioncancel = "Cancel";
  41. 		const string defaultcaptionok = "OK";
  42. 		const string defaultculture = "fr-CA"; // yyyy-MM-dd HH:mm:ss
  43. 		static readonly string defaulttitle = string.Format( "{0},  Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion );
  44. 		const int defaultwindowheight = 135;
  45. 		const int defaultwindowwidth = 220;
  46. 		const float minimumfontsize = 6;
  47. 		const float maximumfontsize = 48;
  48. 		static readonly System.Drawing.FontFamily defaultfontfamily = System.Drawing.FontFamily.GenericSansSerif;
  49. 		static readonly float defaultfontsize = 10;
  50.  
  51. 		#endregion Default Values
  52.  
  53.  
  54. 		static System.Windows.Forms.Form datetimeboxform = null;
  55. 		static System.Windows.Forms.DateTimePicker datepicker = null;
  56. 		static System.Windows.Forms.DateTimePicker timepicker = null;
  57. 		static bool cancelled = false;
  58.  
  59.  
  60. 		#region Methods
  61.  
  62. 		public void CheckUpdate( )
  63. 		{
  64. 			Global.Common.ProgramInfo.CheckUpdate( );
  65. 		}
  66.  
  67.  
  68. 		public string Credits( )
  69. 		{
  70. 			return Global.Common.Credits( );
  71. 		}
  72.  
  73.  
  74. 		static string GetAMDesignator( string culture )
  75. 		{
  76. 			return System.Globalization.CultureInfo.GetCultureInfo( culture, defaultculture ).DateTimeFormat.AMDesignator;
  77. 		}
  78.  
  79.  
  80. 		public static int GetIso8601WeekOfYear( System.DateTime date )
  81. 		{
  82. 			return Global.Common.GetIso8601WeekOfYear( date );
  83. 		}
  84.  
  85.  
  86. 		static string GetPMDesignator( string culture )
  87. 		{
  88. 			return System.Globalization.CultureInfo.GetCultureInfo( culture, defaultculture ).DateTimeFormat.PMDesignator;
  89. 		}
  90.  
  91.  
  92. 		public string Help( int html = 0 )
  93. 		{
  94. 			int col1width = 0;
  95. 			int col2width = 0;
  96. 			int col3width = 0;
  97. 			int col4width = 0;
  98. 			int col5width = 0;
  99. 			string help = string.Empty;
  100. 			string linetemplate = string.Empty;
  101. 			string separatorline = string.Empty;
  102.  
  103. 			if ( html == 1 )
  104. 			{
  105. 				help += "<h1>Help for DateTimeBox class</h1>\n\n";
  106. 				help += "<p>Present a dialog with date and/or time picker, and return the selected date and/or time values</p>\n\n";
  107. 				help += "<h2>COM ProgID: RobvanderWoude.DateTimeBox</h2>\n\n";
  108. 			}
  109. 			else
  110. 			{
  111. 				help += "Help for DateTimeBox class\n";
  112. 				help += new string( '\u2500', help.Length ) + "\n\n";
  113. 				help += "Present a dialog with date and/or time picker, and return the selected date and/or time values\n\n\n";
  114. 				help += "COM ProgID: RobvanderWoude.DateTimeBox\n\n\n";
  115. 			}
  116.  
  117.  
  118. 			#region Properties
  119.  
  120. 			if ( html == 1 )
  121. 			{
  122. 				separatorline = string.Empty;
  123. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n\t<td>{3}</td>\n\t<td>{4}</td>\n</tr>\n";
  124.  
  125. 				help += "<table>\n";
  126. 				help += "<tr>\n";
  127. 				help += "\t<th colspan=\"5\">Properties (Note that all properties are string or integer, no booleans, objects or arrays)</th>\n";
  128. 				help += "</tr>\n";
  129.  
  130. 				help += "<tr>\n";
  131. 				help += "\t<th>Property Name</th>\n";
  132. 				help += "\t<th>Description</th>\n";
  133. 				help += "\t<th>Mandatory</th>\n";
  134. 				help += "\t<th>Read-Only</th>\n";
  135. 				help += "\t<th>Default (Allowed) Values</th>\n";
  136. 				help += "</tr>\n";
  137. 			}
  138. 			else
  139. 			{
  140. 				col1width = 16;
  141. 				col2width = 50;
  142. 				col3width = 9;
  143. 				col4width = 9;
  144. 				col5width = 44;
  145.  
  146. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u253C" + new string( '\u2500', 2 + col4width ) + "\u253C" + new string( '\u2500', 2 + col5width ) + "\u2524\n";
  147. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502 {3,-" + col4width.ToString( ) + "} \u2502 {4,-" + col5width.ToString( ) + "} \u2502\n";
  148.  
  149. 				help += "\u250C" + new string( '\u2500', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2510\n";
  150. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  151. 				help += string.Format( "\u2502 {0,-" + ( 12 + col1width + col2width + col3width + col4width + col5width ).ToString( ) + "} \u2502\n", "Properties        (Note that all properties are string or integer, no booleans, objects or arrays)" );
  152. 				help += "\u2502" + new string( ' ', 14 + col1width + col2width + col3width + col4width + col5width ) + "\u2502\n";
  153. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2564" + new string( '\u2550', 2 + col4width ) + "\u2564" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  154. 				help += string.Format( linetemplate, "Property Name", "Description", "Mandatory", "Read-Only", "Default (Allowed) Values" );
  155. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u256A" + new string( '\u2550', 2 + col4width ) + "\u256A" + new string( '\u2550', 2 + col5width ) + "\u2561\n";
  156. 			}
  157.  
  158. 			help += HelpTableRow( linetemplate, "captioncancel", Global.Common.Help.captioncancel, "no", "no", defaultcaptioncancel, html );
  159. 			help += separatorline;
  160.  
  161. 			help += HelpTableRow( linetemplate, "captionok", Global.Common.Help.captionok, "no", "no", defaultcaptionok, html );
  162. 			help += separatorline;
  163.  
  164. 			help += HelpTableRow( linetemplate, "culturegui", "The \"culture\" used to format date/time in the GUI", "no", "no", defaultculture, html );
  165. 			help += separatorline;
  166.  
  167. 			help += HelpTableRow( linetemplate, "culturein", "The \"culture\" used to format initial date/time", "no", "no", defaultculture, html );
  168. 			help += separatorline;
  169.  
  170. 			help += HelpTableRow( linetemplate, "cultureout", "The \"culture\" used to format output date/time", "no", "no", defaultculture, html );
  171. 			help += separatorline;
  172.  
  173. 			help += HelpTableRow( linetemplate, "dateformatgui", "Date format for GUI, overrides culture", "no", "no", "short date format for culturegui", html );
  174. 			help += separatorline;
  175.  
  176. 			help += HelpTableRow( linetemplate, "dateformatin", "Date format for initial date, overrides culture", "no", "no", "short date format for culturein", html );
  177. 			help += separatorline;
  178.  
  179. 			help += HelpTableRow( linetemplate, "dateformatout", "Date format for output, overrides culture", "no", "no", "short date format for cultureout", html );
  180. 			help += separatorline;
  181.  
  182. 			help += HelpTableRow( linetemplate, "dateonly", "Date picker only, no time picker (0=false, 1=true)", "no", "no", "0: show time picker", html );
  183. 			help += separatorline;
  184.  
  185. 			help += HelpTableRow( linetemplate, "dateseparatorgui", "Date separator used in the GUI", "no", "no", "determined by culturegui", html );
  186. 			help += separatorline;
  187.  
  188. 			help += HelpTableRow( linetemplate, "dateseparatorgui", "Date separator used in initial date", "no", "no", "determined by culturein", html );
  189. 			help += separatorline;
  190.  
  191. 			help += HelpTableRow( linetemplate, "dateseparatorgui", "Date separator used in output", "no", "no", "determined by cultureout", html );
  192. 			help += separatorline;
  193.  
  194. 			help += HelpTableRow( linetemplate, "debuginfo", Global.Common.Help.debuginfo, "N/A", "YES", "", html );
  195. 			help += separatorline;
  196.  
  197. 			help += HelpTableRow( linetemplate, "earliestdate", "Earliest date allowed", "no", "no", string.Format( "{0} ({1} .. {1})", System.DateTime.MinValue, System.DateTime.MaxValue ), html );
  198. 			help += separatorline;
  199.  
  200. 			help += HelpTableRow( linetemplate, "errors", Global.Common.Help.errors, "N/A", "YES", "", html );
  201. 			help += separatorline;
  202.  
  203. 			help += HelpTableRow( linetemplate, "fontfamily", Global.Common.Help.fontfamily, "no", "no", defaultfontfamily.Name, html );
  204. 			help += separatorline;
  205.  
  206. 			help += HelpTableRow( linetemplate, "fontsize", Global.Common.Help.fontsize, "no", "no", string.Format( "{0} ({1}..{2})", defaultfontsize, minimumfontsize, maximumfontsize ), html );
  207. 			help += separatorline;
  208.  
  209. 			help += HelpTableRow( linetemplate, "initialdatetime", "Initial date/time for date/time pickers", "no", "no", "current date/time", html );
  210. 			help += separatorline;
  211.  
  212. 			help += HelpTableRow( linetemplate, "latestdate", "Latest date allowed", "no", "no", string.Format( "{1} ({0} .. {1})", System.DateTime.MinValue, System.DateTime.MaxValue ), html );
  213. 			help += separatorline;
  214.  
  215. 			help += HelpTableRow( linetemplate, "left", Global.Common.Help.left, "no", "no", "Centered (0..screenwidth - windowwidth)", html );
  216. 			help += separatorline;
  217.  
  218. 			help += HelpTableRow( linetemplate, "literal", Global.Common.Help.literal, "no", "no", "0: interpret \"\\t\" as tab and \"\\n\" as newline", html );
  219. 			help += separatorline;
  220.  
  221. 			help += HelpTableRow( linetemplate, "localizecaptions", Global.Common.Help.localizecaptions, "no", "no", "0: English captions", html );
  222. 			help += separatorline;
  223.  
  224. 			help += HelpTableRow( linetemplate, "maxdaysback", "Maximum number of days back from initial date", "no", "no", "-1 (you can set either earliestdate or maxdaysback, but not both)", html );
  225. 			help += separatorline;
  226.  
  227. 			help += HelpTableRow( linetemplate, "maxdaysforward", "Maximum number of days forward from initial date", "no", "no", "-1 (you can set either latestdate or maxdaysback, but not both)", html );
  228. 			help += separatorline;
  229.  
  230. 			help += HelpTableRow( linetemplate, "modal", Global.Common.Help.modal, "no", "no", "1: always on top", html );
  231. 			help += separatorline;
  232.  
  233. 			help += HelpTableRow( linetemplate, "prompt", Global.Common.Help.prompt, "no", "no", "", html );
  234. 			help += separatorline;
  235.  
  236. 			help += HelpTableRow( linetemplate, "selecteddate", "Date selected in date picker", "N/A", "YES", "", html );
  237. 			help += separatorline;
  238.  
  239. 			help += HelpTableRow( linetemplate, "selectedtime", "Time selected in time picker", "N/A", "YES", "", html );
  240. 			help += separatorline;
  241.  
  242. 			help += HelpTableRow( linetemplate, "selectedweek", "Week of year for selected date", "N/A", "YES", "", html );
  243. 			help += separatorline;
  244.  
  245. 			help += HelpTableRow( linetemplate, "selectedweekday", "Day of week for selected date", "N/A", "YES", "", html );
  246. 			help += separatorline;
  247.  
  248. 			help += HelpTableRow( linetemplate, "timeformatgui", "Time format for GUI, overrides culture", "no", "no", "long time format for culturegui", html );
  249. 			help += separatorline;
  250.  
  251. 			help += HelpTableRow( linetemplate, "timeformatin", "Time format for initial time, overrides culture", "no", "no", "long time format for culturein", html );
  252. 			help += separatorline;
  253.  
  254. 			help += HelpTableRow( linetemplate, "timeformatout", "Time format for output, overrides culture", "no", "no", "long time format for cultureout", html );
  255. 			help += separatorline;
  256.  
  257. 			help += HelpTableRow( linetemplate, "timeonly", "Time picker only, no date picker (0=false, 1=true)", "no", "no", "0: show date picker", html );
  258. 			help += separatorline;
  259.  
  260. 			help += HelpTableRow( linetemplate, "timeout", Global.Common.Help.timeout, "no", "no", "0: no timeout", html );
  261. 			help += separatorline;
  262.  
  263. 			help += HelpTableRow( linetemplate, "timeoutelapsed", Global.Common.Help.timeoutelapsed, "N/A", "YES", "", html );
  264. 			help += separatorline;
  265.  
  266. 			help += HelpTableRow( linetemplate, "timeformatgui", "Time format for GUI, overrides culture", "no", "no", "long time format for culturegui", html );
  267. 			help += separatorline;
  268.  
  269. 			help += HelpTableRow( linetemplate, "timeformatin", "Time format for initial date, overrides culture", "no", "no", "long time format for culturein", html );
  270. 			help += separatorline;
  271.  
  272. 			help += HelpTableRow( linetemplate, "timeformatout", "Time format for output, overrides culture", "no", "no", "long time format for cultureout", html );
  273. 			help += separatorline;
  274.  
  275. 			help += HelpTableRow( linetemplate, "timeseparatorgui", "Time separator used in the GUI", "no", "no", "determined by culturegui", html );
  276. 			help += separatorline;
  277.  
  278. 			help += HelpTableRow( linetemplate, "timeseparatorgui", "Time separator used in initial date", "no", "no", "determined by culturein", html );
  279. 			help += separatorline;
  280.  
  281. 			help += HelpTableRow( linetemplate, "timeseparatorgui", "Time separator used in output", "no", "no", "determined by cultureout", html );
  282. 			help += separatorline;
  283.  
  284. 			help += HelpTableRow( linetemplate, "title", Global.Common.Help.title, "no", "no", defaulttitle, html );
  285. 			help += separatorline;
  286.  
  287. 			help += HelpTableRow( linetemplate, "top", Global.Common.Help.top, "no", "no", "Centered (0..screenheight - windowheight)", html );
  288. 			help += separatorline;
  289.  
  290. 			help += HelpTableRow( linetemplate, "Version", Global.Common.Help.version, "N/A", "YES", "", html );
  291. 			help += separatorline;
  292.  
  293. 			help += HelpTableRow( linetemplate, "windowheight", Global.Common.Help.windowheight, "no", "no", string.Format( "{0} ({0}..{1})", defaultwindowheight, "screenheight" ), html );
  294. 			help += separatorline;
  295.  
  296. 			help += HelpTableRow( linetemplate, "windowwidth", Global.Common.Help.windowwidth, "no", "no", string.Format( "{0} ({0}..{1})", defaultwindowwidth, "screenwidth" ), html );
  297.  
  298. 			if ( html == 1 )
  299. 			{
  300. 				help += "</table>\n\n\n";
  301. 			}
  302. 			else
  303. 			{
  304. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2534" + new string( '\u2500', 2 + col4width ) + "\u2534" + new string( '\u2500', 2 + col5width ) + "\u2518\n\n\n";
  305. 			}
  306.  
  307. 			#endregion Properties
  308.  
  309.  
  310. 			#region Methods
  311.  
  312. 			if ( html == 1 )
  313. 			{
  314. 				separatorline = string.Empty;
  315. 				linetemplate = "<tr>\n\t<td>{0}</td>\n\t<td>{1}</td>\n\t<td>{2}</td>\n</tr>\n";
  316.  
  317. 				help += "<table>\n";
  318. 				help += "<tr>\n";
  319. 				help += "\t<th colspan=\"3\">Methods</th>\n";
  320. 				help += "</tr>\n";
  321.  
  322. 				help += "<tr>\n";
  323. 				help += "\t<th>Method Name</th>\n";
  324. 				help += "\t<th>Description</th>\n";
  325. 				help += "\t<th>Requirements</th>\n";
  326. 				help += "</tr>\n";
  327. 			}
  328. 			else
  329. 			{
  330. 				col1width = 16;
  331. 				col2width = 74;
  332. 				col3width = 44;
  333.  
  334. 				separatorline = "\u251C" + new string( '\u2500', 2 + col1width ) + "\u253C" + new string( '\u2500', 2 + col2width ) + "\u253C" + new string( '\u2500', 2 + col3width ) + "\u2524\n";
  335. 				linetemplate = "\u2502 {0,-" + col1width.ToString( ) + "} \u2502 {1,-" + col2width.ToString( ) + "} \u2502 {2,-" + col3width.ToString( ) + "} \u2502\n";
  336.  
  337. 				help += "\u250C" + new string( '\u2500', 8 + col1width + col2width + col3width ) + "\u2510\n";
  338. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  339. 				help += string.Format( "\u2502 {0,-" + ( 6 + col1width + col2width + col3width ).ToString( ) + "} \u2502\n", "Methods" );
  340. 				help += "\u2502" + new string( ' ', 8 + col1width + col2width + col3width ) + "\u2502\n";
  341. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u2564" + new string( '\u2550', 2 + col2width ) + "\u2564" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  342. 				help += string.Format( linetemplate, "Method Name", "Description", "Requirements" );
  343. 				help += "\u255E" + new string( '\u2550', 2 + col1width ) + "\u256A" + new string( '\u2550', 2 + col2width ) + "\u256A" + new string( '\u2550', 2 + col3width ) + "\u2561\n";
  344. 			}
  345.  
  346. 			help += HelpTableRow( linetemplate, "CheckUpdate", Global.Common.Help._checkupdate, "", html );
  347. 			help += separatorline;
  348.  
  349. 			help += HelpTableRow( linetemplate, "Credits", Global.Common.Help._credits, "", html );
  350. 			help += separatorline;
  351.  
  352. 			help += HelpTableRow( linetemplate, "Help", Global.Common.Help._help, "", html );
  353. 			help += separatorline;
  354.  
  355. 			help += HelpTableRow( linetemplate, "ListProperties", Global.Common.Help._listproperties, "", html );
  356. 			help += separatorline;
  357.  
  358. 			help += HelpTableRow( linetemplate, "SampleCode", Global.Common.Help._samplecode, "", html );
  359. 			help += separatorline;
  360.  
  361. 			help += HelpTableRow( linetemplate, "Show", "Presents a date/time picker dialog based on the current property values, and if \"OK\" is clicked, saves the last selected date and time in the \"selecteddate\" and \"selectedtime\" properties (if \"Cancel\" is clicked, \"selecteddate\" and \"selectedtime\" are set to empty strings).", "", html );
  362.  
  363. 			if ( html == 1 )
  364. 			{
  365. 				help += "</table>\n\n\n";
  366. 			}
  367. 			else
  368. 			{
  369. 				help += "\u2514" + new string( '\u2500', 2 + col1width ) + "\u2534" + new string( '\u2500', 2 + col2width ) + "\u2534" + new string( '\u2500', 2 + col3width ) + "\u2518\n\n\n";
  370. 			}
  371.  
  372. 			#endregion Methods
  373.  
  374.  
  375. 			#region Notes
  376.  
  377. 			if ( html == 1 )
  378. 			{
  379. 				help += "<table>\n<tr>\n\t<th>";
  380. 			}
  381.  
  382. 			help += "Notes:";
  383.  
  384. 			if ( html == 1 )
  385. 			{
  386. 				help += "</th>\n\t<td>";
  387. 			}
  388. 			else
  389. 			{
  390. 				help += "\n\t";
  391. 			}
  392.  
  393. 			help += "If the current culture of the local computer does not use AM/PM designators, no AM/PM";
  394.  
  395. 			if ( html == 1 )
  396. 			{
  397. 				help += " ";
  398. 			}
  399. 			else
  400. 			{
  401. 				help += "\n\t";
  402. 			}
  403.  
  404. 			help += "designators can be shown in the date and Time Pickers, regardless of selected GUI culture.";
  405.  
  406. 			if ( html == 1 )
  407. 			{
  408. 				help += "</td>\n</tr>\n</table>";
  409. 			}
  410.  
  411. 			help += "\n\n\n";
  412.  
  413. 			#endregion Notes
  414.  
  415.  
  416. 			#region Example
  417.  
  418. 			if ( html == 1 )
  419. 			{
  420. 				help += "<h2>VBScript usage example:</h2>\n\n<pre>";
  421. 			}
  422. 			else
  423. 			{
  424. 				help += "VBScript usage example:\n";
  425. 				help += new string( '\u2500', 23 ) + "\n\n";
  426. 			}
  427.  
  428. 			help += SampleCode( );
  429.  
  430. 			if ( html == 1 )
  431. 			{
  432. 				help += "</pre>";
  433. 			}
  434.  
  435. 			help += "\n\n";
  436.  
  437. 			#endregion Example
  438.  
  439.  
  440. 			help = help.Replace( "\n", System.Environment.NewLine );
  441. 			return help;
  442. 		}
  443.  
  444.  
  445. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, int html )
  446. 		{
  447. 			if ( html == 1 )
  448. 			{
  449. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text );
  450. 			}
  451. 			else
  452. 			{
  453. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, "", "" );
  454. 			}
  455. 		}
  456.  
  457.  
  458. 		private string HelpTableRow( string template, string col1text, string col2text, string col3text, string col4text, string col5text, int html )
  459. 		{
  460. 			if ( html == 1 )
  461. 			{
  462. 				return Global.Common.Help.HelpTableRowHTML( col1text, col2text, col3text, col4text, col5text );
  463. 			}
  464. 			else
  465. 			{
  466. 				return Global.Common.Help.HelpTableRowText( template, col1text, col2text, col3text, col4text, col5text );
  467. 			}
  468. 		}
  469.  
  470.  
  471. 		public string ListProperties( )
  472. 		{
  473. 			return Global.Common.Lists.Properties( this );
  474. 		}
  475.  
  476.  
  477. 		public string SampleCode( )
  478. 		{
  479. 			string code = "Set objDateTimeBox = CreateObject( \"RobvanderWoude.DateTimeBox\" )\n\n";
  480. 			code += "With objDateTimeBox\n";
  481. 			code += "\t.top     = 200\n";
  482. 			code += "\t.left    = 300\n";
  483. 			code += "\t.timeout = 15\n";
  484. 			code += "\t.title   = \"Pick a Date and Time\"\n";
  485. 			code += "\t.Show\n";
  486. 			code += "\tWScript.Echo \"Selected date and time: \" & .selecteddate & \" \" & .selectedtime\n";
  487. 			code += "\tWScript.Echo\n";
  488. 			code += "\tWScript.Echo .ListProperties( )\n";
  489. 			code += "End With\n\n";
  490. 			code += "Set objDateTimeBox = Nothing";
  491. 			return code;
  492. 		}
  493.  
  494.  
  495. 		[System.STAThread]
  496. 		public void Show( )
  497. 		{
  498. 			_selecteddate = _initialdatetime.Date;
  499. 			_selectedtime = _initialdatetime.TimeOfDay;
  500.  
  501.  
  502. 			#region Timer
  503.  
  504. 			try
  505. 			{
  506. 				_timeoutelapsed = false;
  507. 				if ( _timeout > 0 )
  508. 				{
  509. 					System.Timers.Timer timer = new System.Timers.Timer( );
  510. 					timer.Elapsed += new System.Timers.ElapsedEventHandler( DateTimeBox_Timer_Elapsed );
  511. 					timer.Interval = timeout * 1000;
  512. 					timer.Start( );
  513. 					_debuginfo.Add( timestamp + "Timer started with interval " + timeout.ToString( ) );
  514. 				}
  515. 			}
  516. 			catch ( System.Exception e )
  517. 			{
  518. 				_errors.Add( Global.Common.TimeStamp( ) + "Timer Error: " + e.Message );
  519. 			}
  520.  
  521. 			#endregion Timer
  522.  
  523.  
  524. 			#region Form Controls
  525.  
  526. 			int rows = 2;
  527. 			datetimeboxform = new System.Windows.Forms.Form( );
  528. 			if ( windowheight == defaultwindowheight )
  529. 			{
  530. 				if ( _dateonly || _timeonly )
  531. 				{
  532. 					rows -= 1;
  533. 				}
  534. 				if ( !string.IsNullOrWhiteSpace( prompt ) )
  535. 				{
  536. 					rows += 1;
  537. 				}
  538. 			}
  539. 			if ( rows != 2 )
  540. 			{
  541. 				windowheight += ( rows - 2 ) * 40;
  542. 			}
  543. 			_debuginfo.Add( timestamp + "Form rows: " + rows );
  544. 			_debuginfo.Add( timestamp + "Window height: " + windowheight );
  545. 			System.Drawing.Size size = new System.Drawing.Size( windowwidth, windowheight );
  546. 			datetimeboxform.ClientSize = size;
  547. 			datetimeboxform.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
  548. 			datetimeboxform.MaximizeBox = false;
  549. 			datetimeboxform.MinimizeBox = false;
  550. 			datetimeboxform.Font = new System.Drawing.Font( fontfamily, fontsize );
  551. 			if ( left < 0 || top < 0 )
  552. 			{
  553. 				datetimeboxform.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
  554. 			}
  555. 			else
  556. 			{
  557. 				datetimeboxform.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
  558. 				datetimeboxform.Location = new System.Drawing.Point( left, top );
  559. 			}
  560. 			datetimeboxform.Text = title;
  561. 			datetimeboxform.TopLevel = topmost;
  562.  
  563. 			System.Drawing.Point firstrow = new System.Drawing.Point( 15, 15 );
  564. 			System.Drawing.Point secondrow = new System.Drawing.Point( 15, 55 );
  565. 			System.Drawing.Point thirdrow = new System.Drawing.Point( 15, 95 );
  566.  
  567. 			if ( !string.IsNullOrWhiteSpace( prompt ) )
  568. 			{
  569. 				System.Windows.Forms.Label labelprompt = new System.Windows.Forms.Label( );
  570. 				labelprompt.Location = firstrow;
  571. 				if ( !_literal )
  572. 				{
  573. 					labelprompt.Text = prompt.Replace( "\\n", "\n" ).Replace( "\\r", "\r" );
  574. 				}
  575. 				//datetimeboxform.ClientSize = size;
  576. 				labelprompt.Size = new System.Drawing.Size( size.Width - 30, 40 );
  577. 				datetimeboxform.Controls.Add( labelprompt );
  578. 			}
  579.  
  580. 			_debuginfo.Add( timestamp + $"startposition = {datetimeboxform.StartPosition.ToString( )}; top = {top}; left = {left}; location = {datetimeboxform.Location.X},{datetimeboxform.Location.Y}" );
  581.  
  582. 			if ( !_timeonly )
  583. 			{
  584. 				datepicker = new System.Windows.Forms.DateTimePicker( );
  585. 				datepicker.CustomFormat = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.LongDatePattern;
  586. 				datepicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
  587. 				if ( string.IsNullOrWhiteSpace( prompt ) )
  588. 				{
  589. 					datepicker.Location = firstrow;
  590. 				}
  591. 				else
  592. 				{
  593. 					datepicker.Location = secondrow;
  594. 				}
  595. 				datepicker.MaxDate = _latestdate;
  596. 				datepicker.MinDate = _earliestdate;
  597. 				datepicker.Size = new System.Drawing.Size( datetimeboxform.Width - 30, 25 );
  598. 				datepicker.Value = _initialdatetime;
  599. 				datepicker.TextChanged += new System.EventHandler( DateTimeBox_DatePicker_TextChanged );
  600. 				datetimeboxform.Controls.Add( datepicker );
  601. 			}
  602.  
  603. 			if ( !_dateonly )
  604. 			{
  605. 				timepicker = new System.Windows.Forms.DateTimePicker( );
  606. 				switch ( rows )
  607. 				{
  608. 					case 1:
  609. 						timepicker.Location = firstrow;
  610. 						break;
  611. 					case 2:
  612. 						timepicker.Location = secondrow;
  613. 						break;
  614. 					case 3:
  615. 						timepicker.Location = thirdrow;
  616. 						break;
  617. 				}
  618. 				timepicker.ShowUpDown = true;
  619. 				timepicker.Size = new System.Drawing.Size( datetimeboxform.Width - 30, 25 );
  620. 				timepicker.Value = _initialdatetime;
  621. 				_debuginfo.Add( timestamp + "GUI culture: " + _culturegui );
  622. 				_debuginfo.Add( timestamp + "GUI time format: " + timeformatgui );
  623. 				_debuginfo.Add( timestamp + "GUI AM designator: " + GetAMDesignator( culturegui ) );
  624. 				_debuginfo.Add( timestamp + "GUI PM designator: " + GetPMDesignator( culturegui ) );
  625. 				_debuginfo.Add( timestamp + "Local culture: " + System.Globalization.CultureInfo.CurrentCulture.Name );
  626. 				_debuginfo.Add( timestamp + "Local time format: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.LongTimePattern );
  627. 				_debuginfo.Add( timestamp + "Local AM designator: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator );
  628. 				_debuginfo.Add( timestamp + "Local PM designator: " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.PMDesignator );
  629. 				if ( string.IsNullOrWhiteSpace( System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.AMDesignator ) && !string.IsNullOrWhiteSpace( GetAMDesignator( culturegui ) ) )
  630. 				{
  631. 					_errors.Add( Global.Common.TimeStamp( ) + "The local system is unable to display AM/PM designators in TimePicker GUI" );
  632. 					_debuginfo.Add( timestamp + "Though AM/PM designators in output will be displayed correctly, the local system is unable to display AM/PM designators in TimePicker GUI" );
  633. 				}
  634. 				timepicker.CustomFormat = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.LongTimePattern;
  635. 				timepicker.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
  636. 				timepicker.TextChanged += DateTimeBox_TimePicker_TextChanged;
  637. 				datetimeboxform.Controls.Add( timepicker );
  638. 			}
  639.  
  640. 			System.Windows.Forms.Button okButton = new System.Windows.Forms.Button( );
  641. 			okButton.DialogResult = System.Windows.Forms.DialogResult.OK;
  642. 			okButton.Name = "okButton";
  643. 			okButton.Size = new System.Drawing.Size( 80, 25 );
  644. 			okButton.Text = captionok;
  645. 			okButton.Location = new System.Drawing.Point( datetimeboxform.Width / 2 - 10 - 80, datetimeboxform.Height - 68 );
  646. 			datetimeboxform.Controls.Add( okButton );
  647.  
  648. 			System.Windows.Forms.Button cancelButton = new System.Windows.Forms.Button( );
  649. 			cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
  650. 			cancelButton.Name = "cancelButton";
  651. 			cancelButton.Size = new System.Drawing.Size( 80, 25 );
  652. 			cancelButton.Text = captioncancel;
  653. 			cancelButton.Location = new System.Drawing.Point( datetimeboxform.Width / 2 + 10, datetimeboxform.Height - 68 );
  654. 			datetimeboxform.Controls.Add( cancelButton );
  655.  
  656. 			datetimeboxform.AcceptButton = okButton;  // OK on Enter
  657. 			datetimeboxform.CancelButton = cancelButton; // Cancel on Esc
  658. 			datetimeboxform.Activate( );
  659.  
  660. 			#endregion Form Controls
  661.  
  662.  
  663. 			System.Windows.Forms.DialogResult result = datetimeboxform.ShowDialog( );
  664. 			if ( !_timeoutelapsed )
  665. 			{
  666. 				_debuginfo.Add( timestamp + "DateTimeBox dialog result: " + result.ToString( ) );
  667. 			}
  668. 			if ( !_timeoutelapsed && result == System.Windows.Forms.DialogResult.Cancel )
  669. 			{
  670. 				cancelled = true;
  671. 				_selecteddate = System.DateTime.MinValue.Date;
  672. 				_selectedtime = System.DateTime.MinValue.TimeOfDay;
  673. 			}
  674. 			else
  675. 			{
  676. 				if ( !_timeonly )
  677. 				{
  678. 					try
  679. 					{
  680. 						//_selecteddate = datepicker.Value.Date;
  681. 						_debuginfo.Add( timestamp + "selecteddate: " + selecteddate );
  682. 						string date = _selecteddate.ToString( System.Globalization.CultureInfo.GetCultureInfo( cultureout, defaultculture ).DateTimeFormat.ShortDatePattern );
  683. 						_debuginfo.Add( timestamp + "selecteddate: " + date );
  684. 					}
  685. 					catch ( System.Exception e )
  686. 					{
  687. 						_errors.Add( Global.Common.TimeStamp( ) + "selecteddate: " + e.Message );
  688. 					}
  689. 				}
  690. 				if ( !_dateonly )
  691. 				{
  692. 					try
  693. 					{
  694. 						//_selectedtime = timepicker.Value.TimeOfDay;
  695. 						_debuginfo.Add( timestamp + "selectedtime: " + selectedtime );
  696. 						string time = ( _selecteddate.Date + _selectedtime ).ToString( System.Globalization.CultureInfo.GetCultureInfo( cultureout, defaultculture ).DateTimeFormat.ShortTimePattern );
  697. 						_debuginfo.Add( timestamp + "selectedtime: " + time );
  698. 					}
  699. 					catch ( System.Exception e )
  700. 					{
  701. 						_errors.Add( Global.Common.TimeStamp( ) + "selectedtime: " + e.Message );
  702. 					}
  703. 				}
  704. 			}
  705. 		}
  706.  
  707. 		#endregion Methods
  708.  
  709.  
  710. 		#region Properties
  711.  
  712. 		private string _cancelcaption = defaultcaptioncancel;
  713. 		[System.Runtime.InteropServices.ComVisible( true )]
  714. 		public string captioncancel
  715. 		{
  716. 			get
  717. 			{
  718. 				if ( _localizecaptions && _cancelcaption == defaultcaptioncancel )
  719. 				{
  720. 					_cancelcaption = Global.Common.Localization.Load( "user32.dll", 801, defaultcaptioncancel );
  721. 				}
  722. 				return _cancelcaption;
  723. 			}
  724. 			set
  725. 			{
  726. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  727. 				{
  728. 					_cancelcaption = defaultcaptioncancel;
  729. 				}
  730. 				else
  731. 				{
  732. 					_cancelcaption = value;
  733. 				}
  734. 				//_debuginfo.Add()
  735. 			}
  736. 		}
  737.  
  738.  
  739. 		private string _captionok = defaultcaptionok;
  740. 		[System.Runtime.InteropServices.ComVisible( true )]
  741. 		public string captionok
  742. 		{
  743. 			get
  744. 			{
  745. 				if ( _localizecaptions && _captionok == defaultcaptionok )
  746. 				{
  747. 					_captionok = Global.Common.Localization.Load( "user32.dll", 800, defaultcaptionok );
  748. 				}
  749. 				return _captionok;
  750. 			}
  751. 			set
  752. 			{
  753. 				if ( string.IsNullOrWhiteSpace( value ) || value.Length > 20 )
  754. 				{
  755. 					_captionok = defaultcaptionok;
  756. 				}
  757. 				else
  758. 				{
  759. 					_captionok = value;
  760. 				}
  761. 			}
  762. 		}
  763.  
  764.  
  765. 		private static string _culturegui = defaultculture;
  766. 		[System.Runtime.InteropServices.ComVisible( true )]
  767. 		public string culturegui
  768. 		{
  769. 			get
  770. 			{
  771. 				return _culturegui;
  772. 			}
  773. 			set
  774. 			{
  775. 				if ( Global.Common.Lists.Cultures( ).Contains( value, System.StringComparer.InvariantCultureIgnoreCase ) )
  776. 				{
  777. 					_culturegui = value;
  778. 				}
  779. 				else
  780. 				{
  781. 					_culturegui = defaultculture;
  782. 				}
  783. 				dateformatgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.ShortDatePattern;
  784. 				dateseparatorgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.DateSeparator;
  785. 				timeformatgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.LongTimePattern;
  786. 				timeseparatorgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.TimeSeparator;
  787. 			}
  788. 		}
  789.  
  790.  
  791. 		private static string _culturein = defaultculture;
  792. 		[System.Runtime.InteropServices.ComVisible( true )]
  793. 		public string culturein
  794. 		{
  795. 			get
  796. 			{
  797. 				return _culturein;
  798. 			}
  799. 			set
  800. 			{
  801. 				if ( Global.Common.Lists.Cultures( ).Contains( value, System.StringComparer.InvariantCultureIgnoreCase ) )
  802. 				{
  803. 					_culturein = value;
  804. 				}
  805. 				else
  806. 				{
  807. 					_culturein = defaultculture;
  808. 				}
  809. 				dateformatin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.ShortDatePattern;
  810. 				dateseparatorin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.DateSeparator;
  811. 				timeformatin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.LongTimePattern;
  812. 				timeseparatorin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.TimeSeparator;
  813. 			}
  814. 		}
  815.  
  816.  
  817. 		private static string _cultureout = defaultculture;
  818. 		[System.Runtime.InteropServices.ComVisible( true )]
  819. 		public string cultureout
  820. 		{
  821. 			get
  822. 			{
  823. 				return _cultureout;
  824. 			}
  825. 			set
  826. 			{
  827. 				if ( Global.Common.Lists.Cultures( ).Contains( value, System.StringComparer.InvariantCultureIgnoreCase ) )
  828. 				{
  829. 					_cultureout = value;
  830. 				}
  831. 				else
  832. 				{
  833. 					_cultureout = defaultculture;
  834. 				}
  835. 				dateformatout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.ShortDatePattern;
  836. 				dateseparatorout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.DateSeparator;
  837. 				timeformatout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.LongTimePattern;
  838. 				timeseparatorout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.TimeSeparator;
  839. 			}
  840. 		}
  841.  
  842.  
  843. 		private string _dateformatgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.ShortDatePattern;
  844. 		[System.Runtime.InteropServices.ComVisible( true )]
  845. 		public string dateformatgui
  846. 		{
  847. 			get
  848. 			{
  849. 				return _dateformatgui;
  850. 			}
  851. 			set
  852. 			{
  853. 				if ( value.IndexOfAny( "dMy".ToCharArray( ) ) == -1 )
  854. 				{
  855. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom date format (GUI) should contain at least one of the characters \"d\", \"M\" or \"y\"" );
  856. 				}
  857. 				else
  858. 				{
  859. 					_dateformatgui = value;
  860. 				}
  861. 			}
  862. 		}
  863.  
  864.  
  865. 		private string _dateformatin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.ShortDatePattern;
  866. 		[System.Runtime.InteropServices.ComVisible( true )]
  867. 		public string dateformatin
  868. 		{
  869. 			get
  870. 			{
  871. 				return _dateformatin;
  872. 			}
  873. 			set
  874. 			{
  875. 				if ( value.IndexOfAny( "dMy".ToCharArray( ) ) == -1 )
  876. 				{
  877. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom date format (in) should contain at least one of the characters \"d\", \"M\" or \"y\"" );
  878. 				}
  879. 				else
  880. 				{
  881. 					_dateformatin = value;
  882. 				}
  883. 			}
  884. 		}
  885.  
  886.  
  887. 		private string _dateformatout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.ShortDatePattern;
  888. 		[System.Runtime.InteropServices.ComVisible( true )]
  889. 		public string dateformatout
  890. 		{
  891. 			get
  892. 			{
  893. 				return _dateformatout;
  894. 			}
  895. 			set
  896. 			{
  897. 				if ( value.IndexOfAny( "dMy".ToCharArray( ) ) == -1 )
  898. 				{
  899. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom date format (out) should contain at least one of the characters \"d\", \"M\" or \"y\"" );
  900. 				}
  901. 				else
  902. 				{
  903. 					_dateformatout = value;
  904. 				}
  905. 			}
  906. 		}
  907.  
  908.  
  909. 		private bool _dateonly = false;
  910. 		[System.Runtime.InteropServices.ComVisible( true )]
  911. 		public int dateonly
  912. 		{
  913. 			get
  914. 			{
  915. 				return ( _dateonly ? 1 : 0 );
  916. 			}
  917. 			set
  918. 			{
  919. 				_dateonly = ( value == 1 );
  920. 			}
  921. 		}
  922.  
  923.  
  924. 		private string _dateseparatorgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.DateSeparator;
  925. 		[System.Runtime.InteropServices.ComVisible( true )]
  926. 		public string dateseparatorgui
  927. 		{
  928. 			get
  929. 			{
  930. 				return _dateseparatorgui;
  931. 			}
  932. 			set
  933. 			{
  934. 				_dateseparatorgui = value;
  935. 			}
  936. 		}
  937.  
  938.  
  939. 		[System.Runtime.InteropServices.ComVisible( true )]
  940. 		public string dateseparatorin { get; set; } = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.DateSeparator;
  941.  
  942.  
  943. 		[System.Runtime.InteropServices.ComVisible( true )]
  944. 		public string dateseparatorout { get; set; } = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.DateSeparator;
  945.  
  946.  
  947. 		private System.Collections.Generic.List<string> _debuginfo = new System.Collections.Generic.List<string>( );
  948. 		[System.Runtime.InteropServices.ComVisible( true )]
  949. 		public string debuginfo
  950. 		{
  951. 			get
  952. 			{
  953. 				return string.Join( "\n", _debuginfo.ToArray( ) );
  954. 			}
  955. 		}
  956.  
  957.  
  958. 		private System.DateTime _earliestdate = System.DateTime.MinValue;
  959. 		[System.Runtime.InteropServices.ComVisible( true )]
  960. 		public string earliestdate
  961. 		{
  962. 			get
  963. 			{
  964. 				return _earliestdate.ToString( "yyyy-MM-dd HH:mm:ss" );
  965. 			}
  966. 			set
  967. 			{
  968. 				if ( _maxdaysback != -1 )
  969. 				{
  970. 					_errors.Add( Global.Common.TimeStamp( ) + "You may specify either an earliest date or a maximum number of days back from the initial date, but not both" );
  971. 					_earliestdate = System.DateTime.MinValue;
  972. 				}
  973. 				else if ( System.DateTime.TryParse( value, System.Globalization.CultureInfo.GetCultureInfo( culturein, null ), System.Globalization.DateTimeStyles.None, out System.DateTime testdate ) )
  974. 				{
  975. 					if ( testdate.Ticks > _initialdatetime.Ticks )
  976. 					{
  977. 						_errors.Add( Global.Common.TimeStamp( ) + "Earliest date must be before initial date/time" );
  978. 					}
  979. 					else if ( testdate.Ticks > _latestdate.Ticks )
  980. 					{
  981. 						_errors.Add( Global.Common.TimeStamp( ) + "Earliest date must be before latest date" );
  982. 					}
  983. 					else
  984. 					{
  985. 						_earliestdate = testdate;
  986. 					}
  987. 				}
  988. 				else
  989. 				{
  990. 					_errors.Add( Global.Common.TimeStamp( ) + "Earlist date not recognized as a valid date" );
  991. 				}
  992. 			}
  993. 		}
  994.  
  995.  
  996. 		private System.Collections.Generic.List<string> _errors = new System.Collections.Generic.List<string>( );
  997. 		[System.Runtime.InteropServices.ComVisible( true )]
  998. 		public string errors
  999. 		{
  1000. 			get
  1001. 			{
  1002. 				return string.Join( "\n", _errors.ToArray( ) );
  1003. 			}
  1004. 		}
  1005.  
  1006.  
  1007. 		private System.Drawing.FontFamily _fontfamily = defaultfontfamily;
  1008. 		[System.Runtime.InteropServices.ComVisible( true )]
  1009. 		public string fontfamily
  1010. 		{
  1011. 			get
  1012. 			{
  1013. 				return _fontfamily.Name;
  1014. 			}
  1015. 			set
  1016. 			{
  1017. 				_fontfamily = Global.Common.Validate.FontFamily( value, defaultfontfamily );
  1018. 			}
  1019. 		}
  1020.  
  1021.  
  1022. 		private float _fontsize = defaultfontsize;
  1023. 		[System.Runtime.InteropServices.ComVisible( true )]
  1024. 		public int fontsize
  1025. 		{
  1026. 			get
  1027. 			{
  1028. 				return System.Convert.ToInt32( _fontsize );
  1029. 			}
  1030. 			set
  1031. 			{
  1032. 				_fontsize = System.Convert.ToSingle( value ).LimitToRange( minimumfontsize, maximumfontsize );
  1033. 			}
  1034. 		}
  1035.  
  1036.  
  1037. 		private static System.DateTime _initialdatetime = System.DateTime.Now;
  1038. 		[System.Runtime.InteropServices.ComVisible( true )]
  1039. 		public string initialdatetime
  1040. 		{
  1041. 			get
  1042. 			{
  1043. 				return _initialdatetime.ToString( "yyyy-MM-dd HH:mm:ss" );
  1044. 			}
  1045. 			set
  1046. 			{
  1047. 				if ( System.DateTime.TryParse( value, System.Globalization.CultureInfo.GetCultureInfo( culturein, defaultculture ), System.Globalization.DateTimeStyles.None, out System.DateTime testdatetime ) )
  1048. 				{
  1049. 					if ( testdatetime.Ticks > _latestdate.Ticks )
  1050. 					{
  1051. 						_errors.Add( Global.Common.TimeStamp( ) + "Initial date/time must be before latest date" );
  1052. 						_initialdatetime = System.DateTime.Now;
  1053. 					}
  1054. 					else if ( testdatetime.Ticks > _earliestdate.Ticks )
  1055. 					{
  1056. 						_errors.Add( Global.Common.TimeStamp( ) + "Initial date/time must be after earliest date" );
  1057. 						_initialdatetime = System.DateTime.Now;
  1058. 					}
  1059. 					else
  1060. 					{
  1061. 						_initialdatetime = testdatetime;
  1062. 					}
  1063. 				}
  1064. 				else
  1065. 				{
  1066. 					_errors.Add( Global.Common.TimeStamp( ) + "Initial date/time not recognized as a valid date/time" );
  1067. 					_initialdatetime = System.DateTime.Now;
  1068. 				}
  1069. 			}
  1070. 		}
  1071.  
  1072.  
  1073. 		private System.DateTime _latestdate = System.DateTime.MaxValue;
  1074. 		[System.Runtime.InteropServices.ComVisible( true )]
  1075. 		public string latestdate
  1076. 		{
  1077. 			get
  1078. 			{
  1079. 				return _latestdate.ToString( "yyyy-MM-dd HH:mm:ss" );
  1080. 			}
  1081. 			set
  1082. 			{
  1083. 				if ( _maxdaysforward != -1 )
  1084. 				{
  1085. 					_errors.Add( Global.Common.TimeStamp( ) + "You may specify either a latest date or a maximum number of days forward from the initial date, but not both" );
  1086. 					_latestdate = System.DateTime.MaxValue;
  1087. 				}
  1088. 				else if ( System.DateTime.TryParse( value, System.Globalization.CultureInfo.GetCultureInfo( culturein, null ), System.Globalization.DateTimeStyles.None, out System.DateTime testdate ) )
  1089. 				{
  1090. 					if ( testdate.Ticks < _initialdatetime.Ticks )
  1091. 					{
  1092. 						_errors.Add( Global.Common.TimeStamp( ) + "Latest date must be after initial date/time" );
  1093. 					}
  1094. 					else if ( testdate.Ticks < _earliestdate.Ticks )
  1095. 					{
  1096. 						_errors.Add( Global.Common.TimeStamp( ) + "Latest date must be after earliest date" );
  1097. 					}
  1098. 					else
  1099. 					{
  1100. 						_latestdate = testdate;
  1101. 					}
  1102. 				}
  1103. 				else
  1104. 				{
  1105. 					_errors.Add( Global.Common.TimeStamp( ) + "Latest date not recognized as a valid date" );
  1106. 				}
  1107. 			}
  1108. 		}
  1109.  
  1110.  
  1111. 		private int _left = -1;
  1112. 		[System.Runtime.InteropServices.ComVisible( true )]
  1113. 		public int left
  1114. 		{
  1115. 			get
  1116. 			{
  1117. 				return _left;
  1118. 			}
  1119. 			set
  1120. 			{
  1121. 				if ( value < 0 )
  1122. 				{
  1123. 					_left = 0;
  1124. 				}
  1125. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth )
  1126. 				{
  1127. 					_left = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width - windowwidth;
  1128. 				}
  1129. 				else
  1130. 				{
  1131. 					_left = value;
  1132. 				}
  1133. 			}
  1134. 		}
  1135.  
  1136.  
  1137. 		private bool _literal = false;
  1138. 		[System.Runtime.InteropServices.ComVisible( true )]
  1139. 		public int literal
  1140. 		{
  1141. 			get
  1142. 			{
  1143. 				return ( _literal ? 1 : 0 );
  1144. 			}
  1145. 			set
  1146. 			{
  1147. 				_literal = ( value == 1 );
  1148. 			}
  1149. 		}
  1150.  
  1151.  
  1152. 		private bool _localizecaptions = false;
  1153. 		[System.Runtime.InteropServices.ComVisible( true )]
  1154. 		public int localizecaptions
  1155. 		{
  1156. 			get
  1157. 			{
  1158. 				return ( _localizecaptions ? 1 : 0 );
  1159. 			}
  1160. 			set
  1161. 			{
  1162. 				_localizecaptions = ( value == 1 );
  1163. 			}
  1164. 		}
  1165.  
  1166.  
  1167. 		private int _maxdaysback = -1;
  1168. 		[System.Runtime.InteropServices.ComVisible( true )]
  1169. 		public int maxdaysback
  1170. 		{
  1171. 			get
  1172. 			{
  1173. 				return _maxdaysback;
  1174. 			}
  1175. 			set
  1176. 			{
  1177. 				if ( _latestdate != System.DateTime.MinValue )
  1178. 				{
  1179. 					_errors.Add( Global.Common.TimeStamp( ) + "You may specify either an earliest date or a maximum number of days back from the initial date, but not both" );
  1180. 					_maxdaysback = -1;
  1181. 				}
  1182. 				else if ( value < -1 )
  1183. 				{
  1184. 					_errors.Add( Global.Common.TimeStamp( ) + "Invalid maximum offset in days back" );
  1185. 					_maxdaysback = -1;
  1186. 				}
  1187. 				else if ( _initialdatetime.AddDays( -1 * value ).Ticks > System.DateTime.MaxValue.Ticks )
  1188. 				{
  1189. 					_errors.Add( Global.Common.TimeStamp( ) + "Maximum number of days back from initial date/time exceeds minimum date allowed" );
  1190. 					_maxdaysforward = -1;
  1191. 				}
  1192. 				else
  1193. 				{
  1194. 					_maxdaysback = value;
  1195. 				}
  1196. 			}
  1197. 		}
  1198.  
  1199.  
  1200. 		private int _maxdaysforward = -1;
  1201. 		[System.Runtime.InteropServices.ComVisible( true )]
  1202. 		public int maxdaysforward
  1203. 		{
  1204. 			get
  1205. 			{
  1206. 				return _maxdaysforward;
  1207. 			}
  1208. 			set
  1209. 			{
  1210. 				if ( _latestdate != System.DateTime.MaxValue )
  1211. 				{
  1212. 					_errors.Add( Global.Common.TimeStamp( ) + "You may specify either a latest date or a maximum number of days forward from the initial date, but not both" );
  1213. 					_maxdaysforward = -1;
  1214. 				}
  1215. 				else if ( value < -1 )
  1216. 				{
  1217. 					_errors.Add( Global.Common.TimeStamp( ) + "Invalid maximum offset in days forward" );
  1218. 					_maxdaysforward = -1;
  1219. 				}
  1220. 				else if ( _initialdatetime.AddDays( value ).Ticks > System.DateTime.MaxValue.Ticks )
  1221. 				{
  1222. 					_errors.Add( Global.Common.TimeStamp( ) + "Maximum number of days forward from initial date/time exceeds maximum date allowed" );
  1223. 					_maxdaysforward = -1;
  1224. 				}
  1225. 				else
  1226. 				{
  1227. 					_maxdaysforward = value;
  1228. 				}
  1229. 			}
  1230. 		}
  1231.  
  1232.  
  1233. 		private bool topmost = true;
  1234. 		[System.Runtime.InteropServices.ComVisible( true )]
  1235. 		public int modal
  1236. 		{
  1237. 			get
  1238. 			{
  1239. 				return ( topmost ? 1 : 0 );
  1240. 			}
  1241. 			set
  1242. 			{
  1243. 				topmost = ( value == 1 );
  1244. 			}
  1245. 		}
  1246.  
  1247.  
  1248. 		private string _prompt = string.Empty;
  1249. 		[System.Runtime.InteropServices.ComVisible( true )]
  1250. 		public string prompt
  1251. 		{
  1252. 			get
  1253. 			{
  1254. 				return _prompt;
  1255. 			}
  1256. 			set
  1257. 			{
  1258. 				if ( _literal )
  1259. 				{
  1260. 					_prompt = value.Trim( );
  1261. 				}
  1262. 				else
  1263. 				{
  1264. 					_prompt = value.Replace( "\\n", "\n" ).Replace( "\\t", "\t" ).Trim( );
  1265. 				}
  1266. 			}
  1267. 		}
  1268.  
  1269.  
  1270. 		private System.DateTime _selecteddate = _initialdatetime;
  1271. 		[System.Runtime.InteropServices.ComVisible( true )]
  1272. 		public string selecteddate
  1273. 		{
  1274. 			get
  1275. 			{
  1276. 				if ( cancelled )
  1277. 				{
  1278. 					return string.Empty;
  1279. 				}
  1280. 				else
  1281. 				{
  1282. 					return _selecteddate.ToString( dateformatout, System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ) );
  1283. 				}
  1284. 			}
  1285. 		}
  1286.  
  1287.  
  1288. 		private System.TimeSpan _selectedtime = _initialdatetime.TimeOfDay;
  1289. 		[System.Runtime.InteropServices.ComVisible( true )]
  1290. 		public string selectedtime
  1291. 		{
  1292. 			get
  1293. 			{
  1294. 				if ( cancelled )
  1295. 				{
  1296. 					return string.Empty;
  1297. 				}
  1298. 				else
  1299. 				{
  1300. 					return ( System.DateTime.Now.Date + _selectedtime ).ToString( timeformatout, System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ) );
  1301. 				}
  1302. 			}
  1303. 		}
  1304.  
  1305.  
  1306. 		private int _selectedweek = GetIso8601WeekOfYear( _initialdatetime.Date );
  1307. 		[System.Runtime.InteropServices.ComVisible( true )]
  1308. 		public int selectedweek
  1309. 		{
  1310. 			get
  1311. 			{
  1312. 				if ( cancelled )
  1313. 				{
  1314. 					return -1;
  1315. 				}
  1316. 				else
  1317. 				{
  1318. 					return _selectedweek;
  1319. 				}
  1320. 			}
  1321. 		}
  1322.  
  1323.  
  1324. 		private string _selectedweekday = _initialdatetime.DayOfWeek.ToString( );
  1325. 		[System.Runtime.InteropServices.ComVisible( true )]
  1326. 		public string selectedweekday
  1327. 		{
  1328. 			get
  1329. 			{
  1330. 				if ( cancelled )
  1331. 				{
  1332. 					return string.Empty;
  1333. 				}
  1334. 				else
  1335. 				{
  1336. 					return _selectedweekday;
  1337. 				}
  1338. 			}
  1339. 		}
  1340.  
  1341.  
  1342. 		private string _timeformatgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.LongTimePattern;
  1343. 		[System.Runtime.InteropServices.ComVisible( true )]
  1344. 		public string timeformatgui
  1345. 		{
  1346. 			get
  1347. 			{
  1348. 				return _timeformatgui;
  1349. 			}
  1350. 			set
  1351. 			{
  1352. 				if ( value.IndexOfAny( "hHmst".ToCharArray( ) ) == -1 )
  1353. 				{
  1354. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom time format (GUI) should contain at least one of the characters \"h\", \"H\", \"m\", \"s\" or \"t\"" );
  1355. 				}
  1356. 				else
  1357. 				{
  1358. 					_timeformatgui = value;
  1359. 				}
  1360. 			}
  1361. 		}
  1362.  
  1363.  
  1364. 		private string _timeformatin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.LongTimePattern;
  1365. 		[System.Runtime.InteropServices.ComVisible( true )]
  1366. 		public string timeformatin
  1367. 		{
  1368. 			get
  1369. 			{
  1370. 				return _timeformatin;
  1371. 			}
  1372. 			set
  1373. 			{
  1374. 				if ( value.IndexOfAny( "hHmst".ToCharArray( ) ) == -1 )
  1375. 				{
  1376. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom time format (in) should contain at least one of the characters \"h\", \"H\", \"m\", \"s\" or \"t\"" );
  1377. 				}
  1378. 				else
  1379. 				{
  1380. 					_timeformatin = value;
  1381. 				}
  1382. 			}
  1383. 		}
  1384.  
  1385.  
  1386. 		private string _timeformatout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.LongTimePattern;
  1387. 		[System.Runtime.InteropServices.ComVisible( true )]
  1388. 		public string timeformatout
  1389. 		{
  1390. 			get
  1391. 			{
  1392. 				return _timeformatout;
  1393. 			}
  1394. 			set
  1395. 			{
  1396. 				if ( value.IndexOfAny( "hHmst".ToCharArray( ) ) == -1 )
  1397. 				{
  1398. 					_errors.Add( Global.Common.TimeStamp( ) + "Custom time format (out) should contain at least one of the characters \"h\", \"H\", \"m\", \"s\" or \"t\"" );
  1399. 				}
  1400. 				else
  1401. 				{
  1402. 					_timeformatout = value;
  1403. 				}
  1404. 			}
  1405. 		}
  1406.  
  1407.  
  1408. 		private bool _timeonly = false;
  1409. 		[System.Runtime.InteropServices.ComVisible( true )]
  1410. 		public int timeonly
  1411. 		{
  1412. 			get
  1413. 			{
  1414. 				return ( _timeonly ? 1 : 0 );
  1415. 			}
  1416. 			set
  1417. 			{
  1418. 				_timeonly = ( value == 1 );
  1419. 			}
  1420. 		}
  1421.  
  1422.  
  1423. 		private int _timeout = 0;
  1424. 		[System.Runtime.InteropServices.ComVisible( true )]
  1425. 		public int timeout
  1426. 		{
  1427. 			get
  1428. 			{
  1429. 				return _timeout;
  1430. 			}
  1431. 			set
  1432. 			{
  1433. 				if ( value < 0 || value > 3600 )
  1434. 				{
  1435. 					_timeout = 0;
  1436. 				}
  1437. 				else
  1438. 				{
  1439. 					_timeout = value;
  1440. 				}
  1441. 			}
  1442. 		}
  1443.  
  1444.  
  1445. 		private bool _timeoutelapsed = false;
  1446. 		[System.Runtime.InteropServices.ComVisible( true )]
  1447. 		public int timeoutelapsed => ( _timeoutelapsed ? 1 : 0 );
  1448.  
  1449.  
  1450. 		private string _timeseparatorgui = System.Globalization.CultureInfo.GetCultureInfo( _culturegui, defaultculture ).DateTimeFormat.TimeSeparator;
  1451. 		[System.Runtime.InteropServices.ComVisible( true )]
  1452. 		public string timeseparatorgui
  1453. 		{
  1454. 			get
  1455. 			{
  1456. 				return _timeseparatorgui;
  1457. 			}
  1458. 			set
  1459. 			{
  1460. 				_timeseparatorgui = value;
  1461. 			}
  1462. 		}
  1463.  
  1464.  
  1465. 		private string _timeseparatorin = System.Globalization.CultureInfo.GetCultureInfo( _culturein, defaultculture ).DateTimeFormat.TimeSeparator;
  1466. 		[System.Runtime.InteropServices.ComVisible( true )]
  1467. 		public string timeseparatorin
  1468. 		{
  1469. 			get
  1470. 			{
  1471. 				return _timeseparatorin;
  1472. 			}
  1473. 			set
  1474. 			{
  1475. 				_timeseparatorin = value;
  1476. 			}
  1477. 		}
  1478.  
  1479.  
  1480. 		private string _timeseparatorout = System.Globalization.CultureInfo.GetCultureInfo( _cultureout, defaultculture ).DateTimeFormat.TimeSeparator;
  1481. 		[System.Runtime.InteropServices.ComVisible( true )]
  1482. 		public string timeseparatorout
  1483. 		{
  1484. 			get
  1485. 			{
  1486. 				return _timeseparatorout;
  1487. 			}
  1488. 			set
  1489. 			{
  1490. 				_timeseparatorout = value;
  1491. 			}
  1492. 		}
  1493.  
  1494.  
  1495. 		public static string timestamp => Global.Common.TimeStamp( );
  1496.  
  1497.  
  1498. 		private string _title = defaulttitle;
  1499. 		[System.Runtime.InteropServices.ComVisible( true )]
  1500. 		public string title
  1501. 		{
  1502. 			get
  1503. 			{
  1504. 				return _title;
  1505. 			}
  1506. 			set
  1507. 			{
  1508. 				if ( string.IsNullOrWhiteSpace( value ) )
  1509. 				{
  1510. 					_title = string.Format( "{0},  Version {1}", Global.Common.ProgramInfo.FileName, Global.Common.ProgramInfo.FileVersion );
  1511. 				}
  1512. 				else
  1513. 				{
  1514. 					_title = value.Trim( );
  1515. 				}
  1516. 			}
  1517. 		}
  1518.  
  1519.  
  1520. 		private int _top = -1;
  1521. 		[System.Runtime.InteropServices.ComVisible( true )]
  1522. 		public int top
  1523. 		{
  1524. 			get
  1525. 			{
  1526. 				return _top;
  1527. 			}
  1528. 			set
  1529. 			{
  1530. 				if ( value < 0 )
  1531. 				{
  1532. 					_top = 0;
  1533. 				}
  1534. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight )
  1535. 				{
  1536. 					_top = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height - windowheight;
  1537. 				}
  1538. 				else
  1539. 				{
  1540. 					_top = value;
  1541. 				}
  1542. 			}
  1543. 		}
  1544.  
  1545.  
  1546. 		[System.Runtime.InteropServices.ComVisible( true )]
  1547. 		public string Version
  1548. 		{
  1549. 			get
  1550. 			{
  1551. 				return Global.Common.ProgramInfo.FileVersion;
  1552. 			}
  1553. 		}
  1554.  
  1555.  
  1556. 		private int _windowheight = defaultwindowheight;
  1557. 		[System.Runtime.InteropServices.ComVisible( true )]
  1558. 		public int windowheight
  1559. 		{
  1560. 			get
  1561. 			{
  1562. 				return _windowheight;
  1563. 			}
  1564. 			set
  1565. 			{
  1566. 				if ( value < defaultwindowheight )
  1567. 				{
  1568. 					_windowheight = defaultwindowheight;
  1569. 				}
  1570. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height )
  1571. 				{
  1572. 					_windowheight = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Height;
  1573. 				}
  1574. 				else
  1575. 				{
  1576. 					_windowheight = value;
  1577. 				}
  1578. 			}
  1579. 		}
  1580.  
  1581.  
  1582. 		private int _windowwidth = defaultwindowwidth;
  1583. 		[System.Runtime.InteropServices.ComVisible( true )]
  1584. 		public int windowwidth
  1585. 		{
  1586. 			get
  1587. 			{
  1588. 				return _windowwidth;
  1589. 			}
  1590. 			set
  1591. 			{
  1592. 				if ( value < defaultwindowwidth )
  1593. 				{
  1594. 					_windowwidth = defaultwindowwidth;
  1595. 				}
  1596. 				else if ( value > System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width )
  1597. 				{
  1598. 					_windowwidth = System.Windows.Forms.Screen.PrimaryScreen.Bounds.Width;
  1599. 				}
  1600. 				else
  1601. 				{
  1602. 					_windowwidth = value;
  1603. 				}
  1604. 			}
  1605. 		}
  1606.  
  1607. 		#endregion Properties
  1608.  
  1609.  
  1610. 		#region Event handlers
  1611.  
  1612. 		private void DateTimeBox_DatePicker_TextChanged( object sender, System.EventArgs e )
  1613. 		{
  1614. 			_selecteddate = datepicker.Value;
  1615. 		}
  1616.  
  1617.  
  1618. 		private void DateTimeBox_TimePicker_TextChanged( object sender, System.EventArgs e )
  1619. 		{
  1620. 			_selectedtime = timepicker.Value.TimeOfDay;
  1621. 		}
  1622.  
  1623.  
  1624. 		private void DateTimeBox_Timer_Elapsed( object sender, System.Timers.ElapsedEventArgs e )
  1625. 		{
  1626. 			_timeoutelapsed = true;
  1627. 			if ( !_timeonly )
  1628. 			{
  1629. 				_selecteddate = datepicker.Value;
  1630. 			}
  1631. 			if ( !_dateonly )
  1632. 			{
  1633. 				_selectedtime = timepicker.Value.TimeOfDay;
  1634. 			}
  1635. 			_debuginfo.Add( timestamp + "DateTimeBox dialog result: Timeout elapsed" );
  1636. 			datetimeboxform.Close( );
  1637. 		}
  1638.  
  1639. 		#endregion Event Handlers
  1640. 	}
  1641. }
  1642.  

page last modified: 2024-02-26; loaded in 0.0732 seconds