public void UpdateMethodOK() //Add Method { //create an instance of the class we want to create clsPhoneCollection AllPhones = new clsPhoneCollection(); //create the item of test data clsPhone TestItem = new clsPhone(); //var to store the primary key Int32 PrimaryKey = 0; //set its properties TestItem.Active = true; TestItem.PhoneID = 1; TestItem.Capacity = 128; TestItem.Price = 100; TestItem.Colour = "red"; TestItem.DateAdded = DateTime.Now.Date; TestItem.Description = "This is the latest phone."; TestItem.Make = "Apple"; TestItem.Model = "C3500"; TestItem.StockStatus = true; //set ThisPhone to the test data AllPhones.ThisPhone = TestItem; //add the record PrimaryKey = AllPhones.Add(); //set the primary key of the test data TestItem.PhoneID = PrimaryKey; //modify the test data TestItem.Active = false; TestItem.PhoneID = 1; TestItem.Capacity = 0; TestItem.Price = 0; TestItem.Colour = "0"; TestItem.DateAdded = DateTime.Now.Date; TestItem.Description = "0."; TestItem.Make = "0"; TestItem.Model = "0"; TestItem.StockStatus = false; //set the record based on the new test data AllPhones.ThisPhone = TestItem; //update the method AllPhones.Update(); //find the record AllPhones.ThisPhone.Find(PrimaryKey); //test to see ThisPhone matches the test data Assert.AreEqual(AllPhones.ThisPhone, TestItem); }
protected void btnOK_Click(object sender, EventArgs e) { //create an instance of the phone page class clsPhone ThisPhone = new clsPhone(); //var to store any error messages string ErrorMessage; //test the data on the web form ErrorMessage = ThisPhone.PhoneValid( txtPhoneName.Text, txtBrand.Text, txtScreenSize.Text, txtOperatingSystem.Text, txtBackCamera.Text, txtBatterySize.Text, txtReleaseDate.Text); if (ErrorMessage == "") { //create a new instance of the phone collection class clsPhoneCollection PhoneCollection = new clsPhoneCollection(); //do something with the data - insert or update // //if the Phone Number is -1 if (PhoneNo == -1) { //copy the data from the interface to the object ThisPhone.PhoneName = txtPhoneName.Text; ThisPhone.Brand = txtBrand.Text; ThisPhone.ScreenSize = txtScreenSize.Text; ThisPhone.OperatingSystem = txtOperatingSystem.Text; ThisPhone.BackCamera = txtBackCamera.Text; ThisPhone.BatterySize = txtBatterySize.Text; ThisPhone.CompanyNo = Convert.ToInt32(ddlCompany.SelectedValue); ThisPhone.ReleaseDate = Convert.ToDateTime(txtReleaseDate.Text); //add the new record PhoneCollection.Add(); } else { //this is an existing record //copy the data from the interface to the object ThisPhone.PhoneNo = Convert.ToInt32(PhoneNo); ThisPhone.PhoneName = txtPhoneName.Text; ThisPhone.Brand = txtBrand.Text; ThisPhone.ScreenSize = txtScreenSize.Text; ThisPhone.OperatingSystem = txtOperatingSystem.Text; ThisPhone.BackCamera = txtBackCamera.Text; ThisPhone.BatterySize = txtBatterySize.Text; ThisPhone.CompanyNo = Convert.ToInt32(ddlCompany.SelectedValue); ThisPhone.ReleaseDate = Convert.ToDateTime(txtReleaseDate.Text); //update the exisiting record PhoneCollection.Update(); } //redirect back to the main page Response.Redirect("Default.aspx"); } else { //display the error message lblError.Text = ErrorMessage; } }