コード例 #1
0
        protected void btnGetEmployee_Click(object sender, EventArgs e)
        {
            var empRequest = new EmployeeServiceReference.EmployeeRequest("AXG120ABC", Convert.ToInt32(txtId.Text));

            EmployeeServiceReference.EmployeeInfo empinfo = null;

            var client = new EmployeeServiceReference.EmployeeServiceClient();

            try
            {
                empinfo = client.GetEmployee(empRequest);
            }
            catch (FaultException fultException)
            {
                lblmsg.ForeColor = Color.Red;
                lblmsg.Text      = fultException.Message;
                return;
            }



            if (empinfo != null)
            {
                txtName.Text   = empinfo.Name;
                txtGender.Text = empinfo.Gender;
                txtDoB.Text    = empinfo.DOB.ToShortDateString();


                ddlEmpType.SelectedValue = ((int)empinfo.Type).ToString();

                SetFieldsVisible(empinfo.Type);

                txtAnualSal.Text    = string.Empty;
                txtHourlyPay.Text   = string.Empty;
                txtHoursWorked.Text = string.Empty;

                if (empinfo.Type == EmployeeServiceReference.EmployeeType.EmployeeFullTime)
                {
                    txtAnualSal.Text = empinfo.AnnualSalary.ToString();
                }
                else
                {
                    txtHourlyPay.Text   = empinfo.HourlyPay.ToString();
                    txtHoursWorked.Text = empinfo.HoursWorked.ToString();
                }

                lblmsg.ForeColor = Color.Green;
                lblmsg.Text      = "Employee retrieved";
            }
            else
            {
                lblmsg.ForeColor = Color.Red;
                lblmsg.Text      = "Employee Not Found";
            }
        }
コード例 #2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            EmployeeType empType = ddlEmpType.SelectedValue.ToEmployeeType();

            var empInfo = new EmployeeServiceReference.EmployeeInfo()
            {
                Id     = Convert.ToInt32(txtId.Text),
                Name   = txtName.Text,
                Gender = txtGender.Text,
                DOB    = Convert.ToDateTime(txtDoB.Text),
                Type   = empType
            };


            if (empType == EmployeeType.EmployeeFullTime)
            {
                empInfo.AnnualSalary = Convert.ToDecimal(txtAnualSal.Text);
            }
            else if (empType == EmployeeType.EmployeePartTime)
            {
                empInfo.HourlyPay   = Convert.ToDecimal(txtHourlyPay.Text);
                empInfo.HoursWorked = Convert.ToInt32(txtHoursWorked.Text);
            }
            else
            {
                lblmsg.ForeColor = Color.Red;
                lblmsg.Text      = "Please Select Employee Type";
                return;
            }

            var client = new EmployeeServiceReference.EmployeeServiceClient();

            client.SaveEmployee(empInfo);

            lblmsg.ForeColor = Color.Green;
            lblmsg.Text      = "Employee Saved";
        }