Esempio n. 1
0
    //function for updating new records
    void Update()
    {
        //create an instance of the Ticket Book
        clsTicketCollection TicketBook = new clsTicketCollection();
        //validate the data on the web form
        string Error = TicketBook.ThisTicket.Valid(txtTicketPurchaseDate.Text, txtTicketNo.Text, txtFlightNo.Text, txtSeatNo.Text);

        //if the data is ok then add it to the object
        if (Error == "")
        {
            //find the record to update
            TicketBook.ThisTicket.Find(TicketID);
            //get the data entered by the user
            TicketBook.ThisTicket.TicketPurchaseDate = Convert.ToDateTime(txtTicketPurchaseDate.Text);
            TicketBook.ThisTicket.TicketNo           = txtTicketNo.Text;
            TicketBook.ThisTicket.FlightNo           = Convert.ToInt32(txtFlightNo.Text);
            TicketBook.ThisTicket.SeatNo             = txtSeatNo.Text;
            //update the record
            TicketBook.Update();
            //all done so redirect back to the main page
            Response.Redirect("TicketList.aspx");
        }
        else
        {
            //report the error
            lblError.Text = "There were problems with the data entered " + Error;
        }
    }
        public void UpdateMethod()
        {
            //create an instance of a class
            clsTicketCollection AllTicket = new clsTicketCollection();
            //create the item of test data
            clsTicket TestItem = new clsTicket();
            //var to store the primarykey
            Int32 PrimaryKey = 0;

            //set its properties
            TestItem.TicketPurchaseDate = DateTime.Now.Date;
            TestItem.TicketNo           = "ASD456GH";
            TestItem.FlightNo           = 535;
            TestItem.SeatNo             = "53B";
            //set thisticket to the test data
            AllTicket.ThisTicket = TestItem;
            //add the record
            PrimaryKey = AllTicket.Add();
            //set the primary key of the test data
            TestItem.TicketID = PrimaryKey;
            //modify the test data
            TestItem.TicketPurchaseDate = DateTime.Now.Date;
            TestItem.TicketNo           = "HGF3F72";
            TestItem.FlightNo           = 767;
            TestItem.SeatNo             = "5B";
            //Set the record based on the new test data
            AllTicket.ThisTicket = TestItem;
            //update the record
            AllTicket.Update();
            //find the record
            AllTicket.ThisTicket.Find(PrimaryKey);
            //test to see this ticket matches the test data
            Assert.AreEqual(AllTicket.ThisTicket, TestItem);
        }