Click here to Skip to main content
15,881,139 members
Articles / Web Development / HTML

Implementing WS-SecureConversation in Microsoft IssueVision

Rate me:
Please Sign up or sign in to vote.
4.61/5 (12 votes)
27 Sep 20056 min read 73.1K   776   38  
Adding secure communications to the Microsoft IssueVision sample application using WSE 2.0.
using System;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Resources;
using System.Windows.Forms;

namespace IssueVision
{
	public class IssueNewForm : Form, IObserver
	{
		private Label labelTitle;
		private TextBox txtTitle;
		private Label labelAssigned;
		private Label labelIssue;
		private PaneCaption paneBack;
		private Button btnCancel;
		private Panel Panel11;
		private Button btnSave;
		private PaneCaption paneHeader;
		private TextBox txtComment;
		private ComboBox cmbAssignedTo;
		private ComboBox cmbIssueType;

		private IssueSubject m_subject = null;
		private static string m_lastAssignedTo = string.Empty;
		private static string m_lastIssueType = string.Empty;

		private IContainer components = null;

		public ISubject Subject
		{
			set
			{
				m_subject = (IssueSubject)value;
			}
		}

		public IssueNewForm()
		{
			InitializeComponent();
		}

		public IssueNewForm(Form ownerForm) : this()
		{
			Owner = ownerForm;
		}

