예제 #1
0
        public void DeleteMethodOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create the item of test data
            clsCourses TestItem = new clsCourses();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Available = true;
            TestItem.IDno      = 1;
            TestItem.Title     = "Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "R Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 180;
            //set ThisCourse to the test data
            AllCourses.ThisCourse = TestItem;
            //add the record
            PrimaryKey = AllCourses.Add();
            //set the primary key of the test data
            TestItem.IDno = PrimaryKey;
            //find the record
            AllCourses.ThisCourse.Find(PrimaryKey);
            //delete the record
            AllCourses.Delete();
            //now find the record
            Boolean Found = AllCourses.ThisCourse.Find(PrimaryKey);

            //test to see that the record was not found
            Assert.IsFalse(Found);
        }
예제 #2
0
        public void UpdateMethodOK()
        {
            //Create an instance of the class we want to create
            clsCourseCollection AllCourses = new clsCourseCollection();
            //create the item of test data
            clsCourses TestItem = new clsCourses();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.Available = true;
            TestItem.IDno      = 1;
            TestItem.Title     = "Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "R Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 180;
            //set ThisCourse to the test data
            AllCourses.ThisCourse = TestItem;
            //add the record
            PrimaryKey = AllCourses.Add();
            //set the primary key of the test data
            TestItem.IDno = PrimaryKey;
            //modify the test data
            TestItem.Available = false;
            TestItem.IDno      = 11;
            TestItem.Title     = "Front-end Web Development";
            TestItem.Category  = "Technology";
            TestItem.Tutor     = "S Sunderland";
            TestItem.LiveDate  = DateTime.Now.Date;
            TestItem.Price     = 150;
            //set the record based on the new test data
            AllCourses.ThisCourse = TestItem;
            //update the record
            AllCourses.Update();
            //find the record
            AllCourses.ThisCourse.Find(PrimaryKey);
            //test to see ThisCourse matches the test data
            Assert.AreEqual(AllCourses.ThisCourse, TestItem);
        }
예제 #3
0
    protected void Button1_Click(object sender, EventArgs e)
    {
        lblError.Text = "";
        //create a new instance of clsCourses
        clsCourses aCourse = new clsCourses();
        //capture the CourseTitle
        string Title = txtTitleCourse.Text;
        //capture the  courseCategory
        string Category = txtCategoryCourse.Text;
        //capture the  courseTutor
        string Tutor = txtTutorCourse.Text;
        //capture the courseLiveDate
        string LiveDate = txtLiveDateCourse.Text;
        //capture the coursePrice
        string Price = txtpriceCourse.Text;
        //variable to store any error messages
        string Error = "";

        //validate the data
        Error = aCourse.Valid(Title, Category, Tutor, LiveDate, Price);
        if (Error == "")
        {
            //capture the IDno
            aCourse.IDno = IDno;
            //capture the Title
            aCourse.Title = Title;
            //capture the Category
            aCourse.Category = Category;
            //capture the Tutor
            aCourse.Tutor = Tutor;
            //capture the LiveDate
            aCourse.LiveDate = Convert.ToDateTime(LiveDate);
            //capture the Price
            aCourse.Price = Convert.ToDecimal(Price);
            //capture Available
            aCourse.Available = Available.Checked;
            //create a new instance of the address collection
            clsCourseCollection courseList = new clsCourseCollection();

            //if this is a new record i.e IDno = -1 then add the data
            if (IDno == -1)
            {
                //set the ThisCourse property
                courseList.ThisCourse = aCourse;
                //add the new record
                courseList.Add();
            }
            //otherwise it must be an update
            else
            {
                //find the record to update
                courseList.ThisCourse.Find(IDno);
                //set the ThisCourse property
                courseList.ThisCourse = aCourse;
                //update the record
                courseList.Update();
            }
            //redirect back to the listpage
            Response.Redirect("CourseList.aspx");
        }
        else
        {
            //display the error message
            lblError.Text = Error;
        }
    }