示例#1
0
 private void tbChange_Click(object sender, EventArgs e)
 {
     var selectedContact = gvContactsList.SelectedRows[0].DataBoundItem as EmergencyContact;
     if (selectedContact == null)
         return;
     EmergencyPhoneEditorForm editor = new EmergencyPhoneEditorForm(_dataContexts)
     {
         Text = @"Изменение аварийного контакта",
         tbComments = {Text = selectedContact.Comment},
         tbContactPerson1 = {Text = selectedContact.ContactPerson1},
         tbContactPerson2 = {Text = selectedContact.ContactPerson2},
         tbContactPhone1 = {Text = selectedContact.ContactPhone1},
         tbContactPhone2 = {Text = selectedContact.ContactPhone2},
         tbEmail = {Text = selectedContact.Email},
         tbPlace = {Text = selectedContact.PlaceDescription}
     };
     if (editor.ShowDialog(this) == DialogResult.OK)
     {
         try
         {
             Cursor = Cursors.WaitCursor;
             selectedContact.ContactPerson1 = editor.tbContactPerson1.Text;
             selectedContact.ContactPerson2 = editor.tbContactPerson2.Text;
             selectedContact.ContactPhone1 = editor.tbContactPhone1.Text;
             selectedContact.ContactPhone2 = editor.tbContactPhone2.Text;
             selectedContact.PlaceDescription = editor.tbPlace.Text;
             selectedContact.Email = editor.tbEmail.Text;
             selectedContact.Comment = editor.tbComments.Text;
             _dataContexts.AccEquipmentV2Entities.SaveChanges();
             RefreshData();
             Cursor = Cursors.Default;
         }
         catch
         {
             throw;
         }
     }
 }
示例#2
0
        private void tbNew_Click(object sender, EventArgs e)
        {
            EmergencyPhoneEditorForm editor = new EmergencyPhoneEditorForm(_dataContexts) {Text = @"Создание нового аварийного контакта"};
            if (editor.ShowDialog(this) == DialogResult.OK)
            {
                try
                {
                    Cursor = Cursors.WaitCursor;
                    EmergencyContact contact = new EmergencyContact
                    {
                        Id = Guid.NewGuid(),
                        ContactPerson1 = editor.tbContactPerson1.Text,
                        ContactPerson2 = editor.tbContactPerson2.Text,
                        ContactPhone1 = editor.tbContactPhone1.Text,
                        ContactPhone2 = editor.tbContactPhone2.Text,
                        PlaceDescription = editor.tbPlace.Text,
                        Email = editor.tbEmail.Text,
                        Comment = editor.tbComments.Text
                    };
                    _dataContexts.AccEquipmentV2Entities.EmergencyContacts.Add(contact);
                    _dataContexts.AccEquipmentV2Entities.SaveChanges();
                    RefreshData();
                    Cursor = Cursors.Default;
                }
                catch 
                {
                    throw;
                }
            }

        }