/// <summary>
        /// Event Handler for click event on btnAdd which adds a new student in database
        /// </summary>
        /// <param name="sender">Control on which event occured</param>
        /// <param name="e">Args for event occured</param>
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            //getting the entered information
            string fullname    = txtFullName.Text;
            string fathersName = txtFathersName.Text;
            int    rollNo      = Convert.ToInt32(txtRollNo.Text);
            int    age         = Convert.ToInt16(txtAge.Text);
            int    stream      = Convert.ToInt32(listStream.SelectedValue);
            string address     = txtAddress.Text;
            int    state       = Convert.ToInt32(listState.SelectedValue);

            //calling AddStudent() method to add the record to database
            StudentDataHandler studHandler = new StudentDataHandler();
            bool result = studHandler.AddStudent(fullname, fathersName, rollNo, age, stream, address, state);

            if (result)
            {
                //if record gets added
                Response.Write(Messages.RecordAddSuccess);
                resetControls();  //resetting the controls for new student
            }
            else
            {
                //if record adding failed.
                Response.Write(Messages.RecordAddFailed);
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// CLick Event Handler for btnUpdate button to update record of a student
        /// </summary>
        /// <param name="source">Control attribute on which this event has occured</param>
        /// <param name="args">Event Args for the control</param>
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            //getting the newly entered data for student
            string fullname    = txtFullName.Text;
            string fathersName = txtFathersName.Text;
            int    rollNo      = Convert.ToInt32(txtRollNo.Text);
            int    age         = Convert.ToInt16(txtAge.Text);
            int    stream      = Convert.ToInt32(listStream.SelectedValue);
            string address     = txtAddress.Text;
            int    state       = Convert.ToInt32(listState.SelectedValue);

            //updating the Student object
            stud.FullName    = fullname;
            stud.FathersName = fathersName;
            stud.RollNo      = rollNo;
            stud.Age         = age;
            stud.Stream      = stream;
            stud.Address     = address;
            stud.State       = state;

            //calling the update method
            bool result = StudentDataHandler.UpdateStudent(stud);

            if (result)
            {
                // if result gets updated
                Response.Write(Messages.RecordUpdateSuccess);
            }
            else
            {
                //if updation gets failed.
                Response.Write(Messages.RecordUpdateFailed);
            }
        }
Exemplo n.º 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //checking whether there is any querystring or not
                if (Request.QueryString.Count == 0)
                {
                    //Redirecting to AllStudents page to select a student to update
                    Response.Redirect("AllStudents.aspx");
                }

                AddStreams();   //to add streams to the respective listBox
                AddStates();    //to add states to the respective listBox

                //extracting the student ID from query string
                string queryData = Request.QueryString["StudID"];
                int    studID    = Convert.ToInt32(queryData);

                //getting the Student record from the database
                stud = StudentDataHandler.FindStudent(studID);

                //filling up the controls with the old data
                txtFullName.Text         = stud.FullName;
                txtFathersName.Text      = stud.FathersName;
                txtRollNo.Text           = stud.RollNo.ToString();
                txtAge.Text              = stud.Age.ToString();
                listStream.SelectedValue = stud.Stream.ToString();
                string address = txtAddress.Text = stud.Address;
                listState.SelectedValue = stud.State.ToString();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// SelctIndexChanged Event Handler for listStream to show the students from the selected stream
        /// </summary>
        /// <param name="sender">Control on which the event occured</param>
        /// <param name="e">Args for the event occured.</param>
        protected void listStream_SelectedIndexChanged(object sender, EventArgs e)
        {
            //creating a new DataTable for GridView
            DataTable studTable = new DataTable();

            //settign the columns for the table
            studTable.Columns.Add("StudID", typeof(int));
            studTable.Columns.Add("FullName", typeof(string));
            studTable.Columns.Add("FathersName", typeof(string));
            studTable.Columns.Add("RollNo", typeof(int));
            studTable.Columns.Add("Age", typeof(int));
            studTable.Columns.Add("Stream", typeof(string));
            studTable.Columns.Add("Address", typeof(string));
            studTable.Columns.Add("State", typeof(string));

            //reading the data from database
            List <Student> students = StudentDataHandler.ListAllStudent();


            if (listStream.SelectedIndex == 0)   //if user selects 'All'
            {
                //adding rows to the DataTable
                foreach (Student item in students)
                {
                    studTable.Rows.Add(
                        item.StudID,
                        item.FullName,
                        item.FathersName,
                        item.RollNo,
                        item.Age,
                        UtilityFunctions.GetStreamName(item.Stream),
                        item.Address,
                        UtilityFunctions.GetStateName(item.State)
                        );
                }
            }
            else  //if user selects a specific stream
            {
                //adding rows to the DataTable
                foreach (Student item in students)
                {
                    if (item.Stream == Convert.ToInt32(listStream.SelectedValue))
                    {
                        studTable.Rows.Add(
                            item.StudID,
                            item.FullName,
                            item.FathersName,
                            item.RollNo,
                            item.Age,
                            UtilityFunctions.GetStreamName(item.Stream),
                            item.Address,
                            UtilityFunctions.GetStateName(item.State)
                            );
                    }
                }
            }
            //setting up the DataSource for the GridView
            gridStudents.DataSource = studTable;
            gridStudents.DataBind();
        }
        /// <summary>
        /// SelectedIndexChanged Event Handler for listStreams
        /// </summary>
        /// <param name="sender">lisStream object</param>
        /// <param name="e">Args for event</param>
        protected void listStreams_SelectedIndexChanged(object sender, EventArgs e)
        {
            //reading the data from database
            List <Student> students = StudentDataHandler.ListAllStudent();

            listStudLeft.Items.Clear();
            listStudRight.Items.Clear();

            if (listStreams.SelectedIndex == 0)   //if user selects 'All'
            {
                //adding rows to the DataTable
                foreach (Student item in students)
                {
                    listStudLeft.Items.Add(new ListItem(item.FullName, item.RollNo.ToString()));
                }
            }
            else  //if user selects a specific stream
            {
                //adding rows to the DataTable
                foreach (Student item in students)
                {
                    if (item.Stream == Convert.ToInt32(listStreams.SelectedValue))
                    {
                        listStudLeft.Items.Add(new ListItem(item.FullName, item.RollNo.ToString()));
                    }
                }
            }
        }
        public static string DeleteStudents(string rollNos)
        {
            string result = Messages.RecordDeletedFailed;

            if (StudentDataHandler.DeleteStudent(rollNos))
            {
                result = Messages.RecordDeletedSuccess;
            }
            return(result);
        }