コード例 #1
0
        private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            //int i = 0;

            if (dataGridView1.Columns[e.ColumnIndex].Name == "Add_to_group" && (e.RowIndex >= 0))
            {
                conn.Open();
                try
                {
                    if (MessageBox.Show("Are You Sure You Want to Add this?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        int id = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells["Id"].Value);

                        string     g      = string.Format("Select MAX(Id) From [Group]");
                        SqlCommand f      = new SqlCommand(g, conn);
                        int        Grp_id = (int)f.ExecuteScalar();

                        string     m1       = String.Format("INSERT INTO [GroupStudent](GroupId, StudentId, Status, AssignmentDate) values('{0}', '{1}', '{2}', '{3}' )", Grp_id, id, 3, DateTime.Now);
                        SqlCommand command1 = new SqlCommand(m1, conn);
                        //command1.Parameters.Add(new SqlParameter("@Id", id));
                        int rows1 = command1.ExecuteNonQuery();
                        if (rows1 != 0)
                        {
                            MessageBox.Show("Added");
                            //counter = counter + 1;
                            if (MessageBox.Show("Do you want to add another student?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                            {
                                //MessageBox.Show("Assign at least two students to a group");
                                this.Close();
                                //Group1 b = new Group1();
                            }
                            else
                            {
                                Group1 b = new Group1();
                                b.Show();
                            }
                        }
                    }
                    conn.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
コード例 #2
0
 private void button2_Click(object sender, EventArgs e)
 {
     if (conn.State == System.Data.ConnectionState.Open)
     {
         try
         {
             //conn.Open();
             string k = String.Format("INSERT INTO [Group](Created_On) values('{0}')", DateTime.Now);
             //String cmd3 = String.Format("INSERT INTO Student(Id, RegistrationNo) values('{0}', '{1}')", id2, C1.Get_Reg_No());
             SqlCommand f      = new SqlCommand(k, conn);
             int        Grp_id = f.ExecuteNonQuery();
             conn.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         Group1 g = new Group1();
         g.Show();
     }
     else
     {
         conn.Open();
         try
         {
             //conn.Open();
             string k = String.Format("INSERT INTO [Group](Created_On) values('{0}')", DateTime.Now);
             //String cmd3 = String.Format("INSERT INTO Student(Id, RegistrationNo) values('{0}', '{1}')", id2, C1.Get_Reg_No());
             SqlCommand f      = new SqlCommand(k, conn);
             int        Grp_id = f.ExecuteNonQuery();
             conn.Close();
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         Group1 g = new Group1();
         g.Show();
     }
 }
コード例 #3
0
        private void label6_Click(object sender, EventArgs e)
        {
            Group1 g = new Group1();

            g.Show();
        }