frmSetTime.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Text;
  7. using System.Windows.Forms;
  8. namespace Core.LgMes.Client.Comm
  9. {
  10. public partial class frmSetTime : Form
  11. {
  12. public frmSetTime(object obj)
  13. {
  14. InitializeComponent();
  15. try
  16. {
  17. if (obj.ToString().Substring(0, 1) == "0")
  18. _currDateTime = DateTime.Now;
  19. else
  20. _currDateTime = Convert.ToDateTime(obj);
  21. }
  22. catch
  23. {
  24. _currDateTime = DateTime.Now;
  25. }
  26. }
  27. #region " Valiable "
  28. DateTime _currDateTime = new DateTime(2000, 1, 1, 0, 0, 0, 0);
  29. public DateTime _returnTime = new DateTime(2000, 1, 1, 0, 0, 0, 0);
  30. private DateTime _tempDt = new DateTime(2000, 1, 1, 0, 0, 0, 0);
  31. private DateTime _tempClickTime = new DateTime(2000, 1, 1, 0, 0, 0, 0);
  32. private TimeSpan _timeSpan = new TimeSpan(5);
  33. #endregion
  34. private void frmSetTime_Load(object sender, EventArgs e)
  35. {
  36. this.monthCalendar1.SetDate(_currDateTime);
  37. this.ultraDateTimeEditor1.Value = _currDateTime;
  38. }
  39. private void button1_Click(object sender, EventArgs e)
  40. {
  41. try
  42. {
  43. this.ultraDateTimeEditor1.Update();
  44. _returnTime = (DateTime)this.ultraDateTimeEditor1.Value;
  45. this.Close();
  46. }
  47. catch
  48. {
  49. MessageBox.Show("日期格式输入错误,请检查!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
  50. }
  51. }
  52. private void button2_Click(object sender, EventArgs e)
  53. {
  54. this.Close();
  55. }
  56. private void monthCalendar1_DateSelected(object sender, DateRangeEventArgs e)
  57. {
  58. int hour = ((DateTime)this.ultraDateTimeEditor1.Value).Hour;
  59. int minute = ((DateTime)this.ultraDateTimeEditor1.Value).Minute;
  60. _currDateTime = e.Start.AddHours(hour);
  61. _currDateTime = _currDateTime.AddMinutes(minute);
  62. if (_currDateTime != _tempDt)
  63. {
  64. this.ultraDateTimeEditor1.Value = _currDateTime;
  65. _tempDt = _currDateTime;
  66. }
  67. else
  68. {
  69. TimeSpan span = DateTime.Now - _tempClickTime;
  70. if (span.Milliseconds < 200)
  71. {
  72. _returnTime = _currDateTime;
  73. this.Close();
  74. }
  75. }
  76. _tempClickTime = DateTime.Now;
  77. }
  78. private void ultraDateTimeEditor1_ValueChanged(object sender, EventArgs e)
  79. {
  80. try
  81. {
  82. this.ultraDateTimeEditor1.Update();
  83. DateTime dt = (DateTime)this.ultraDateTimeEditor1.Value;
  84. this.monthCalendar1.SetDate(dt);
  85. }
  86. catch { }
  87. }
  88. private void ultraDateTimeEditor1_EditorButtonClick(object sender, Infragistics.Win.UltraWinEditors.EditorButtonEventArgs e)
  89. {
  90. if (e.Button.Key == "now")
  91. {
  92. this.ultraDateTimeEditor1.Value = System.DateTime.Now;
  93. }
  94. }
  95. }
  96. }