コード例 #1
0
    void Add()
    {
        //create an instance of the Staff
        MyClassLibrary.clsStaffCollection Astaff = new MyClassLibrary.clsStaffCollection();
        //validate the data on the web form
        String Error = Astaff.ThisStaff.Valid(TextBoxStaffNubmer.Text, TextBoxFirstName.Text, TextBoxLastName.Text, TextBoxGender.Text, TextBoxPosition.Text, TextBoxPassword.Text, Convert.ToInt32(TextBoxAttendence.Text), TextBoxAddress.Text, TextBoxPhoneNumber.Text);

        //if the data is OK then add it to the object
        if (Error == "")
        {
            //get the data entered by the user
            Astaff.ThisStaff.StaffNumber = TextBoxStaffNubmer.Text;
            Astaff.ThisStaff.FirstName   = TextBoxFirstName.Text;
            Astaff.ThisStaff.LastName    = TextBoxLastName.Text;
            Astaff.ThisStaff.Gender      = TextBoxGender.Text;
            Astaff.ThisStaff.Position    = TextBoxPosition.Text;
            Astaff.ThisStaff.Password    = TextBoxPassword.Text;
            Astaff.ThisStaff.Attendence  = Convert.ToInt32(TextBoxAttendence.Text);
            Astaff.ThisStaff.Address     = TextBoxAddress.Text;
            Astaff.ThisStaff.PhoneNumber = TextBoxPhoneNumber.Text;
            //add the record
            Astaff.Add();
            //all done so redirect back to the main page
            Response.Redirect("Staff%20Information.aspx");
        }
        else
        {
            //report an error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }
コード例 #2
0
 void DisplayStaffs()
 {
     //create an instance of the County Collection
     MyClassLibrary.clsStaffCollection Staffs = new MyClassLibrary.clsStaffCollection();
     //set the data source to the list of counties in the collection
     lstStaffs.DataSource = Staffs.StaffList;
     //set the name of the primary key
     lstStaffs.DataValueField = "StaffID";
     //set the data field to display
     lstStaffs.DataTextField = "StaffNumber";
     //bind the data to the list
     lstStaffs.DataBind();
 }