Esempio n. 1
0
    protected void bttnOK_Click(object sender, EventArgs e)
    {
        //create a new instance of clsMember
        clsMember AMember = new clsMember();

        //capture all data for validation
        string FullName    = txtbxFullName.Text;
        string Address     = txtbxAddress.Text;
        string DOB         = txtbxDOB.Text;
        string PhoneNumber = txtbxPhoneNumber.Text;
        //variable to store error messages
        string Error = "";

        Error = AMember.Valid(FullName, Address, DOB, PhoneNumber);
        if (Error == "")
        {
            //capture all the data
            AMember.MemberID          = MemberID;
            AMember.FullName          = FullName;
            AMember.Address           = Address;
            AMember.DOB               = Convert.ToDateTime(DOB);
            AMember.PhoneNumber       = PhoneNumber;
            AMember.MedicalConditions = chkbxMedicalConditions.Checked;

            //create a new instance of the Member collection
            clsMemberCollection AllMembers = new clsMemberCollection();

            //if this is a new record  then add the data
            if (MemberID == -1)
            {
                //set the ThisMember property
                AllMembers.ThisMember = AMember;
                //add the new record
                AllMembers.Add();
            }
            else //otherwise it must be an update
            {
                //find the record to update
                AllMembers.ThisMember.Find(MemberID);
                //set the ThisMember property
                AllMembers.ThisMember = AMember;
                //update the record
                AllMembers.Update();
            }

            //redirect back to the listpage
            Response.Redirect("MemberList.aspx");
        }
        else
        {
            lblErrorMessage.Text = Error;
        }
    }
        public void UpdateMethodOK()
        {
            //create an instance of the class we want to create
            clsMemberCollection AllMembers = new clsMemberCollection();
            //create an item of test data
            clsMember Test1 = new clsMember();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            Test1.FullName          = "Sofyan Ronaldo";
            Test1.Address           = "1 Leicester Road";
            Test1.PhoneNumber       = "07745984535";
            Test1.DOB               = DateTime.Parse("1988/07/08");
            Test1.MedicalConditions = true;
            //set ThisMember to the test data
            AllMembers.ThisMember = Test1;
            //set the primary key of the test data
            PrimaryKey = AllMembers.Add();
            //set the primary key of the test data
            Test1.MemberID = PrimaryKey;
            //modify the test data
            Test1.FullName          = "Cristiano Ronaldo";
            Test1.Address           = "1 London Road";
            Test1.PhoneNumber       = "07405610874";
            Test1.DOB               = DateTime.Parse("1978/07/08");
            Test1.MedicalConditions = true;
            //set the record based on the new test data
            AllMembers.ThisMember = Test1;
            //update the record
            AllMembers.Update();
            //fimd the record
            AllMembers.ThisMember.Find(PrimaryKey);
            //test to see ThisMember matches the test data
            Assert.AreEqual(AllMembers.ThisMember, Test1);
            //
        }