Exemplo n.º 1
0
    protected void btnOK_Click(object sender, EventArgs e)
    {
        ClsEmployee AnEmployee = new ClsEmployee();


        string emp_Name   = txtemp_Name.Text;
        string job_Name   = txtjob_Name.Text;
        string dep_ID     = txtdep_ID.Text;
        string hire_Date  = txthire_Date.Text;
        string manager_ID = txtmanager_ID.Text;
        string salary     = txtsalary.Text;
        string check      = chkActive.Text;
        string Error      = "";

        Error = AnEmployee.Valid(emp_Name, job_Name, manager_ID, Convert.ToDateTime(hire_Date), salary, dep_ID, chkActive.Checked);
        if (Error == "")
        {
            AnEmployee.Emp_ID     = emp_ID;
            AnEmployee.Emp_Name   = emp_Name;
            AnEmployee.Job_Name   = job_Name;
            AnEmployee.Manager_ID = Convert.ToInt32(manager_ID);
            AnEmployee.Hire_Date  = Convert.ToDateTime(hire_Date);
            AnEmployee.Salary     = Convert.ToInt32(salary);
            AnEmployee.Dep_ID     = Convert.ToInt32(dep_ID);
            AnEmployee.Active     = chkActive.Checked;

            clsEmployeeCollection EmployeeList = new clsEmployeeCollection();

            if (Convert.ToInt32(emp_ID) == -1)
            {
                EmployeeList.ThisEmployee = AnEmployee;
                EmployeeList.Add();
            }
            else
            {
                EmployeeList.ThisEmployee.Find(Convert.ToInt32(emp_ID));
                EmployeeList.ThisEmployee = AnEmployee;
                EmployeeList.Update();
            }
            Response.Redirect("DefaultEmployee.aspx");
        }
        else
        {
            lblError.Text = Error;
        }
    }
Exemplo n.º 2
0
        public void UpdateMethodOK()
        {
            //create an instance of the class we want to create
            clsEmployeeCollection AllEmployees = new clsEmployeeCollection();
            //create the item of test data
            ClsEmployee TestEmployee = new ClsEmployee();
            //var to store the primary key
            Int32 PrimaryKey = 117;

            //set its properties
            TestEmployee.Emp_Name   = "Jake Wills";
            TestEmployee.Job_Name   = "Supporter";
            TestEmployee.Manager_ID = 2;
            TestEmployee.Hire_Date  = DateTime.Now.Date;
            TestEmployee.Salary     = 22000;
            TestEmployee.Dep_ID     = 3;
            TestEmployee.Active     = true;
            //set ThisAddress to the test data
            AllEmployees.ThisEmployee = TestEmployee;
            //add the record
            PrimaryKey = AllEmployees.Add();
            //set the primary key of the test data
            TestEmployee.Emp_ID = PrimaryKey;
            //modify the test data
            TestEmployee.Emp_Name   = "Jake Williams";
            TestEmployee.Job_Name   = "Supporter";
            TestEmployee.Manager_ID = 2;
            TestEmployee.Hire_Date  = DateTime.Now.Date;
            TestEmployee.Salary     = 22000;
            TestEmployee.Dep_ID     = 3;
            TestEmployee.Active     = true;
            //set the record based on the new test data
            AllEmployees.ThisEmployee = TestEmployee;
            //update the record
            AllEmployees.Update();
            //find the record
            AllEmployees.ThisEmployee.Find(PrimaryKey);
            //test to see ThisAddress matches the test data
            Assert.AreEqual(AllEmployees.ThisEmployee, TestEmployee);
        }