		#region Windows Form Designer generated code
		protected override void Dispose(bool disposing)
		{
			if (disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(disposing);
		}

		[DebuggerStepThroughAttribute()]
		private void InitializeComponent()
		{
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(IssueNewForm));
			this.Panel11 = new System.Windows.Forms.Panel();
			this.txtTitle = new System.Windows.Forms.TextBox();
			this.cmbAssignedTo = new System.Windows.Forms.ComboBox();
			this.cmbIssueType = new System.Windows.Forms.ComboBox();
			this.txtComment = new System.Windows.Forms.TextBox();
			this.labelIssue = new System.Windows.Forms.Label();
			this.labelAssigned = new System.Windows.Forms.Label();
			this.labelTitle = new System.Windows.Forms.Label();
			this.paneHeader = new IssueVision.PaneCaption();
			this.btnSave = new System.Windows.Forms.Button();
			this.btnCancel = new System.Windows.Forms.Button();
			this.paneBack = new IssueVision.PaneCaption();
			this.Panel11.SuspendLayout();
			this.SuspendLayout();
			// 
			// Panel11
			// 
			this.Panel11.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(231)), ((System.Byte)(255)));
			this.Panel11.Controls.Add(this.txtTitle);
			this.Panel11.Controls.Add(this.cmbAssignedTo);
			this.Panel11.Controls.Add(this.cmbIssueType);
			this.Panel11.Controls.Add(this.txtComment);
			this.Panel11.Controls.Add(this.labelIssue);
			this.Panel11.Controls.Add(this.labelAssigned);
			this.Panel11.Controls.Add(this.labelTitle);
			this.Panel11.DockPadding.Left = 8;
			this.Panel11.DockPadding.Right = 8;
			this.Panel11.Location = new System.Drawing.Point(8, 30);
			this.Panel11.Name = "Panel11";
			this.Panel11.Size = new System.Drawing.Size(256, 280);
			this.Panel11.TabIndex = 2;
			// 
			// txtTitle
			// 
			this.txtTitle.Location = new System.Drawing.Point(88, 72);
			this.txtTitle.MaxLength = 100;
			this.txtTitle.Name = "txtTitle";
			this.txtTitle.Size = new System.Drawing.Size(160, 20);
			this.txtTitle.TabIndex = 5;
			this.txtTitle.Text = "";
			this.txtTitle.TextChanged += new System.EventHandler(this.txtTitle_TextChanged);
			// 
			// cmbAssignedTo
			// 
			this.cmbAssignedTo.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cmbAssignedTo.Location = new System.Drawing.Point(88, 8);
			this.cmbAssignedTo.Name = "cmbAssignedTo";
			this.cmbAssignedTo.Size = new System.Drawing.Size(160, 21);
			this.cmbAssignedTo.TabIndex = 1;
			// 
			// cmbIssueType
			// 
			this.cmbIssueType.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
			this.cmbIssueType.Location = new System.Drawing.Point(88, 40);
			this.cmbIssueType.Name = "cmbIssueType";
			this.cmbIssueType.Size = new System.Drawing.Size(160, 21);
			this.cmbIssueType.TabIndex = 3;
			// 
			// txtComment
			// 
			this.txtComment.AcceptsReturn = true;
			this.txtComment.Location = new System.Drawing.Point(8, 104);
			this.txtComment.MaxLength = 2000;
			this.txtComment.Multiline = true;
			this.txtComment.Name = "txtComment";
			this.txtComment.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
			this.txtComment.Size = new System.Drawing.Size(240, 164);
			this.txtComment.TabIndex = 6;
			this.txtComment.Text = "";
			// 
			// labelIssue
			// 
			this.labelIssue.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.labelIssue.Location = new System.Drawing.Point(8, 44);
			this.labelIssue.Name = "labelIssue";
			this.labelIssue.Size = new System.Drawing.Size(72, 16);
			this.labelIssue.TabIndex = 2;
			this.labelIssue.Text = "&Issue Type:";
			// 
			// labelAssigned
			// 
			this.labelAssigned.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.labelAssigned.Location = new System.Drawing.Point(8, 12);
			this.labelAssigned.Name = "labelAssigned";
			this.labelAssigned.Size = new System.Drawing.Size(72, 16);
			this.labelAssigned.TabIndex = 0;
			this.labelAssigned.Text = "A&ssigned To:";
			// 
			// labelTitle
			// 
			this.labelTitle.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.labelTitle.Location = new System.Drawing.Point(8, 76);
			this.labelTitle.Name = "labelTitle";
			this.labelTitle.Size = new System.Drawing.Size(72, 16);
			this.labelTitle.TabIndex = 4;
			this.labelTitle.Text = "&Title:";
			// 
			// paneHeader
			// 
			this.paneHeader.AllowActive = false;
			this.paneHeader.AntiAlias = false;
			this.paneHeader.Caption = "Issue";
			this.paneHeader.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
			this.paneHeader.ForeColor = System.Drawing.SystemColors.AppWorkspace;
			this.paneHeader.InactiveGradientHighColor = System.Drawing.Color.FromArgb(((System.Byte)(175)), ((System.Byte)(200)), ((System.Byte)(245)));
			this.paneHeader.InactiveGradientLowColor = System.Drawing.Color.FromArgb(((System.Byte)(205)), ((System.Byte)(225)), ((System.Byte)(250)));
			this.paneHeader.InactiveTextColor = System.Drawing.Color.Black;
			this.paneHeader.Location = new System.Drawing.Point(8, 8);
			this.paneHeader.Name = "paneHeader";
			this.paneHeader.Size = new System.Drawing.Size(256, 22);
			this.paneHeader.TabIndex = 1;
			// 
			// btnSave
			// 
			this.btnSave.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(231)), ((System.Byte)(255)));
			this.btnSave.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnSave.Location = new System.Drawing.Point(104, 320);
			this.btnSave.Name = "btnSave";
			this.btnSave.TabIndex = 0;
			this.btnSave.Text = "Save";
			this.btnSave.Click += new System.EventHandler(this.btnSave_Click);
			// 
			// btnCancel
			// 
			this.btnCancel.BackColor = System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(231)), ((System.Byte)(255)));
			this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
			this.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.System;
			this.btnCancel.Location = new System.Drawing.Point(192, 320);
			this.btnCancel.Name = "btnCancel";
			this.btnCancel.TabIndex = 1;
			this.btnCancel.Text = "Cancel";
			this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
			// 
			// paneBack
			// 
			this.paneBack.AllowActive = false;
			this.paneBack.AntiAlias = false;
			this.paneBack.Font = new System.Drawing.Font("Tahoma", 12F, System.Drawing.FontStyle.Bold);
			this.paneBack.InactiveGradientHighColor = System.Drawing.Color.FromArgb(((System.Byte)(222)), ((System.Byte)(231)), ((System.Byte)(255)));
			this.paneBack.InactiveGradientLowColor = System.Drawing.Color.FromArgb(((System.Byte)(165)), ((System.Byte)(199)), ((System.Byte)(255)));
			this.paneBack.Location = new System.Drawing.Point(0, 0);
			this.paneBack.Name = "paneBack";
			this.paneBack.Size = new System.Drawing.Size(272, 352);
			this.paneBack.TabIndex = 0;
			// 
			// IssueNewForm
			// 
			this.AcceptButton = this.btnSave;
			this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
			this.CancelButton = this.btnCancel;
			this.ClientSize = new System.Drawing.Size(272, 350);
			this.Controls.Add(this.paneHeader);
			this.Controls.Add(this.btnSave);
			this.Controls.Add(this.btnCancel);
			this.Controls.Add(this.Panel11);
			this.Controls.Add(this.paneBack);
			this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
			this.MaximizeBox = false;
			this.Name = "IssueNewForm";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			this.Text = "New Issue";
			this.Load += new System.EventHandler(this.IssueNewForm_Load);
			this.Panel11.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		// Initialize the window, this includes setting the initial position
		// populating the comboboxes and enabling / disabling the OK button.
		private void IssueNewForm_Load(object sender, EventArgs e)
		{
			CenterWindow();
			LoadLookups();
			UpdateButtons();
		}

		// Save button was clicked, add new issue and close window.
		private void btnSave_Click(object sender, EventArgs e)
		{
			// Remember the settings so they can be restored next time. This
			// is a short-time persist, it's reset when the app restarts.
			m_lastAssignedTo = cmbAssignedTo.Text;
			m_lastIssueType = cmbIssueType.Text;
			
			//Add the new issue to the local dataset.
			m_subject.AddIssue(	(int)cmbAssignedTo.SelectedValue, 
								(int)cmbIssueType.SelectedValue, 
								txtTitle.Text.Trim(), 
								txtComment.Text.Trim());
			Close();
		}

		// Decided not to add a new issue, close the window.
		private void btnCancel_Click(object sender, EventArgs e)
		{
			Close();
		}

		// Center the window position to its owner.
		private void CenterWindow()
		{
			// Use default position if the owner is not specified.
			if (Owner != null)
			{
				// Center the window to its owner, could call Form.CenterWindow.
				Location = new Point(	Owner.Location.X + (Owner.Width - Width) / 2, 
										Owner.Location.Y + (Owner.Height - Height) / 2);
			}
		}

		// Populate the comboboxes with the lookup values.
		private void LoadLookups()
		{
			cmbAssignedTo.DataSource = m_subject.Staffers;
			cmbAssignedTo.DisplayMember = "DisplayName";
			cmbAssignedTo.ValueMember = "StafferID";
			cmbAssignedTo.Text = m_lastAssignedTo;
			
			cmbIssueType.DataSource = m_subject.IssueTypes;
			cmbIssueType.DisplayMember = "IssueType";
			cmbIssueType.ValueMember = "IssueTypeID";
			cmbIssueType.Text = m_lastIssueType;
		}

		// Enable / disable the OK button when the title changes.
		private void txtTitle_TextChanged(object sender, EventArgs e)
		{
			UpdateButtons();
		}

		// Disable the OK button if there is not a title.
		private void UpdateButtons()
		{
			btnSave.Enabled = txtTitle.Text.Trim().Length > 0;
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
Weidong has been an information system professional since 1990. He has a Master's degree in Computer Science, and is currently a MCSD .NET

Comments and Discussions