44b535859372c22e3f8cca4f64188f55155897bc.svn-base 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.Configuration;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.IO;
  9. using System.Text;
  10. namespace Core.Mes.ServerManager
  11. {
  12. /// <summary>
  13. /// FrmSeverMain 的摘要说明。
  14. /// </summary>
  15. public class FrmSeverMain : System.Windows.Forms.Form
  16. {
  17. /// <summary>
  18. /// 必需的设计器变量。
  19. /// </summary>
  20. private System.ComponentModel.Container components = null;
  21. public FrmSeverMain()
  22. {
  23. //
  24. // Windows 窗体设计器支持所必需的
  25. //
  26. InitializeComponent();
  27. //
  28. // TODO: 在 InitializeComponent 调用后添加任何构造函数代码
  29. //
  30. }
  31. /// <summary>
  32. /// 清理所有正在使用的资源。
  33. /// </summary>
  34. protected override void Dispose(bool disposing)
  35. {
  36. try
  37. {
  38. if (disposing)
  39. {
  40. if (cMain != null)
  41. {
  42. cMain.Dispose();
  43. }
  44. if (components != null)
  45. {
  46. components.Dispose();
  47. }
  48. }
  49. System.GC.Collect();
  50. base.Dispose(disposing);
  51. }
  52. catch
  53. {
  54. }
  55. }
  56. #region Windows 窗体设计器生成的代码
  57. /// <summary>
  58. /// 设计器支持所需的方法 - 不要使用代码编辑器修改
  59. /// 此方法的内容。
  60. /// </summary>
  61. private void InitializeComponent()
  62. {
  63. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  64. this.listBox1 = new System.Windows.Forms.ListBox();
  65. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  66. this.SuspendLayout();
  67. //
  68. // pictureBox1
  69. //
  70. this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  71. this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
  72. this.pictureBox1.Location = new System.Drawing.Point(0, 0);
  73. this.pictureBox1.Name = "pictureBox1";
  74. this.pictureBox1.Size = new System.Drawing.Size(480, 112);
  75. this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  76. this.pictureBox1.TabIndex = 0;
  77. this.pictureBox1.TabStop = false;
  78. //
  79. // listBox1
  80. //
  81. this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  82. this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
  83. this.listBox1.ItemHeight = 12;
  84. this.listBox1.Location = new System.Drawing.Point(0, 112);
  85. this.listBox1.Name = "listBox1";
  86. this.listBox1.Size = new System.Drawing.Size(480, 98);
  87. this.listBox1.TabIndex = 1;
  88. //
  89. // FrmSeverMain
  90. //
  91. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  92. this.ClientSize = new System.Drawing.Size(480, 215);
  93. this.Controls.Add(this.listBox1);
  94. this.Controls.Add(this.pictureBox1);
  95. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  96. this.MaximizeBox = false;
  97. this.Name = "FrmSeverMain";
  98. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  99. this.Text = "应用服务";
  100. this.Load += new System.EventHandler(this.FrmSeverMain_Load);
  101. this.Closing += new System.ComponentModel.CancelEventHandler(this.FrmSeverMain_Closing);
  102. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  103. this.ResumeLayout(false);
  104. }
  105. #endregion
  106. //[STAThread]
  107. //static void Main()
  108. //{
  109. // Application.Run(new FrmSeverMain());
  110. //}
  111. public static Configuration config;
  112. private System.Windows.Forms.PictureBox pictureBox1;
  113. private System.Windows.Forms.ListBox listBox1;
  114. private ClsServerMain cMain;
  115. private void FrmSeverMain_Load(object sender, System.EventArgs e)
  116. {
  117. //==>
  118. //if (System.DateTime.Today > new System.DateTime(2007,1,1)) return;
  119. ApplicationStart();
  120. config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
  121. this.pictureBox1.Image = System.Drawing.Image.FromFile(@"Image\登录框.jpg");
  122. cMain = new ClsServerMain();
  123. cMain.ShowLogEvent += new Core.Mes.ServerManager.ClsServerMain.ShowLogDelegate(cMain_ShowLog);
  124. cMain.InitServerMain();
  125. }
  126. private void cMain_ShowLog(string log)
  127. {
  128. this.listBox1.Items.Add(log);
  129. this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
  130. }
  131. private void FrmSeverMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  132. {
  133. if (MessageBox.Show("是否确认退出服务端程序?", "提示", MessageBoxButtons.YesNo,
  134. MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
  135. {
  136. e.Cancel = true;
  137. }
  138. else
  139. {
  140. ApplicationExit();
  141. Application.Exit();
  142. System.Diagnostics.Process.GetCurrentProcess().Kill();
  143. }
  144. }
  145. private static void ApplicationExit()
  146. {
  147. string path = string.Format(@"{0}/log/Application/{1}.txt", Application.StartupPath, System.DateTime.Now.ToString("yyyy_MM_dd"));
  148. using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
  149. {
  150. StringBuilder sbtxt = new StringBuilder();
  151. sbtxt.AppendLine("==============================================");
  152. sbtxt.AppendLine(string.Format("服务关闭时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm::ss")));
  153. sbtxt.AppendLine("==============================================");
  154. sw.WriteLine(sbtxt.ToString());
  155. }
  156. }
  157. private static void ApplicationStart()
  158. {
  159. string path = string.Format(@"{0}/log/Application/{1}.txt", Application.StartupPath, System.DateTime.Now.ToString("yyyy_MM_dd"));
  160. using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
  161. {
  162. StringBuilder sbtxt = new StringBuilder();
  163. sbtxt.AppendLine("==============================================");
  164. sbtxt.AppendLine(string.Format("服务开启时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm::ss")));
  165. sbtxt.AppendLine("==============================================");
  166. sw.WriteLine(sbtxt.ToString());
  167. }
  168. }
  169. }
  170. }