ucCarFormTop.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. namespace MeterModuleLibrary.uc
  12. {
  13. public partial class ucCarFormTop : UserControl
  14. {
  15. public ucCarFormTop()
  16. {
  17. InitializeComponent();
  18. }
  19. private delegate void UpdateUIEventHander(object sender, UpdateUIArgs args); //自定义事件用来从线程中更新控件的值
  20. public class UpdateUIArgs : EventArgs
  21. {
  22. public string textValue { get; private set; }
  23. public UpdateUIArgs(string textValue)
  24. {
  25. this.textValue = textValue;
  26. }
  27. }
  28. private void UpdateUI_Method(object sender, UpdateUIArgs args)
  29. {
  30. if (sender is Label)
  31. {
  32. if (args.textValue == "VisibleTrue")
  33. {
  34. ((Label)sender).Visible = true;
  35. }
  36. else if (args.textValue == "VisibleFalse")
  37. {
  38. ((Label)sender).Visible = false;
  39. }
  40. else if (args.textValue == "ColorRed")
  41. ((Label)sender).ForeColor = Color.Red;
  42. else
  43. {
  44. ((Label)sender).Text = args.textValue;
  45. }
  46. }
  47. }
  48. private void timer1_Tick(object sender, EventArgs e)
  49. {
  50. try
  51. {
  52. DateTime databaseTime = DateTime.Now;//本地时间
  53. string showTime = databaseTime.ToString("yyyy年MM月dd日 HH:mm:ss") + " " + System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat.GetDayName(DateTime.Now.DayOfWeek);
  54. if (lblNowTime.IsHandleCreated)
  55. {
  56. lblNowTime.Invoke(new UpdateUIEventHander(UpdateUI_Method), lblNowTime, new UpdateUIArgs(showTime));
  57. }
  58. }
  59. catch (Exception exp)
  60. {
  61. WriteLog("顶部样式时间显示异常!" + exp.Message);
  62. }
  63. }
  64. private void WriteLog(string str)
  65. {
  66. string m_szRunPath;
  67. m_szRunPath = System.Environment.CurrentDirectory;
  68. if (System.IO.Directory.Exists(m_szRunPath + "\\log") == false)
  69. {
  70. System.IO.Directory.CreateDirectory(m_szRunPath + "\\log");
  71. }
  72. string strDate = System.DateTime.Now.ToString("yyyyMMdd");
  73. string strPathFile = m_szRunPath + "\\log\\" + strDate;
  74. if (!Directory.Exists(strPathFile))//如果不存在就创建file文件夹
  75. {
  76. Directory.CreateDirectory(strPathFile);
  77. }
  78. System.IO.TextWriter tw = new System.IO.StreamWriter(strPathFile + "\\顶部样式_" + strDate + ".log", true);
  79. tw.WriteLine(System.DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
  80. tw.WriteLine(str);
  81. tw.WriteLine("\r\n");
  82. tw.Close();
  83. }
  84. private void pictureBox1_DoubleClick(object sender, EventArgs e)
  85. {
  86. fromLoginOut fo = new fromLoginOut();
  87. fo.ShowDialog();
  88. }
  89. }
  90. }