コード例 #1
0
        void PopulateArray(clsDataConnection DB)
        {
            //var for the index
            Int32 Index = 0;
            //var to store the record count
            Int32 RecordCount = 0;

            //get the count of records
            RecordCount = DB.Count;
            //Clear the private array list
            mAddressList = new List <ClsAddress>();
            //while there are records to process
            while (Index < RecordCount)
            {
                //create a blank address
                ClsAddress AnAddress = new ClsAddress();
                //read in the fields from the current record
                AnAddress.Active    = Convert.ToBoolean(DB.DataTable.Rows[Index]["Active"]);
                AnAddress.AddressNo = Convert.ToInt32(DB.DataTable.Rows[Index]["AddressNo"]);
                AnAddress.CountyNo  = Convert.ToInt32(DB.DataTable.Rows[Index]["CountyNo"]);
                AnAddress.DateAdded = Convert.ToDateTime(DB.DataTable.Rows[Index]["DateAddded"]);
                AnAddress.HouseNo   = Convert.ToString(DB.DataTable.Rows[Index]["HouseNo"]);
                AnAddress.PostCode  = Convert.ToString(DB.DataTable.Rows[Index]["PostCode"]);
                AnAddress.Street    = Convert.ToString(DB.DataTable.Rows[Index]["Street"]);
                AnAddress.Town      = Convert.ToString(DB.DataTable.Rows[Index]["Town"]);
                //add the record to the private data member
                mAddressList.Add(AnAddress);
                //point to the next record
                Index++;
            }
        }
コード例 #2
0
        protected void btnFind_Click(object sender, EventArgs e)
        {
            //create an instance of the address class
            ClsAddress AnAddress = new ClsAddress();
            //variable to store the primary key
            Int32 AddressNo;
            //variable to store the result of the fing operation
            Boolean Found = false;

            //get the primary key entered by the user
            AddressNo = Convert.ToInt32(txtAddressNo.Text);
            //find the record
            Found = AnAddress.Find(AddressNo);
            //if founnd
            if (Found == true)
            {
                //display the values of the properties in the form
                txtHouseNo.Text   = AnAddress.HouseNo;
                txtStreet.Text    = AnAddress.Street;
                txtTown.Text      = AnAddress.Town;
                txtPostCode.Text  = AnAddress.PostCode;
                txtCounty.Text    = AnAddress.CountyNo.ToString();
                txtDateAdded.Text = AnAddress.DateAdded.ToString();
            }
        }
コード例 #3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //create a new instance of clsAddress
            ClsAddress AnAddress = new ClsAddress();

            //get the data from the session object
            AnAddress = (ClsAddress)Session["AnAddress"];
            //display the house number for this entry
            Response.Write(AnAddress.HouseNo);
        }
コード例 #4
0
        public void btnOK_Clicked(object sender, EventArgs args)
        {
            ClsAddress AnAddress = new ClsAddress();
            //capture the house no
            string HouseNo = txtHouseNo.Text;
            //capture the street
            string Street = txtStreet.Text;
            //capture the town
            string Town = txtTown.Text;
            //capture the post code
            string PostCode = txtPostalCode.Text;
            //capture the county
            string CountyNo = txtCounty.Text;
            //capture date added
            string DateAdded = Convert.ToDateTime(txtDateAdded.Text);
            //Store the address in th session object
            //variable to store any error message
            string Error = "";

            Error = AnAddress.Valid(HouseNo, Street, Town, PostCode, DateAdded);
            if (Error == "")
            {
                //capture the address no
                AnAddress.AddressNo = AddressNo;
                //capture the house no
                AnAddress.HouseNo = HouseNo;
                //capture the street
                AnAddress.Street = Street;
                //capture the town
                AnAddress.Town = Town;
                //capture the post code
                AnAddress.PostCode = PostCode;
                //capture the county
                AnAddress.CountyNo = Convert.ToInt32(CountyNo);
                //capture date added
                AnAddress.DateAdded = Convert.ToDateTime(DateAdded);
                //capture active
                AnAddress.Active = chkActive.Checked;
                //Store the address in th session object
                //create new instance of the address collection
                ClsAddressCollection AddressList = new ClsAddressCollection();

                if (AddressNo == -1)
                {
                    //set the ThisAddress property
                    AddressList.ThisAddress = AnAddress;
                    //add the new record
                    AddressList.Add();
                }
                //otherwise
                else
                {
                    //find the record to update
                    AddressList.ThisAddress.Find(AddressNo);
                    //set the ThisAddress property
                    AddressList.ThisAddress = AnAddress;
                    //update the record
                    AddressList.Update();
                }
                //redirect back to the listpage
                Response.Redirect("AnAddressList.aspx");
            }
            else
            {
                //display the error message
                lblError.Text = Error;
            }
        }