public DataTable ScoreTable() { try { SqlCommand command = new SqlCommand("select * from SCORE", db.GetConnection); Student student = new Student(); Course course = new Course(); Score score = new Score(); //create column SqlCommand cmd = new SqlCommand("Select id, fname, lname from STD_LIST", db.GetConnection); DataTable result = student.getStudent(cmd); result.Columns[0].ColumnName = "ID"; result.Columns[1].ColumnName = "First Name"; result.Columns[2].ColumnName = "Last Name"; DataTable coursesLabel = course.getAllCourse(); DataTable scores = score.getAllScorebyID(); DataTable avgScore = score.GetAvgbyStudent(); for (int i = 0; i < coursesLabel.Rows.Count; i++) { result.Columns.Add(coursesLabel.Rows[i][1].ToString().Trim()); } //test empty if (scores.Rows.Count < 1) { return(result); } //fill score to table int scoreRow = 0; for (int row = 0; row < result.Rows.Count; row++) { try { int courseIndex = 0; while (result.Rows[row][0].ToString().Trim() == scores.Rows[scoreRow][0].ToString().Trim()) { result.Rows[row][courseIndex + 3] = scores.Rows[scoreRow][2].ToString().Trim(); courseIndex++; scoreRow++; if (scoreRow > scores.Rows.Count - 1) { break; } } } catch (Exception) { continue; } } return(result); } catch (Exception) { throw; } }
public DataTable ResultTable() { try { SqlCommand command = new SqlCommand("select * from SCORE", db.GetConnection); Student student = new Student(); Course course = new Course(); Score score = new Score(); //create column SqlCommand cmd = new SqlCommand("Select id, fname, lname from STD_LIST", db.GetConnection); DataTable result = student.getStudent(cmd); result.Columns[0].ColumnName = "ID"; result.Columns[1].ColumnName = "First Name"; result.Columns[2].ColumnName = "Last Name"; DataTable coursesLabel = course.getAllCourse(); DataTable scores = score.getAllScorebyID(); DataTable avgScore = score.GetAvgbyStudent(); for (int i = 0; i < coursesLabel.Rows.Count; i++) { result.Columns.Add(coursesLabel.Rows[i][1].ToString().Trim()); } result.Columns.Add("Average"); result.Columns.Add("Result"); //test empty if (scores.Rows.Count < 1) { return(result); } //fill score to table int scoreRow = 0; for (int row = 0; row < result.Rows.Count; row++) { try { int courseIndex = 0; while (result.Rows[row][0].ToString().Trim() == scores.Rows[scoreRow][0].ToString().Trim()) { result.Rows[row][courseIndex + 3] = scores.Rows[scoreRow][2].ToString().Trim(); courseIndex++; scoreRow++; if (scoreRow > scores.Rows.Count - 1) { break; } } } catch (Exception) { continue; } } // fill avg score for (int row = 0; row < result.Rows.Count; row++) { try { result.Rows[row][result.Columns.Count - 2] = avgScore.Rows[row][1].ToString().Trim(); int avg = Convert.ToInt32(avgScore.Rows[row][1]); if (avg < 5) { result.Rows[row][result.Columns.Count - 1] = "Fail"; } else { { result.Rows[row][result.Columns.Count - 1] = "Pass"; } } } catch (Exception) { continue; } } //DataTable table = score.GetScore(command); //for (int row = 0; row < result.Rows.Count; row++) //{ // try // { // result.Rows[row][result.Columns.Count - 1] // = table.Rows[row][3].ToString().Trim(); // } // catch (Exception) // { // continue; // } //} return(result); } catch (Exception) { throw; } }