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

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 Security.
  12. /// </summary>
  13. public class wfrm_Security : 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_pEdit;
  18. private LumiSoft.UI.Controls.WButton m_pDelete;
  19. /// <summary>
  20. /// Required designer variable.
  21. /// </summary>
  22. private System.ComponentModel.Container components = null;
  23. private ServerAPI m_ServerAPI = null;
  24. private DataView  m_DvSec     = null;
  25. /// <summary>
  26. /// Default constructor.
  27. /// </summary>
  28. /// <param name="serverAPI"></param>
  29. public wfrm_Security(ServerAPI serverAPI)
  30. {
  31. //
  32. // Required for Windows Form Designer support
  33. //
  34. InitializeComponent();
  35. //
  36. // TODO: Add any constructor code after InitializeComponent call
  37. //
  38. m_ServerAPI = serverAPI;
  39. InitGrid();
  40. m_DvSec = serverAPI.GetSecurityList();
  41. grid.DataSource = m_DvSec;
  42. UpdateButtons();
  43. }
  44. #region function Dispose
  45. /// <summary>
  46. /// Clean up any resources being used.
  47. /// </summary>
  48. protected override void Dispose( bool disposing )
  49. {
  50. if( disposing )
  51. {
  52. if(components != null)
  53. {
  54. components.Dispose();
  55. }
  56. }
  57. base.Dispose( disposing );
  58. }
  59. #endregion
  60. #region Windows Form Designer generated code
  61. /// <summary>
  62. /// Required method for Designer support - do not modify
  63. /// the contents of this method with the code editor.
  64. /// </summary>
  65. private void InitializeComponent()
  66. {
  67. this.grid = new LumiSoft.UI.Controls.WDataGrid();
  68. this.m_pNew = new LumiSoft.UI.Controls.WButton();
  69. this.m_pEdit = new LumiSoft.UI.Controls.WButton();
  70. this.m_pDelete = new LumiSoft.UI.Controls.WButton();
  71. ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
  72. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).BeginInit();
  73. ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).BeginInit();
  74. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).BeginInit();
  75. this.SuspendLayout();
  76. // 
  77. // grid
  78. // 
  79. this.grid.CaptionVisible = false;
  80. this.grid.DataMember = "";
  81. this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  82. this.grid.Location = new System.Drawing.Point(14, 64);
  83. this.grid.Name = "grid";
  84. this.grid.Size = new System.Drawing.Size(600, 288);
  85. this.grid.TabIndex = 0;
  86. // 
  87. // m_pNew
  88. // 
  89. this.m_pNew.Location = new System.Drawing.Point(376, 16);
  90. this.m_pNew.Name = "m_pNew";
  91. this.m_pNew.Size = new System.Drawing.Size(64, 24);
  92. this.m_pNew.TabIndex = 1;
  93. this.m_pNew.Text = "New...";
  94. this.m_pNew.UseStaticViewStyle = true;
  95. this.m_pNew.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pNew_Click);
  96. // 
  97. // m_pEdit
  98. // 
  99. this.m_pEdit.Location = new System.Drawing.Point(456, 16);
  100. this.m_pEdit.Name = "m_pEdit";
  101. this.m_pEdit.Size = new System.Drawing.Size(64, 24);
  102. this.m_pEdit.TabIndex = 2;
  103. this.m_pEdit.Text = "Edit...";
  104. this.m_pEdit.UseStaticViewStyle = true;
  105. this.m_pEdit.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pEdit_Click);
  106. // 
  107. // m_pDelete
  108. // 
  109. this.m_pDelete.Location = new System.Drawing.Point(536, 16);
  110. this.m_pDelete.Name = "m_pDelete";
  111. this.m_pDelete.Size = new System.Drawing.Size(64, 24);
  112. this.m_pDelete.TabIndex = 3;
  113. this.m_pDelete.Text = "Delete";
  114. this.m_pDelete.UseStaticViewStyle = true;
  115. this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
  116. // 
  117. // Security
  118. // 
  119. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  120. this.ClientSize = new System.Drawing.Size(628, 373);
  121. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  122.   this.m_pDelete,
  123.   this.m_pEdit,
  124.   this.m_pNew,
  125.   this.grid});
  126. this.Name = "Security";
  127. this.Text = "Security";
  128. ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
  129. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).EndInit();
  130. ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).EndInit();
  131. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).EndInit();
  132. this.ResumeLayout(false);
  133. }
  134. #endregion
  135. #region Events handling
  136. #region function m_pNew_Click
  137. private void m_pNew_Click(object sender, System.EventArgs e)
  138. {
  139. try
  140. {
  141. wfrm_SecurityEntry frm = new wfrm_SecurityEntry();
  142. if(frm.ShowDialog(this) == DialogResult.OK){
  143. DataRow dr = m_ServerAPI.AddSecurityEntry(frm.wp_Description,frm.wp_Protocol,frm.wp_Type,frm.wp_Action,frm.wp_Content,frm.wp_StartIP,frm.wp_EndIP);
  144. if(dr == null){
  145. MessageBox.Show("Error updating alias.");
  146. return;
  147. }
  148. m_DvSec.Table.ImportRow(dr);
  149. UpdateButtons();
  150. }
  151. }
  152. catch(Exception x)
  153. {
  154. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  155. frm.ShowDialog(this);
  156. }
  157. }
  158. #endregion
  159. #region function m_pEdit_Click
  160. private void m_pEdit_Click(object sender, System.EventArgs e)
  161. {
  162. try
  163. {
  164. DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
  165. if(dr != null){
  166. wfrm_SecurityEntry frm = new wfrm_SecurityEntry(dr);
  167. if(frm.ShowDialog(this) == DialogResult.OK){
  168. m_ServerAPI.UpdateSecurityEntry(dr["SecurityID"].ToString(),frm.wp_Description,frm.wp_Protocol,frm.wp_Type,frm.wp_Action,frm.wp_Content,frm.wp_StartIP,frm.wp_EndIP);
  169. dr["Description"] = frm.wp_Description;
  170. dr["Protocol"]    = frm.wp_Protocol;
  171. dr["Type"]        = frm.wp_Type;
  172. dr["Action"]      = frm.wp_Action;
  173. dr["Content"]     = frm.wp_Content;
  174. dr["StartIP"]     = frm.wp_StartIP;
  175. dr["EndIP"]       = frm.wp_EndIP;
  176. }
  177. }
  178. }
  179. catch(Exception x)
  180. {
  181. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  182. frm.ShowDialog(this);
  183. }
  184. }
  185. #endregion
  186. #region function m_pDelete_Click
  187. private void m_pDelete_Click(object sender, System.EventArgs e)
  188. {
  189. try
  190. {
  191. DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
  192. if(dr != null){
  193. m_ServerAPI.DeleteSecurityEntry(dr["SecurityID"].ToString());
  194. dr.Delete();
  195. UpdateButtons();
  196. }
  197. }
  198. catch(Exception x)
  199. {
  200. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  201. frm.ShowDialog(this);
  202. }
  203. }
  204. #endregion
  205. #endregion
  206. #region function UpdateButtons
  207. private void UpdateButtons()
  208. {
  209. int rowCount = ((DataView)(grid.DataSource)).Count;
  210. if(rowCount > 0){
  211. m_pEdit.Enabled   = true;
  212. m_pDelete.Enabled = true;
  213. }
  214. else{
  215. m_pEdit.Enabled   = false;
  216. m_pDelete.Enabled = false;
  217. }
  218. }
  219. #endregion
  220. #region Grid Init stuff
  221. private void InitGrid()
  222. {
  223. grid.ReadOnly = true;
  224. DataGridTableStyle ts1 = new DataGridTableStyle();
  225. ts1.MappingName = "Security_List";
  226.       
  227. DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
  228. TextCol.MappingName = "Description";
  229. TextCol.HeaderText = "Description";
  230. TextCol.Width = 180;
  231. ts1.GridColumnStyles.Add(TextCol);
  232. DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
  233. TextCol2.MappingName = "Protocol";
  234. TextCol2.HeaderText = "Protocol";
  235. TextCol2.Width = 55;
  236. ts1.GridColumnStyles.Add(TextCol2);
  237. DataGridNoActiveCellColumn TextCol3 = new DataGridNoActiveCellColumn();
  238. TextCol3.MappingName = "Type";
  239. TextCol3.HeaderText = "Type";
  240. TextCol3.Width = 65;
  241. ts1.GridColumnStyles.Add(TextCol3);
  242. DataGridNoActiveCellColumn TextCol4 = new DataGridNoActiveCellColumn();
  243. TextCol4.MappingName = "Action";
  244. TextCol4.HeaderText = "Action";
  245. TextCol4.Width = 65;
  246. ts1.GridColumnStyles.Add(TextCol4);
  247. DataGridNoActiveCellColumn TextCol5 = new DataGridNoActiveCellColumn();
  248. TextCol5.MappingName = "Content";
  249. TextCol5.HeaderText = "Content";
  250. TextCol5.Width = 180;
  251. ts1.GridColumnStyles.Add(TextCol5);
  252. grid.TableStyles.Add(ts1);
  253. }
  254. #endregion
  255. }
  256. }