private void DeleteChildren() { if (childrenBindingSource?.Current == null) { return; } var dResult = MessageBox.Show(@"Delete Children's current record?", @"Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1); if (dResult == DialogResult.Yes) { if (ChildrenManagement.Delete(((Children)childrenBindingSource.Current).ChildrenNo)) { MessageBox.Show(@"Record was deleted successfully.", @"Delete", MessageBoxButtons.OK, MessageBoxIcon.Information); childrenBindingSource.RemoveCurrent(); } else { MessageBox.Show(@"Error on delete operation.", @"Delete", MessageBoxButtons.OK, MessageBoxIcon.Error); childrenDataGridView.Focus(); } } }
private void SpouseForm_Load(object sender, EventArgs e) { bindingNavigatorDeleteItem.Enabled = false; if (Spouse == null) { return; } spousBindingSource.DataSource = Spouse; childrenBindingSource.DataSource = ChildrenManagement.GetAll(Spouse.SpouseNo); }
private void spousBindingSource_CurrentChanged(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; if (spousBindingSource != null) { if (spousBindingSource.Current != null) { Spouse = (Spous)spousBindingSource.Current; childrenBindingSource.DataSource = ChildrenManagement.GetAll(((Spous)spousBindingSource.Current).SpouseNo); } else { childrenBindingSource.DataSource = ChildrenManagement.GetAll(0); } } Cursor.Current = Cursors.Default; }
private void saveSpouse() { var listChildren = new List <Children>(); if ((childrenBindingSource != null) && (childrenDataGridView != null)) { foreach (Children item in childrenBindingSource) { var c = new Children { ChildrenNo = item.ChildrenNo, ChildrenLastName = item.ChildrenLastName, ChildrenFirstName = item.ChildrenFirstName, ChildrenMiddleName = item.ChildrenMiddleName, ChildrenBirthDate = item.ChildrenBirthDate, SpouseNo = item.SpouseNo }; listChildren.Add(c); } } if (spousBindingSource != null) { Validate(); ((Spous)spousBindingSource.Current).PersonnelNo = PersonnelNo; spousBindingSource.EndEdit(); var iResult = SpouseManagement.Save((Spous)spousBindingSource.Current); if (iResult > 0) { var iCount = 0; foreach (var item in listChildren) { var c = new Children { ChildrenNo = item.ChildrenNo, ChildrenLastName = item.ChildrenLastName, ChildrenFirstName = item.ChildrenFirstName, ChildrenMiddleName = item.ChildrenMiddleName, ChildrenBirthDate = item.ChildrenBirthDate, modifieddate = DateTime.Now, SpouseNo = iResult }; if (ChildrenManagement.Save(c) > 0) { iCount += 1; } } if (listChildren.Count == iCount) { MessageBox.Show(@"Record was successfully saved.", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); spouseSurNameTextBox.Focus(); } else { MessageBox.Show(@"There was problem on the children record on saving.", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Information); } } else { MessageBox.Show(@"Error occurred in saving.", @"Save", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }