void Add()
    {
        //create an instance
        clsCarRepairsCollection CarRepair = new clsCarRepairsCollection();
        //validate the data on webform
        Boolean OK = CarRepair.ThisCarRepair.Valid(txtMechanicDaysInForRepair.Text, txtMechanicDeadlineDate.Text, txtMechanicPartPrice.Text, txtMechanicPartRequired.Text, txtMechanicCarID.Text, txtMechanicStaffID.Text);

        //if data is okay then add to object
        if (OK == true)
        {
            //Fetch data entered by user
            CarRepair.ThisCarRepair.DaysInForRepair = Convert.ToInt32(txtMechanicDaysInForRepair.Text);
            CarRepair.ThisCarRepair.DeadlineDate    = Convert.ToDateTime(txtMechanicDeadlineDate.Text);
            CarRepair.ThisCarRepair.PartPrice       = Convert.ToDecimal(txtMechanicPartPrice.Text);
            CarRepair.ThisCarRepair.PartRequired    = txtMechanicPartRequired.Text;
            CarRepair.ThisCarRepair.CarID           = Convert.ToInt32(txtMechanicCarID.Text);
            CarRepair.ThisCarRepair.StaffID         = Convert.ToInt32(txtMechanicStaffID.Text);
            //add record
            CarRepair.Add();
            Response.Redirect("MechanicHomepage.aspx");
            lblMechanicError.Text = "Repair successfully added";
        }
        else
        {
            //report error
            lblMechanicError.Text = "There were problems with the data you have entered, please try again";
        }
    }
        public void AddMethodOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();
            //create the item of test data
            clsCarRepairs TestItem = new clsCarRepairs();
            //Var to store the primary key
            Int32 PrimaryKey = 0;

            //Set its properties
            TestItem.CarRepairID     = 2000;
            TestItem.DaysInForRepair = 27;
            TestItem.DeadlineDate    = DateTime.Now.Date.AddDays(60);
            TestItem.PartPrice       = 52.99m;
            TestItem.PartRequired    = "Add test";

            TestItem.CarID   = 2000;
            TestItem.StaffID = 2000;
            //set this repair to the test data
            AllCarRepairs.ThisCarRepair = TestItem;
            //add the record
            PrimaryKey = AllCarRepairs.Add();
            //set the primary key of the test data
            TestItem.CarRepairID = PrimaryKey;
            //find the record
            AllCarRepairs.ThisCarRepair.Find(PrimaryKey);
            //Test to see if the two values are the same
            Assert.AreEqual(AllCarRepairs.ThisCarRepair, TestItem);
        }
        public void CarRepairListOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();
            //create some test data to assign to the property
            //in this case the data needs to be a list of objects
            List <clsCarRepairs> TestList = new List <clsCarRepairs>();
            //Add an item to the list
            //create the item of test data
            clsCarRepairs TestItem = new clsCarRepairs();

            //Set its properties
            TestItem.CarRepairID     = 1;
            TestItem.DaysInForRepair = 30;
            TestItem.DeadlineDate    = DateTime.Now.Date;
            TestItem.PartPrice       = 99.99m;
            TestItem.PartRequired    = "Test part";

            //Add the item to the list
            TestList.Add(TestItem);
            //Assign the data to the property
            AllCarRepairs.CarRepairList = TestList;
            //Test to see if the two values are the same
            Assert.AreEqual(AllCarRepairs.CarRepairList, TestList);
        }
        public void DeleteMethodOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();
            //create the item of test data
            clsCarRepairs TestItem = new clsCarRepairs();
            //Var to store the primary key
            Int32 PrimaryKey = 0;

            //Set its properties
            TestItem.CarRepairID     = 8;
            TestItem.DaysInForRepair = 1;
            TestItem.DeadlineDate    = DateTime.Now.Date.AddDays(9);
            TestItem.PartPrice       = 200.00m;
            TestItem.PartRequired    = "4 new tyres";
            //set this repair to the test data
            AllCarRepairs.ThisCarRepair = TestItem;
            //add the record
            PrimaryKey = AllCarRepairs.Add();
            //set the primary key of the test data
            TestItem.CarRepairID = PrimaryKey;
            //find the record
            AllCarRepairs.ThisCarRepair.Find(PrimaryKey);
            //Delete the record
            AllCarRepairs.Archive();
            //Now find the record
            Boolean Found = AllCarRepairs.ThisCarRepair.Find(PrimaryKey);

            //Test to see if the two values are the same
            Assert.IsFalse(Found);
        }
        public void CarRepairInstanceOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();

            //Test to see if it exists
            Assert.IsNotNull(AllCarRepairs);
        }
        public void FilterByPartRequiredNoneFound()
        {
            //Create an instance of the class containing filtered results
            clsCarRepairsCollection FilteredCarRepairs = new clsCarRepairsCollection();

            //apply a blank string
            FilteredCarRepairs.FilterByPartRequired("XXXX");
            //test to see two values are the same
            Assert.AreEqual(0, FilteredCarRepairs.Count);
        }
