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

Email服务器

开发平台:

C#

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