wfrm_Security.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:8k
- using System;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using LumiSoft.UI.Controls;
- namespace LumiSoft.MailServer
- {
- /// <summary>
- /// Summary description for Security.
- /// </summary>
- public class wfrm_Security : System.Windows.Forms.Form
- {
- private LumiSoft.UI.Controls.WDataGrid grid;
- private LumiSoft.UI.Controls.WButton m_pNew;
- private LumiSoft.UI.Controls.WButton m_pEdit;
- private LumiSoft.UI.Controls.WButton m_pDelete;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
-
- private ServerAPI m_ServerAPI = null;
- private DataView m_DvSec = null;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="serverAPI"></param>
- public wfrm_Security(ServerAPI serverAPI)
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- m_ServerAPI = serverAPI;
- InitGrid();
- m_DvSec = serverAPI.GetSecurityList();
- grid.DataSource = m_DvSec;
- UpdateButtons();
- }
- #region function Dispose
- /// <summary>
- /// Clean up any resources being used.
- /// </summary>
- protected override void Dispose( bool disposing )
- {
- if( disposing )
- {
- if(components != null)
- {
- components.Dispose();
- }
- }
- base.Dispose( disposing );
- }
- #endregion
- #region Windows Form Designer generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InitializeComponent()
- {
- this.grid = new LumiSoft.UI.Controls.WDataGrid();
- this.m_pNew = new LumiSoft.UI.Controls.WButton();
- this.m_pEdit = new LumiSoft.UI.Controls.WButton();
- this.m_pDelete = new LumiSoft.UI.Controls.WButton();
- ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).BeginInit();
- this.SuspendLayout();
- //
- // grid
- //
- this.grid.CaptionVisible = false;
- this.grid.DataMember = "";
- this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
- this.grid.Location = new System.Drawing.Point(14, 64);
- this.grid.Name = "grid";
- this.grid.Size = new System.Drawing.Size(600, 288);
- this.grid.TabIndex = 0;
- //
- // m_pNew
- //
- this.m_pNew.Location = new System.Drawing.Point(376, 16);
- this.m_pNew.Name = "m_pNew";
- this.m_pNew.Size = new System.Drawing.Size(64, 24);
- this.m_pNew.TabIndex = 1;
- this.m_pNew.Text = "New...";
- this.m_pNew.UseStaticViewStyle = true;
- this.m_pNew.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pNew_Click);
- //
- // m_pEdit
- //
- this.m_pEdit.Location = new System.Drawing.Point(456, 16);
- this.m_pEdit.Name = "m_pEdit";
- this.m_pEdit.Size = new System.Drawing.Size(64, 24);
- this.m_pEdit.TabIndex = 2;
- this.m_pEdit.Text = "Edit...";
- this.m_pEdit.UseStaticViewStyle = true;
- this.m_pEdit.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pEdit_Click);
- //
- // m_pDelete
- //
- this.m_pDelete.Location = new System.Drawing.Point(536, 16);
- this.m_pDelete.Name = "m_pDelete";
- this.m_pDelete.Size = new System.Drawing.Size(64, 24);
- this.m_pDelete.TabIndex = 3;
- this.m_pDelete.Text = "Delete";
- this.m_pDelete.UseStaticViewStyle = true;
- this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
- //
- // Security
- //
- this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
- this.ClientSize = new System.Drawing.Size(628, 373);
- this.Controls.AddRange(new System.Windows.Forms.Control[] {
- this.m_pDelete,
- this.m_pEdit,
- this.m_pNew,
- this.grid});
- this.Name = "Security";
- this.Text = "Security";
- ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- #region Events handling
- #region function m_pNew_Click
- private void m_pNew_Click(object sender, System.EventArgs e)
- {
- try
- {
- wfrm_SecurityEntry frm = new wfrm_SecurityEntry();
- if(frm.ShowDialog(this) == DialogResult.OK){
- 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);
- if(dr == null){
- MessageBox.Show("Error updating alias.");
- return;
- }
- m_DvSec.Table.ImportRow(dr);
-
- UpdateButtons();
- }
- }
- catch(Exception x)
- {
- wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
- frm.ShowDialog(this);
- }
- }
- #endregion
- #region function m_pEdit_Click
- private void m_pEdit_Click(object sender, System.EventArgs e)
- {
- try
- {
- DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
- if(dr != null){
- wfrm_SecurityEntry frm = new wfrm_SecurityEntry(dr);
- if(frm.ShowDialog(this) == DialogResult.OK){
- 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);
-
- dr["Description"] = frm.wp_Description;
- dr["Protocol"] = frm.wp_Protocol;
- dr["Type"] = frm.wp_Type;
- dr["Action"] = frm.wp_Action;
- dr["Content"] = frm.wp_Content;
- dr["StartIP"] = frm.wp_StartIP;
- dr["EndIP"] = frm.wp_EndIP;
- }
- }
- }
- catch(Exception x)
- {
- wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
- frm.ShowDialog(this);
- }
- }
- #endregion
- #region function m_pDelete_Click
- private void m_pDelete_Click(object sender, System.EventArgs e)
- {
- try
- {
- DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
- if(dr != null){
- m_ServerAPI.DeleteSecurityEntry(dr["SecurityID"].ToString());
- dr.Delete();
- UpdateButtons();
- }
- }
- catch(Exception x)
- {
- wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
- frm.ShowDialog(this);
- }
- }
- #endregion
- #endregion
- #region function UpdateButtons
- private void UpdateButtons()
- {
- int rowCount = ((DataView)(grid.DataSource)).Count;
- if(rowCount > 0){
- m_pEdit.Enabled = true;
- m_pDelete.Enabled = true;
- }
- else{
- m_pEdit.Enabled = false;
- m_pDelete.Enabled = false;
- }
- }
- #endregion
- #region Grid Init stuff
- private void InitGrid()
- {
- grid.ReadOnly = true;
- DataGridTableStyle ts1 = new DataGridTableStyle();
- ts1.MappingName = "Security_List";
-
- DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
- TextCol.MappingName = "Description";
- TextCol.HeaderText = "Description";
- TextCol.Width = 180;
- ts1.GridColumnStyles.Add(TextCol);
- DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
- TextCol2.MappingName = "Protocol";
- TextCol2.HeaderText = "Protocol";
- TextCol2.Width = 55;
- ts1.GridColumnStyles.Add(TextCol2);
- DataGridNoActiveCellColumn TextCol3 = new DataGridNoActiveCellColumn();
- TextCol3.MappingName = "Type";
- TextCol3.HeaderText = "Type";
- TextCol3.Width = 65;
- ts1.GridColumnStyles.Add(TextCol3);
- DataGridNoActiveCellColumn TextCol4 = new DataGridNoActiveCellColumn();
- TextCol4.MappingName = "Action";
- TextCol4.HeaderText = "Action";
- TextCol4.Width = 65;
- ts1.GridColumnStyles.Add(TextCol4);
- DataGridNoActiveCellColumn TextCol5 = new DataGridNoActiveCellColumn();
- TextCol5.MappingName = "Content";
- TextCol5.HeaderText = "Content";
- TextCol5.Width = 180;
- ts1.GridColumnStyles.Add(TextCol5);
- grid.TableStyles.Add(ts1);
- }
- #endregion
-
- }
- }