public void AddMethodOK()
        {
            clsVendorCollection AllVendors = new clsVendorCollection();
            clsVendors          TestItem   = new clsVendors();
            Int32 PrimaryKey = 0;

            TestItem.OpenToBookings = true;
            TestItem.VendorNo       = 1;
            TestItem.VendorName     = "Pizza place";
            TestItem.HouseNo        = "12a";
            TestItem.Street         = "street name";
            TestItem.City           = "city name";
            TestItem.Country        = "Country name";
            TestItem.PostCode       = "PO5 7CO";
            TestItem.DateAdded      = DateTime.Now.Date;
            TestItem.VendorType     = "Food";
            TestItem.Summary        = "The best pizza place.";
            //set ThisVendor to the test data
            AllVendors.ThisVendor = TestItem;
            PrimaryKey            = AllVendors.Add();
            TestItem.VendorNo     = PrimaryKey;
            //find record
            AllVendors.ThisVendor.Find(PrimaryKey);
            Assert.AreEqual(AllVendors.ThisVendor, TestItem);
        }
Пример #2
0
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        //create new instance of clsVendors
        clsVendors AVendor = new clsVendors();
        //captures information
        string VendorName     = txtVendorName.Text;
        string HouseNo        = txtHouseNo.Text;
        string Street         = txtStreet.Text;
        string City           = txtCity.Text;
        string PostCode       = txtPostcode.Text;
        string Country        = txtCountry.Text;
        string VendorType     = txtVendorType.Text;
        string DateAdded      = txtDateAdded.Text;
        string Summary        = txtSummary.Text;
        bool   OpenToBookings = chkOpenToBookings.Checked;
        //variable to store any error messages
        string Error = "";

        //validate data
        Error = AVendor.Valid(HouseNo, Street, City, PostCode, Country, DateAdded, VendorName, VendorType, Summary);
        if (Error == "")
        {
            //capture the vendor no
            AVendor.VendorNo = VendorNo;
            //captures information
            AVendor.VendorName     = VendorName;
            AVendor.HouseNo        = HouseNo;
            AVendor.Street         = Street;
            AVendor.City           = City;
            AVendor.PostCode       = PostCode;
            AVendor.Country        = Country;
            AVendor.DateAdded      = Convert.ToDateTime(DateAdded);
            AVendor.VendorType     = VendorType;
            AVendor.Summary        = Summary;
            AVendor.OpenToBookings = chkOpenToBookings.Checked;

            clsVendorCollection VendorList = new clsVendorCollection();
            //if it is a new record
            if (VendorNo == -1)
            {
                VendorList.ThisVendor = AVendor;
                VendorList.Add();
            }
            else //it is an update
            {
                VendorList.ThisVendor.Find(VendorNo);
                VendorList.ThisVendor = AVendor;
                VendorList.Update();
            }

            Response.Redirect("VendorList.aspx");
        }
        else
        {
            //display error message
            lblError.Text = Error;
        }
    }