namespace pop { using Application = System.Windows.Forms.Application; using System; using System.Drawing; using System.Collections; using System.ComponentModel; using System.Windows.Forms; using Thread = System.Threading.Thread; /// /// Summary description for PopMenu. /// public class PopMenu : System.Windows.Forms.Form { private Pop iPop; private System.ComponentModel.Container components; private System.Windows.Forms.TextBox iLogTextArea; private System.Windows.Forms.MenuItem iNextMenuItem; private System.Windows.Forms.MenuItem iFirstMenuItem; private System.Windows.Forms.MenuItem iGetMenuItem; private System.Windows.Forms.MenuItem iRemoveMenuItem; private System.Windows.Forms.MenuItem iAddMenuItem; private System.Windows.Forms.MenuItem iQuitMenuItem; private System.Windows.Forms.MenuItem iOperationsMenu; private System.Windows.Forms.MenuItem iFileMenu; private System.Windows.Forms.MainMenu iMainMenuBar; private System.Windows.Forms.TextBox iResultsTextBox; public PopMenu(Pop pPop) { // // Required for Windows Form Designer support // InitializeComponent(); iPop = pPop; // // TODO: Add any constructor code after InitializeComponent call // } /// /// Clean up any resources being used. /// public override void Dispose() { base.Dispose(); components.Dispose(); } /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.components = new System.ComponentModel.Container (); this.iNextMenuItem = new System.Windows.Forms.MenuItem (); this.iFileMenu = new System.Windows.Forms.MenuItem (); this.iFirstMenuItem = new System.Windows.Forms.MenuItem (); this.iQuitMenuItem = new System.Windows.Forms.MenuItem (); this.iAddMenuItem = new System.Windows.Forms.MenuItem (); this.iRemoveMenuItem = new System.Windows.Forms.MenuItem (); this.iLogTextArea = new System.Windows.Forms.TextBox (); this.iResultsTextBox = new System.Windows.Forms.TextBox (); this.iMainMenuBar = new System.Windows.Forms.MainMenu (); this.iGetMenuItem = new System.Windows.Forms.MenuItem (); this.iOperationsMenu = new System.Windows.Forms.MenuItem (); //@this.TrayHeight = 90; //@this.TrayLargeIcon = false; //@this.TrayAutoArrange = true; iNextMenuItem.Text = "Next"; iNextMenuItem.Index = 4; iNextMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iFileMenu.Text = "File"; iFileMenu.Index = 0; iFileMenu.MenuItems.Add(this.iQuitMenuItem); iFirstMenuItem.Text = "First"; iFirstMenuItem.Index = 3; iFirstMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iQuitMenuItem.Text = "Quit"; iQuitMenuItem.Index = 0; iQuitMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iAddMenuItem.Text = "Add"; iAddMenuItem.Index = 0; iAddMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iRemoveMenuItem.Text = "Remove"; iRemoveMenuItem.Index = 1; iRemoveMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iLogTextArea.Location = new System.Drawing.Point (32, 96); iLogTextArea.Multiline = true; iLogTextArea.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; iLogTextArea.TabIndex = 1; iLogTextArea.Size = new System.Drawing.Size (224, 88); iResultsTextBox.Location = new System.Drawing.Point (32, 48); iResultsTextBox.TabIndex = 0; iResultsTextBox.Size = new System.Drawing.Size (224, 20); //@iMainMenuBar.SetLocation (new System.Drawing.Point (7, 7)); iMainMenuBar.MenuItems.Add(this.iFileMenu); iMainMenuBar.MenuItems.Add(this.iOperationsMenu); iGetMenuItem.Text = "Get"; iGetMenuItem.Index = 2; iGetMenuItem.Click += new System.EventHandler (this.iMenuItemClick); iOperationsMenu.Text = "Operations"; iOperationsMenu.Index = 1; iOperationsMenu.MenuItems.Add(this.iAddMenuItem); iOperationsMenu.MenuItems.Add(this.iRemoveMenuItem); iOperationsMenu.MenuItems.Add(this.iGetMenuItem); iOperationsMenu.MenuItems.Add(this.iFirstMenuItem); iOperationsMenu.MenuItems.Add(this.iNextMenuItem); this.Text = "PopMenu"; this.AutoScaleBaseSize = new System.Drawing.Size (5, 13); this.Menu = this.iMainMenuBar; this.Controls.Add (this.iLogTextArea); this.Controls.Add (this.iResultsTextBox); } protected void iMenuItemClick (object sender, System.EventArgs e) { String tLabel = ((MenuItem)sender).Text; switch (tLabel) { case "Add": { PersonInputDialog tPersonInputDialog = new PersonInputDialog(); tPersonInputDialog.ShowDialog(); Person tPerson = tPersonInputDialog.Person; bool tResult = iPop.Add(tPerson); iResultsTextBox.Text = "Person: " + tPerson + " OK:" + tResult; iLogTextArea.Text += "add\r\n"; } break; case "Remove": { NameInputDialog tNameInputDialog = new NameInputDialog(); tNameInputDialog.ShowDialog(); String tName = tNameInputDialog.Name; bool tResult = iPop.Remove(tName); iResultsTextBox.Text = "Name: " + tName + " OK:" + tResult; iLogTextArea.Text += "remove\r\n"; } break; case "Get": { NameInputDialog tNameInputDialog = new NameInputDialog(); tNameInputDialog.ShowDialog(); String tName = tNameInputDialog.Name; Person tPerson = iPop.Get(tName); iDisplayPersonOutputDialog(tPerson); iLogTextArea.Text += "get\r\n"; } break; case "First": { Person tPerson = iPop.GetFirst(); iDisplayPersonOutputDialog(tPerson); iLogTextArea.Text += "first\r\n"; } break; case "Next": { Person tPerson = iPop.Next(); iDisplayPersonOutputDialog(tPerson); iLogTextArea.Text += "next\r\n"; } break; case "Quit": { Application.Exit(); } break; default: { Console.WriteLine("Bad Command"); } break; } } private void iDisplayPersonOutputDialog(Person pPerson) { if (pPerson==null) { iResultsTextBox.Text = "No person has been found"; } else { iResultsTextBox.Text = " "; PersonOutputDialog tPersonOutputDialog = new PersonOutputDialog(pPerson); tPersonOutputDialog.ShowDialog(); } } } }