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

Email服务器

开发平台:

C#

  1. using System;
  2. using System.IO;
  3. using System.Drawing;
  4. using System.Collections;
  5. using System.ComponentModel;
  6. using System.Windows.Forms;
  7. using System.Data;
  8. using LumiSoft.UI.Controls;
  9. namespace LumiSoft.MailServer
  10. {
  11. /// <summary>
  12. /// Summary description for Aliases.
  13. /// </summary>
  14. public class wfrm_Aliases : System.Windows.Forms.Form
  15. {
  16. private LumiSoft.UI.Controls.WDataGrid grid;
  17. private LumiSoft.UI.Controls.WLabel mt_domain;
  18. private LumiSoft.UI.Controls.WComboBox m_pDomains;
  19. private LumiSoft.UI.Controls.WButton m_pNew;
  20. private LumiSoft.UI.Controls.WButton m_pEdit;
  21. private LumiSoft.UI.Controls.WButton m_pDelete;
  22. private LumiSoft.UI.Controls.WLabel wLabel1;
  23. /// <summary>
  24. /// Required designer variable.
  25. /// </summary>
  26. private System.ComponentModel.Container components = null;
  27. private ServerAPI m_ServerAPI = null;
  28. private DataView  m_DvAliases = null;
  29. /// <summary>
  30. /// Default constructor.
  31. /// </summary>
  32. /// <param name="serverAPI"></param>
  33. public wfrm_Aliases(ServerAPI serverAPI)
  34. {
  35. //
  36. // Required for Windows Form Designer support
  37. //
  38. InitializeComponent();
  39. //
  40. // TODO: Add any constructor code after InitializeComponent call
  41. //
  42. try
  43. {
  44. m_ServerAPI = serverAPI;
  45. InitGrid();
  46. RefreshForm();
  47. }
  48. catch(Exception x)
  49. {
  50. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  51. frm.ShowDialog(this);
  52. }
  53. }
  54. #region function Dispose
  55. /// <summary>
  56. /// Clean up any resources being used.
  57. /// </summary>
  58. protected override void Dispose( bool disposing )
  59. {
  60. if( disposing )
  61. {
  62. if(components != null)
  63. {
  64. components.Dispose();
  65. }
  66. }
  67. base.Dispose( disposing );
  68. }
  69. #endregion
  70. #region Windows Form Designer generated code
  71. /// <summary>
  72. /// Required method for Designer support - do not modify
  73. /// the contents of this method with the code editor.
  74. /// </summary>
  75. private void InitializeComponent()
  76. {
  77. System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(wfrm_Aliases));
  78. this.grid = new LumiSoft.UI.Controls.WDataGrid();
  79. this.m_pDelete = new LumiSoft.UI.Controls.WButton();
  80. this.m_pEdit = new LumiSoft.UI.Controls.WButton();
  81. this.m_pNew = new LumiSoft.UI.Controls.WButton();
  82. this.m_pDomains = new LumiSoft.UI.Controls.WComboBox();
  83. this.mt_domain = new LumiSoft.UI.Controls.WLabel();
  84. this.wLabel1 = new LumiSoft.UI.Controls.WLabel();
  85. ((System.ComponentModel.ISupportInitialize)(this.grid)).BeginInit();
  86. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).BeginInit();
  87. ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).BeginInit();
  88. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).BeginInit();
  89. ((System.ComponentModel.ISupportInitialize)(this.m_pDomains)).BeginInit();
  90. this.SuspendLayout();
  91. // 
  92. // grid
  93. // 
  94. this.grid.CaptionVisible = false;
  95. this.grid.DataMember = "";
  96. this.grid.HeaderForeColor = System.Drawing.SystemColors.ControlText;
  97. this.grid.Location = new System.Drawing.Point(14, 64);
  98. this.grid.Name = "grid";
  99. this.grid.Size = new System.Drawing.Size(600, 288);
  100. this.grid.TabIndex = 0;
  101. // 
  102. // m_pDelete
  103. // 
  104. this.m_pDelete.Location = new System.Drawing.Point(536, 16);
  105. this.m_pDelete.Name = "m_pDelete";
  106. this.m_pDelete.Size = new System.Drawing.Size(64, 24);
  107. this.m_pDelete.TabIndex = 3;
  108. this.m_pDelete.Text = "Delete";
  109. this.m_pDelete.UseStaticViewStyle = true;
  110. this.m_pDelete.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pDelete_Click);
  111. // 
  112. // m_pEdit
  113. // 
  114. this.m_pEdit.Location = new System.Drawing.Point(456, 16);
  115. this.m_pEdit.Name = "m_pEdit";
  116. this.m_pEdit.Size = new System.Drawing.Size(64, 24);
  117. this.m_pEdit.TabIndex = 2;
  118. this.m_pEdit.Text = "Edit...";
  119. this.m_pEdit.UseStaticViewStyle = true;
  120. this.m_pEdit.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pEdit_Click);
  121. // 
  122. // m_pNew
  123. // 
  124. this.m_pNew.Location = new System.Drawing.Point(376, 16);
  125. this.m_pNew.Name = "m_pNew";
  126. this.m_pNew.Size = new System.Drawing.Size(64, 24);
  127. this.m_pNew.TabIndex = 1;
  128. this.m_pNew.Text = "New...";
  129. this.m_pNew.UseStaticViewStyle = true;
  130. this.m_pNew.ButtonPressed += new LumiSoft.UI.Controls.ButtonPressedEventHandler(this.m_pNew_Click);
  131. // 
  132. // m_pDomains
  133. // 
  134. this.m_pDomains.AcceptsPlussKey = true;
  135. this.m_pDomains.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(228)), ((System.Byte)(224)), ((System.Byte)(220)));
  136. this.m_pDomains.ButtonIcon = ((System.Drawing.Icon)(resources.GetObject("m_pDomains.ButtonIcon")));
  137. this.m_pDomains.ButtonWidth = 18;
  138. this.m_pDomains.DropDownWidth = 168;
  139. this.m_pDomains.Location = new System.Drawing.Point(96, 16);
  140. this.m_pDomains.Mask = LumiSoft.UI.Controls.WEditBox_Mask.Text;
  141. this.m_pDomains.MaxLength = 32767;
  142. this.m_pDomains.Name = "m_pDomains";
  143. this.m_pDomains.ReadOnly = true;
  144. this.m_pDomains.SelectedIndex = -1;
  145. this.m_pDomains.Size = new System.Drawing.Size(168, 20);
  146. this.m_pDomains.TabIndex = 4;
  147. this.m_pDomains.UseStaticViewStyle = true;
  148. this.m_pDomains.VisibleItems = 5;
  149. this.m_pDomains.SelectedIndexChanged += new System.EventHandler(this.m_pDomains_SelectedIndexChanged);
  150. // 
  151. // mt_domain
  152. // 
  153. this.mt_domain.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  154. this.mt_domain.Location = new System.Drawing.Point(16, 16);
  155. this.mt_domain.Name = "mt_domain";
  156. this.mt_domain.Size = new System.Drawing.Size(80, 24);
  157. this.mt_domain.TabIndex = 5;
  158. this.mt_domain.Text = "Domain";
  159. this.mt_domain.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
  160. this.mt_domain.UseStaticViewStyle = true;
  161. // 
  162. // wLabel1
  163. // 
  164. this.wLabel1.Font = new System.Drawing.Font("Microsoft Sans Serif", 8F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
  165. this.wLabel1.Location = new System.Drawing.Point(16, 40);
  166. this.wLabel1.Name = "wLabel1";
  167. this.wLabel1.Size = new System.Drawing.Size(264, 24);
  168. this.wLabel1.TabIndex = 6;
  169. this.wLabel1.Text = "NOTE: Only authenticated users can access aliases !";
  170. this.wLabel1.TextAlign = System.Windows.Forms.HorizontalAlignment.Left;
  171. this.wLabel1.UseStaticViewStyle = false;
  172. // 
  173. // wfrm_Aliases
  174. // 
  175. this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
  176. this.ClientSize = new System.Drawing.Size(628, 373);
  177. this.Controls.AddRange(new System.Windows.Forms.Control[] {
  178.   this.wLabel1,
  179.   this.m_pDelete,
  180.   this.m_pEdit,
  181.   this.m_pNew,
  182.   this.m_pDomains,
  183.   this.mt_domain,
  184.   this.grid});
  185. this.Name = "wfrm_Aliases";
  186. this.Text = "Aliases";
  187. ((System.ComponentModel.ISupportInitialize)(this.grid)).EndInit();
  188. ((System.ComponentModel.ISupportInitialize)(this.m_pDelete)).EndInit();
  189. ((System.ComponentModel.ISupportInitialize)(this.m_pEdit)).EndInit();
  190. ((System.ComponentModel.ISupportInitialize)(this.m_pNew)).EndInit();
  191. ((System.ComponentModel.ISupportInitialize)(this.m_pDomains)).EndInit();
  192. this.ResumeLayout(false);
  193. }
  194. #endregion
  195. #region Events handling
  196. #region function m_pDomains_SelectedIndexChanged
  197. private void m_pDomains_SelectedIndexChanged(object sender, System.EventArgs e)
  198. {
  199. if(m_DvAliases != null){
  200. if(m_pDomains.SelectedItem.ToString() == "ALL"){
  201. m_DvAliases.RowFilter = "";
  202. }
  203. else{
  204. m_DvAliases.RowFilter = "DomainID='" + m_pDomains.SelectedItem.Tag.ToString() + "'";
  205. }
  206. }
  207. }
  208. #endregion
  209. #region function m_pNew_Click
  210. private void m_pNew_Click(object sender, System.EventArgs e)
  211. {
  212. try
  213. {
  214. if(m_pDomains.Items.Count > 0){
  215. wfrm_Alias frm = new wfrm_Alias(m_ServerAPI,m_pDomains.SelectedItem.Tag.ToString());
  216. if(frm.ShowDialog(this) == DialogResult.OK){
  217. DataRow dr = m_ServerAPI.AddAlias(frm.AliasName,frm.Descriprion,frm.Members,frm.DomainID);
  218. if(dr == null){
  219. MessageBox.Show("Error adding alias.");
  220. return;
  221. }
  222. m_DvAliases.Table.ImportRow(dr);
  223. UpdateButtons();
  224. }
  225. }
  226. else{
  227. MessageBox.Show("Please open Emails domain before !");
  228. }
  229. }
  230. catch(Exception x)
  231. {
  232. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  233. frm.ShowDialog(this);
  234. }
  235. }
  236. #endregion
  237. #region function m_pEdit_Click
  238. private void m_pEdit_Click(object sender, System.EventArgs e)
  239. {
  240. try
  241. {
  242. DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
  243. if(dr != null){
  244. wfrm_Alias frm = new wfrm_Alias(m_ServerAPI,dr);
  245. if(frm.ShowDialog(this) == DialogResult.OK){
  246. m_ServerAPI.UpdateAlias(dr["AliasID"].ToString(),frm.AliasName,frm.Descriprion,frm.Members,frm.DomainID);
  247. dr["ALIAS"]       = frm.AliasName;
  248. dr["Description"] = frm.Descriprion;
  249. dr["MEMBERS"]     = frm.Members;
  250. dr["DomainID"]   = frm.DomainID;
  251. }
  252. }
  253. }
  254. catch(Exception x)
  255. {
  256. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  257. frm.ShowDialog(this);
  258. }
  259. }
  260. #endregion
  261. #region function m_pDelete_Click
  262. private void m_pDelete_Click(object sender, System.EventArgs e)
  263. {
  264. try
  265. {
  266. if(MessageBox.Show(this,"To delete User click Yes","Delete confirmation",MessageBoxButtons.YesNo) == DialogResult.Yes)
  267. {
  268. DataRow dr = ((DataView)(grid.DataSource))[grid.CurrentRowIndex].Row;
  269. if(dr != null){
  270. m_ServerAPI.DeleteAlias(dr["AliasID"].ToString());
  271. dr.Delete();
  272. }
  273. UpdateButtons();
  274. }
  275. }
  276. catch(Exception x)
  277. {
  278. wfrm_Error frm = new wfrm_Error(x,new System.Diagnostics.StackTrace());
  279. frm.ShowDialog(this);
  280. }
  281. }
  282. #endregion
  283. #endregion
  284. #region function Fill_Combo
  285. private void Fill_Combo()
  286. {
  287. m_pDomains.Items.Clear();
  288. m_pDomains.Items.Add("ALL","ALL");
  289. DataView dvDomains = m_ServerAPI.GetDomainList();
  290. foreach(DataRowView vDr in dvDomains){
  291. m_pDomains.Items.Add(vDr["DomainName"].ToString(),vDr["DomainID"].ToString());
  292. }
  293. if(m_pDomains.Items.Count > 0){
  294. m_pDomains.SelectedIndex = 0;
  295. }
  296. }
  297. #endregion
  298. #region function UpdateButtons
  299. private void UpdateButtons()
  300. {
  301. int rowCount = ((DataView)(grid.DataSource)).Count;
  302. if(rowCount > 0){
  303. m_pEdit.Enabled   = true;
  304. m_pDelete.Enabled = true;
  305. }
  306. else{
  307. m_pEdit.Enabled   = false;
  308. m_pDelete.Enabled = false;
  309. }
  310. }
  311. #endregion
  312. #region function RefreshForm
  313. public void RefreshForm()
  314. {
  315. Fill_Combo();
  316. m_DvAliases = m_ServerAPI.GetAliasesList("ALL");
  317. grid.DataSource = m_DvAliases;
  318. UpdateButtons();
  319. }
  320. #endregion
  321. #region Grid Init stuff
  322. private void InitGrid()
  323. {
  324. grid.ReadOnly = true;
  325. DataGridTableStyle ts1 = new DataGridTableStyle();
  326. ts1.MappingName = "Aliases";
  327.       
  328. DataGridNoActiveCellColumn TextCol = new DataGridNoActiveCellColumn();
  329. TextCol.MappingName = "AliasName";
  330. TextCol.HeaderText = "AliasName Name";
  331. TextCol.Width = 273;
  332. ts1.GridColumnStyles.Add(TextCol);
  333. DataGridNoActiveCellColumn TextCol2 = new DataGridNoActiveCellColumn();
  334. TextCol2.MappingName = "Description";
  335. TextCol2.HeaderText = "Description";
  336. TextCol2.Width = 272;
  337. ts1.GridColumnStyles.Add(TextCol2);
  338. DataGridNoActiveCellColumn TextCol3 = new DataGridNoActiveCellColumn();
  339. TextCol3.MappingName = "AliasMembers";
  340. TextCol3.HeaderText = "Members";
  341. TextCol3.Width = 545;
  342. ts1.GridColumnStyles.Add(TextCol3);
  343. grid.TableStyles.Add(ts1);
  344. }
  345. #endregion
  346. }
  347. }