Example #1
0
        /// <summary>
        /// Load of the page.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Student_Load(object sender, EventArgs e)
        {
            String     cmd     = "SELECT LookupId FROM Lookup";
            SqlCommand command = new SqlCommand(cmd, conn);

            command.Parameters.Add(new SqlParameter("0", 1));
            conn.Open();
            SqlDataReader reader = command.ExecuteReader();

            while (reader.Read())
            {
                cmbStatus.Items.Add(reader[0]);
            }
            conn.Close();


            // TODO: This line of code loads data into the 'projectBDataSet.Student' table. You can move, or remove it, as needed.
            this.studentTableAdapter.Fill(this.projectBDataSet.Student);
            lblID.Hide();
            conn.Open();
            cmd     = String.Format("SELECT *FROM Student");
            command = new SqlCommand(cmd, conn);
            reader  = command.ExecuteReader();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            gridStudentInformation.DataSource = table;
            TabViewStudent.Refresh();
            conn.Close();
        }
Example #2
0
        /// <summary>
        /// This is the click event of Student
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void TabViewStudent_Click(object sender, EventArgs e)
        {
            conn.Open();
            string         cmd     = String.Format("SELECT *FROM Student");
            SqlCommand     command = new SqlCommand(cmd, conn);
            SqlDataReader  reader  = command.ExecuteReader();
            SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
            DataTable      table   = new DataTable();

            adapter.Fill(table);
            gridStudentInformation.DataSource = table;
            TabViewStudent.Refresh();
            conn.Close();
        }
Example #3
0
        /// <summary>
        /// This is the cell click event of the grid view.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void gridStudentInformation_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            var element = gridStudentInformation.Columns["Delete"].Index;

            if (e.ColumnIndex == element)
            {
                int ID;
                ID = Convert.ToInt32(gridStudentInformation.Rows[e.RowIndex].Cells[0].Value);
                string        cmd;
                SqlCommand    command;
                SqlDataReader reader;
                cmd     = "Delete from StudentAttendance where StudentId = @id";
                command = new SqlCommand(cmd, conn);
                command.Parameters.Add(new SqlParameter("@id", ID));
                conn.Open();
                command.ExecuteReader();
                conn.Close();

                cmd     = "DELETE FROM StudentResult WHERE StudentId = @id1";
                command = new SqlCommand(cmd, conn);
                command.Parameters.Add(new SqlParameter("@id1", ID));
                conn.Open();
                command.ExecuteReader();
                conn.Close();



                cmd     = String.Format("DELETE FROM Student WHERE Id = @ID");
                command = new SqlCommand(cmd, conn);

                command.Parameters.Add(new SqlParameter("@ID", ID));
                conn.Open();
                reader = command.ExecuteReader();
                conn.Close();
                conn.Open();
                cmd    = String.Format("SELECT *FROM Student");
                reader = command.ExecuteReader();
                SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
                DataTable      table   = new DataTable();
                adapter.Fill(table);
                gridStudentInformation.DataSource = table;
                TabViewStudent.Refresh();
                conn.Close();
            }
            else
            {
                var item = gridStudentInformation.Rows[e.RowIndex].Cells[0].Value;
                //int IdOfItem;
                //var SecondItem = gridStudentInformation.Rows[e.RowIndex].Cells[6].Value;
                string     cmd     = String.Format("SELECT * FROM Student WHERE Id = @item");
                SqlCommand command = new SqlCommand(cmd, conn);
                command.Parameters.Add(new SqlParameter("@item", item));
                conn.Open();
                SqlDataReader reader = command.ExecuteReader();
                Student       s      = new Student();
                //tabControl1.SelectedTab = tabControl1.TabPages["View Student"].Show;
                TabADDStudent.Show();
                btnAddStudent.Text = "Update Student";
                while (reader.Read())
                {
                    lblID.Text                 = Convert.ToString(reader[0]);
                    txtFirstName.Text          = Convert.ToString(reader[1]);
                    txtLastName.Text           = Convert.ToString(reader[2]);
                    txtContact.Text            = Convert.ToString(reader[3]);
                    txtEmail.Text              = Convert.ToString(reader[4]);
                    txtRegistrationNumber.Text = Convert.ToString(reader[5]);
                    cmbStatus.Text             = Convert.ToString(reader[6]);
                }

                conn.Close();
            }
        }
