10052c5efc6c1e5f830b0223b677a5dac07a6005.svn-base 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FrmSeverMain));
  64. this.pictureBox1 = new System.Windows.Forms.PictureBox();
  65. this.listBox1 = new System.Windows.Forms.ListBox();
  66. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();
  67. this.SuspendLayout();
  68. //
  69. // pictureBox1
  70. //
  71. this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  72. this.pictureBox1.Dock = System.Windows.Forms.DockStyle.Top;
  73. this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  74. this.pictureBox1.Location = new System.Drawing.Point(0, 0);
  75. this.pictureBox1.Name = "pictureBox1";
  76. this.pictureBox1.Size = new System.Drawing.Size(480, 112);
  77. this.pictureBox1.SizeMode = System.Windows.Forms.PictureBoxSizeMode.StretchImage;
  78. this.pictureBox1.TabIndex = 0;
  79. this.pictureBox1.TabStop = false;
  80. //
  81. // listBox1
  82. //
  83. this.listBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
  84. this.listBox1.Dock = System.Windows.Forms.DockStyle.Fill;
  85. this.listBox1.ItemHeight = 12;
  86. this.listBox1.Location = new System.Drawing.Point(0, 112);
  87. this.listBox1.Name = "listBox1";
  88. this.listBox1.Size = new System.Drawing.Size(480, 98);
  89. this.listBox1.TabIndex = 1;
  90. //
  91. // FrmSeverMain
  92. //
  93. this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
  94. this.ClientSize = new System.Drawing.Size(480, 215);
  95. this.Controls.Add(this.listBox1);
  96. this.Controls.Add(this.pictureBox1);
  97. this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
  98. this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
  99. this.MaximizeBox = false;
  100. this.Name = "FrmSeverMain";
  101. this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
  102. this.Text = "应用服务";
  103. this.Load += new System.EventHandler(this.FrmSeverMain_Load);
  104. this.Closing += new System.ComponentModel.CancelEventHandler(this.FrmSeverMain_Closing);
  105. ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();
  106. this.ResumeLayout(false);
  107. }
  108. #endregion
  109. //[STAThread]
  110. //static void Main()
  111. //{
  112. // Application.Run(new FrmSeverMain());
  113. //}
  114. public static AppSettingsReader app;
  115. private System.Windows.Forms.PictureBox pictureBox1;
  116. private System.Windows.Forms.ListBox listBox1;
  117. private ClsServerMain cMain;
  118. private void FrmSeverMain_Load(object sender, System.EventArgs e)
  119. {
  120. //==>
  121. //if (System.DateTime.Today > new System.DateTime(2007,1,1)) return;
  122. ApplicationStart();
  123. app = new AppSettingsReader();
  124. this.pictureBox1.Image = System.Drawing.Image.FromFile(@"Image\登录框.jpg");
  125. cMain = new ClsServerMain();
  126. cMain.ShowLogEvent += new Core.Mes.ServerManager.ClsServerMain.ShowLogDelegate(cMain_ShowLog);
  127. cMain.InitServerMain();
  128. }
  129. private void cMain_ShowLog(string log)
  130. {
  131. this.listBox1.Items.Add(log);
  132. this.listBox1.SelectedIndex = this.listBox1.Items.Count - 1;
  133. }
  134. private void FrmSeverMain_Closing(object sender, System.ComponentModel.CancelEventArgs e)
  135. {
  136. if (MessageBox.Show("是否确认退出服务端程序?", "提示", MessageBoxButtons.YesNo,
  137. MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) == DialogResult.No)
  138. {
  139. e.Cancel = true;
  140. }
  141. else
  142. {
  143. ApplicationExit();
  144. Application.Exit();
  145. System.Diagnostics.Process.GetCurrentProcess().Kill();
  146. }
  147. }
  148. private static void ApplicationExit()
  149. {
  150. string path = string.Format(@"{0}/log/Application/{1}.txt", Application.StartupPath, System.DateTime.Now.ToString("yyyy_MM_dd"));
  151. using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
  152. {
  153. StringBuilder sbtxt = new StringBuilder();
  154. sbtxt.AppendLine("==============================================");
  155. sbtxt.AppendLine(string.Format("服务关闭时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm::ss")));
  156. sbtxt.AppendLine("==============================================");
  157. sw.WriteLine(sbtxt.ToString());
  158. }
  159. }
  160. private static void ApplicationStart()
  161. {
  162. string path = string.Format(@"{0}/log/Application/{1}.txt", Application.StartupPath, System.DateTime.Now.ToString("yyyy_MM_dd"));
  163. using (StreamWriter sw = new StreamWriter(path, true, Encoding.UTF8))
  164. {
  165. StringBuilder sbtxt = new StringBuilder();
  166. sbtxt.AppendLine("==============================================");
  167. sbtxt.AppendLine(string.Format("服务开启时间:{0}", DateTime.Now.ToString("yyyy-MM-dd HH:mm::ss")));
  168. sbtxt.AppendLine("==============================================");
  169. sw.WriteLine(sbtxt.ToString());
  170. }
  171. }
  172. }
  173. }