private int createNewAddress()
        {
            using (var ctx = new DataLayer.ScheduleEntities())
            {
                DataLayer.address newAddress = new DataLayer.address();
                newAddress.address1     = textBoxAddress1.Text;
                newAddress.address2     = textBoxAddress2.Text;
                newAddress.cityId       = comboBoxCity.SelectedIndex + 1;
                newAddress.createDate   = DateTime.Now.ToUniversalTime();
                newAddress.createdBy    = CurrentUserName;
                newAddress.postalCode   = textBoxPostCode.Text;
                newAddress.lastUpdate   = DateTime.Now.ToUniversalTime();
                newAddress.lastUpdateBy = CurrentUserName;
                newAddress.phone        = textBoxPhone.Text;



                Validate(); // validate the input fields
                //addressBindingSource.EndEdit();

                // try to save changes
                try
                {
                    ctx.addresses.Add(newAddress);
                    ctx.SaveChanges(); // write changes to database file
                }
                catch (DbEntityValidationException)
                {
                    MessageBox.Show("Something has gone wrong saving this data",
                                    "Entity Validation Exception");
                }
                return(newAddress.addressId);
            }
        }
Example #2
0
 private void customerDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
 {
     if (e.Value is DataLayer.address)
     {
         DataLayer.address thisAddress = (DataLayer.address)e.Value;
         e.Value = FormatAddressString(thisAddress.addressId);
     }
 }