Example #4
0
        /// <summary>
        /// This is the click event of Button of add student
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnAddStudent_Click(object sender, EventArgs e)
        {
            if (btnAddStudent.Text == "Update Student")
            {
                String FirstName, LastName, Contact, Email, RegistrationNumber;
                int    Status;
                string ID = lblID.Text;
                if (IsValidString(txtFirstName.Text))
                {
                    if (IsValidString(txtLastName.Text) || txtLastName.Text.Length == 0)
                    {
                        if (isValidContact(txtContact.Text) || txtContact.Text.Length == 0)
                        {
                            if (isDigit(cmbStatus.Text) && isDigit(cmbStatus.Text))
                            {
                                if (IsValidEmail(txtEmail.Text) && isValidRegistrationNumber(txtRegistrationNumber.Text))
                                {
                                    FirstName          = txtFirstName.Text;
                                    LastName           = txtLastName.Text;
                                    Contact            = txtContact.Text;
                                    Email              = txtEmail.Text;
                                    RegistrationNumber = txtRegistrationNumber.Text;
                                    Status             = Convert.ToInt32(cmbStatus.Text);
                                    conn.Open();
                                    string     cmd     = String.Format("UPDATE Student SET FirstName = @FirstName, LastName = @LastName, Contact = @Contact, Email = @Email, RegistrationNumber = @RegistrationNumber, Status = @Status WHERE Id = @ID");
                                    SqlCommand command = new SqlCommand(cmd, conn);
                                    command.Parameters.Add(new SqlParameter("@FirstName", FirstName));
                                    command.Parameters.Add(new SqlParameter("@LastName", LastName));
                                    command.Parameters.Add(new SqlParameter("@Contact", Contact));
                                    command.Parameters.Add(new SqlParameter("@Email", Email));
                                    command.Parameters.Add(new SqlParameter("@RegistrationNumber", RegistrationNumber));
                                    command.Parameters.Add(new SqlParameter("@Status", Status));
                                    command.Parameters.Add(new SqlParameter("@Id", ID));
                                    SqlDataReader reader = command.ExecuteReader();
                                    btnAddStudent.Text = "Add Student";
                                    SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
                                    txtContact.Text            = "";
                                    txtEmail.Text              = "";
                                    txtFirstName.Text          = "";
                                    txtLastName.Text           = "";
                                    txtRegistrationNumber.Text = "";
                                    cmbStatus.Text             = "";
                                    conn.Close();
                                    TabADDStudent.Hide();
                                    TabViewStudent.Show();

                                    conn.Open();
                                    cmd     = String.Format("SELECT *FROM Student");
                                    command = new SqlCommand(cmd, conn);
                                    reader  = command.ExecuteReader();
                                    adapter = new SqlDataAdapter(cmd, conn);
                                    DataTable table = new DataTable();
                                    adapter.Fill(table);
                                    gridStudentInformation.DataSource = table;
                                    TabViewStudent.Refresh();
                                    conn.Close();
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                lblID.Hide();
                String FirstName, LastName, Contact, Email, RegistrationNumber;
                int    Status;

                if (IsValidString(txtFirstName.Text))
                {
                    if (IsValidString(txtLastName.Text) || txtLastName.Text.Length == 0)
                    {
                        if (isValidContact(txtContact.Text) || txtContact.Text.Length == 0)
                        {
                            if (isDigit(cmbStatus.Text) && isDigit(cmbStatus.Text))
                            {
                                if (IsValidEmail(txtEmail.Text) && isValidRegistrationNumber(txtRegistrationNumber.Text))
                                {
                                    ClassStudent student = new ClassStudent();
                                    student.FirstName          = txtFirstName.Text;
                                    student.LastName           = txtLastName.Text;
                                    student.Contact            = txtContact.Text;
                                    student.Email              = txtEmail.Text;
                                    student.RegistrationNumber = txtRegistrationNumber.Text;
                                    student.Status             = Convert.ToInt32(cmbStatus.Text);
                                    FirstName          = txtFirstName.Text = student.FirstName;
                                    LastName           = txtLastName.Text = student.LastName;
                                    Contact            = txtContact.Text = student.Contact;
                                    Email              = txtEmail.Text = student.Email;
                                    RegistrationNumber = txtRegistrationNumber.Text = student.RegistrationNumber;
                                    Status             = Convert.ToInt32(cmbStatus.Text);
                                    conn.Open();
                                    String     cmd     = String.Format("INSERT INTO Student(FirstName, LastName,Contact, Email, RegistrationNumber, Status) values('{0}','{1}','{2}','{3}','{4}','{5}')", FirstName, LastName, Contact, Email, RegistrationNumber, Status);
                                    SqlCommand command = new SqlCommand(cmd, conn);
                                    command.Parameters.Add(new SqlParameter("0", 1));

                                    SqlDataReader  reader  = command.ExecuteReader();
                                    SqlDataAdapter adapter = new SqlDataAdapter(cmd, conn);
                                    MessageBox.Show("Student has been added");
                                    txtContact.Text            = "";
                                    txtEmail.Text              = "";
                                    txtFirstName.Text          = "";
                                    txtLastName.Text           = "";
                                    txtRegistrationNumber.Text = "";
                                    cmbStatus.Text             = "";
                                    conn.Close();
                                }
                                else
                                {
                                    if (!IsValidEmail(txtEmail.Text))
                                    {
                                        MessageBox.Show("Invalid Email");
                                    }
                                    if (!isValidRegistrationNumber(txtRegistrationNumber.Text))
                                    {
                                        MessageBox.Show("Invalid Registration Number");
                                    }
                                }
                            }
                            else
                            {
                                MessageBox.Show("Invalid Status");
                                if (!IsValidEmail(txtEmail.Text))
                                {
                                    MessageBox.Show("Invalid Email");
                                }
                                if (!isValidRegistrationNumber(txtRegistrationNumber.Text))
                                {
                                    MessageBox.Show("Invalid Registration Number");
                                }
                            }
                        }
                        else
                        {
                            MessageBox.Show("Invalid Contact");

                            if (!IsValidEmail(txtEmail.Text))
                            {
                                MessageBox.Show("Invalid Email");
                            }
                            if (!isValidRegistrationNumber(txtRegistrationNumber.Text))
                            {
                                MessageBox.Show("Invalid Registration Number");
                            }
                            if (!isDigit(cmbStatus.Text))
                            {
                                MessageBox.Show("Invalid Status");
                            }
                        }
                    }
                    else
                    {
                        MessageBox.Show("Invalid Last Name");
                        if (!isValidContact(txtContact.Text) && txtContact.Text.Length > 0)
                        {
                            MessageBox.Show("Invalid Contact");
                        }
                        if (!IsValidEmail(txtEmail.Text))
                        {
                            MessageBox.Show("Invalid Email");
                        }
                        if (!isValidRegistrationNumber(txtRegistrationNumber.Text))
                        {
                            MessageBox.Show("Invalid Registration Number");
                        }
                        if (!isDigit(cmbStatus.Text))
                        {
                            MessageBox.Show("Invalid Status");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Invalid First Name");
                    if (!IsValidString(txtLastName.Text) && txtLastName.Text.Length > 0)
                    {
                        MessageBox.Show("Invalid Last Name");
                    }
                    if (!isValidContact(txtContact.Text) && txtContact.Text.Length > 0)
                    {
                        MessageBox.Show("Invalid Contact");
                    }
                    if (!IsValidEmail(txtEmail.Text))
                    {
                        MessageBox.Show("Invalid Email");
                    }
                    if (!isValidRegistrationNumber(txtRegistrationNumber.Text))
                    {
                        MessageBox.Show("Invalid Registration Number");
                    }
                    if (!isDigit(cmbStatus.Text))
                    {
                        MessageBox.Show("Invalid Status");
                    }
                }
            }
        }