public static bool DeleteData(TempFamily t) { foreach (var c in t.TempChilds) { TempChild.DeleteData(c); } return(BaseDataBase._StoredProcedure("sp_DeleteFromTempFamily" , new SqlParameter("@ID", t.ID))); }
private void btnChild_Click(object sender, RoutedEventArgs e) { var tf = this.DataContext as TempFamily; var tc = grdChild.DataContext as TempChild; if (tc == null) { return; } if (radDel.IsChecked == true) { if (MyMessageBox.Show("هل تريد تأكيد الحذف", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { if (!tc.ChildID.HasValue || TempChild.DeleteData(tc)) { tf.TempChilds.Remove(tc); dgChild.Items.Refresh(); MyMessage.DeleteMessage(); radAdd.IsChecked = true; } } } else { if (tc.IsValidate()) { if (radAdd.IsChecked == true) { tc.TempFamilyID = tf.ID; if (!tf.ID.HasValue || TempChild.InsertData(tc)) { tf.TempChilds.Add(tc); dgChild.Items.Refresh(); grdChild.DataContext = new TempChild(); Keyboard.Focus(txtChildName); if (tf.ID.HasValue) { MyMessage.InsertMessage(); } } } else { tc.TempFamilyID = tf.ID; if (!tf.ID.HasValue || TempChild.UpdateData(tc)) { dgChild.Items.Refresh(); if (tf.ID.HasValue) { MyMessage.UpdateMessage(); } } } } } }