private void Manage_Advisors_Click(object sender, EventArgs e) { this.Hide(); Add_Advisor f1 = new Add_Advisor(); f1.ShowDialog(); this.Close(); }
private void addStudt_Click(object sender, EventArgs e) { this.Hide(); Add_Advisor f4 = new Add_Advisor(); f4.ShowDialog(); this.Close(); }
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) { con1.Open(); int UP_Row = int.Parse(e.RowIndex.ToString()); int UP_RowIndex = int.Parse(e.ColumnIndex.ToString()); ID1 = Convert.ToInt32(dataGridView1.Rows[UP_Row].Cells[0].Value.ToString()); int dd = (int)dataGridView1.CurrentRow.Cells[0].Value; if (UP_RowIndex == 10) { if (UP_RowIndex == 1) { if (UP_RowIndex == 0) { MessageBox.Show("lala"); } } if (UP_RowIndex != 0) { var askfirst1 = MessageBox.Show("Are you sure you want to Update this?", "Update", MessageBoxButtons.YesNo); if (askfirst1 == DialogResult.Yes) { Add_Advisor s = new Add_Advisor(dd); ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString()); s.textBox2.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString(); s.textBox3.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString(); s.textBox4.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString(); s.textBox5.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString(); s.dateTimePicker1.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString(); s.textBox1.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString(); if (dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString() == "") { s.comboBox1.Text = ""; } else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value) == 1) { s.comboBox1.Text = "Male"; } else if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[6].Value) == 2) { s.comboBox1.Text = "Female"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 6) { s.comboBox2.Text = "Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 7) { s.comboBox2.Text = "Associate Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 8) { s.comboBox2.Text = "Assisstant Professor"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 9) { s.comboBox2.Text = "Lecturer"; } if (Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[7].Value) == 10) { s.comboBox2.Text = "Industry Professional"; } s.ShowDialog(); con1.Close(); } else { con1.Close(); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); DisplayAdvisor(); } } } else if (UP_RowIndex == 9) { int URow = int.Parse(e.RowIndex.ToString()); int URowIndex = int.Parse(e.ColumnIndex.ToString()); ID = Convert.ToInt32(dataGridView1.Rows[URow].Cells[0].Value.ToString()); if (URowIndex == 0) { MessageBox.Show("Click on Delete Again"); } if (URowIndex != 0) { var askfirst = MessageBox.Show("Are you sure you want to delete this?", "Delete", MessageBoxButtons.YesNo); if (askfirst == DialogResult.Yes) { cmd1 = new SqlCommand("DELETE FROM Person where ID = @Id", con1); cmd2 = new SqlCommand("DELETE FROM Advisor where ID = @Id", con1); cmd2.Parameters.AddWithValue("@Id", ID); cmd1.Parameters.AddWithValue("@Id", ID); cmd2.ExecuteNonQuery(); cmd1.ExecuteNonQuery(); con1.Close(); MessageBox.Show("Deleted Succesfully"); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); this.Close(); } else { con1.Close(); this.Hide(); Advisor f2 = new Advisor(); f2.ShowDialog(); DisplayAdvisor(); } } } else { con1.Close(); } }
private void Save_Click(object sender, EventArgs e) { string pa = @"^([a-zA-Z0-9_\-])([a-zA-Z0-9_\-\.]*)@(\[((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}|((([a-zA-Z0-9\-]+)\.)+))([a-zA-Z]{2,}|(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\])$"; if (comboBox2.Text != "" && textBox2.Text != "" && textBox5.Text != "" && Regex.IsMatch(textBox1.Text, @"^[0-9]{0,18}")) { if (Regex.IsMatch(textBox5.Text, pa) && Regex.IsMatch(textBox2.Text, @"^[a-zA-Z]+$")) { if ((Regex.IsMatch(textBox3.Text, @"^[a-zA-Z\s]+$") && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (textBox3.Text == "" && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (!Regex.IsMatch(textBox3.Text, @"^[a-zA-Z0-9_\-]+$") && Regex.IsMatch(textBox4.Text, @"^9[0-9]{9}")) || (Regex.IsMatch(textBox3.Text, @"^[a-zA-Z\s]+$") && textBox4.Text == "") || (textBox3.Text == "" && textBox4.Text == "")) { bool s = Salary_check(textBox1.Text); if (s == true || textBox1.Text == "") { bool email = Email_exists(textBox5.Text); if (comboBox1.Text != "") { if (Flag1 == 0) { if (email == false) { con1.Open(); string gId = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox1.Text); SqlCommand cmd3 = new SqlCommand(gId, con1); int g = (Int32)cmd3.ExecuteScalar(); cmd1 = new SqlCommand("insert into [Person] (FirstName, LastName, Contact, Email, DateOfBirth, gender) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + dateTimePicker1.Text + "','" + g + "')", con1); string designation_Id = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox2.Text); SqlCommand cmd = new SqlCommand(designation_Id, con1); int d_Id = (Int32)cmd.ExecuteScalar(); cmd2 = new SqlCommand("insert into Advisor(Advisor.Id, Designation, Salary) values ( (SELECT MAX(Person.Id) From Person),'" + d_Id + "','" + textBox1.Text + "')", con1); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); cmd3.ExecuteNonQuery(); cmd.ExecuteNonQuery(); con1.Close(); MessageBox.Show("Inserted Successfully"); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Clear(); textBox5.Clear(); this.Hide(); Add_Advisor f4 = new Add_Advisor(); f4.ShowDialog(); this.Close(); } else { MessageBox.Show("Email Exists"); } } if (Flag1 > 0) { bool Upemail = UpdateEmail_exists(textBox5.Text); if (Upemail == false) { con1.Open(); string designation_Id = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox2.Text); SqlCommand cmd = new SqlCommand(designation_Id, con1); int d_Id = (Int32)cmd.ExecuteScalar(); cmd1 = new SqlCommand("UPDATE Person set FirstName = @FirstName, LastName = @LastName ,Contact = @Contact, Email = @Email, DateOfBirth =@DateOfBirth, Gender = @Gender WHERE ID = @dd", con1); cmd1.Parameters.AddWithValue("@dd", Flag1); cmd1.Parameters.AddWithValue("@FirstName", textBox2.Text); cmd1.Parameters.AddWithValue("@LastName", textBox3.Text); cmd1.Parameters.AddWithValue("@Contact", textBox4.Text); cmd1.Parameters.AddWithValue("@Email", textBox5.Text); cmd1.Parameters.AddWithValue("@DateOfBirth", dateTimePicker1.Text); string gId = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox1.Text); SqlCommand cmd3 = new SqlCommand(gId, con1); int g = (Int32)cmd3.ExecuteScalar(); cmd1.Parameters.AddWithValue("@Gender", g); cmd2 = new SqlCommand("UPDATE Advisor SET Designation = @Designation, Salary = @Salary WHERE ID = @Id", con1); cmd2.Parameters.AddWithValue("@Id", Flag1); cmd2.Parameters.AddWithValue("@Salary", textBox1.Text); cmd2.Parameters.AddWithValue("@Designation", d_Id); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); cmd3.ExecuteNonQuery(); cmd.ExecuteNonQuery(); con1.Close(); Flag1 = 0; MessageBox.Show("Updated successfully"); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Clear(); textBox5.Clear(); this.Hide(); Add_Advisor f4 = new Add_Advisor(); f4.ShowDialog(); this.Close(); } else { MessageBox.Show("Email Exists"); } } } else { if (Flag1 == 0) { if (email == false) { con1.Open(); cmd1 = new SqlCommand("insert into [Person] (FirstName, LastName, Contact, Email, DateOfBirth) values ('" + textBox2.Text + "','" + textBox3.Text + "','" + textBox4.Text + "','" + textBox5.Text + "','" + dateTimePicker1.Text + "')", con1); string designation_Id = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox2.Text); SqlCommand cmd = new SqlCommand(designation_Id, con1); int d_Id = (Int32)cmd.ExecuteScalar(); if (textBox1.Text != "") { cmd2 = new SqlCommand("insert into Advisor(Advisor.Id, Designation, Salary) values ( (SELECT MAX(Person.Id) From Person),'" + d_Id + "','" + textBox1.Text + "')", con1); } else { cmd2 = new SqlCommand("insert into Advisor(Advisor.Id, Designation) values ( (SELECT MAX(Person.Id) From Person),'" + d_Id + "')", con1); } cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); cmd.ExecuteNonQuery(); con1.Close(); MessageBox.Show("Inserted Successfully"); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Clear(); textBox5.Clear(); this.Hide(); Add_Advisor f4 = new Add_Advisor(); f4.ShowDialog(); this.Close(); } else { MessageBox.Show("Email Exists"); } } if (Flag1 > 0) { bool Upemail = UpdateEmail_exists(textBox5.Text); if (Upemail == false) { con1.Open(); string designation_Id = string.Format("SELECT Lookup.Id From Lookup WHERE Value = '{0}'", comboBox2.Text); SqlCommand cmd = new SqlCommand(designation_Id, con1); int d_Id = (Int32)cmd.ExecuteScalar(); cmd1 = new SqlCommand("UPDATE Person set FirstName = @FirstName, LastName = @LastName ,Contact = @Contact, Email = @Email, DateOfBirth =@DateOfBirth WHERE ID = @dd", con1); cmd1.Parameters.AddWithValue("@dd", Flag1); cmd1.Parameters.AddWithValue("@FirstName", textBox2.Text); cmd1.Parameters.AddWithValue("@LastName", textBox3.Text); cmd1.Parameters.AddWithValue("@Contact", textBox4.Text); cmd1.Parameters.AddWithValue("@Email", textBox5.Text); cmd1.Parameters.AddWithValue("@DateOfBirth", dateTimePicker1.Text); if (textBox1.Text != "") { cmd2 = new SqlCommand("UPDATE Advisor SET Designation = @Designation, Salary = @Salary WHERE ID = @Id", con1); cmd2.Parameters.AddWithValue("@Id", Flag1); cmd2.Parameters.AddWithValue("@Salary", textBox1.Text); cmd2.Parameters.AddWithValue("@Designation", d_Id); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); cmd.ExecuteNonQuery(); } else { cmd2 = new SqlCommand("UPDATE Advisor SET Designation = @Designation WHERE ID = @Id", con1); cmd2.Parameters.AddWithValue("@Id", Flag1); cmd2.Parameters.AddWithValue("@Designation", d_Id); cmd1.ExecuteNonQuery(); cmd2.ExecuteNonQuery(); cmd.ExecuteNonQuery(); } con1.Close(); Flag1 = 0; MessageBox.Show("Updated successfully"); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); textBox1.Clear(); textBox5.Clear(); this.Hide(); Add_Advisor f4 = new Add_Advisor(); f4.ShowDialog(); this.Close(); } else { MessageBox.Show("Email Exists"); } } } } else { MessageBox.Show("Invalid Salary"); } } else { MessageBox.Show("Please check Last Name and Contact Number(9331xxyyzzz"); } } else { MessageBox.Show("Please check Email(Full Email Id) and first name"); } } else { MessageBox.Show("Please check Email(Full Email Id), Designation and first name"); } con1.Close(); }