Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using the techniques you learned in Section 23.8 of your textbook, create a web-based address book with similar functionality to the address book app that

Using the techniques you learned in Section 23.8 of your textbook, create a web-based address book with similar functionality to the address book app that you created in Section 22.9 (completed in Programming Exercise 9). Display the address books contents in a GridView. Allow the user to search for entries with a particular last name. I tried the code from a previous answer, 3 years ago and it doesn't work.

The code for the 22.9

using System; using System.Data; using System.Linq; using System.Runtime.Serialization; using System.Windows.Forms; using AddressExample;

namespace CustomerContact { public partial class Contacts : Form { public Contacts() { InitializeComponent(); } // End constructor

// Entity Framework DbContext private AddressExample.AddressBookEntities dbcontext = null;

internal AddressBookEntities Dbcontext { get => Dbcontext2; set => Dbcontext2 = value; } internal AddressBookEntities Dbcontext1 { get => Dbcontext2; set => Dbcontext2 = value; } internal AddressBookEntities Dbcontext2 { get => Dbcontext3; set => Dbcontext3 = value; } internal AddressBookEntities Dbcontext3 { get => dbcontext; set => dbcontext = value; }

// fill our addressBindingSource with all rows, ordered by name private void RefreshContacts() { // Dispose old DbContext, if any if (Dbcontext != null) Dbcontext.Dispose();

// create new DbContext so we can reorder records based on edits Dbcontext = new AddressExample.AddressBookEntities();

//use LINQ to order the Addresses table contents by last name, then first name Dbcontext.Addresses .OrderBy(entry => entry.LastName) .ThenBy(entry => entry.FirstName) .Load();

// specify DataSource for AddressBindingSource addressBindingSource.DataSource = Dbcontext.Addresses.Local; addressBindingSource.MoveFirst(); // go to first result findTextBox.Clear(); // clear the Find TextBox } // End method RefreshContacts

// when the form load, fill it with data from the database private void Contacts_Load(object sender, EventArgs e) { RefreshContacts(); // fill binding with data from database } // end method Contacts_Load

// click event handler for the Save Button in the BlindNavigator saves the changes made in the data private void addressBindingNavigatorSaveItem_Click( object sender, EventArgs e) { Validate(); // validate input fields addressBindingSource.EndEdit(); // complete current edit, if any try to save changes

try { Dbcontext.SaveChanges(); // write changes to database } // end try catch (DbEntityValidateException) { MessageBox.Show("Columns cannot be empty, Entity Validation Exception"); } // end catch

RefreshContacts(); // change back to intial unfiltered data } // end method addressBindingNavigatorSaveItem_Click

// Use Linq to create a data source that contains only people // With last names that start with the specified text private void findbutton_Click(object sender, EventArgs e) { // use LINQ to filter contacts with last names that start with FindTextBox contents var lastNameQuery = from address in Dbcontext.Addresses where address.LastName.Address.StartsWith(findTextBox.Text) orderby address.LastName, address.FirstName select address;

// display matching contacts addressBindingSource.DataSource = lastNameQuery.ToList(); addressBindingSource.MoveFirst(); // go to first result

// don't allow add/delete when contacts are filtered bindingNavigatorAddNewItem.Enabled = false; bindingNavigatorDeleteItem.Enabled = false; } // end method findButton_Click

// reload addressBindingSource with all rows private void browseAllButton_Click(object sender, EventArgs e) { // allow add/delete when contacts are not filtered bindingNavigatorAddNewItem.Enabled = true; bindingNavigatorDeleteItem.Enabled = true; RefreshContacts(); // Change back to intial unfiltered data } // end method browseButton_Click

private class addressBindingSource { public static object DataSource { get; internal set; }

internal static void EndEdit() { throw new NotImplementedException(); }

internal static void MoveFirst() { throw new NotImplementedException(); } }

private class findTextBox { internal static void Clear() { throw new NotImplementedException(); } }

[Serializable] private class DbEntityValidateException : Exception { public DbEntityValidateException() { }

public DbEntityValidateException(string message) : base(message) { }

public DbEntityValidateException(string message, Exception innerException) : base(message, innerException) { }

protected DbEntityValidateException(SerializationInfo info, StreamingContext context) : base(info, context) { } } }// end class Contacts } // end namespace AddressBook

Code for the Design 22.9

using System.ComponentModel; using System.Windows.Forms;

namespace CustomerContact { partial class Contacts { ///

/// Required designer variable. /// private System.ComponentModel.IContainer components = null;

///

/// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); }

#region Windows Form Designer generated code

///

/// 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(); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Contacts)); this.textBox1 = new System.Windows.Forms.TextBox(); this.label1 = new System.Windows.Forms.Label(); this.textBox2 = new System.Windows.Forms.TextBox(); this.label2 = new System.Windows.Forms.Label(); this.textBox3 = new System.Windows.Forms.TextBox(); this.label3 = new System.Windows.Forms.Label(); this.textBox4 = new System.Windows.Forms.TextBox(); this.label4 = new System.Windows.Forms.Label(); this.textBox5 = new System.Windows.Forms.TextBox(); this.label5 = new System.Windows.Forms.Label(); this.textBox6 = new System.Windows.Forms.TextBox(); this.label6 = new System.Windows.Forms.Label(); this.label7 = new System.Windows.Forms.Label(); this.button1 = new System.Windows.Forms.Button(); this.bindingNavigator1 = new System.Windows.Forms.BindingNavigator(this.components); this.bindingNavigatorAddNewItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorCountItem = new System.Windows.Forms.ToolStripLabel(); this.bindingNavigatorDeleteItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorMoveFirstItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorMovePreviousItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorSeparator = new System.Windows.Forms.ToolStripSeparator(); this.bindingNavigatorPositionItem = new System.Windows.Forms.ToolStripTextBox(); this.bindingNavigatorSeparator1 = new System.Windows.Forms.ToolStripSeparator(); this.bindingNavigatorMoveNextItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorMoveLastItem = new System.Windows.Forms.ToolStripButton(); this.bindingNavigatorSeparator2 = new System.Windows.Forms.ToolStripSeparator(); this.button2 = new System.Windows.Forms.Button(); ((System.ComponentModel.ISupportInitialize)(this.bindingNavigator1)).BeginInit(); this.bindingNavigator1.SuspendLayout(); this.SuspendLayout(); // // textBox1 // this.textBox1.Location = new System.Drawing.Point(109, 47); this.textBox1.Name = "textBox1"; this.textBox1.ReadOnly = true; this.textBox1.Size = new System.Drawing.Size(228, 20); this.textBox1.TabIndex = 0; // // label1 // this.label1.AutoSize = true; this.label1.Location = new System.Drawing.Point(11, 50); this.label1.Name = "label1"; this.label1.Size = new System.Drawing.Size(62, 13); this.label1.TabIndex = 1; this.label1.Text = "Address ID:"; // // textBox2 // this.textBox2.Location = new System.Drawing.Point(109, 84); this.textBox2.Name = "textBox2"; this.textBox2.Size = new System.Drawing.Size(228, 20); this.textBox2.TabIndex = 2; // // label2 // this.label2.AutoSize = true; this.label2.Location = new System.Drawing.Point(11, 87); this.label2.Name = "label2"; this.label2.Size = new System.Drawing.Size(60, 13); this.label2.TabIndex = 3; this.label2.Text = "First Name:"; // // textBox3 // this.textBox3.Location = new System.Drawing.Point(109, 124); this.textBox3.Name = "textBox3"; this.textBox3.Size = new System.Drawing.Size(228, 20); this.textBox3.TabIndex = 4; // // label3 // this.label3.AutoSize = true; this.label3.Location = new System.Drawing.Point(10, 127); this.label3.Name = "label3"; this.label3.Size = new System.Drawing.Size(61, 13); this.label3.TabIndex = 5; this.label3.Text = "Last Name:"; // // textBox4 // this.textBox4.Location = new System.Drawing.Point(109, 161); this.textBox4.Name = "textBox4"; this.textBox4.Size = new System.Drawing.Size(228, 20); this.textBox4.TabIndex = 6; // // label4 // this.label4.AutoSize = true; this.label4.Location = new System.Drawing.Point(10, 164); this.label4.Name = "label4"; this.label4.Size = new System.Drawing.Size(39, 13); this.label4.TabIndex = 7; this.label4.Text = "E-Mail:"; // // textBox5 // this.textBox5.Location = new System.Drawing.Point(109, 199); this.textBox5.Name = "textBox5"; this.textBox5.Size = new System.Drawing.Size(228, 20); this.textBox5.TabIndex = 8; // // label5 // this.label5.AutoSize = true; this.label5.Location = new System.Drawing.Point(10, 202); this.label5.Name = "label5"; this.label5.Size = new System.Drawing.Size(81, 13); this.label5.TabIndex = 9; this.label5.Text = "Phone Number:"; // // textBox6 // this.textBox6.Location = new System.Drawing.Point(109, 259); this.textBox6.Name = "textBox6"; this.textBox6.Size = new System.Drawing.Size(172, 20); this.textBox6.TabIndex = 10; // // label6 // this.label6.AutoSize = true; this.label6.Location = new System.Drawing.Point(10, 243); this.label6.Name = "label6"; this.label6.Size = new System.Drawing.Size(130, 13); this.label6.TabIndex = 11; this.label6.Text = "Find an entry by last name"; // // label7 // this.label7.AutoSize = true; this.label7.Location = new System.Drawing.Point(10, 261); this.label7.Name = "label7"; this.label7.Size = new System.Drawing.Size(61, 13); this.label7.TabIndex = 12; this.label7.Text = "Last Name:"; // // button1 // this.button1.Location = new System.Drawing.Point(287, 256); this.button1.Name = "button1"; this.button1.Size = new System.Drawing.Size(75, 23); this.button1.TabIndex = 13; this.button1.Text = "Find"; this.button1.UseVisualStyleBackColor = true; // // bindingNavigator1 // this.bindingNavigator1.AddNewItem = this.bindingNavigatorAddNewItem; this.bindingNavigator1.CountItem = this.bindingNavigatorCountItem; this.bindingNavigator1.DeleteItem = this.bindingNavigatorDeleteItem; this.bindingNavigator1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.bindingNavigatorMoveFirstItem, this.bindingNavigatorMovePreviousItem, this.bindingNavigatorSeparator, this.bindingNavigatorPositionItem, this.bindingNavigatorCountItem, this.bindingNavigatorSeparator1, this.bindingNavigatorMoveNextItem, this.bindingNavigatorMoveLastItem, this.bindingNavigatorSeparator2, this.bindingNavigatorAddNewItem, this.bindingNavigatorDeleteItem}); this.bindingNavigator1.Location = new System.Drawing.Point(0, 0); this.bindingNavigator1.MoveFirstItem = this.bindingNavigatorMoveFirstItem; this.bindingNavigator1.MoveLastItem = this.bindingNavigatorMoveLastItem; this.bindingNavigator1.MoveNextItem = this.bindingNavigatorMoveNextItem; this.bindingNavigator1.MovePreviousItem = this.bindingNavigatorMovePreviousItem; this.bindingNavigator1.Name = "bindingNavigator1"; this.bindingNavigator1.PositionItem = this.bindingNavigatorPositionItem; this.bindingNavigator1.Size = new System.Drawing.Size(372, 25); this.bindingNavigator1.TabIndex = 14; this.bindingNavigator1.Text = "bindingNavigator1"; // // bindingNavigatorAddNewItem // this.bindingNavigatorAddNewItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorAddNewItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorAddNewItem.Image"))); this.bindingNavigatorAddNewItem.Name = "bindingNavigatorAddNewItem"; this.bindingNavigatorAddNewItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorAddNewItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorAddNewItem.Text = "Add new"; // // bindingNavigatorCountItem // this.bindingNavigatorCountItem.Name = "bindingNavigatorCountItem"; this.bindingNavigatorCountItem.Size = new System.Drawing.Size(35, 22); this.bindingNavigatorCountItem.Text = "of {0}"; this.bindingNavigatorCountItem.ToolTipText = "Total number of items"; // // bindingNavigatorDeleteItem // this.bindingNavigatorDeleteItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorDeleteItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorDeleteItem.Image"))); this.bindingNavigatorDeleteItem.Name = "bindingNavigatorDeleteItem"; this.bindingNavigatorDeleteItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorDeleteItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorDeleteItem.Text = "Delete"; // // bindingNavigatorMoveFirstItem // this.bindingNavigatorMoveFirstItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveFirstItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveFirstItem.Image"))); this.bindingNavigatorMoveFirstItem.Name = "bindingNavigatorMoveFirstItem"; this.bindingNavigatorMoveFirstItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveFirstItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveFirstItem.Text = "Move first"; // // bindingNavigatorMovePreviousItem // this.bindingNavigatorMovePreviousItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMovePreviousItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMovePreviousItem.Image"))); this.bindingNavigatorMovePreviousItem.Name = "bindingNavigatorMovePreviousItem"; this.bindingNavigatorMovePreviousItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMovePreviousItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMovePreviousItem.Text = "Move previous"; // // bindingNavigatorSeparator // this.bindingNavigatorSeparator.Name = "bindingNavigatorSeparator"; this.bindingNavigatorSeparator.Size = new System.Drawing.Size(6, 25); // // bindingNavigatorPositionItem // this.bindingNavigatorPositionItem.AccessibleName = "Position"; this.bindingNavigatorPositionItem.AutoSize = false; this.bindingNavigatorPositionItem.Name = "bindingNavigatorPositionItem"; this.bindingNavigatorPositionItem.Size = new System.Drawing.Size(50, 23); this.bindingNavigatorPositionItem.Text = "0"; this.bindingNavigatorPositionItem.ToolTipText = "Current position"; // // bindingNavigatorSeparator1 // this.bindingNavigatorSeparator1.Name = "bindingNavigatorSeparator1"; this.bindingNavigatorSeparator1.Size = new System.Drawing.Size(6, 25); // // bindingNavigatorMoveNextItem // this.bindingNavigatorMoveNextItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveNextItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveNextItem.Image"))); this.bindingNavigatorMoveNextItem.Name = "bindingNavigatorMoveNextItem"; this.bindingNavigatorMoveNextItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveNextItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveNextItem.Text = "Move next"; // // bindingNavigatorMoveLastItem // this.bindingNavigatorMoveLastItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image; this.bindingNavigatorMoveLastItem.Image = ((System.Drawing.Image)(resources.GetObject("bindingNavigatorMoveLastItem.Image"))); this.bindingNavigatorMoveLastItem.Name = "bindingNavigatorMoveLastItem"; this.bindingNavigatorMoveLastItem.RightToLeftAutoMirrorImage = true; this.bindingNavigatorMoveLastItem.Size = new System.Drawing.Size(23, 22); this.bindingNavigatorMoveLastItem.Text = "Move last"; // // bindingNavigatorSeparator2 // this.bindingNavigatorSeparator2.Name = "bindingNavigatorSeparator2"; this.bindingNavigatorSeparator2.Size = new System.Drawing.Size(6, 25); // // button2 // this.button2.Location = new System.Drawing.Point(133, 285); this.button2.Name = "button2"; this.button2.Size = new System.Drawing.Size(106, 23); this.button2.TabIndex = 15; this.button2.Text = "Browse All Entries"; this.button2.UseVisualStyleBackColor = true; // // Contacts // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(372, 327); this.Controls.Add(this.button2); this.Controls.Add(this.bindingNavigator1); this.Controls.Add(this.button1); this.Controls.Add(this.label7); this.Controls.Add(this.label6); this.Controls.Add(this.textBox6); this.Controls.Add(this.label5); this.Controls.Add(this.textBox5); this.Controls.Add(this.label4); this.Controls.Add(this.textBox4); this.Controls.Add(this.label3); this.Controls.Add(this.textBox3); this.Controls.Add(this.label2); this.Controls.Add(this.textBox2); this.Controls.Add(this.label1); this.Controls.Add(this.textBox1); this.Name = "Contacts"; this.Text = "Address Book"; ((System.ComponentModel.ISupportInitialize)(this.bindingNavigator1)).EndInit(); this.bindingNavigator1.ResumeLayout(false); this.bindingNavigator1.PerformLayout(); this.ResumeLayout(false); this.PerformLayout();

}

#endregion

private System.Windows.Forms.TextBox textBox1; private System.Windows.Forms.Label label1; private System.Windows.Forms.TextBox textBox2; private System.Windows.Forms.Label label2; private System.Windows.Forms.TextBox textBox3; private System.Windows.Forms.Label label3; private System.Windows.Forms.TextBox textBox4; private System.Windows.Forms.Label label4; private System.Windows.Forms.TextBox textBox5; private System.Windows.Forms.Label label5; private System.Windows.Forms.TextBox textBox6; private System.Windows.Forms.Label label6; private System.Windows.Forms.Label label7; private System.Windows.Forms.Button button1; private System.Windows.Forms.BindingNavigator bindingNavigator1; private System.Windows.Forms.ToolStripButton bindingNavigatorAddNewItem; private System.Windows.Forms.ToolStripLabel bindingNavigatorCountItem; private System.Windows.Forms.ToolStripButton bindingNavigatorDeleteItem; private System.Windows.Forms.ToolStripButton bindingNavigatorMoveFirstItem; private System.Windows.Forms.ToolStripButton bindingNavigatorMovePreviousItem; private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator; private System.Windows.Forms.ToolStripTextBox bindingNavigatorPositionItem; private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator1; private System.Windows.Forms.ToolStripButton bindingNavigatorMoveNextItem; private System.Windows.Forms.ToolStripButton bindingNavigatorMoveLastItem; private System.Windows.Forms.ToolStripSeparator bindingNavigatorSeparator2; private System.Windows.Forms.Button button2;

public IContainer Components { get => components; set => components = value; } public TextBox TextBox1 { get => textBox1; set => textBox1 = value; } public Label Label1 { get => label1; set => label1 = value; } public TextBox TextBox2 { get => textBox2; set => textBox2 = value; } public Label Label2 { get => label2; set => label2 = value; } public TextBox TextBox3 { get => textBox3; set => textBox3 = value; } public Label Label3 { get => label3; set => label3 = value; } public TextBox TextBox4 { get => textBox4; set => textBox4 = value; } public Label Label4 { get => label4; set => label4 = value; } public TextBox TextBox5 { get => textBox5; set => textBox5 = value; } public Label Label5 { get => label5; set => label5 = value; } public TextBox TextBox6 { get => textBox6; set => textBox6 = value; } public Label Label6 { get => label6; set => label6 = value; } public Label Label7 { get => label7; set => label7 = value; } public Button Button1 { get => button1; set => button1 = value; } public BindingNavigator BindingNavigator1 { get => bindingNavigator1; set => bindingNavigator1 = value; } public ToolStripButton BindingNavigatorAddNewItem { get => bindingNavigatorAddNewItem; set => bindingNavigatorAddNewItem = value; } public ToolStripLabel BindingNavigatorCountItem { get => bindingNavigatorCountItem; set => bindingNavigatorCountItem = value; } public ToolStripButton BindingNavigatorDeleteItem { get => bindingNavigatorDeleteItem; set => bindingNavigatorDeleteItem = value; } public ToolStripButton BindingNavigatorMoveFirstItem { get => bindingNavigatorMoveFirstItem; set => bindingNavigatorMoveFirstItem = value; } public ToolStripButton BindingNavigatorMovePreviousItem { get => bindingNavigatorMovePreviousItem; set => bindingNavigatorMovePreviousItem = value; } public ToolStripSeparator BindingNavigatorSeparator { get => bindingNavigatorSeparator; set => bindingNavigatorSeparator = value; } public ToolStripTextBox BindingNavigatorPositionItem { get => bindingNavigatorPositionItem; set => bindingNavigatorPositionItem = value; } public ToolStripSeparator BindingNavigatorSeparator1 { get => bindingNavigatorSeparator1; set => bindingNavigatorSeparator1 = value; } public ToolStripButton BindingNavigatorMoveNextItem { get => bindingNavigatorMoveNextItem; set => bindingNavigatorMoveNextItem = value; } public ToolStripButton BindingNavigatorMoveLastItem { get => bindingNavigatorMoveLastItem; set => bindingNavigatorMoveLastItem = value; } public ToolStripSeparator BindingNavigatorSeparator2 { get => bindingNavigatorSeparator2; set => bindingNavigatorSeparator2 = value; } public Button Button2 { get => button2; set => button2 = value; } } }

image text in transcribed

CustomerComact . Microsoft wsual St.dis Quick Lzunch (Ctrl+ odress It: Finalab Bowse Al Entres CorescDOCats,ett.se Code Dusiipiin Cs 261 object' dosn contzin a definition for OrdeBynd ro eterin mathod rdey accepting 2firt arqument ofpobject cou d befound are you misin asirq cirectve or an 2ssmbly refesnc Farm P Prog am lype here to search

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing Fundamentals, Design, and Implementation

Authors: David M. Kroenke, David J. Auer

14th edition

133876705, 9781292107639, 1292107634, 978-0133876703

More Books

Students also viewed these Databases questions

Question

How would you manage data using dynamic memory allocation?

Answered: 1 week ago

Question

Are S 3 bucket name globally unique?

Answered: 1 week ago