private void BackBtn_Click(object sender, EventArgs e) { Advisors form = new Advisors(); form.Show(); this.Hide(); }
private void DeleteAdvisorBtn_Click(object sender, EventArgs e) { SqlConnection conn = new SqlConnection(conURL); conn.Open(); if (AdvisorsGridView.SelectedCells.Count != 0) { int row = AdvisorsGridView.SelectedCells[0].RowIndex; int id = Convert.ToInt32(AdvisorsGridView.Rows[row].Cells[0].Value); String delAdvisorCMD2 = String.Format("DELETE FROM ProjectAdvisor WHERE AdvisorId = {0}", id); SqlCommand delAdvisorCommand2 = new SqlCommand(delAdvisorCMD2, conn); int count = delAdvisorCommand2.ExecuteNonQuery(); String delAdvisorCMD = String.Format("DELETE FROM Advisor WHERE Id = {0}", id); SqlCommand delAdvisorCommand = new SqlCommand(delAdvisorCMD, conn); count = delAdvisorCommand.ExecuteNonQuery(); String delPersonCMD = String.Format("DELETE FROM Person WHERE Id = {0}", id); SqlCommand delPersonCommand = new SqlCommand(delPersonCMD, conn); count = delPersonCommand.ExecuteNonQuery(); Advisors form = new Advisors(); this.Hide(); form.Show(); } }
private void AddStudentSaveBtn_Click(object sender, EventArgs e) { if (ValidateEntries()) { if (flag == 0) { SqlConnection conn = new SqlConnection(conURL); conn.Open(); String AddPersonCMD = "INSERT INTO Person (FirstName, LastName, Contact, Email, DateOfBirth, Gender) VALUES (@fname, @lname, @contact, @email, @dob, @gender)"; SqlCommand AddPersonCommand = new SqlCommand(AddPersonCMD, conn); AddPersonCommand.Parameters.Add(new SqlParameter("fname", FirstNameTextBox.Text)); //LastName if (!String.IsNullOrEmpty(LastNameTextBox.Text)) { AddPersonCommand.Parameters.Add(new SqlParameter("lname", LastNameTextBox.Text)); } else { AddPersonCommand.Parameters.Add(new SqlParameter("lname", DBNull.Value)); } //Contact if (!String.IsNullOrEmpty(ContactTextBox.Text)) { AddPersonCommand.Parameters.Add(new SqlParameter("contact", ContactTextBox.Text)); } else { AddPersonCommand.Parameters.Add(new SqlParameter("contact", DBNull.Value)); } //DOB if (!String.IsNullOrEmpty(DobDateTimePicker.Text.ToString())) { AddPersonCommand.Parameters.Add(new SqlParameter("dob", DobDateTimePicker.Value)); } else { AddPersonCommand.Parameters.Add(new SqlParameter("dob", DBNull.Value)); } AddPersonCommand.Parameters.Add(new SqlParameter("email", EmailTextBox.Text)); //GENDER if (!String.IsNullOrEmpty(GenderComboBox.Text)) { String getGenderIdCMD = String.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", GenderComboBox.Text); SqlCommand getGenderIdCommand = new SqlCommand(getGenderIdCMD, conn); int genderid = (Int32)getGenderIdCommand.ExecuteScalar(); AddPersonCommand.Parameters.Add(new SqlParameter("gender", genderid)); } else { AddPersonCommand.Parameters.Add(new SqlParameter("gender", DBNull.Value)); } int count = AddPersonCommand.ExecuteNonQuery(); String getpIdCMD = "SELECT MAX(Id) FROM Person"; SqlCommand getpIdCommand = new SqlCommand(getpIdCMD, conn); int pId = (Int32)getpIdCommand.ExecuteScalar(); //DesignationID String getDesignationIdCMD = String.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", DesignationComboBox.Text); SqlCommand getDesignationIdCommand = new SqlCommand(getDesignationIdCMD, conn); int designationid = (Int32)getDesignationIdCommand.ExecuteScalar(); String AddAdvisorCMD = "INSERT INTO Advisor (Id, Designation, Salary) VALUES (@advisorid, @designation, @salary)"; SqlCommand AddAdvisorCommand = new SqlCommand(AddAdvisorCMD, conn); AddAdvisorCommand.Parameters.Add(new SqlParameter("advisorid", pId)); AddAdvisorCommand.Parameters.Add(new SqlParameter("designation", designationid)); if (!String.IsNullOrEmpty(SalaryTextBox.Text)) { AddAdvisorCommand.Parameters.Add(new SqlParameter("salary", Convert.ToDecimal(SalaryTextBox.Text))); } else { AddAdvisorCommand.Parameters.Add(new SqlParameter("salary", DBNull.Value)); } count = AddAdvisorCommand.ExecuteNonQuery(); Advisors form = new Advisors(); form.Show(); this.Hide(); } if (flag == 1) { SqlConnection conn = new SqlConnection(conURL); conn.Open(); String UpdatePersonCMD = "UPDATE Person SET FirstName = @fname, LastName = @lname, Contact = @contact, Email = @email, DateOfBirth = @dob, Gender = @gender WHERE Id = @id"; SqlCommand UpdatePersonCommand = new SqlCommand(UpdatePersonCMD, conn); UpdatePersonCommand.Parameters.Add(new SqlParameter("fname", FirstNameTextBox.Text)); //LastName if (!String.IsNullOrEmpty(LastNameTextBox.Text)) { UpdatePersonCommand.Parameters.Add(new SqlParameter("lname", LastNameTextBox.Text)); } else { UpdatePersonCommand.Parameters.Add(new SqlParameter("lname", DBNull.Value)); } //Contact if (!String.IsNullOrEmpty(ContactTextBox.Text)) { UpdatePersonCommand.Parameters.Add(new SqlParameter("contact", ContactTextBox.Text)); } else { UpdatePersonCommand.Parameters.Add(new SqlParameter("contact", DBNull.Value)); } //DOB if (!String.IsNullOrEmpty(DobDateTimePicker.Text)) { UpdatePersonCommand.Parameters.Add(new SqlParameter("dob", DobDateTimePicker.Value)); } else { UpdatePersonCommand.Parameters.Add(new SqlParameter("dob", DBNull.Value)); } UpdatePersonCommand.Parameters.Add(new SqlParameter("email", EmailTextBox.Text)); //GENDER if (!String.IsNullOrEmpty(GenderComboBox.Text)) { String getGenderIdCMD = String.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", GenderComboBox.Text); SqlCommand getGenderIdCommand = new SqlCommand(getGenderIdCMD, conn); int genderid = (Int32)getGenderIdCommand.ExecuteScalar(); UpdatePersonCommand.Parameters.Add(new SqlParameter("gender", genderid)); } else { UpdatePersonCommand.Parameters.Add(new SqlParameter("gender", DBNull.Value)); } UpdatePersonCommand.Parameters.Add(new SqlParameter("id", incomingId)); int count = UpdatePersonCommand.ExecuteNonQuery(); //DesignationID String getDesignationIdCMD = String.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", DesignationComboBox.Text); SqlCommand getDesignationIdCommand = new SqlCommand(getDesignationIdCMD, conn); int designationid = (Int32)getDesignationIdCommand.ExecuteScalar(); String UpdateAdvisorCMD = "UPDATE Advisor SET Designation = @designation, Salary = @salary WHERE Id = @id"; SqlCommand UpdateAdvisorCommand = new SqlCommand(UpdateAdvisorCMD, conn); UpdateAdvisorCommand.Parameters.Add(new SqlParameter("id", incomingId)); UpdateAdvisorCommand.Parameters.Add(new SqlParameter("designation", designationid)); if (!String.IsNullOrEmpty(SalaryTextBox.Text)) { UpdateAdvisorCommand.Parameters.Add(new SqlParameter("salary", Convert.ToDecimal(SalaryTextBox.Text))); } else { UpdateAdvisorCommand.Parameters.Add(new SqlParameter("salary", DBNull.Value)); } count = UpdateAdvisorCommand.ExecuteNonQuery(); Advisors form = new Advisors(); form.Show(); this.Hide(); } } else { MessageBox.Show("Invalid input"); } }