public void GetTrainees() { if (ID.HasValue) { Trainees = Trained.GetAllTrainedByTraining(this); } }
private void btnAddTrained_Click(object sender, RoutedEventArgs e) { var drv = dgTemp.SelectedItem as DataRowView; if (drv != null) { var tr = this.DataContext as Training; Trained t = new Trained(); var lst = dgTrained.ItemsSource as List <Trained>; t.TrainedID = (int)drv["ID"]; t.TrainedName = drv["Name"].ToString(); t.TrainedType = (Trained.TrainedEnumType)drv["Type"]; t.Training = tr; foreach (var item in lst) { if (item.TrainedID == t.TrainedID && t.TrainedType == item.TrainedType) { MyMessageBox.Show("تم اختيار هذا المتدرب مسبقاً"); return; } } lst.Add(t); dgTrained.Items.Refresh(); } }
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))); }
public static bool UpdateData(Trained x) { return(BaseDataBase._StoredProcedure("sp_Update_Trained" , new SqlParameter("@ID", x.ID) , new SqlParameter("@TrainingID", x.Training.ID) , new SqlParameter("@TrainedType", (int)x.TrainedType) , new SqlParameter("@TrainedID", x.TrainedID) , new SqlParameter("@IsAttended", x.IsAttended) , new SqlParameter("@IsAbiding", x.IsAbiding) , new SqlParameter("@Evaluation", x.Evaluation) , new SqlParameter("@Notes", x.Notes) , new SqlParameter("@AttendedExam", x.AttendedExam) , new SqlParameter("@TakeCertificate", x.TakeCertificate))); }
public static bool InsertData(Trained x) { x.ID = BaseDataBase._StoredProcedureReturnable("sp_Add_Trained" , new SqlParameter("@ID", System.Data.SqlDbType.Int) , new SqlParameter("@TrainingID", x.Training.ID) , new SqlParameter("@TrainedType", (int)x.TrainedType) , new SqlParameter("@TrainedID", x.TrainedID) , new SqlParameter("@IsAttended", x.IsAttended) , new SqlParameter("@IsAbiding", x.IsAbiding) , new SqlParameter("@Evaluation", x.Evaluation) , new SqlParameter("@Notes", x.Notes) , new SqlParameter("@AttendedExam", x.AttendedExam) , new SqlParameter("@TakeCertificate", x.TakeCertificate)); return(x.ID.HasValue); }
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(); } } }
public static List <Trained> GetAllTrainedByTraining(Training t) { List <Trained> xx = new List <Trained>(); SqlConnection con = new SqlConnection(BaseDataBase.ConnectionString); SqlCommand com = new SqlCommand("sp_Get_All_Trained_ByTrainingID", con); com.CommandType = System.Data.CommandType.StoredProcedure; com.Parameters.Add(new SqlParameter("@TrainingID", t.ID)); try { con.Open(); SqlDataReader rd = com.ExecuteReader(); while (rd.Read()) { Trained x = new Trained(); x.ID = int.Parse(rd["ID"].ToString()); x.Training = t; x.TrainedType = (TrainedEnumType)rd["TrainedType"]; x.TrainedID = int.Parse(rd["TrainedID"].ToString()); x.IsAttended = bool.Parse(rd["IsAttended"].ToString()); x.IsAbiding = bool.Parse(rd["IsAbiding"].ToString()); x.Evaluation = rd["Evaluation"].ToString(); x.Notes = rd["Notes"].ToString(); x.AttendedExam = bool.Parse(rd["AttendedExam"].ToString()); x.TrainedName = rd["TrainedName"].ToString(); x.TakeCertificate = bool.Parse(rd["TakeCertificate"].ToString()); xx.Add(x); } rd.Close(); } catch { xx = null; } finally { con.Close(); } return(xx); }
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(); } }
private void btnSave_Click(object sender, RoutedEventArgs e) { var x = this.DataContext as Training; if (x.IsValidate()) { if (x.ID == null) { if (Training.InsertData(x)) { foreach (var t in x.Trainees) { Trained.InsertData(t); } MyMessage.InsertMessage(); } } else { foreach (var t in x.Trainees) { if (t.ID.HasValue) { Trained.UpdateData(t); } else { Trained.InsertData(t); } } if (Training.UpdateData(x)) { MyMessage.UpdateMessage(); } } } }
public static bool DeleteData(Trained x) { return(BaseDataBase._StoredProcedure("sp_Delete_Trained" , new SqlParameter("@ID", x.ID))); }