Example #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection con = new SqlConnection(conURL);

            con.Open();

            int currentRow         = int.Parse(e.RowIndex.ToString());
            int currentColumnIndex = int.Parse(e.ColumnIndex.ToString());
            int prid = Convert.ToInt32(dataGridView1.Rows[currentRow].Cells[2].Value.ToString());

            if (currentColumnIndex == 0)
            {
                ManageProjectAdvisors_1 form = new ManageProjectAdvisors_1(prid);
                this.Close();
                form.Show();
            }

            if (currentColumnIndex == 1)
            {
                ManageProjectAdvisors_2 form1 = new ManageProjectAdvisors_2(prid);
                this.Close();
                form1.Show();
            }
        }
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            SqlConnection con = new SqlConnection(conURL);

            con.Open();
            int    currentRow         = int.Parse(e.RowIndex.ToString());
            int    currentColumnIndex = int.Parse(e.ColumnIndex.ToString());
            string advemail           = dataGridView1.Rows[currentRow].Cells[4].Value.ToString();



            if (currentColumnIndex == 0)
            {
                bool j = myvalidations();
                if (j == true)
                {
                    if (advisor_role.Text == "Main Advisor")
                    {
                        string     display1 = "SELECT * FROM ProjectAdvisor WHERE AdvisorRole = @val1 AND ProjectId = @val2";
                        SqlCommand cmd3     = new SqlCommand(display1, con);

                        string     role    = string.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", "Main Advisor");
                        SqlCommand cmd4    = new SqlCommand(role, con);
                        int        roleid1 = (Int32)cmd4.ExecuteScalar();
                        cmd3.Parameters.AddWithValue("@val1", roleid1);

                        cmd3.Parameters.AddWithValue("@val2", flag);
                        cmd3.ExecuteNonQuery();
                        SqlDataAdapter sda1 = new SqlDataAdapter();
                        sda1.SelectCommand = cmd3;
                        DataTable roledt = new DataTable();
                        sda1.Fill(roledt);
                        if (roledt.Rows.Count > 0)
                        {
                            MessageBox.Show("Project can not have more than one main advisor");
                        }
                        else
                        {
                            string     groupst = "INSERT INTO ProjectAdvisor(AdvisorId, ProjectId, AdvisorRole, AssignmentDate) values(@AdvisorId, @ProjectId, @AdvisorRole, @AssignmentDate)";
                            SqlCommand cmd     = new SqlCommand(groupst, con);
                            cmd.Parameters.AddWithValue("@ProjectId", flag);

                            string     email = string.Format("SELECT Id FROM Person WHERE Email = '{0}'", advemail);
                            SqlCommand cmd1  = new SqlCommand(email, con);
                            int        advid = (Int32)cmd1.ExecuteScalar();
                            cmd.Parameters.AddWithValue("@AdvisorId", advid);

                            string     status = string.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", advisor_role.Text);
                            SqlCommand cmd2   = new SqlCommand(status, con);
                            int        roleid = (Int32)cmd2.ExecuteScalar();
                            cmd.Parameters.AddWithValue("@AdvisorRole", roleid);

                            cmd.Parameters.AddWithValue("@AssignmentDate", DateTime.Today);
                            cmd.ExecuteNonQuery();

                            MessageBox.Show("Advisor Assigned to Project");
                            ManageProjectAdvisors_1 form = new ManageProjectAdvisors_1(flag);
                            this.Close();
                            form.Show();
                        }
                    }

                    else

                    {
                        string     groupst = "INSERT INTO ProjectAdvisor(AdvisorId, ProjectId, AdvisorRole, AssignmentDate) values(@AdvisorId, @ProjectId, @AdvisorRole, @AssignmentDate)";
                        SqlCommand cmd     = new SqlCommand(groupst, con);
                        cmd.Parameters.AddWithValue("@ProjectId", flag);

                        string     email = string.Format("SELECT Id FROM Person WHERE Email = '{0}'", advemail);
                        SqlCommand cmd1  = new SqlCommand(email, con);
                        int        advid = (Int32)cmd1.ExecuteScalar();
                        cmd.Parameters.AddWithValue("@AdvisorId", advid);

                        string     status = string.Format("SELECT Id FROM Lookup WHERE Value = '{0}'", advisor_role.Text);
                        SqlCommand cmd2   = new SqlCommand(status, con);
                        int        roleid = (Int32)cmd2.ExecuteScalar();
                        cmd.Parameters.AddWithValue("@AdvisorRole", roleid);

                        cmd.Parameters.AddWithValue("@AssignmentDate", DateTime.Today);
                        cmd.ExecuteNonQuery();

                        MessageBox.Show("Advisor Assigned to Project");
                        ManageProjectAdvisors_1 form = new ManageProjectAdvisors_1(flag);
                        this.Close();
                        form.Show();
                    }
                }
            }
        }