wfrm_Users.cs
上传用户:horngjaan
上传日期:2009-12-12
资源大小:2882k
文件大小:11k
- using System;
- using System.IO;
- using System.Drawing;
- using System.Collections;
- using System.ComponentModel;
- using System.Windows.Forms;
- using System.Data;
- using System.Data.SqlClient;
- using LumiSoft.UI.Controls;
- namespace LumiSoft.MailServer
- {
- /// <summary>
- /// Summary description for User.
- /// </summary>
- public class wfrm_Users : 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;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- private ServerAPI m_ServerAPI = null;
- private DataView m_DvUsers = null;
- /// <summary>
- /// Default constructor.
- /// </summary>
- /// <param name="serverAPI"></param>
- public wfrm_Users(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_Users));
- this.grid = new LumiSoft.UI.Controls.WDataGrid();
- this.mt_domain = new LumiSoft.UI.Controls.WLabel();
- this.m_pDomains = new LumiSoft.UI.Controls.WComboBox();
- 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_pDomains)).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;
- //
- // 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;
- //
- // 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 = 1;
- this.m_pDomains.UseStaticViewStyle = true;
- this.m_pDomains.VisibleItems = 5;
- this.m_pDomains.SelectedIndexChanged += new System.EventHandler(this.m_pDomains_SelectedIndexChanged);
- //
- // 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 = 2;
- 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 = 3;
- 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 = 4;
- this.m_pDelete.Text = "Delete";
- this.m_pDelete.UseStaticViewStyle = true;
- this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
- //
- // wfrm_Users
- //
- 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.m_pDomains,
- this.mt_domain,
- this.grid});
- this.Name = "wfrm_Users";
- this.Text = "User";
- ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
- ((System.ComponentModel.ISupportInitialize)(this.m_pDomains)).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_pDomains_SelectedIndexChanged
- private void m_pDomains_SelectedIndexChanged(object sender, System.EventArgs e)
- {
- if(m_DvUsers != null){
- if(m_pDomains.SelectedItem.ToString() == "ALL"){
- m_DvUsers.RowFilter = "";
- }
- else{
- m_DvUsers.RowFilter = "DomainID='" + m_pDomains.SelectedItem.Tag.ToString() + "'";
- }
- }
- }
- #endregion
- #region function m_pNew_Click
- private void m_pNew_Click(object sender, System.EventArgs e)
- {
- if(m_pDomains.Items.Count > 1){
- wfrm_User frm = new wfrm_User(m_ServerAPI,m_pDomains.SelectedItem.Tag.ToString());
- if(frm.ShowDialog(this) == DialogResult.OK){
- DataRow dr = m_ServerAPI.AddUser(frm.FullName,frm.UserName,frm.Password,frm.Description,frm.Emailss,frm.DomainID,frm.MailboxSize);
- if(dr == null){
- MessageBox.Show("Error adding user.");
- return;
- }
- m_DvUsers.Table.ImportRow(dr);
- UpdateButtons();
- }
- }
- else{
- MessageBox.Show("Please open Emails domain before !");
- }
- }
- #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_User frm = new wfrm_User(m_ServerAPI,dr);
- if(frm.ShowDialog(this) == DialogResult.OK){
-
- m_ServerAPI.UpdateUser(dr["UserID"].ToString(),frm.FullName,frm.Password,frm.Description,frm.Emailss,frm.DomainID,frm.MailboxSize);
- dr["FULLNAME"] = frm.FullName;
- dr["USERNAME"] = frm.UserName;
- dr["PASSWORD"] = frm.Password;
- dr["Description"] = frm.Description;
- dr["Emails"] = frm.Emailss;
- dr["DomainID"] = frm.DomainID;
- dr["Mailbox_Size"] = frm.MailboxSize;
- }
- }
- }
- 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.DeleteUser(dr["UserID"].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_DvUsers = m_ServerAPI.GetUserList("ALL");
- grid.DataSource = m_DvUsers;
- UpdateButtons();
- }
- #endregion
- #region Grid Init stuff
- private void InitGrid()
- {
- grid.ReadOnly = true;
- DataGridTableStyle ts1 = new DataGridTableStyle();
- ts1.MappingName = "Users";
- DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
- TextCol2.MappingName = "UserName";
- TextCol2.HeaderText = "Mailbox";
- TextCol2.Width = 145;
- ts1.GridColumnStyles.Add(TextCol2);
-
- DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
- TextCol.MappingName = "Emails";
- TextCol.HeaderText = "E-mail Address";
- TextCol.Width = 400;
- ts1.GridColumnStyles.Add(TextCol);
-
- DataGridNoActiveCellColumn TextCol3 = new DataGridNoActiveCellColumn();
- TextCol3.MappingName = "Description";
- TextCol3.HeaderText = "Description";
- TextCol3.Width = 250;
- ts1.GridColumnStyles.Add(TextCol3);
- grid.TableStyles.Add(ts1);
- }
- #endregion
-
- }
- }