コード例 #1
0
ファイル: Form1.cs プロジェクト: NellyHaglund/WCF
        private void buttonSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (!ValidateInputWhenSaveButtonIsPressed()) return;
                if (host.State == CommunicationState.Faulted)
                {
                    host = new EmployeeServiceClient();
                }

                var employee = new Employee
                {
                    EmployeeID = int.Parse(textBoxId.Text),
                    FirstName = textBoxFirstname.Text,
                    LastName = textBoxLastName.Text,
                    Title = textBoxTitle.Text,
                    Country = textBoxContry.Text
                };

                host.SaveEmployee(employee);
                MessageBox.Show("Changes Saved");
            }
            catch (FaultException<SqlException> exception)
            {
                MessageBox.Show(exception.Detail.Message);
            }
            catch (Exception exception)
            {
                MessageBox.Show(exception.Message);
            }
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: Montagu-Evans/WCF
        private void btn_Save_Click(object sender, EventArgs e)
        {
            try
            {
                if (host.State == CommunicationState.Faulted)
                {
                    host = new EmployeeServiceClient();
                }

                var saveEmployee = new Employee()
                {
                    EmployeeId = int.Parse(txtBoxForEmpId.Text),
                    FirstName = txtBox_First.Text,
                    LastName = txtBox_Last.Text,
                    Country = txtBox_Country.Text,
                    Title = txtBox_Title.Text
                };

                host.SaveEmployee(saveEmployee);
            }
            catch (FaultException<SqlException> ex)
            {
                MessageBox.Show(ex.Detail.Message);
            }
        }
コード例 #3
0
ファイル: Form1.cs プロジェクト: nihlen/WCFExercises
        private void buttonSaveEmployee_Click(object sender, EventArgs e)
        {
            try
            {
                var employee = new Employee
                {
                    Id = int.Parse(txtEmployeeId.Text),
                    Address = txtAddress.Text,
                    BirthDate = DateTime.Parse(txtBirthDate.Text),
                    City = txtCity.Text,
                    Country = txtCountry.Text,
                    Extension = txtExtension.Text,
                    FirstName = txtFirstName.Text,
                    HireDate = DateTime.Parse(txtHireDate.Text),
                    HomePhone = txtHomePhone.Text,
                    LastName = txtLastName.Text,
                    Notes = txtNotes.Text,
                    PostalCode = txtPostalCode.Text,
                    Region = txtRegion.Text,
                    ReportsTo = int.Parse(txtReportsTo.Text),
                    Title = txtTitle.Text,
                    TitleOfCourtesy = txtTitleOfCourtesy.Text
                };

                var success = client.SaveEmployee(employee);
                if (success)
                    MessageBox.Show("Updated successfully");
                else
                    MessageBox.Show("Failed to update employee");


                //var employee = new Employee { Id = int.Parse(txtEmployeeId.Text) };

                //employee.Address = txtAddress.Text;
                //employee.BirthDate = DateTime.Parse(txtBirthDate.Text);
                //employee.City = txtCity.Text;
                //employee.Country = txtCountry.Text;
                //employee.Extension = txtExtension.Text;
                //employee.FirstName = txtFirstName.Text;
                //employee.HireDate = DateTime.Parse(txtHireDate.Text);
                //employee.HomePhone = txtHomePhone.Text;
                //employee.LastName = txtLastName.Text;
                //employee.Notes = txtNotes.Text;
                //employee.PostalCode = txtPostalCode.Text;
                //employee.Region = txtRegion.Text;
                //employee.ReportsTo = int.Parse(txtReportsTo.Text);
                //employee.Extension = txtExtension.Text;
                //employee.Title = txtTitle.Text;
                //employee.TitleOfCourtesy = txtTitleOfCourtesy.Text;
            }
            catch (FaultException ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error: " + ex.Message);
            }
        }
コード例 #4
0
ファイル: Default.aspx.cs プロジェクト: Hoodie79/WCF_Labb3
        protected void Btn_add_Click(object sender, EventArgs e)
        {

            try
            {
                EmployeeService1Client client = new EmployeeService1Client();

                var myEmployee = new Employee
                {

                    EmployeeID = int.Parse(Tbx_GetEmployee.Text),
                    Address = Tbox_Address.Text,
                    LastName = Tbox_LastName.Text,
                    Notes = Tbox_Notes.Text,
                    Title = Tbox_Title.Text,
                    PostalCode = Tbox_postalcode.Text,
                    Region = Tbox_region.Text,
                    Extension = Tbx_Extension.Text,
                    FirstName = Tbx_FName.Text,
                    HomePhone = Tbx_Phone.Text,
                    City = Tbx_city.Text,
                    Country = Tbx_country.Text,
                    BirthDate = DateTime.Parse(Tbx_BDay.Text),
                    HireDate = DateTime.Parse(Tbx_hireDate.Text),
                };

                var result = client.AddNewEmployee(myEmployee);

                Lbl_result.Text = "Update ok!";
            }

            catch (FaultException ex)
            {
                Lbl_result.Text = "Fault Exception" + ex.Message;
            }

            catch (Exception)
            {
                Lbl_result.Text = "Bee Bopp Bopp! ERROR";
               
            }
         
        }