private void gvStudents_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action3") { if (MessageBox.Show("Are you sure you want to delete?", "Delete Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) { string id = gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString(); DatabaseConnection.start(); DatabaseConnection.createStatement("Delete from GroupStudent where StudentId =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from Student where Id =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from Person where Id =" + id); DatabaseConnection.performAction(); } } if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action2") { Student student = new Student(); DatabaseConnection.start(); DatabaseConnection.createStatement("select Person.Id[id], FirstName[FName], LastName[LName], Contact[Contact], Email[Email] from Person join Student on Person.Id = Student.Id where Student.Id =" + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { student.PersonId = int.Parse(reader["id"].ToString()); student.FirstName = reader["FName"].ToString(); student.LastName = reader["LName"].ToString(); student.Contact = reader["Contact"].ToString(); student.Email = reader["Email"].ToString(); } TempData.CurrentStudent = student; EditStudent editStudent = new EditStudent(); editStudent.Show(); this.Hide(); } if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action") { gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString(); DatabaseConnection.createStatement("select * from Person join Student on Person.Id = Student.Id join GroupStudent on Student.Id = GroupStudent.StudentId join GroupProject on GroupStudent.GroupId = GroupProject.GroupId join Project on GroupProject.ProjectId = Project.Id where Student.Id =" + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); SqlDataReader dataReader = DatabaseConnection.getData(); if (dataReader.Read()) { Student student = new Student(); student.FirstName = dataReader["FirstName"].ToString(); student.LastName = dataReader["LastName"].ToString(); student.Contact = dataReader["Contact"].ToString(); student.Email = dataReader["Email"].ToString(); student.DateOfBirth = DateTime.Parse(dataReader["DateOfBirth"].ToString()); student.Gender = int.Parse(dataReader["Gender"].ToString()); student.RegistrationNo = dataReader["RegistrationNo"].ToString(); student.Status = int.Parse(dataReader["Status"].ToString()); student.ProjectTitle = dataReader["Title"].ToString(); TempData.CurrentStudent = student; ViewStudent view = ViewStudent.GetInstance(); this.Hide(); view.Show(); } } }
private void ManageAdvisors_Load(object sender, EventArgs e) { tabControl1.SelectedIndex = 3; gvAdvisors.Rows.Clear(); gvAdvisors.Refresh(); bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select Person.Id[id], FirstName[FName], LastName[LName], Designation[Des] from Person join Advisor on Person.Id = Advisor.Id"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { string name = reader["FName"].ToString() + " " + reader["LName"].ToString(); string designation = "Professor"; string inputDesignation = reader["Des"].ToString(); if (inputDesignation == "7") { designation = "Associate Professor"; } if (inputDesignation == "8") { designation = "Assistant Professor"; } if (inputDesignation == "9") { designation = "Lecturer"; } if (inputDesignation == "10") { designation = "Industry Professional"; } gvAdvisors.Rows.Add(reader["id"].ToString(), name, designation); } }
private void gvStudents_CellContentClick_1(object sender, DataGridViewCellEventArgs e) { if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action") { Project project = new Project(); project.Title = gvStudents.Rows[e.RowIndex].Cells[1].Value.ToString(); DatabaseConnection.createStatement("select Description from Project where Id = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); SqlDataReader newReader = DatabaseConnection.getData(); if (newReader.Read()) { project.Description = newReader["Description"].ToString(); } project.Id = int.Parse(gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); TempData.CurrentProject = project; ProjectDashboard projectDashboard = ProjectDashboard.GetInstance(); projectDashboard.Show(); this.Hide(); } if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Action3") { if (MessageBox.Show("Are you sure you want to delete?", "Delete Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) { string id = gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString(); DatabaseConnection.start(); DatabaseConnection.createStatement("Delete from ProjectAdvisor where ProjectId =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from GroupProject where ProjectId =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from Project where Id =" + id); DatabaseConnection.performAction(); } } }
private void btnAddProject_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(txtTitle.Text)) { lblTitleWarning.Visible = true; } else if (string.IsNullOrWhiteSpace(txtDescription.Text)) { lblDescriptionWarning.Visible = true; } else { DatabaseConnection.createStatement("INSERT INTO Project ( Title, Description)" + " VALUES('" + txtTitle.Text + "' , '" + txtDescription.Text + "') "); DatabaseConnection.performAction(); Project project = new Project(); project.Title = txtTitle.Text; DatabaseConnection.createStatement("Select @@identity as id from Project"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { project.Id = int.Parse(reader["id"].ToString()); } TempData.CurrentProject = project; ProjectDashboard dashboard = ProjectDashboard.GetInstance(); dashboard.Show(); this.Hide(); } }
private void gvStudents_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (gvStudents.Columns[e.ColumnIndex].Name.ToString() == "Assign") { bool IsAlready = false; DatabaseConnection.createStatement("select ProjectId from GroupProject where GroupId = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); SqlDataReader newReader = DatabaseConnection.getData(); if (newReader.Read()) { IsAlready = true; } if (IsAlready) { MessageBox.Show("This group is already assigned"); } else { string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DatabaseConnection.start(); DatabaseConnection.createStatement("Insert into GroupProject (ProjectId, GroupId, AssignmentDate)" + " Values (" + TempData.CurrentProject.Id + ", " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString() + ", '" + sqlFormattedDate + "')"); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Update GroupStudent set Status = 4 where GroupId = " + gvStudents.Rows[e.RowIndex].Cells[0].Value.ToString()); DatabaseConnection.performAction(); ProjectDashboard projectDashboard = ProjectDashboard.GetInstance(); projectDashboard.Show(); this.Hide(); } } }
private void btnEvaluate_Click(object sender, EventArgs e) { if (ValidateForm()) { DatabaseConnection.start(); DatabaseConnection.createStatement("select GroupId from Project join GroupProject on Project.Id = GroupProject.ProjectId where Project.Title = '" + cmbTitles.Text + "' "); SqlDataReader dataReader = DatabaseConnection.getData(); if (dataReader.Read()) { TempData.CurrentGroupId = int.Parse(dataReader["GroupId"].ToString()); } DatabaseConnection.createStatement("Insert into Evaluation ( Name, TotalMarks, TotalWeightage) " + "Values ('Group', " + txtTotalMarks.Text + ", " + txtWeightage.Text + ")"); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Select @@identity as id from Evaluation"); SqlDataReader reader = DatabaseConnection.getData(); string id = "0"; while (reader.Read()) { id = (reader["id"].ToString()); } string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DatabaseConnection.createStatement("INSERT INTO GroupEvaluation (GroupId, EvaluationId, ObtainedMarks, EvaluationDate) " + "VALUES (" + TempData.CurrentGroupId.ToString() + ", " + id + ", " + txtObtainedMarks.Text + ", '" + sqlFormattedDate + "') "); DatabaseConnection.performAction(); cmbTitles.Text = ""; lblObtainedMarks.Text = ""; MessageBox.Show("Project Evaluated"); } }
private void ProjectDashboard_Load(object sender, EventArgs e) { if (gvGroupStudents.RowCount == 0) { btnChangeGroup.Text = "Add Group"; label1.Visible = true; } else { btnChangeGroup.Text = "Change Group"; label1.Visible = false; } lblTitle.Text = TempData.CurrentProject.Title; txtDesc.Text = TempData.CurrentProject.Description; List <Advisor> advisors = new List <Advisor>(); DatabaseConnection.createStatement("select AdvisorId, FirstName, LastName, AdvisorRole from ProjectAdvisor join Advisor on ProjectAdvisor.AdvisorId = Advisor.Id join Person on Advisor.Id = Person.Id where ProjectAdvisor.ProjectId = " + TempData.CurrentProject.Id.ToString()); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { Advisor advisor = new Advisor(); advisor.AdvisorId1 = int.Parse(reader["AdvisorId"].ToString()); advisor.BasicDetails.FirstName = reader["FirstName"].ToString(); advisor.BasicDetails.LastName = reader["LastName"].ToString(); advisor.Role = int.Parse(reader["AdvisorRole"].ToString()); advisors.Add(advisor); } foreach (Advisor a in advisors) { if (a.Role == 11) { lblMainAdvisorName.Text = a.BasicDetails.FirstName + " " + a.BasicDetails.LastName; btnAddMainAdvisor.Text = "Change"; } if (a.Role == 12) { lblCoAdvisorName.Text = a.BasicDetails.FirstName + " " + a.BasicDetails.LastName; btnAddCoAdvisor.Text = "Change"; } if (a.Role == 14) { lblIndustryAdvisorName.Text = a.BasicDetails.FirstName + " " + a.BasicDetails.LastName; btnAddIndustryAdvisor.Text = "Change"; } } gvGroupStudents.Rows.Clear(); gvGroupStudents.Refresh(); DatabaseConnection.createStatement("select * from Project join GroupProject on Project.Id = GroupProject.ProjectId join GroupStudent on GroupProject.GroupId = GroupStudent.GroupId join Student on GroupStudent.StudentId = Student.Id join Person on Student.Id = Person.Id where Project.Id =" + TempData.CurrentProject.Id); SqlDataReader newReader = DatabaseConnection.getData(); while (newReader.Read()) { gvGroupStudents.Rows.Add(newReader["RegistrationNo"].ToString(), newReader["FirstName"].ToString() + " " + newReader["LastName"].ToString()); } }
private void CreateGroup_Load(object sender, EventArgs e) { DatabaseConnection.start(); DatabaseConnection.createStatement("select RegistrationNo from Person join Student on Person.Id = Student.Id "); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { cmbSelectStudent.Items.Add(reader["RegistrationNO"].ToString()); } }
private void button2_Click(object sender, EventArgs e) { DatabaseConnection.createStatement("update Person set FirstName = '" + txtFirstName.Text + "' , LastName = '" + txtLastName.Text + "', Contact = '" + txtContactNo.Text + "', Email = '" + txtEmail.Text + "'" + " where Id = " + TempData.CurrentStudent.PersonId); DatabaseConnection.performAction(); MessageBox.Show("Changes are saved"); ManageStudent manageStudent = ManageStudent.GetInstance(); manageStudent.Show(); this.Hide(); }
private void AddAdvisorToProject_Load(object sender, EventArgs e) { DatabaseConnection.start(); DatabaseConnection.createStatement("select FirstName[FName], LastName[LName] from Person join Advisor on Person.Id = Advisor.Id "); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { cmbSelctAdvisor.Items.Add(reader["FName"].ToString() + " " + reader["LName"].ToString()); } }
private void Marksheet_Load(object sender, EventArgs e) { DatabaseConnection.createStatement("Select * from GroupStudent join Student on GroupStudent.StudentId = Student.Id where GroupId = " + TempData.CurrentGroupId); SqlDataReader sqlDataReader = DatabaseConnection.getData(); int i = 4; while (sqlDataReader.Read()) { gvMarksheet.Columns[i].HeaderText = sqlDataReader["RegistrationNo"].ToString(); ++i; } }
private void ProjectEvaluation_Load(object sender, EventArgs e) { DatabaseConnection.createStatement("select Title from Project"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { cmbTitles.Items.Add(reader["Title"].ToString()); } lblCurrentDate.Text = DateTime.Now.ToShortDateString(); }
private void btnMarksheet_Click(object sender, EventArgs e) { DatabaseConnection.createStatement("Select * from GroupProject where ProjectId = " + TempData.CurrentProject.Id.ToString()); SqlDataReader reader2 = DatabaseConnection.getData(); if (reader2.Read()) { TempData.CurrentGroupId = int.Parse(reader2["GroupId"].ToString()); } Marksheet marksheet = Marksheet.GetInstance(); marksheet.Show(); this.Hide(); }
private void btnSave_Click(object sender, EventArgs e) { DatabaseConnection.createStatement("update Person set FirstName = '" + txtFirstName.Text + "' , LastName = '" + txtLastName.Text + "', Contact = '" + txtContactNo.Text + "', Email = '" + txtEmail.Text + "'" + " where Id = " + TempData.CurrentAdvisor.AdvisorId1); DatabaseConnection.performAction(); DatabaseConnection.createStatement("update Advisor set Salary = " + txtSallary.Text + " where Id = " + TempData.CurrentAdvisor.AdvisorId1); DatabaseConnection.performAction(); MessageBox.Show("Changes are saved"); ManageAdvisors manageAdvisor = ManageAdvisors.GetInstance(); manageAdvisor.Show(); this.Hide(); }
private void ManageStudent_Load(object sender, EventArgs e) { tabControl1.SelectedIndex = 2; gvStudents.Rows.Clear(); gvStudents.Refresh(); bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select Person.Id[id], FirstName[Name], RegistrationNo[Registration No] from Person join Student on Person.Id = Student.Id"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { gvStudents.Rows.Add(reader["id"].ToString(), reader["Registration No"].ToString(), reader["Name"].ToString()); } }
private void ManageProjects_Load(object sender, EventArgs e) { tabControl1.SelectedIndex = 1; gvStudents.Rows.Clear(); gvStudents.Refresh(); bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select * from Project"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { gvStudents.Rows.Add(reader["Id"].ToString(), reader["Title"].ToString()); } }
private void txtCreateGroup_Click(object sender, EventArgs e) { if (gvStudents.RowCount != 0) { // These queries are done without the Database class. string conStr = "Data Source=MUSHI\\MUSHISQL;Initial Catalog=LabProjectA;Integrated Security=True; MultipleActiveResultSets=true"; SqlConnection con = new SqlConnection(conStr); con.Open(); string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); if (con.State == ConnectionState.Open) { string Insert = "INSERT INTO [dbo].[Group](Created_On) VALUES ('" + sqlFormattedDate + "')"; SqlCommand cmd = new SqlCommand(Insert, con); cmd.ExecuteNonQuery(); } string I = "Select @@identity as id from [Group]"; SqlCommand cm = new SqlCommand(I, con); SqlDataReader reader = cm.ExecuteReader(); string id = "0"; if (reader.Read()) { id = (reader["id"].ToString()); } foreach (Student s in TempData.GetGroupStudents()) { DatabaseConnection.createStatement("Insert into GroupStudent (GroupId, StudentId ,Status , AssignmentDate) " + "Values (" + id + "," + s.StudentId.ToString() + ", 4 ,'" + DateTime.Now.ToString("yyyy-MM-dd") + "')"); DatabaseConnection.performAction(); } TempData.Clear_GroupStudents(); gvStudents.Rows.Clear(); gvStudents.Refresh(); cmbSelectStudent.Text = ""; MessageBox.Show("Group has been Created"); } else { MessageBox.Show("Select at least one student"); } }
private void btnAddStudent_Click(object sender, EventArgs e) { string RegNo = cmbSelectStudent.Text; bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select * from GroupStudent join Student on GroupStudent.StudentId = Student.Id where Student.RegistrationNo = '" + RegNo + "'"); SqlDataReader sqlDataReader = DatabaseConnection.getData(); if (!sqlDataReader.Read()) { DatabaseConnection.createStatement("Select Id from Student where RegistrationNo = '" + RegNo + "'"); SqlDataReader reader = DatabaseConnection.getData(); string StudentId = ""; if (reader.Read()) { StudentId = reader.GetValue(reader.GetOrdinal("Id")).ToString(); } DatabaseConnection.createStatement("Select * from Person where Id = " + StudentId); reader = DatabaseConnection.getData(); Student student = new Student(); student.RegistrationNo = RegNo; student.StudentId = int.Parse(StudentId); if (reader.Read()) { student.FirstName = reader.GetString(1).ToString(); student.LastName = reader.GetString(2).ToString(); student.Contact = reader.GetString(3).ToString(); student.Email = reader.GetString(4).ToString(); student.DateOfBirth = Convert.ToDateTime(reader.GetDateTime(5)); } TempData.add_GroupStudent(student); gvStudents.Rows.Clear(); gvStudents.Refresh(); foreach (Student s in TempData.GetGroupStudents()) { gvStudents.Rows.Add(s.RegistrationNo, s.FirstName); } } else { MessageBox.Show("Student already a part of another group"); } }
private void AssignGroup_Load(object sender, EventArgs e) { DatabaseConnection.start(); gvStudents.Rows.Clear(); gvStudents.Refresh(); List <string> groupIds = new List <string>(); bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select Id from [Group]"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { groupIds.Add(reader["Id"].ToString()); } foreach (string group in groupIds) { List <string> groupMembers = new List <string>(); DatabaseConnection.createStatement("select Student.RegistrationNo[reg] from GroupStudent join Student on GroupStudent.StudentId = Student.Id where GroupId = " + group); SqlDataReader reader2 = DatabaseConnection.getData(); while (reader2.Read()) { groupMembers.Add(reader2["reg"].ToString()); } if (groupMembers.Count != 0) { DataGridViewRow row = (DataGridViewRow)gvStudents.Rows[0].Clone(); row.Cells[0].Value = group; int i = 1; foreach (string member in groupMembers) { row.Cells[i].Value = member; ++i; } gvStudents.Rows.Add(row); } } }
private void lblAdd_Click(object sender, EventArgs e) { if (string.IsNullOrWhiteSpace(cmbSelctAdvisor.Text)) { lblWarning.Visible = true; } else { string[] names = cmbSelctAdvisor.Text.Split(new char[] { ' ' }); DatabaseConnection.createStatement("select Advisor.Id[id] from Person join Advisor on Advisor.Id = Person.Id where FirstName = '" + names[0] + "'" + " and LastName = '" + names[1] + "'"); SqlDataReader reader = DatabaseConnection.getData(); Advisor advisor = new Advisor(); if (reader.Read()) { int x = advisor.AdvisorId1 = int.Parse(reader["id"].ToString()); MessageBox.Show(x.ToString()); TempData.CurrentAdvisor = advisor; } MessageBox.Show(TempData.CurrentAdvisor.AdvisorId1.ToString()); string sqlFormattedDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"); DatabaseConnection.createStatement("Insert into ProjectAdvisor (AdvisorId, ProjectId, AdvisorRole, AssignmentDate)" + " Values (" + TempData.CurrentAdvisor.AdvisorId1.ToString() + ", " + TempData.CurrentProject.Id + "," + TempData.CurrentRole.ToString() + ", '" + sqlFormattedDate + "') "); try { DatabaseConnection.performAction(); } catch { MessageBox.Show("Advisor already assigned to the group"); } ProjectDashboard projectDashboard = ProjectDashboard.GetInstance(); projectDashboard.Show(); this.Hide(); } }
private void gvAdvisors_CellContentClick(object sender, DataGridViewCellEventArgs e) { if (gvAdvisors.Columns[e.ColumnIndex].Name.ToString() == "Action3") { if (MessageBox.Show("Are you sure you want to delete?", "Delete Confirmation", MessageBoxButtons.YesNo) == DialogResult.Yes) { string id = gvAdvisors.Rows[e.RowIndex].Cells[0].Value.ToString(); DatabaseConnection.start(); DatabaseConnection.createStatement("Delete from ProjectAdvisor where AdvisorId =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from Advisor where Id =" + id); DatabaseConnection.performAction(); DatabaseConnection.createStatement("Delete from Person where Id =" + id); DatabaseConnection.performAction(); } } if (gvAdvisors.Columns[e.ColumnIndex].Name.ToString() == "Action2") { Advisor advisor = new Advisor(); DatabaseConnection.start(); DatabaseConnection.createStatement("select Person.Id[id], FirstName[FName], LastName[LName], Contact[Contact], Email[Email], Salary[Salary] from Person join Advisor on Person.Id = Advisor.Id where Advisor.Id =" + gvAdvisors.Rows[e.RowIndex].Cells[0].Value.ToString()); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { advisor.AdvisorId1 = int.Parse(reader["id"].ToString()); advisor.BasicDetails.FirstName = reader["FName"].ToString(); advisor.BasicDetails.LastName = reader["LName"].ToString(); advisor.BasicDetails.Contact = reader["Contact"].ToString(); advisor.BasicDetails.Email = reader["Email"].ToString(); advisor.Salary = int.Parse(reader["Salary"].ToString()); } TempData.CurrentAdvisor = advisor; EditAdvisor editAdvisor = new EditAdvisor(); editAdvisor.Show(); this.Hide(); } }
private void btnRegister_Click(object sender, EventArgs e) { if (!IsAnyTextBoxEmpty()) { bool IsConnnected = DatabaseConnection.start(); bool ISValidStudent = true; Student student = new Student(); try { student.FirstName = txtFirstName.Text; } catch (ArgumentException) { ISValidStudent = false; lblFNameWarning.Visible = true; } try { student.LastName = txtLastName.Text; } catch (ArgumentException) { ISValidStudent = false; lblLNameWarning.Visible = true; } try { student.RegistrationNo = txtRegNo.Text; } catch (ArgumentException) { ISValidStudent = false; lblRegWarning.Visible = true; } try { student.Email = txtEmail.Text; } catch (ArgumentException) { ISValidStudent = false; lblEmailWarning.Visible = true; } if (ISValidStudent) { string StudentGender = "0"; if (cmbGender.Text == "Male") { StudentGender = "1"; } string day = cmbDay.Text; string month = cmbMonth.SelectedIndex.ToString(); string year = cmbYear.Text; string studentDOB = year + " - " + month + " - " + day; bool IsException = false; DatabaseConnection.createStatement("select * from Student where RegistrationNo = '" + txtRegNo.Text + " '"); SqlDataReader r = DatabaseConnection.getData(); if (r.Read()) { IsException = true; MessageBox.Show("This Registration Number already exists"); } if (!IsException) { try { DatabaseConnection.createStatement("INSERT INTO Person ( FirstName, LastName, Contact, Email, DateOfBirth, Gender)" + " VALUES('" + txtFirstName.Text + "' , '" + txtLastName.Text + "', '" + txtContactNo.Text + "', '" + txtEmail.Text + "', '" + studentDOB + "' ," + StudentGender + "); "); DatabaseConnection.performAction(); } catch (SqlException) { IsException = true; lblDOBwarning.Visible = true; } } if (!IsException) { DatabaseConnection.createStatement("Select @@identity as id from Person"); SqlDataReader reader = DatabaseConnection.getData(); string id = "0"; while (reader.Read()) { id = (reader["id"].ToString()); } DatabaseConnection.createStatement("INSERT INTO Student (Id, RegistrationNo) VALUES (" + id + ", '" + txtRegNo.Text + "') "); DatabaseConnection.performAction(); if (!IsException) { MessageBox.Show("Student added"); ManageStudent manageStudent = ManageStudent.GetInstance(); manageStudent.Show(); this.Hide(); } } } } }
private void btnAddAdvisor_Click(object sender, EventArgs e) { if (!IsAnyTextBoxEmpty()) { bool IsConnnected = DatabaseConnection.start(); bool ISValidAdvisor = true; Student student = new Student(); Advisor advisor = new Advisor(); try { student.FirstName = txtFirstName.Text; } catch (ArgumentException) { ISValidAdvisor = false; lblFNameWarning.Visible = true; } try { student.LastName = txtLastName.Text; } catch (ArgumentException) { ISValidAdvisor = false; lblLNameWarning.Visible = true; } try { student.Email = txtEmail.Text; } catch (ArgumentException) { ISValidAdvisor = false; lblEmailWarning.Visible = true; } if (ISValidAdvisor) { string StudentGender = "2"; if (cmbGender.Text == "Male") { StudentGender = "1"; } string day = cmbDay.Text; string month = cmbMonth.SelectedIndex.ToString(); string year = cmbYear.Text; string advisorDOB = year + " - " + month + " - " + day; bool IsException = false; if (!IsException) { try { DatabaseConnection.createStatement("INSERT INTO Person ( FirstName, LastName, Contact, Email, DateOfBirth, Gender)" + " VALUES('" + txtFirstName.Text + "' , '" + txtLastName.Text + "', '" + txtContactNo.Text + "', '" + txtEmail.Text + "', '" + advisorDOB + "'," + StudentGender + "); "); DatabaseConnection.performAction(); } catch (SqlException) { IsException = true; lblDOBwarning.Visible = true; } } if (!IsException) { DatabaseConnection.createStatement("Select @@identity as id from Person"); SqlDataReader reader = DatabaseConnection.getData(); string id = "0"; while (reader.Read()) { id = (reader["id"].ToString()); } string advisorDesignation = "6"; if (cmbDesignation.SelectedIndex == 1) { advisorDesignation = "7"; } if (cmbDesignation.SelectedIndex == 2) { advisorDesignation = "8"; } if (cmbDesignation.SelectedIndex == 3) { advisorDesignation = "9"; } if (cmbDesignation.SelectedIndex == 4) { advisorDesignation = "10"; } DatabaseConnection.createStatement("INSERT INTO Advisor (Id, Designation, Salary) VALUES (" + id + "," + advisorDesignation + "," + txtSalary.Text + ") "); DatabaseConnection.performAction(); if (!IsException) { MessageBox.Show("Advisor added"); ManageAdvisors manageAdvisors = ManageAdvisors.GetInstance(); manageAdvisors.Show(); this.Hide(); } } } } }
private void ProjectsReport_Load(object sender, EventArgs e) { DatabaseConnection.start(); gvReport.Rows.Clear(); gvReport.Refresh(); List <string> ProjectIds = new List <string>(); bool IsConnnected = DatabaseConnection.start(); DatabaseConnection.createStatement("select Id from Project"); SqlDataReader reader = DatabaseConnection.getData(); while (reader.Read()) { ProjectIds.Add(reader["Id"].ToString()); } foreach (string project_id in ProjectIds) { ProjectReport report = new ProjectReport(); List <string> members = new List <string>(); DatabaseConnection.createStatement("select * from Project join GroupProject on Project.Id = GroupProject.ProjectID join GroupStudent on GroupProject.GroupId = GroupStudent.GroupId join Student on GroupStudent.StudentId = Student.Id where Project.Id = " + project_id); SqlDataReader reader3 = DatabaseConnection.getData(); if (reader3.Read()) { report.Title = reader3["Title"].ToString(); } while (reader3.Read()) { members.Add(reader3["RegistrationNo"].ToString()); } // Adding Members accrording to number of group members if (members.Count == 1) { report.Member1 = members[0]; } if (members.Count == 2) { report.Member1 = members[0]; report.Member2 = members[1]; } if (members.Count == 3) { report.Member1 = members[0]; report.Member2 = members[1]; report.Member3 = members[2]; } if (members.Count == 3) { report.Member1 = members[0]; report.Member2 = members[1]; report.Member3 = members[2]; report.Member4 = members[3]; } DatabaseConnection.createStatement("select * from Project join ProjectAdvisor on Project.Id = ProjectAdvisor.ProjectId join Advisor on ProjectAdvisor.AdvisorId = Advisor.Id join Person on Advisor.Id = Person.Id where Project.Id = " + project_id); SqlDataReader reader4 = DatabaseConnection.getData(); while (reader4.Read()) { string role = reader4["AdvisorRole"].ToString(); if (role == "11") { report.MainAdvisor = reader4["FirstName"].ToString() + " " + reader4["LastName"].ToString(); } if (role == "12") { report.CoAdvisor = reader4["FirstName"].ToString() + " " + reader4["LastName"].ToString(); } if (role == "14") { report.MainAdvisor = reader4["FirstName"].ToString() + " " + reader4["LastName"].ToString(); } } if (report.Title != null) { reports.Add(report); } } var bindingSource = new BindingSource(); bindingSource.DataSource = reports; gvReport.DataSource = bindingSource; }
private void btnMarkSheet_Click(object sender, EventArgs e) { List <Project> Projects = new List <Project>(); List <DateTime> Dates = new List <DateTime>(); DatabaseConnection.createStatement("select CONVERT(date, EvaluationDate)as EDate from GroupEvaluation group by CONVERT(date, EvaluationDate) order by CONVERT(date, EvaluationDate) desc"); SqlDataReader firstReader = DatabaseConnection.getData(); while (firstReader.Read()) { Dates.Add(DateTime.Parse(firstReader["EDate"].ToString())); } DatabaseConnection.createStatement("select * from Project"); SqlDataReader dataReader = DatabaseConnection.getData(); while (dataReader.Read()) { Project project = new Project(); project.Id = int.Parse(dataReader["Id"].ToString()); project.Title = dataReader["Title"].ToString(); Projects.Add(project); } StringWriter sw = new StringWriter(); HtmlTextWriter hw = new HtmlTextWriter(sw); StringBuilder sb = new StringBuilder(); //Generate Invoice (Bill) Header. sb.Append("<p style=\"text-align:center; font-size: 32px; \"><b>University of Engineering and Technology, Lahore</b></p>"); sb.Append("<p style=\"text-align:center; font-size: 20px; \"><b>CSE Department</b></p>"); sb.Append("<p style=\"text-align:center; \"><b><u>Mark Sheet</b></u></p>"); StringReader sr = new StringReader(sb.ToString()); PdfPTable tbl = new PdfPTable(Dates.Count + 1); tbl.AddCell("Date"); foreach (DateTime date in Dates) { tbl.AddCell(date.ToShortDateString().ToString()); } List <Evaluation> evaluations = new List <Evaluation>(); foreach (DateTime date in Dates) { string d = date.ToString("yyyy-MM-dd"); DatabaseConnection.createStatement("Select * from GroupEvaluation join Evaluation on GroupEvaluation.EvaluationId = Evaluation.Id where CONVERT(date, GroupEvaluation.EvaluationDate) = CONVERT(date, '" + d + "')"); SqlDataReader sqlDataReader = DatabaseConnection.getData(); if (sqlDataReader.Read()) { Evaluation evaluation = new Evaluation(); evaluation.Date = d; evaluation.TotalMarks = sqlDataReader["TotalMarks"].ToString(); evaluation.TotalWeightage = sqlDataReader["TotalWeightage"].ToString(); evaluations.Add(evaluation); } } tbl.AddCell("Total Marks"); foreach (Evaluation eval in evaluations) { tbl.AddCell(eval.TotalMarks); } tbl.AddCell("Weightage"); foreach (Evaluation eval in evaluations) { tbl.AddCell(eval.TotalWeightage); } foreach (Project p in Projects) { tbl.AddCell(p.Title); foreach (DateTime d in Dates) { string date = d.ToString("yyyy-MM-dd"); DatabaseConnection.createStatement("select * from Project join GroupProject on Project.Id = GroupProject.ProjectId join GroupEvaluation on GroupProject.GroupId = GroupEvaluation.GroupId join Evaluation on GroupEvaluation.EvaluationId = Evaluation.Id where Project.Id = " + p.Id + " and CONVERT(date, GroupEvaluation.EvaluationDate) = CONVERT(date, '" + date + "') order by GroupEvaluation.EvaluationDate"); SqlDataReader reader2 = DatabaseConnection.getData(); if (reader2.Read()) { tbl.AddCell(reader2["ObtainedMarks"].ToString()); } else { tbl.AddCell("N/A"); } } } SaveFileDialog saveFileDialog = new SaveFileDialog() { Filter = "PDF file|*.pdf", ValidateNames = true }; if (saveFileDialog.ShowDialog() == DialogResult.OK) { iTextSharp.text.Document document = new iTextSharp.text.Document(PageSize.A4.Rotate()); HTMLWorker htmlparser = new HTMLWorker(document); try { PdfWriter.GetInstance(document, new FileStream(saveFileDialog.FileName, FileMode.Create)); document.Open(); htmlparser.Parse(sr); document.Add(new iTextSharp.text.Paragraph("\n Date : " + DateTime.Now.ToShortDateString() + "\n \n")); document.Add(tbl); document.Add(new iTextSharp.text.Paragraph("\n \n This report was generated by computer. Errors are acceptible. ")); } catch (Exception ex) { MessageBox.Show(ex.Message); } finally { document.Close(); } MessageBox.Show("Report saved successfully"); } }