public void UpdateMethodOK()
        {
            //create an instance of the class we want to create
            clsDepartmentCollection AllDepartments = new clsDepartmentCollection();
            //create the item of test data
            clsDepartment TestDepartment = new clsDepartment();
            //var to store the primary key
            Int32 PrimaryKey = 0;

            //set its properties
            TestDepartment.Dep_Name     = "Store";
            TestDepartment.Dep_Location = "Liverpool";
            TestDepartment.No_Employees = 44;
            //set ThisAddress to the test data
            AllDepartments.ThisDepartment = TestDepartment;
            //add the record
            PrimaryKey = AllDepartments.Add();
            //set the primary key of the test data
            TestDepartment.Dep_ID = PrimaryKey;
            //modify the test data
            TestDepartment.Dep_Name     = "Stores";
            TestDepartment.Dep_Location = "Liverpool";
            TestDepartment.No_Employees = 45;
            //set the record based on the new test data
            AllDepartments.ThisDepartment = TestDepartment;
            //update the record
            AllDepartments.Update();
            //find the record
            AllDepartments.ThisDepartment.Find(PrimaryKey);
            //test to see ThisAddress matches the test data
            Assert.AreEqual(AllDepartments.ThisDepartment, TestDepartment);
        }
Exemple #2
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        clsDepartment ADepartment = new clsDepartment();


        string dep_Location = txtdep_Location.Text;
        string dep_Name     = txtdep_Name.Text;
        string no_Employees = txtno_Employee.Text;
        string Error        = "";

        Error = ADepartment.Valid(dep_Name, dep_Location, no_Employees);
        if (Error == "")
        {
            ADepartment.Dep_ID       = dep_ID;
            ADepartment.Dep_Name     = dep_Name;
            ADepartment.Dep_Location = dep_Location;
            ADepartment.No_Employees = Convert.ToInt32(no_Employees);

            clsDepartmentCollection DepartmentList = new clsDepartmentCollection();

            if (Convert.ToInt32(dep_ID) == -1)
            {
                DepartmentList.ThisDepartment = ADepartment;
                DepartmentList.Add();
            }
            else
            {
                DepartmentList.ThisDepartment.Find(Convert.ToInt32(dep_ID));
                DepartmentList.ThisDepartment = ADepartment;
                DepartmentList.Update();
            }
            Response.Redirect("DefaultDepartment.aspx");
        }
        else
        {
            lblError.Text = Error;
        }
    }