wfrm_Aliases.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:12k
- using System;
- using System.IO;
- 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 Aliases.
- /// </summary>
- public class wfrm_Aliases : System.Windows.Forms.Form
- {
- private LumiSoft.UI.Controls.WDataGrid grid;
- private LumiSoft.UI.Controls.WLabel mt_domain;
- private LumiSoft.UI.Controls.WComboBox m_pDomains;
- private LumiSoft.UI.Controls.WButton m_pNew;
- private LumiSoft.UI.Controls.WButton m_pEdit;
- private LumiSoft.UI.Controls.WButton m_pDelete;
- private LumiSoft.UI.Controls.WLabel wLabel1;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private ServerAPI m_ServerAPI = null;
- private DataView m_DvAliases = null;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="serverAPI"></param>
- public wfrm_Aliases(ServerAPI serverAPI)
- {
- //
- // Required for Windows Form Designer support
- //
- InitializeComponent();
- //
- // TODO: Add any constructor code after InitializeComponent call
- //
- try
- {
- m_ServerAPI = serverAPI;
- InitGrid();
- RefreshForm();
- }
- 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()
- {
- System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wfrm_Aliases));
- this.grid = new LumiSoft.UI.Controls.WDataGrid();
- this.m_pDelete = new LumiSoft.UI.Controls.WButton();
- this.m_pEdit = new LumiSoft.UI.Controls.WButton();
- this.m_pNew = new LumiSoft.UI.Controls.WButton();
- this.m_pDomains = new LumiSoft.UI.Controls.WComboBox();
- this.mt_domain = new LumiSoft.UI.Controls.WLabel();
- this.wLabel1 = new LumiSoft.UI.Controls.WLabel();
- ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).BeginInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDomains)).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_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);
- //
- // 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_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_pDomains
- //
- this.m_pDomains.AcceptsPlussKey = true;
- this.m_pDomains.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(228)), ((System.Byte)(224)), ((System.Byte)(220)));
- this.m_pDomains.ButtonIcon = ((System.Drawing.Icon)(resources.GetObject("m_pDomains.ButtonIcon")));
- this.m_pDomains.ButtonWidth = 18;
- this.m_pDomains.DropDownWidth = 168;
- this.m_pDomains.Location = new System.Drawing.Point(96, 16);
- this.m_pDomains.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
- this.m_pDomains.MaxLength = 32767;
- this.m_pDomains.Name = "m_pDomains";
- this.m_pDomains.ReadOnly = true;
- this.m_pDomains.SelectedIndex = -1;
- this.m_pDomains.Size = new System.Drawing.Size(168, 20);
- this.m_pDomains.TabIndex = 4;
- this.m_pDomains.UseStaticViewStyle = true;
- this.m_pDomains.VisibleItems = 5;
- this.m_pDomains.SelectedIndexChanged += new System.EventHandler(this.m_pDomains_SelectedIndexChanged);
- //
- // mt_domain
- //
- this.mt_domain.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
- this.mt_domain.Location = new System.Drawing.Point(16, 16);
- this.mt_domain.Name = "mt_domain";
- this.mt_domain.Size = new System.Drawing.Size(80, 24);
- this.mt_domain.TabIndex = 5;
- this.mt_domain.Text = "Domain";
- this.mt_domain.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
- this.mt_domain.UseStaticViewStyle = true;
- //
- // wLabel1
- //
- this.wLabel1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
- this.wLabel1.Location = new System.Drawing.Point(16, 40);
- this.wLabel1.Name = "wLabel1";
- this.wLabel1.Size = new System.Drawing.Size(264, 24);
- this.wLabel1.TabIndex = 6;
- this.wLabel1.Text = "NOTE: Only authenticated users can access aliases !";
- this.wLabel1.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
- this.wLabel1.UseStaticViewStyle = false;
- //
- // wfrm_Aliases
- //
- 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.wLabel1,
- this.m_pDelete,
- this.m_pEdit,
- this.m_pNew,
- this.m_pDomains,
- this.mt_domain,
- this.grid});
- this.Name = "wfrm_Aliases";
- this.Text = "Aliases";
- ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDomains)).EndInit();
- this.ResumeLayout(false);
- }
- #endregion
- #region Events handling
-
- #region function m_pDomains_SelectedIndexChanged
- private void m_pDomains_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- if(m_DvAliases != null){
- if(m_pDomains.SelectedItem.ToString() == "ALL"){
- m_DvAliases.RowFilter = "";
- }
- else{
- m_DvAliases.RowFilter = "DomainID='" + m_pDomains.SelectedItem.Tag.ToString() + "'";
- }
- }
- }
- #endregion
- #region function m_pNew_Click
- private void m_pNew_Click(object sender, System.EventArgs e)
- {
- try
- {
- if(m_pDomains.Items.Count > 0){
- wfrm_Alias frm = new wfrm_Alias(m_ServerAPI,m_pDomains.SelectedItem.Tag.ToString());
- if(frm.ShowDialog(this) == DialogResult.OK){
- DataRow dr = m_ServerAPI.AddAlias(frm.AliasName,frm.Descriprion,frm.Members,frm.DomainID);
- if(dr == null){
- MessageBox.Show("Error adding alias.");
- return;
- }
- m_DvAliases.Table.ImportRow(dr);
- UpdateButtons();
- }
- }
- else{
- MessageBox.Show("Please open Emails domain before !");
- }
- }
- 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_Alias frm = new wfrm_Alias(m_ServerAPI,dr);
- if(frm.ShowDialog(this) == DialogResult.OK){
- m_ServerAPI.UpdateAlias(dr["AliasID"].ToString(),frm.AliasName,frm.Descriprion,frm.Members,frm.DomainID);
-
- dr["ALIAS"] = frm.AliasName;
- dr["Description"] = frm.Descriprion;
- dr["MEMBERS"] = frm.Members;
- dr["DomainID"] = frm.DomainID;
- }
- }
- }
- 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
- {
- if(MessageBox.Show(this,"To delete User click Yes","Delete confirmation",MessageBoxButtons.YesNo) == DialogResult.Yes)
- {
- DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
- if(dr != null){
- m_ServerAPI.DeleteAlias(dr["AliasID"].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 Fill_Combo
- private void Fill_Combo()
- {
- m_pDomains.Items.Clear();
- m_pDomains.Items.Add("ALL","ALL");
- DataView dvDomains = m_ServerAPI.GetDomainList();
- foreach(DataRowView vDr in dvDomains){
- m_pDomains.Items.Add(vDr["DomainName"].ToString(),vDr["DomainID"].ToString());
- }
-
- if(m_pDomains.Items.Count > 0){
- m_pDomains.SelectedIndex = 0;
- }
- }
- #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 function RefreshForm
- public void RefreshForm()
- {
- Fill_Combo();
- m_DvAliases = m_ServerAPI.GetAliasesList("ALL");
- grid.DataSource = m_DvAliases;
- UpdateButtons();
- }
- #endregion
- #region Grid Init stuff
- private void InitGrid()
- {
- grid.ReadOnly = true;
- DataGridTableStyle ts1 = new DataGridTableStyle();
- ts1.MappingName = "Aliases";
-
- DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
- TextCol.MappingName = "AliasName";
- TextCol.HeaderText = "AliasName Name";
- TextCol.Width = 273;
- ts1.GridColumnStyles.Add(TextCol);
- DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
- TextCol2.MappingName = "Description";
- TextCol2.HeaderText = "Description";
- TextCol2.Width = 272;
- ts1.GridColumnStyles.Add(TextCol2);
- DataGridNoActiveCellColumn TextCol3 = new DataGridNoActiveCellColumn();
- TextCol3.MappingName = "AliasMembers";
- TextCol3.HeaderText = "Members";
- TextCol3.Width = 545;
- ts1.GridColumnStyles.Add(TextCol3);
- grid.TableStyles.Add(ts1);
- }
- #endregion
- }
- }