// GET: Teachers public async Task <IActionResult> Index(string teacherDegree, string teacherRank, string searchString) { IQueryable <Teacher> teachers = _context.Teacher.AsQueryable(); teachers = _context.Teacher.Include(t => t.AllCourses); IQueryable <string> degreeQuery = _context.Teacher.OrderBy(m => m.Degree).Select(m => m.Degree).Distinct(); IQueryable <string> rankQuery = _context.Teacher.OrderBy(m => m.AcademicRank).Select(m => m.AcademicRank).Distinct(); if (!string.IsNullOrEmpty(searchString)) { teachers = teachers.Where(s => (s.FirstName + " " + s.LastName).Contains(searchString)); } if (!string.IsNullOrEmpty(teacherDegree)) { teachers = teachers.Where(x => x.Degree == teacherDegree); } if (!string.IsNullOrEmpty(teacherRank)) { teachers = teachers.Where(x => x.AcademicRank == teacherRank); } var searchTeacherVM = new SearchTeacher { Degrees = new SelectList(await degreeQuery.ToListAsync()), Ranks = new SelectList(await rankQuery.ToListAsync()), Teachers = await teachers.ToListAsync() }; return(View(searchTeacherVM)); }
private void searchbutton_Click(object sender, EventArgs e) { SearchTeacher st = new SearchTeacher(); st.TID = idtextBox.Text; st.Name = nametextBox.Text; st.Desegnation = desegnationtextBox.Text; st.Depertment = depertmenttextBox.Text; st.CouncellingHour = councellinghourtextBox.Text; st.CourseAdvisor = courseadvisorcomboBox.Text; st.ContactNo = contactnotextBox.Text; st.Adress = adresstextBox.Text; st.Salary = 0; float.TryParse(salarytextBox.Text, out st.Salary); Search_teacher_BL steacher = new Search_teacher_BL(); DataTable result = steacher.search_TeacherANDsendToDAL(st); if (result != null) { teachersearchinfodataGridView.DataSource = result; idtextBox.Text = ""; nametextBox.Text = ""; desegnationtextBox.Text = ""; depertmenttextBox.Text = ""; courseadvisorcomboBox.Text = ""; councellinghourtextBox.Text = ""; salarytextBox.Text = ""; adresstextBox.Text = ""; contactnotextBox.Text = ""; } else { MessageBox.Show("AN Error Has Been Occured!!!"); } }
public DataTable search_TeacherANDsendToDAL(SearchTeacher aST) { DataTable result = null; if (aST.TID == "" && aST.Name == "" && aST.Desegnation == "" && aST.Depertment == "" && aST.CourseAdvisor == "" && aST.CouncellingHour == "" && aST.Salary == 0 && aST.ContactNo == "" && aST.Adress == "") { return(result); } else { Search_Teacher_DAL stdal = new Search_Teacher_DAL(); result = stdal.SearchTeacherDAL(aST); return(result); } }
public DataTable SearchTeacherDAL(SearchTeacher ateacher) { string query = "Select * From Teacher"; string Condition = ""; bool Condition_joiner = false; if (ateacher.TID != "") { if (Condition_joiner) { Condition += "and"; } Condition += " TId like '%" + ateacher.TID + "%'"; Condition_joiner = true; } if (ateacher.Name != "") { if (Condition_joiner) { Condition += "and"; } Condition += " Name like '%" + ateacher.Name + "%'"; Condition_joiner = true; } if (ateacher.Desegnation != "") { if (Condition_joiner) { Condition += "and"; } Condition += " Desegnation like '%" + ateacher.Desegnation + "%'"; Condition_joiner = true; } if (ateacher.Depertment != "") { if (Condition_joiner) { Condition += "and"; } Condition += " Depertment like '%" + ateacher.Depertment + "%'"; Condition_joiner = true; } if (ateacher.Salary != 0) { if (Condition_joiner) { Condition += "and"; } Condition += " Salary like '%" + ateacher.Salary + "%'"; Condition_joiner = true; } if (ateacher.CourseAdvisor != "") { if (Condition_joiner) { Condition += "and"; } Condition += " CourseAdvisor like '%" + ateacher.CourseAdvisor + "%'"; Condition_joiner = true; } if (ateacher.CouncellingHour != "") { if (Condition_joiner) { Condition += "and"; } Condition += " CouncellingHour like '%" + ateacher.CouncellingHour + "%'"; Condition_joiner = true; } if (ateacher.ContactNo != "") { if (Condition_joiner) { Condition += "and"; } Condition += " ContactNo like '%" + ateacher.ContactNo + "%'"; Condition_joiner = true; } if (ateacher.Adress != "") { if (Condition_joiner) { Condition += "and"; } Condition += " Adress like '%" + ateacher.Adress + "%'"; Condition_joiner = true; } if (Condition_joiner) { query += " WHERE"; } query += Condition; SqlConnection connection = DatabaseConnection.Search_teacher(); SqlCommand command = new SqlCommand(query, connection); SqlDataAdapter ada = new SqlDataAdapter(); DataTable dt = new DataTable(); ada.SelectCommand = command; ada.Fill(dt); return(dt); }