private bool CheckKey(string text) { var db = new ProjectEntities(); var query = from C in db.Courses where C.CourseID.Equals(text) select C; return(query.Count() == 1); }
private void FormMarkOfStudent_Load(object sender, EventArgs e) { txtStudentID.Enabled = false; btnSave.Enabled = false; //LoadData(); var db = new ProjectEntities(); // lay danh sach ten Lecturers var query = from Lec in db.Lecturers select new { NameDistinct = Lec.Name }; query = query.Distinct(); foreach (var item in query) { lstLecturer.Items.Add(item.NameDistinct); } // lay danh sach ten Courses query = from Cour in db.Courses select new { NameDistinct = Cour.CourseName }; query = query.Distinct(); foreach (var item in query) { lstCourse.Items.Add(item.NameDistinct); } // lay danh sach Year Study query = from YS in db.YearStudies select new { NameDistinct = YS.Year.ToString() }; query = query.Distinct(); foreach (var item in query) { lstYear.Items.Add(item.NameDistinct); } // lay danh sach ten ky hoc query = from YS in db.YearStudies select new { NameDistinct = YS.Semester }; query = query.Distinct(); foreach (var item in query) { lstSemester.Items.Add(item.NameDistinct); } }
private void btnSearch_Click(object sender, EventArgs e) { dataGridView1.Rows.Clear(); var year = Convert.ToInt32(lstYear.SelectedItem); var semester = lstSemester.SelectedItem.ToString(); var lecturerName = lstLecturer.SelectedItem.ToString(); var courseName = lstCourse.SelectedItem.ToString(); var db = new ProjectEntities(); var query = from SS in db.StudentStudies join Lec in db.Lecturers on SS.LecturerID equals Lec.LecturerID join Cou in db.Courses on SS.CourseID equals Cou.CourseID join Year in db.YearStudies on SS.YearStudyID equals Year.YearStudyID where Lec.Name.Equals(lecturerName) && Cou.CourseName.Equals(courseName) && Year.Year == year && Year.Semester.Equals(semester) select SS; if (query.Count() >= 1) { foreach (var item in query) { int rowIndex = dataGridView1.Rows.Add(); //int rowIndex = 1; dataGridView1.Rows[rowIndex].Cells[0].Value = item.StudentStudyID; dataGridView1.Rows[rowIndex].Cells[1].Value = item.StudentID; dataGridView1.Rows[rowIndex].Cells[2].Value = item.LecturerID; dataGridView1.Rows[rowIndex].Cells[3].Value = item.YearStudyID; dataGridView1.Rows[rowIndex].Cells[4].Value = item.CourseID; dataGridView1.Rows[rowIndex].Cells[5].Value = item.GradeNumber; dataGridView1.Rows[rowIndex].Cells[6].Value = item.GradeCharacter; rowIndex++; } } else { MessageBox.Show("No data avaliable", "Thông báo"); } }