예제 #1
0
        public static bool DeleteData(Training x)
        {
            foreach (var t in x.Trainees)
            {
                Trained.DeleteData(t);
            }

            return(BaseDataBase._StoredProcedure("sp_Delete_Training"
                                                 , new SqlParameter("@ID", x.ID)));
        }
예제 #2
0
        private void DeleteTrained_CommandExecuted(object sender, ExecutedRoutedEventArgs e)
        {
            var t = dgTrainees.SelectedCells[0].Item as Trained;

            if (t != null)
            {
                if (MyMessageBox.Show("هل تريد حذف السجل؟", MessageBoxButton.YesNo) == MessageBoxResult.Yes)
                {
                    if (t.ID.HasValue)
                    {
                        Trained.DeleteData(t);
                    }
                    t.Training.Trainees.Remove(t);
                    dgTrainees.Items.Refresh();
                }
            }
        }
예제 #3
0
        private void btnAddTrained_Click(object sender, RoutedEventArgs e)
        {
            var tr = this.DataContext as Training;
            SelectTraineesControl w = new SelectTraineesControl(tr);

            if (w.ShowDialog() == true)
            {
                List <Trained> TraineesToRemove = new List <Trained>();
                foreach (var tt in tr.Trainees)
                {
                    if ((w.dgTrained.ItemsSource as List <Trained>).Where(x => x.TrainedID == tt.TrainedID && x.TrainedType == tt.TrainedType).FirstOrDefault() == null)
                    {
                        TraineesToRemove.Add(tt);
                    }
                }
                foreach (var tt in TraineesToRemove)
                {
                    if (tt.ID.HasValue)
                    {
                        Trained.DeleteData(tt);
                    }
                    tr.Trainees.Remove(tt);
                }

                foreach (var tt in w.dgTrained.ItemsSource as List <Trained> )
                {
                    if (tr.Trainees.Where(x => x.TrainedID == tt.TrainedID && x.TrainedType == tt.TrainedType).FirstOrDefault() == null)
                    {
                        tr.Trainees.Add(tt);

                        if (tr.ID.HasValue)
                        {
                            Trained.InsertData(tt);
                        }
                    }
                }
                dgTrainees.Items.Refresh();
            }
        }