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

Email服务器

开发平台:

C#

  1. using System;
  2. using System.Drawing;
  3. using System.Collections;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Data;
  7. using LumiSoft.UI.Controls;
  8. namespace LumiSoft.MailServer
  9. {
  10. /// <summary>
  11. /// Summary description for Domain.
  12. /// </summary>
  13. public class wfrm_Domains : System.Windows.Forms.Form
  14. {
  15. private LumiSoft.UI.Controls.WDataGrid grid;
  16. private LumiSoft.UI.Controls.WButton m_pNew;
  17. private LumiSoft.UI.Controls.WButton m_pDelete;
  18. /// <summary>
  19. /// Required designer variable.
  20. /// </summary>
  21. private System.ComponentModel.Container components = null;
  22. private ServerAPI m_ServerAPI    = null;
  23. private wfrm_Main m_pMailManager = null;
  24. private DataView  m_Dv           = null;
  25. /// <summary>
  26. /// Default constructor.
  27. /// </summary>
  28. /// <param name="serverAPI"></param>
  29. /// <param name="frmM"></param>
  30. public wfrm_Domains(ServerAPI serverAPI,wfrm_Main frmM)
  31. {
  32. //
  33. // Required for Windows Form Designer support
  34. //
  35. InitializeComponent();
  36. //
  37. // TODO: Add any constructor code after InitializeComponent call
  38. //
  39. try
  40. {
  41. m_ServerAPI    = serverAPI;
  42. m_pMailManager = frmM;
  43. InitGrid();
  44. m_Dv = serverAPI.GetDomainList();
  45. grid.DataSource = m_Dv;
  46.                 UpdateButtons();
  47. }
  48. catch(Exception x)
  49. {
  50. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  51. frm.ShowDialog(this);
  52. }
  53. }
  54. #region function Dispose
  55. /// <summary>
  56. /// Clean up any resources being used.
  57. /// </summary>
  58. protected override void Dispose( bool disposing )
  59. {
  60. if( disposing )
  61. {
  62. if(components != null)
  63. {
  64. components.Dispose();
  65. }
  66. }
  67. base.Dispose( disposing );
  68. }
  69. #endregion
  70. #region Windows Form Designer generated code
  71. /// <summary>
  72. /// Required method for Designer support - do not modify
  73. /// the contents of this method with the code editor.
  74. /// </summary>
  75. private void InitializeComponent()
  76. {
  77. this.grid = new LumiSoft.UI.Controls.WDataGrid();
  78. this.m_pNew = new LumiSoft.UI.Controls.WButton();
  79. this.m_pDelete = new LumiSoft.UI.Controls.WButton();
  80. ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
  81. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).BeginInit();
  82. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).BeginInit();
  83. this.SuspendLayout();
  84. // 
  85. // grid
  86. // 
  87. this.grid.CaptionVisible = false;
  88. this.grid.DataMember = "";
  89. this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  90. this.grid.Location = new System.Drawing.Point(14, 64);
  91. this.grid.Name = "grid";
  92. this.grid.Size = new System.Drawing.Size(600, 288);
  93. this.grid.TabIndex = 0;
  94. // 
  95. // m_pNew
  96. // 
  97. this.m_pNew.Location = new System.Drawing.Point(456, 16);
  98. this.m_pNew.Name = "m_pNew";
  99. this.m_pNew.Size = new System.Drawing.Size(64, 24);
  100. this.m_pNew.TabIndex = 1;
  101. this.m_pNew.Text = "New...";
  102. this.m_pNew.UseStaticViewStyle = true;
  103. this.m_pNew.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pNew_Click);
  104. // 
  105. // m_pDelete
  106. // 
  107. this.m_pDelete.Location = new System.Drawing.Point(536, 16);
  108. this.m_pDelete.Name = "m_pDelete";
  109. this.m_pDelete.Size = new System.Drawing.Size(64, 24);
  110. this.m_pDelete.TabIndex = 2;
  111. this.m_pDelete.Text = "Delete";
  112. this.m_pDelete.UseStaticViewStyle = true;
  113. this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
  114. // 
  115. // Domains
  116. // 
  117. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  118. this.ClientSize = new System.Drawing.Size(628, 373);
  119. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  120.   this.m_pDelete,
  121.   this.m_pNew,
  122.   this.grid});
  123. this.Name = "Domains";
  124. this.Text = "Domain";
  125. ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
  126. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).EndInit();
  127. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).EndInit();
  128. this.ResumeLayout(false);
  129. }
  130. #endregion
  131. #region Events handling
  132. #region function m_pNew_Click
  133. private void m_pNew_Click(object sender, System.EventArgs e)
  134. {
  135. wfrm_Domain frm = new wfrm_Domain(m_ServerAPI);
  136. if(frm.ShowDialog(this) == DialogResult.OK){
  137. m_Dv.Table.ImportRow(frm.wp_Dr);
  138. UpdateButtons();
  139. m_pMailManager.RefreshForms();
  140. }
  141. }
  142. #endregion
  143. #region function m_pDelete_Click
  144. private void m_pDelete_Click(object sender, System.EventArgs e)
  145. {
  146. if(MessageBox.Show(this,"Warning: Deleting domain, deletes all domain users and aliases !!!","Delete confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2) == DialogResult.Yes)
  147. {
  148. DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
  149. if(dr != null){
  150. if(!m_ServerAPI.DeleteDomain(dr["DomainID"].ToString())){
  151. MessageBox.Show("Error deleting domain.");
  152. return;
  153. }
  154. dr.Delete();
  155. m_pMailManager.RefreshForms();
  156. UpdateButtons();
  157. }
  158. }
  159. }
  160. #endregion
  161. #endregion
  162. #region function UpdateButtons
  163. private void UpdateButtons()
  164. {
  165. int rowCount = ((DataView)(grid.DataSource)).Count;
  166. if(rowCount > 0){
  167. m_pDelete.Enabled = true;
  168. }
  169. else{
  170. m_pDelete.Enabled = false;
  171. }
  172. }
  173. #endregion
  174. #region Grid Init stuff
  175. private void InitGrid()
  176. {
  177. grid.ReadOnly = true;
  178. DataGridTableStyle ts1 = new DataGridTableStyle();
  179. ts1.MappingName = "Domains";
  180.       
  181. DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
  182. TextCol.MappingName = "DomainName";
  183. TextCol.HeaderText = "Domain Name";
  184. TextCol.Width = 200;
  185. ts1.GridColumnStyles.Add(TextCol);
  186. DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
  187. TextCol2.MappingName = "Description";
  188. TextCol2.HeaderText = "Description";
  189. TextCol2.Width = 345;
  190. ts1.GridColumnStyles.Add(TextCol2);
  191. grid.TableStyles.Add(ts1);
  192. }
  193. #endregion
  194. }
  195. }