wfrm_BackUp.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:7k
源码类别:

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Data;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. namespace LumiSoft.MailServer
  8. {
  9. /// <summary>
  10. /// Summary description for BackUp.
  11. /// </summary>
  12. public class wfrm_BackUp : System.Windows.Forms.Form
  13. {
  14. private System.Windows.Forms.GroupBox mt_backup;
  15. private LumiSoft.UI.Controls.WButton m_pLoadConf;
  16. private LumiSoft.UI.Controls.WButton m_pSaveConf;
  17. private LumiSoft.UI.Controls.WLabel mt_reload;
  18. private LumiSoft.UI.Controls.WLabel mt_save;
  19. /// <summary>
  20. /// Required designer variable.
  21. /// </summary>
  22. private System.ComponentModel.Container components = null;
  23. private ServerAPI m_ServerAPI  = null;
  24. private wfrm_Main m_pManager   = null;
  25. private DataSet   m_dsSettings = null;
  26. /// <summary>
  27. /// Default constructor.
  28. /// </summary>
  29. /// <param name="serverAPI"></param>
  30. /// <param name="manager"></param>
  31. /// <param name="dsSettings"></param>
  32. public wfrm_BackUp(ServerAPI serverAPI,wfrm_Main manager,DataSet dsSettings)
  33. {
  34. //
  35. // Required for Windows Form Designer support
  36. //
  37. InitializeComponent();
  38. //
  39. // TODO: Add any constructor code after InitializeComponent call
  40. //
  41. m_ServerAPI  = serverAPI;
  42. m_pManager   = manager;
  43. m_dsSettings = dsSettings;
  44. }
  45. #region function Dispose
  46. /// <summary>
  47. /// Clean up any resources being used.
  48. /// </summary>
  49. protected override void Dispose( bool disposing )
  50. {
  51. if( disposing )
  52. {
  53. if(components != null)
  54. {
  55. components.Dispose();
  56. }
  57. }
  58. base.Dispose( disposing );
  59. }
  60. #endregion
  61. #region Windows Form Designer generated code
  62. /// <summary>
  63. /// Required method for Designer support - do not modify
  64. /// the contents of this method with the code editor.
  65. /// </summary>
  66. private void InitializeComponent()
  67. {
  68. this.mt_backup = new System.Windows.Forms.GroupBox();
  69. this.m_pLoadConf = new LumiSoft.UI.Controls.WButton();
  70. this.m_pSaveConf = new LumiSoft.UI.Controls.WButton();
  71. this.mt_reload = new LumiSoft.UI.Controls.WLabel();
  72. this.mt_save = new LumiSoft.UI.Controls.WLabel();
  73. this.mt_backup.SuspendLayout();
  74. ((System.ComponentModel.ISupportInitialize)(this.m_pLoadConf)).BeginInit();
  75. ((System.ComponentModel.ISupportInitialize)(this.m_pSaveConf)).BeginInit();
  76. this.SuspendLayout();
  77. // 
  78. // mt_backup
  79. // 
  80. this.mt_backup.Controls.AddRange(new System.Windows.Forms.Control[] {
  81. this.m_pLoadConf,
  82. this.m_pSaveConf,
  83. this.mt_reload,
  84. this.mt_save});
  85. this.mt_backup.Location = new System.Drawing.Point(8, 24);
  86. this.mt_backup.Name = "mt_backup";
  87. this.mt_backup.Size = new System.Drawing.Size(600, 72);
  88. this.mt_backup.TabIndex = 8;
  89. this.mt_backup.TabStop = false;
  90. this.mt_backup.Text = "Setup Backup";
  91. // 
  92. // m_pLoadConf
  93. // 
  94. this.m_pLoadConf.Location = new System.Drawing.Point(440, 40);
  95. this.m_pLoadConf.Name = "m_pLoadConf";
  96. this.m_pLoadConf.Size = new System.Drawing.Size(144, 22);
  97. this.m_pLoadConf.TabIndex = 13;
  98. this.m_pLoadConf.Text = "Restore Configuration";
  99. this.m_pLoadConf.UseStaticViewStyle = true;
  100. this.m_pLoadConf.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pLoadConf_Click);
  101. // 
  102. // m_pSaveConf
  103. // 
  104. this.m_pSaveConf.Location = new System.Drawing.Point(440, 16);
  105. this.m_pSaveConf.Name = "m_pSaveConf";
  106. this.m_pSaveConf.Size = new System.Drawing.Size(144, 22);
  107. this.m_pSaveConf.TabIndex = 12;
  108. this.m_pSaveConf.Text = "Save Configuration";
  109. this.m_pSaveConf.UseStaticViewStyle = true;
  110. this.m_pSaveConf.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pSaveConf_Click);
  111. // 
  112. // mt_reload
  113. // 
  114. this.mt_reload.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  115. this.mt_reload.Location = new System.Drawing.Point(16, 40);
  116. this.mt_reload.Name = "mt_reload";
  117. this.mt_reload.Size = new System.Drawing.Size(400, 24);
  118. this.mt_reload.TabIndex = 11;
  119. this.mt_reload.Text = "Click Reload to restore previous settings from a file.";
  120. this.mt_reload.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  121. this.mt_reload.UseStaticViewStyle = true;
  122. // 
  123. // mt_save
  124. // 
  125. this.mt_save.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  126. this.mt_save.Location = new System.Drawing.Point(16, 16);
  127. this.mt_save.Name = "mt_save";
  128. this.mt_save.Size = new System.Drawing.Size(400, 24);
  129. this.mt_save.TabIndex = 10;
  130. this.mt_save.Text = "Click Save Configuraton to save all current settings to a file, including Users.";
  131. this.mt_save.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  132. this.mt_save.UseStaticViewStyle = true;
  133. // 
  134. // BackUp
  135. // 
  136. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  137. this.ClientSize = new System.Drawing.Size(616, 221);
  138. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  139.   this.mt_backup});
  140. this.Name = "BackUp";
  141. this.Text = "BackUp";
  142. this.mt_backup.ResumeLayout(false);
  143. ((System.ComponentModel.ISupportInitialize)(this.m_pLoadConf)).EndInit();
  144. ((System.ComponentModel.ISupportInitialize)(this.m_pSaveConf)).EndInit();
  145. this.ResumeLayout(false);
  146. }
  147. #endregion
  148. #region function m_pSaveConf_Click
  149. private void m_pSaveConf_Click(object sender, System.EventArgs e)
  150. {
  151. try
  152. {
  153. string file = DateTime.Today.Year.ToString()   + "_";
  154. file += DateTime.Today.Month.ToString() + "_";
  155. file += DateTime.Today.Day.ToString();
  156. System.Windows.Forms.SaveFileDialog filedlg = new System.Windows.Forms.SaveFileDialog();
  157. filedlg.Filter = "(*.bcp)|*.bcp";
  158. filedlg.InitialDirectory = Application.StartupPath + "\BackUP";
  159. filedlg.RestoreDirectory = true;
  160. filedlg.FileName = file;
  161. if(filedlg.ShowDialog() == DialogResult.OK){
  162. m_ServerAPI.CreateBackUp(filedlg.FileName,m_dsSettings);
  163. }
  164. }
  165. catch(Exception x)
  166. {
  167. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  168. frm.ShowDialog(this);
  169. }
  170. }
  171. #endregion
  172. #region function m_pLoadConf_Click
  173. private void m_pLoadConf_Click(object sender, System.EventArgs e)
  174. {
  175. try
  176. {
  177. if(MessageBox.Show(this,"Warning: Restore overwrites current settings. BackUp Recommended !!!","Restore confirmation",MessageBoxButtons.YesNo) == DialogResult.Yes)
  178. {
  179. System.Windows.Forms.OpenFileDialog filedlg = new System.Windows.Forms.OpenFileDialog();
  180. filedlg.Filter = "(*.bcp)|*.bcp";
  181. filedlg.InitialDirectory = Application.StartupPath + "\BackUP";
  182. filedlg.RestoreDirectory = true;
  183. if(filedlg.ShowDialog() == DialogResult.OK){
  184. m_pSaveConf.Enabled = false;
  185. m_pManager.DisableTabs();
  186. m_ServerAPI.RestoreBackUp(filedlg.FileName);
  187. MessageBox.Show("Please close manager and open it agian to apply settings !");
  188. }
  189. }
  190. }
  191. catch(Exception x)
  192. {
  193. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  194. frm.ShowDialog(this);
  195. }
  196. }
  197. #endregion
  198. }
  199. }