private void Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            ProjectAdvisorManagement datap = new ProjectAdvisorManagement();

            datap.ShowDialog();
            this.Close();// close the form
        }
Exemple #2
0
        // goes to manage project advisors
        private void button1_Click(object sender, EventArgs e)
        {
            ProjectAdvisorManagement pa = new ProjectAdvisorManagement();

            pa.ShowDialog();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(conURL);

            // connection opens
            con.Open();

            int ID = buffer;

            if (ID < 0)
            {
                try
                {
                    // here check whether boxes are empty for not
                    if (String.IsNullOrEmpty(comboBoxNames.Text) || String.IsNullOrEmpty(comboBoxAdvisor.Text))
                    {
                        MessageBox.Show("Fill first name and advisor role must");
                    }
                    else
                    {
                        string cmdText = "INSERT INTO ProjectAdvisor (AdvisorId, ProjectId, AdvisorRole, AssignmentDate) VALUES ((SELECT Advisor.Id FROM (Person JOIN Advisor ON Advisor.Id = Person.Id) where FirstName=@FirstName AND LastName = @LastName), @ProjectId, (SELECT Id FROM [Lookup] where Category = 'ADVISOR_ROLE' AND Value = @Value), @AssignmentDate)";
                        // command store in string then execute it by passing into sqlcommand object
                        SqlCommand c = new SqlCommand(cmdText, con);

                        c.Parameters.Add(new SqlParameter("@FirstName", comboBoxNames.Text));
                        c.Parameters.Add(new SqlParameter("@LastName", comboBoxLast.Text));
                        c.Parameters.Add(new SqlParameter("@ProjectId", ProjectAdvisorManagement.projectID));
                        c.Parameters.Add(new SqlParameter("@Value", comboBoxAdvisor.Text));
                        c.Parameters.Add(new SqlParameter("@AssignmentDate", DateTime.Now));
                        //execute it
                        int result = c.ExecuteNonQuery();
                        if (result < 0)
                        {
                            MessageBox.Show("Error");
                        }


                        // show dialog box if added in table of database
                        MessageBox.Show("Successfully Added");
                        con.Close();
                        this.Hide();
                        ProjectAdvisorManagement datap = new ProjectAdvisorManagement();
                        datap.ShowDialog();
                        this.Close(); // close the form
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Enter name and role in correct Format!!");
                }
            }

            else
            {
                try
                {      // trycatch handles exceptions
                       // update data

                    if (!String.IsNullOrEmpty(comboBoxNames.Text) && !String.IsNullOrEmpty(comboBoxAdvisor.Text))
                    {
                        string     cmdText2 = "Update ProjectAdvisor SET AdvisorId = (SELECT Advisor.Id FROM Person JOIN Advisor ON Advisor.Id = Person.Id where FirstName = @FirstName AND LastName = @LastName), AdvisorRole= (SELECT Id FROM [Lookup] where Category = 'ADVISOR_ROLE' AND Value = @Value) WHERE ProjectId = @ProjectId AND AdvisorId = @AdvisorId";
                        SqlCommand c2       = new SqlCommand(cmdText2, con);
                        c2.Parameters.Add(new SqlParameter("@ProjectId", ProjectAdvisorManagement.projectID));
                        c2.Parameters.Add(new SqlParameter("@AdvisorId", ID));
                        c2.Parameters.Add(new SqlParameter("@FirstName", comboBoxNames.Text));
                        c2.Parameters.Add(new SqlParameter("@LastName", comboBoxLast.Text));
                        c2.Parameters.Add(new SqlParameter("@Value", comboBoxAdvisor.Text));



                        c2.ExecuteNonQuery();
                        MessageBox.Show("Successfully Updated");
                        con.Close();
                        this.Hide();
                        ProjectAdvisorManagement datap = new ProjectAdvisorManagement();
                        datap.ShowDialog();
                        this.Close(); // close the form
                    }
                    else
                    {
                        throw new ArgumentNullException();
                    }
                }

                catch (Exception)
                {
                    MessageBox.Show("Enter name and role in correct Format!!");
                }
            }
        }