示例#1
0
        private void Cancel_Click(object sender, EventArgs e)
        {
            this.Hide();
            StudentgroupManagment sgm = new StudentgroupManagment();

            sgm.ShowDialog();
            this.Close(); // close the form
        }
示例#2
0
        // goes to manage studdent group
        private void buttonSg_Click(object sender, EventArgs e)
        {
            StudentgroupManagment sg = new StudentgroupManagment();

            sg.ShowDialog();
        }
示例#3
0
        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(textBoxRegNo.Text) || String.IsNullOrEmpty(comboBox1.Text))
                    {
                        MessageBox.Show("Fill all boxes must");
                    }
                    else
                    {
                        if (isRegNovalid(textBoxRegNo.Text))
                        {
                            int      groupID = StudentgroupManagment.groupID;
                            DateTime now     = DateTime.Now;

                            // command store in string then execute it by passing into sqlcommand object

                            string cmdText = "INSERT INTO GroupStudent (GroupId, StudentId, Status, AssignmentDate) VALUES (@GroupId,(SELECT Id FROM Student where RegistrationNo = @RegistrationNo) ,(SELECT Id FROM [Lookup] where Category = 'STATUS' AND Value = @Value), @AssignmentDate )";

                            SqlCommand c = new SqlCommand(cmdText, con);

                            c.Parameters.Add(new SqlParameter("@GroupId", groupID));
                            c.Parameters.Add(new SqlParameter("@RegistrationNo", textBoxRegNo.Text));
                            c.Parameters.Add(new SqlParameter("@Value", comboBox1.Text));
                            c.Parameters.Add(new SqlParameter("@AssignmentDate", 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");
                            StudentgroupManagment.groupID = -1;
                            con.Close();
                            this.Hide();
                            StudentgroupManagment sgm = new StudentgroupManagment();
                            sgm.ShowDialog();
                            this.Close(); // close the form
                        }
                        else
                        {
                            throw new ArgumentNullException();
                        }
                    }
                }
                catch (Exception)
                {
                    MessageBox.Show("Enter RegNo in correct Format and RegNo should be present in Student record only once!!");
                }
            }

            else
            {
                try
                {
                    if (!String.IsNullOrEmpty(textBoxRegNo.Text) && !String.IsNullOrEmpty(comboBox1.Text) && isRegNovalid(textBoxRegNo.Text))
                    {
                        string     cmdText2 = "Update GroupStudent SET StudentId = (SELECT Id FROM Student where RegistrationNo = @RegistrationNo), Status= (SELECT Id FROM [Lookup] where Category = 'STATUS' AND Value = @Value) WHERE StudentId = @StudentId AND GroupId = @GroupId";
                        SqlCommand c2       = new SqlCommand(cmdText2, con);
                        c2.Parameters.Add(new SqlParameter("@StudentId", ID));
                        c2.Parameters.Add(new SqlParameter("@GroupId", StudentgroupManagment.groupID));

                        c2.Parameters.Add(new SqlParameter("@Value", comboBox1.Text));
                        c2.Parameters.Add(new SqlParameter("@RegistrationNo", textBoxRegNo.Text));



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

                catch (Exception)
                {
                    MessageBox.Show("Enter RegNo in correct Format and RegNo should be present in Student record only once!!");
                }
            }
        }