wfrm_Domains.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:6k
- 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 Domain.
- /// </summary>
- public class wfrm_Domains : System.Windows.Forms.Form
- {
- private LumiSoft.UI.Controls.WDataGrid grid;
- private LumiSoft.UI.Controls.WButton m_pNew;
- private LumiSoft.UI.Controls.WButton m_pDelete;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private ServerAPI m_ServerAPI = null;
- private wfrm_Main m_pMailManager = null;
- private DataView m_Dv = null;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="serverAPI"></param>
- /// <param name="frmM"></param>
- public wfrm_Domains(ServerAPI serverAPI,wfrm_Main frmM)
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- try
- {
- m_ServerAPI = serverAPI;
- m_pMailManager = frmM;
- InitGrid();
-
- m_Dv = serverAPI.GetDomainList();
- grid.DataSource = m_Dv;
- UpdateButtons();
- }
- catch(Exception x)
- {
- wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
- frm.ShowDialog(this);
- }
- }
- #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_pDelete = new LumiSoft.UI.Controls.WButton();
- ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).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(456, 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_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 = 2;
- this.m_pDelete.Text = "Delete";
- this.m_pDelete.UseStaticViewStyle = true;
- this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
- //
- // Domains
- //
- 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_pNew,
- this.grid});
- this.Name = "Domains";
- this.Text = "Domain";
- ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).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)
- {
- wfrm_Domain frm = new wfrm_Domain(m_ServerAPI);
- if(frm.ShowDialog(this) == DialogResult.OK){
- m_Dv.Table.ImportRow(frm.wp_Dr);
- UpdateButtons();
- m_pMailManager.RefreshForms();
- }
- }
- #endregion
- #region function m_pDelete_Click
- private void m_pDelete_Click(object sender, System.EventArgs e)
- {
- if(MessageBox.Show(this,"Warning: Deleting domain, deletes all domain users and aliases !!!","Delete confirmation",MessageBoxButtons.YesNo,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2) == DialogResult.Yes)
- {
- DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
-
- if(dr != null){
- if(!m_ServerAPI.DeleteDomain(dr["DomainID"].ToString())){
- MessageBox.Show("Error deleting domain.");
- return;
- }
- dr.Delete();
-
- m_pMailManager.RefreshForms();
- UpdateButtons();
- }
- }
- }
- #endregion
- #endregion
- #region function UpdateButtons
- private void UpdateButtons()
- {
- int rowCount = ((DataView)(grid.DataSource)).Count;
-
- if(rowCount > 0){
- m_pDelete.Enabled = true;
- }
- else{
- m_pDelete.Enabled = false;
- }
- }
- #endregion
- #region Grid Init stuff
- private void InitGrid()
- {
- grid.ReadOnly = true;
- DataGridTableStyle ts1 = new DataGridTableStyle();
- ts1.MappingName = "Domains";
-
- DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
- TextCol.MappingName = "DomainName";
- TextCol.HeaderText = "Domain Name";
- TextCol.Width = 200;
- ts1.GridColumnStyles.Add(TextCol);
- DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
- TextCol2.MappingName = "Description";
- TextCol2.HeaderText = "Description";
- TextCol2.Width = 345;
- ts1.GridColumnStyles.Add(TextCol2);
- grid.TableStyles.Add(ts1);
- }
- #endregion
-
- }
- }