예제 #7
0
    //fucntion for archiving repair
    void ArchiveRepair()
    {
        //create an instance
        clsCarRepairsCollection CarRepair = new clsCarRepairsCollection();

        //run CarRepairID through the Find method
        CarRepair.ThisCarRepair.Find(CarRepairID);
        //call Archive method
        CarRepair.Archive();
    }
    //Function to display records from the database
    void DisplayRepairs()
    {
        //Create instance in repair collection class
        clsCarRepairsCollection Repairs = new clsCarRepairsCollection();

        //set the datasource for the list box to the car repair list
        lstMechanicRepairs.DataSource = Repairs.CarRepairList;
        //Give each line the value of primary CarRepairID
        lstMechanicRepairs.DataValueField = "CarRepairID";
        //Show the part required field in the list
        lstMechanicRepairs.DataTextField = "PartRequired";
        //Bind the data to the list
        lstMechanicRepairs.DataBind();
    }
    void FilterRepairs()
    {
        //create an instance
        clsCarRepairsCollection CarRepair = new clsCarRepairsCollection();

        //Pass the text box value through the filter method
        CarRepair.ThisCarRepair.PartRequired = txtMechanicFilter.Text;
        CarRepair.FilterByPartRequired(CarRepair.ThisCarRepair.PartRequired);
        //set the datasource for the list boc to the car repair list
        lstMechanicRepairs.DataSource = CarRepair.CarRepairList;
        //Give each line the value of primary CarRepairID
        lstMechanicRepairs.DataValueField = "CarRepairID";
        //Show the part required field in the list
        lstMechanicRepairs.DataTextField = "PartRequired";
        //Bind the data to the list
        lstMechanicRepairs.DataBind();
    }
    void DisplayRecordData()
    {
        //set variable equal to the session number
        CarRepairID = Convert.ToInt32(Session["CarRepairID"]);
        //Create instance in repair collection class
        clsCarRepairsCollection CarRepair = new clsCarRepairsCollection();

        //run carRepairId through the find function
        CarRepair.ThisCarRepair.Find(CarRepairID);
        //assign the data from records in the database to the text boxes
        txtMechanicRepairID.Text        = CarRepair.ThisCarRepair.CarRepairID.ToString();
        txtMechanicDeadlineDate.Text    = CarRepair.ThisCarRepair.DeadlineDate.ToShortDateString();
        txtMechanicPartRequired.Text    = CarRepair.ThisCarRepair.PartRequired;
        txtMechanicPartPrice.Text       = CarRepair.ThisCarRepair.PartPrice.ToString();
        txtMechanicDaysInForRepair.Text = CarRepair.ThisCarRepair.DaysInForRepair.ToString();
        txtMechanicCarID.Text           = CarRepair.ThisCarRepair.CarID.ToString();
        txtMechanicStaffID.Text         = CarRepair.ThisCarRepair.StaffID.ToString();
    }
        public void ThisCarRepairPropertyOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();
            //create tsome test data to assign to the property
            clsCarRepairs TestCarRepair = new clsCarRepairs();

            //Set the properties of the test object
            TestCarRepair.CarRepairID     = 1;
            TestCarRepair.DaysInForRepair = 30;
            TestCarRepair.DeadlineDate    = DateTime.Now.Date;
            TestCarRepair.PartPrice       = 99.99m;
            TestCarRepair.PartRequired    = "Test part";

            //Assign the data to the property
            AllCarRepairs.ThisCarRepair = TestCarRepair;
            //Test to see if the two values are the same
            Assert.AreEqual(AllCarRepairs.ThisCarRepair, TestCarRepair);
        }
        public void UpdateMethodOK()
        {
            //Create an instance of the class
            clsCarRepairsCollection AllCarRepairs = new clsCarRepairsCollection();
            //create the item of test data
            clsCarRepairs TestItem = new clsCarRepairs();
            //Var to store the primary key
            Int32 PrimaryKey = 0;

            //Set its properties
            TestItem.DaysInForRepair = 1;
            TestItem.DeadlineDate    = DateTime.Now.Date.AddDays(9);
            TestItem.PartPrice       = 200.00m;
            TestItem.PartRequired    = "4 new tyres";

            //set this repair to the test data
            AllCarRepairs.ThisCarRepair = TestItem;
            //add the record
            PrimaryKey = AllCarRepairs.Add();
            //set the primary key of the test data
            TestItem.CarRepairID = PrimaryKey;
            //Modify the data
            TestItem.DaysInForRepair = 2;
            TestItem.DeadlineDate    = DateTime.Now.Date.AddDays(12);
            TestItem.PartPrice       = 210.00m;
            TestItem.PartRequired    = "7 new tyres";

            //set this repair to the new test data
            AllCarRepairs.ThisCarRepair = TestItem;
            //Update the record
            AllCarRepairs.Update();
            //find the record
            AllCarRepairs.ThisCarRepair.Find(PrimaryKey);
            //Test to see if the two values are the same
            Assert.AreEqual(AllCarRepairs.ThisCarRepair, TestItem);
        }