Example #1
0
        private void btnDelete_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("Do you want to delete this record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    var assign = new LecturerCourses();
                    assign.Id = Convert.ToInt32(recordId);

                    var result = LecturerCoursesDataAccess.delete(assign);

                    if (result == true)
                    {
                        MessageBox.Show("Record has been removed successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        gridRefresh(); // call grid refresh method
                        clearFileds(); // call clear field method
                    }
                    else
                    {
                        MessageBox.Show("Unable to delete record", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                return;
            }
        }
        // assign courses to lecturers
        public static bool assignCourse(LecturerCourses assign)
        {
            using (var db = new NipunaDataContext())
            {
                db.LecturerCourses.Add(assign);
                db.SaveChanges();

                return(true);
            }
        }
        // delete data
        public static bool delete(LecturerCourses assign)
        {
            using (var db = new NipunaDataContext())
            {
                var record = db.LecturerCourses.SingleOrDefault(x => x.Id == assign.Id);
                db.LecturerCourses.Remove(record);

                db.SaveChanges();
                return(true);
            }
        }
        // edit data
        public static bool edit(LecturerCourses assign)
        {
            using (var db = new NipunaDataContext())
            {
                var record = db.LecturerCourses.SingleOrDefault(x => x.Id == assign.Id);
                record.LecturerId   = assign.LecturerId;
                record.LecturerName = assign.LecturerName;
                record.CourseId     = assign.CourseId;
                record.CourseName   = assign.CourseName;

                db.SaveChanges();
                return(true);
            }
        }
Example #5
0
        private void btnEdit_Click(object sender, EventArgs e)
        {
            // edit lecturer course assign data
            if (MessageBox.Show("Do you want to update this record ?", "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
            {
                try
                {
                    var assign = new LecturerCourses();
                    assign.Id           = Convert.ToInt32(recordId);
                    assign.LecturerId   = txtLecturerId.Text;
                    assign.LecturerName = txtLecturerName.Text;
                    assign.CourseId     = txtCourseId.Text;
                    assign.CourseName   = txtCourseName.Text;

                    var result = LecturerCoursesDataAccess.edit(assign);

                    if (result == true)
                    {
                        MessageBox.Show("Data have been updated sucessfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        gridRefresh(); // call grid refresh method
                        clearFileds(); // call clear field method
                    }
                    else
                    {
                        MessageBox.Show("Unable to update data", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                return;
            }
        }
Example #6
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            // assign courses
            if (txtLecturerId.Text == "" || txtLecturerName.Text == "" || txtCourseId.Text == "" || txtCourseName.Text == "")
            {
                MessageBox.Show("Please check the fields", "Alert", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
            }
            else
            {
                try
                {
                    var assign = new LecturerCourses();
                    assign.LecturerId   = txtLecturerId.Text;
                    assign.LecturerName = txtLecturerName.Text;
                    assign.CourseId     = txtCourseId.Text;
                    assign.CourseName   = txtCourseName.Text;

                    var result = LecturerCoursesDataAccess.assignCourse(assign);

                    if (result == true)
                    {
                        MessageBox.Show("Lecturer has been added successfully", "Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        gridRefresh(); // call grid refresh method
                        clearFileds(); // call clear field method
                    }
                    else
                    {
                        MessageBox.Show("Unable to add lecturer", "Message", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show("Failed : " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }