Using the techniques you learned in Section 23.8 of your textbook, create a web-
ID: 3858742 • Letter: U
Question
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 book’s 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
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
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; }
}
}
Explanation / Answer
Program.cs
----------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
namespace AddressBook
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Contacts());
}
}
}
-----------------------------------------
Contacts.cs
-------------------------
using System;
using System.Linq;
using System.Windows.Forms;
namespace AddressBook
{
public partial class Contacts : Form
{
public Contacts()
{
InitializeComponent();
} // end constructor
// LINQ to SQL data context
private AddressBookDataContext database =
new AddressBookDataContext();
// fill our addressBindingSource with all rows, ordered by name
private void RefreshContacts()
{
// use LINQ to create a data source from the database
addressBindingSource.DataSource =
from address in database.Addresses
orderby address.LastName, address.FirstName
select address;
addressBindingSource.MoveFirst(); // go to the first result
findTextBox.Clear(); // clear the Find TextBox
} // end method RefreshContacts
// when the form loads, 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
// BindingNavigator saves the changes made to the data
private void addressBindingNavigatorSaveItem_Click(
object sender, EventArgs e )
{
Validate(); // validate input fields
addressBindingSource.EndEdit(); // indicate edits are complete
database.SubmitChanges(); // write changes to database file
RefreshContacts(); // change back to initial 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 create a data source from the database
addressBindingSource.DataSource =
from address in database.Addresses
where address.LastName.StartsWith( findTextBox.Text )
orderby address.LastName, address.FirstName
select address;
addressBindingSource.MoveFirst(); // go to first result
} // end method findButton_Click
// reload addressBindingSource with all rows
private void browseButton_Click( object sender, EventArgs e )
{
RefreshContacts(); // change back to initial unfiltered data
} // end method browseButton_Click
} // end class Contacts
} // end namespace AddressBook
-------------------------------------------
Contacts.Designer.cs
--------------------------
namespace AddressBook
{
partial class Contacts
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Windows.Forms.Label addressIDLabel;
System.Windows.Forms.Label emailLabel;
System.Windows.Forms.Label firstNameLabel;
System.Windows.Forms.Label lastNameLabel;
System.Windows.Forms.Label phoneNumberLabel;
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(Contacts));
this.addressBindingNavigator = new System.Windows.Forms.BindingNavigator(this.components);
this.bindingNavigatorAddNewItem = new System.Windows.Forms.ToolStripButton();
this.addressBindingSource = new System.Windows.Forms.BindingSource(this.components);
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.addressBindingNavigatorSaveItem = new System.Windows.Forms.ToolStripButton();
this.addressIDTextBox = new System.Windows.Forms.TextBox();
this.emailTextBox = new System.Windows.Forms.TextBox();
this.firstNameTextBox = new System.Windows.Forms.TextBox();
this.lastNameTextBox = new System.Windows.Forms.TextBox();
this.phoneNumberTextBox = new System.Windows.Forms.TextBox();
this.browseAllButton = new System.Windows.Forms.Button();
this.findGroupBox = new System.Windows.Forms.GroupBox();
this.findButton = new System.Windows.Forms.Button();
this.findLabel = new System.Windows.Forms.Label();
this.findTextBox = new System.Windows.Forms.TextBox();
addressIDLabel = new System.Windows.Forms.Label();
emailLabel = new System.Windows.Forms.Label();
firstNameLabel = new System.Windows.Forms.Label();
lastNameLabel = new System.Windows.Forms.Label();
phoneNumberLabel = new System.Windows.Forms.Label();
((System.ComponentModel.ISupportInitialize)(this.addressBindingNavigator)).BeginInit();
this.addressBindingNavigator.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.addressBindingSource)).BeginInit();
this.findGroupBox.SuspendLayout();
this.SuspendLayout();
//
// addressIDLabel
//
addressIDLabel.AutoSize = true;
addressIDLabel.Location = new System.Drawing.Point(49, 35);
addressIDLabel.Name = "addressIDLabel";
addressIDLabel.Size = new System.Drawing.Size(66, 15);
addressIDLabel.TabIndex = 1;
addressIDLabel.Text = "Address ID:";
//
// emailLabel
//
emailLabel.AutoSize = true;
emailLabel.Location = new System.Drawing.Point(49, 122);
emailLabel.Name = "emailLabel";
emailLabel.Size = new System.Drawing.Size(39, 15);
emailLabel.TabIndex = 3;
emailLabel.Text = "Email:";
//
// firstNameLabel
//
firstNameLabel.AutoSize = true;
firstNameLabel.Location = new System.Drawing.Point(49, 64);
firstNameLabel.Name = "firstNameLabel";
firstNameLabel.Size = new System.Drawing.Size(67, 15);
firstNameLabel.TabIndex = 5;
firstNameLabel.Text = "First Name:";
//
// lastNameLabel
//
lastNameLabel.AutoSize = true;
lastNameLabel.Location = new System.Drawing.Point(49, 93);
lastNameLabel.Name = "lastNameLabel";
lastNameLabel.Size = new System.Drawing.Size(66, 15);
lastNameLabel.TabIndex = 7;
lastNameLabel.Text = "Last Name:";
//
// phoneNumberLabel
//
phoneNumberLabel.AutoSize = true;
phoneNumberLabel.Location = new System.Drawing.Point(49, 151);
phoneNumberLabel.Name = "phoneNumberLabel";
phoneNumberLabel.Size = new System.Drawing.Size(91, 15);
phoneNumberLabel.TabIndex = 9;
phoneNumberLabel.Text = "Phone Number:";
//
// addressBindingNavigator
//
this.addressBindingNavigator.AddNewItem = this.bindingNavigatorAddNewItem;
this.addressBindingNavigator.BindingSource = this.addressBindingSource;
this.addressBindingNavigator.CountItem = this.bindingNavigatorCountItem;
this.addressBindingNavigator.DeleteItem = this.bindingNavigatorDeleteItem;
this.addressBindingNavigator.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.addressBindingNavigatorSaveItem});
this.addressBindingNavigator.Location = new System.Drawing.Point(0, 0);
this.addressBindingNavigator.MoveFirstItem = this.bindingNavigatorMoveFirstItem;
this.addressBindingNavigator.MoveLastItem = this.bindingNavigatorMoveLastItem;
this.addressBindingNavigator.MoveNextItem = this.bindingNavigatorMoveNextItem;
this.addressBindingNavigator.MovePreviousItem = this.bindingNavigatorMovePreviousItem;
this.addressBindingNavigator.Name = "addressBindingNavigator";
this.addressBindingNavigator.PositionItem = this.bindingNavigatorPositionItem;
this.addressBindingNavigator.Size = new System.Drawing.Size(295, 25);
this.addressBindingNavigator.TabIndex = 0;
this.addressBindingNavigator.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";
//
// addressBindingSource
//
this.addressBindingSource.DataSource = typeof(AddressBook.Address);
//
// 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);
//
// addressBindingNavigatorSaveItem
//
this.addressBindingNavigatorSaveItem.DisplayStyle = System.Windows.Forms.ToolStripItemDisplayStyle.Image;
this.addressBindingNavigatorSaveItem.Image = ((System.Drawing.Image)(resources.GetObject("addressBindingNavigatorSaveItem.Image")));
this.addressBindingNavigatorSaveItem.Name = "addressBindingNavigatorSaveItem";
this.addressBindingNavigatorSaveItem.Size = new System.Drawing.Size(23, 22);
this.addressBindingNavigatorSaveItem.Text = "Save Data";
this.addressBindingNavigatorSaveItem.Click += new System.EventHandler(this.addressBindingNavigatorSaveItem_Click);
//
// addressIDTextBox
//
this.addressIDTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.addressBindingSource, "AddressID", true));
this.addressIDTextBox.Location = new System.Drawing.Point(146, 32);
this.addressIDTextBox.Name = "addressIDTextBox";
this.addressIDTextBox.ReadOnly = true;
this.addressIDTextBox.Size = new System.Drawing.Size(100, 23);
this.addressIDTextBox.TabIndex = 2;
//
// emailTextBox
//
this.emailTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.addressBindingSource, "Email", true));
this.emailTextBox.Location = new System.Drawing.Point(146, 119);
this.emailTextBox.Name = "emailTextBox";
this.emailTextBox.Size = new System.Drawing.Size(100, 23);
this.emailTextBox.TabIndex = 8;
//
// firstNameTextBox
//
this.firstNameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.addressBindingSource, "FirstName", true));
this.firstNameTextBox.Location = new System.Drawing.Point(146, 61);
this.firstNameTextBox.Name = "firstNameTextBox";
this.firstNameTextBox.Size = new System.Drawing.Size(100, 23);
this.firstNameTextBox.TabIndex = 4;
//
// lastNameTextBox
//
this.lastNameTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.addressBindingSource, "LastName", true));
this.lastNameTextBox.Location = new System.Drawing.Point(146, 90);
this.lastNameTextBox.Name = "lastNameTextBox";
this.lastNameTextBox.Size = new System.Drawing.Size(100, 23);
this.lastNameTextBox.TabIndex = 6;
//
// phoneNumberTextBox
//
this.phoneNumberTextBox.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.addressBindingSource, "PhoneNumber", true));
this.phoneNumberTextBox.Location = new System.Drawing.Point(146, 148);
this.phoneNumberTextBox.Name = "phoneNumberTextBox";
this.phoneNumberTextBox.Size = new System.Drawing.Size(100, 23);
this.phoneNumberTextBox.TabIndex = 10;
//
// browseAllButton
//
this.browseAllButton.Location = new System.Drawing.Point(89, 248);
this.browseAllButton.Name = "browseAllButton";
this.browseAllButton.Size = new System.Drawing.Size(114, 23);
this.browseAllButton.TabIndex = 16;
this.browseAllButton.Text = "Browse All Entries";
this.browseAllButton.UseVisualStyleBackColor = true;
this.browseAllButton.Click += new System.EventHandler(this.browseButton_Click);
//
// findGroupBox
//
this.findGroupBox.Controls.Add(this.findButton);
this.findGroupBox.Controls.Add(this.findLabel);
this.findGroupBox.Controls.Add(this.findTextBox);
this.findGroupBox.Location = new System.Drawing.Point(11, 191);
this.findGroupBox.Name = "findGroupBox";
this.findGroupBox.Size = new System.Drawing.Size(272, 51);
this.findGroupBox.TabIndex = 15;
this.findGroupBox.TabStop = false;
this.findGroupBox.Text = "Find an entry by last name";
//
// findButton
//
this.findButton.Location = new System.Drawing.Point(188, 19);
this.findButton.Name = "findButton";
this.findButton.Size = new System.Drawing.Size(75, 23);
this.findButton.TabIndex = 13;
this.findButton.Text = "Find";
this.findButton.UseVisualStyleBackColor = true;
this.findButton.Click += new System.EventHandler(this.findButton_Click);
//
// findLabel
//
this.findLabel.AutoSize = true;
this.findLabel.Location = new System.Drawing.Point(6, 22);
this.findLabel.Name = "findLabel";
this.findLabel.Size = new System.Drawing.Size(66, 15);
this.findLabel.TabIndex = 11;
this.findLabel.Text = "Last Name:";
//
// findTextBox
//
this.findTextBox.Location = new System.Drawing.Point(78, 19);
this.findTextBox.Name = "findTextBox";
this.findTextBox.Size = new System.Drawing.Size(104, 23);
this.findTextBox.TabIndex = 12;
//
// Contacts
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(295, 283);
this.Controls.Add(this.browseAllButton);
this.Controls.Add(this.findGroupBox);
this.Controls.Add(addressIDLabel);
this.Controls.Add(this.addressIDTextBox);
this.Controls.Add(emailLabel);
this.Controls.Add(this.emailTextBox);
this.Controls.Add(firstNameLabel);
this.Controls.Add(this.firstNameTextBox);
this.Controls.Add(lastNameLabel);
this.Controls.Add(this.lastNameTextBox);
this.Controls.Add(phoneNumberLabel);
this.Controls.Add(this.phoneNumberTextBox);
this.Controls.Add(this.addressBindingNavigator);
this.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.Name = "Contacts";
this.Text = "Address Book";
this.Load += new System.EventHandler(this.Contacts_Load);
((System.ComponentModel.ISupportInitialize)(this.addressBindingNavigator)).EndInit();
this.addressBindingNavigator.ResumeLayout(false);
this.addressBindingNavigator.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.addressBindingSource)).EndInit();
this.findGroupBox.ResumeLayout(false);
this.findGroupBox.PerformLayout();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.BindingSource addressBindingSource;
private System.Windows.Forms.BindingNavigator addressBindingNavigator;
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.ToolStripButton addressBindingNavigatorSaveItem;
private System.Windows.Forms.TextBox addressIDTextBox;
private System.Windows.Forms.TextBox emailTextBox;
private System.Windows.Forms.TextBox firstNameTextBox;
private System.Windows.Forms.TextBox lastNameTextBox;
private System.Windows.Forms.TextBox phoneNumberTextBox;
internal System.Windows.Forms.Button browseAllButton;
internal System.Windows.Forms.GroupBox findGroupBox;
internal System.Windows.Forms.Button findButton;
internal System.Windows.Forms.Label findLabel;
internal System.Windows.Forms.TextBox findTextBox;
}
}
---------------------------------------------
AddressBook.designer.cs
-----------------------
#pragma warning disable 1591
namespace AddressBook
{
using System.Data.Linq;
using System.Data.Linq.Mapping;
using System.Data;
using System.Collections.Generic;
using System.Reflection;
using System.Linq;
using System.Linq.Expressions;
using System.ComponentModel;
using System;
[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="AddressBook")]
public partial class AddressBookDataContext : System.Data.Linq.DataContext
{
private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
#region Extensibility Method Definitions
partial void OnCreated();
partial void InsertAddress(Address instance);
partial void UpdateAddress(Address instance);
partial void DeleteAddress(Address instance);
#endregion
public AddressBookDataContext() :
base(global::AddressBook.Properties.Settings.Default.AddressBookConnectionString, mappingSource)
{
OnCreated();
}
public AddressBookDataContext(string connection) :
base(connection, mappingSource)
{
OnCreated();
}
public AddressBookDataContext(System.Data.IDbConnection connection) :
base(connection, mappingSource)
{
OnCreated();
}
public AddressBookDataContext(string connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public AddressBookDataContext(System.Data.IDbConnection connection, System.Data.Linq.Mapping.MappingSource mappingSource) :
base(connection, mappingSource)
{
OnCreated();
}
public System.Data.Linq.Table<Address> Addresses
{
get
{
return this.GetTable<Address>();
}
}
}
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Addresses")]
public partial class Address : INotifyPropertyChanging, INotifyPropertyChanged
{
private static PropertyChangingEventArgs emptyChangingEventArgs = new PropertyChangingEventArgs(String.Empty);
private int _AddressID;
private string _FirstName;
private string _LastName;
private string _Email;
private string _PhoneNumber;
#region Extensibility Method Definitions
partial void OnLoaded();
partial void OnValidate(System.Data.Linq.ChangeAction action);
partial void OnCreated();
partial void OnAddressIDChanging(int value);
partial void OnAddressIDChanged();
partial void OnFirstNameChanging(string value);
partial void OnFirstNameChanged();
partial void OnLastNameChanging(string value);
partial void OnLastNameChanged();
partial void OnEmailChanging(string value);
partial void OnEmailChanged();
partial void OnPhoneNumberChanging(string value);
partial void OnPhoneNumberChanged();
#endregion
public Address()
{
OnCreated();
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_AddressID", AutoSync=AutoSync.OnInsert, DbType="Int NOT NULL IDENTITY", IsPrimaryKey=true, IsDbGenerated=true)]
public int AddressID
{
get
{
return this._AddressID;
}
set
{
if ((this._AddressID != value))
{
this.OnAddressIDChanging(value);
this.SendPropertyChanging();
this._AddressID = value;
this.SendPropertyChanged("AddressID");
this.OnAddressIDChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_FirstName", DbType="VarChar(30) NOT NULL", CanBeNull=false)]
public string FirstName
{
get
{
return this._FirstName;
}
set
{
if ((this._FirstName != value))
{
this.OnFirstNameChanging(value);
this.SendPropertyChanging();
this._FirstName = value;
this.SendPropertyChanged("FirstName");
this.OnFirstNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_LastName", DbType="VarChar(30) NOT NULL", CanBeNull=false)]
public string LastName
{
get
{
return this._LastName;
}
set
{
if ((this._LastName != value))
{
this.OnLastNameChanging(value);
this.SendPropertyChanging();
this._LastName = value;
this.SendPropertyChanged("LastName");
this.OnLastNameChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_Email", DbType="VarChar(50) NOT NULL", CanBeNull=false)]
public string Email
{
get
{
return this._Email;
}
set
{
if ((this._Email != value))
{
this.OnEmailChanging(value);
this.SendPropertyChanging();
this._Email = value;
this.SendPropertyChanged("Email");
this.OnEmailChanged();
}
}
}
[global::System.Data.Linq.Mapping.ColumnAttribute(Storage="_PhoneNumber", DbType="VarChar(15) NOT NULL", CanBeNull=false)]
public string PhoneNumber
{
get
{
return this._PhoneNumber;
}
set
{
if ((this._PhoneNumber != value))
{
this.OnPhoneNumberChanging(value);
this.SendPropertyChanging();
this._PhoneNumber = value;
this.SendPropertyChanged("PhoneNumber");
this.OnPhoneNumberChanged();
}
}
}
public event PropertyChangingEventHandler PropertyChanging;
public event PropertyChangedEventHandler PropertyChanged;
protected virtual void SendPropertyChanging()
{
if ((this.PropertyChanging != null))
{
this.PropertyChanging(this, emptyChangingEventArgs);
}
}
protected virtual void SendPropertyChanged(String propertyName)
{
if ((this.PropertyChanged != null))
{
this.PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
}
}
#pragma warning restore 1591
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.