//"Task"- option// //Shows task info static public void ShowTaskInfo(int _TaskId) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Tasks.ToList()) { if (item.TaskId == _TaskId) { MessageBox.Show( "TASK INFO" + Environment.NewLine + Environment.NewLine + "Id:" + "" + item.TaskId + Environment.NewLine + Environment.NewLine + "Name:" + "" + item.TaskName + Environment.NewLine + Environment.NewLine + "Url:" + "" + item.TaskUrl + Environment.NewLine + Environment.NewLine + "Start Date:" + "" + item.TaskStartDate + Environment.NewLine + Environment.NewLine + "Task Duration:" + "" + item.TaskDuration + Environment.NewLine + Environment.NewLine + "Details:" + "" + item.TaskDetails + Environment.NewLine + Environment.NewLine + "Category Id:" + "" + item.TaskCategoryId + Environment.NewLine ); } StudentForm.dgwStudentAllTasks.Enabled = true; TeacherForm.dgwTeacherAllTasks.Enabled = true; MentorForm.dgwMentorTasks.Enabled = true; } }
//Fills a combo box With the tasks names static public void FillCbxTask(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Tasks.ToList()) { _cbx.Items.Add(item.TaskName); } }
//Fills a combo box with the task categories static public void FillWithCategories(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.TaskCategories.ToList()) { _cbx.Items.Add(item.TaskCategoryId); } }
//Fills a combo box with the Mentors email static public void FillWithMentorsEmails(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Mentors.Where(x => x.MentorEmail != WelcomeScreen.UserEmail).ToList()) { _cbx.Items.Add(item.MentorEmail); } }
//////// //End Student// /////////// //////// //Mentor extensions// /////////// //Fills a combo box with the Students email static public void FillWithStudentsEmails(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Groups.Where(x => x.GroupId == MentorForm.GroupId).ToList()) { _cbx.Items.Add(item.GroupEmail); } }
//////// //End "For all Forms extensions"// /////////// //////// //Studen extensions// /////////// //Fills a combo box with the Groupmates email static public void FillWithGroupmatesEmails(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Students.Where(x => x.GroupId == StudentForm.GroupId && x.StudentEmail != WelcomeScreen.UserEmail).ToList()) { _cbx.Items.Add(item.StudentEmail); } }
//Fills a combo box with the Mentors emails static public void FillCbxMentor(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item in db.Mentors.ToList()) { _cbx.Items.Add(item.MentorEmail); } }
//////// //End Teacher// /////////// //////// //For all Forms extensions// /////////// //Sends message to the chose person public static void SendMessage(string _to, string _title, string _body) { EducationProjectEntities db = new EducationProjectEntities(); Message message = new Message() { MessageFrom = WelcomeScreen.UserEmail, MessageTo = _to, MessageTitle = _title, MessageBody = _body }; db.Messages.Add(message); db.SaveChanges(); }
//"Mentor info","Groups","Assign Task" ,"My Messages" - options// //Fills a combo box with the groups names static public void FillCbxGroups(ComboBox _cbx) { EducationProjectEntities db = new EducationProjectEntities(); foreach (var item1 in db.Teachers.ToList()) { if (item1.TeacherEmail == WelcomeScreen.UserEmail) { TeacherId = item1.TeacherId; } } foreach (var item in db.Groups.Where(x => x.TeacherId == TeacherId).ToList()) { _cbx.Items.Add(item.GroupName); } }
//Deletes Task from the database static public void DeleteTask(int _TaskId) { EducationProjectEntities db = new EducationProjectEntities(); try { foreach (var item in db.Tasks.ToList()) { if (item.TaskId == _TaskId) { db.Tasks.Remove(item); db.SaveChanges(); } } } catch (Exception) { MessageBox.Show("You can't delete this task , because it has been assigned to a student"); } }
//"Library"- option// //Chooses and copy a pdf file to the our PdfSource folder static public void AddPdfFile() { EducationProjectEntities db = new EducationProjectEntities(); if (fileDialog.ShowDialog() == DialogResult.OK) { //set paths rootPath = Directory.GetCurrentDirectory().ToString(); PdfSource = Path.Combine(rootPath, "PdfSource"); ChosedFile = fileDialog.FileName; FileName = Path.GetFileName(ChosedFile); if (Path.GetExtension(FileName) == ".pdf") { //Check if this name is already exist in the database if (db.PdfSources.All(e => e.PdfSourceName != FileName)) { PdfSource pdf = new PdfSource() { PdfSourceName = FileName.ToString() }; //Copy the file to the PdfSource folder File.Copy(ChosedFile, Path.Combine(PdfSource, FileName)); db.PdfSources.Add(pdf); db.SaveChanges(); } else { MessageBox.Show("This name is exist in the database, please change the name or choose another one"); } } else { MessageBox.Show("Selected file must be in a pdf format"); } } }