private void ShowEmployees() { EmployeeServiceClient klijent = new EmployeeServiceClient(); IEnumerable <EmployeeCon> employeeList = klijent.ReturnEmployees(); klijent.Close(); ListBox1.DisplayMemberPath = "LastName"; ListBox1.ItemsSource = null; ListBox1.ItemsSource = employeeList; }
private void ButtonRemove_Click(object sender, RoutedEventArgs e) { EmployeeServiceClient klijent = new EmployeeServiceClient(); if (ListBox1.SelectedIndex < 0) { MessageBox.Show("Select employee"); return; } EmployeeCon e2 = ListBox1.SelectedItem as EmployeeCon; MessageBoxResult mbr = MessageBox.Show("Delete employee: " + e2.ToString(), "Delete", MessageBoxButton.YesNo); if (mbr == MessageBoxResult.No) { return; } int result = klijent.DeleteEmployee(e2); klijent.Close(); if (result == 0) { ShowEmployees(); TextBoxFirstName.Clear(); TextBoxLastName.Clear(); TextBoxDateOfBirth.Clear(); MessageBox.Show("Employee deleted"); } else { MessageBox.Show("Error"); } }
static void Main(string[] args) { string filePath = Path.Combine(Environment.CurrentDirectory, "klient.jpg"); CallbackHandler callbackHandler = new CallbackHandler(); InstanceContext instanceContext = new InstanceContext(callbackHandler); EmployeeServiceClient client = new EmployeeServiceClient(instanceContext); CallbackHandler callbackHandler2 = new CallbackHandler(); InstanceContext instanceContext2 = new InstanceContext(callbackHandler2); EmployeeServiceClient client2 = new EmployeeServiceClient(instanceContext); Console.WriteLine("Klient wystartowal"); Employee witold = new Employee { id = 1, firstname = "Witold", surname = "Mormul", age = 30, salary = 3000 }; Employee marlena = new Employee { id = 2, firstname = "Marlena", surname = "Ziarkiewicz", age = 26, salary = 5000 }; client.AddEmployee(witold); client.AddEmployee(marlena); Console.WriteLine("Dostepne opcje:"); Console.WriteLine("\t1. Dodanie pracownika"); Console.WriteLine("\t2. Wyswietlenie pracownika"); Console.WriteLine("\t3. Usuniecie pracownika"); Console.WriteLine("\t4. Wyszukanie pracownika po nazwisku"); Console.WriteLine("\t5. Wyswietlenie wszystkich pracownikow"); Console.WriteLine("\t6. Wyswietlenie sumy pensji pracownikow (Callback)"); Console.WriteLine("\t7. Pobranie obrazka (nie dziala)"); Console.WriteLine("\t8. Zakonczenie dzialania"); while (true) { string decision = ""; decision = Console.ReadLine(); int caseSwitch = Int32.Parse(decision); switch (caseSwitch) { case 1: Console.WriteLine("Podaj imie pracownika"); string imie = Console.ReadLine(); Console.WriteLine("Podaj nazwisko pracownika"); string nazwisko = Console.ReadLine(); Console.WriteLine("Podaj id pracownika"); string numer = Console.ReadLine(); Console.WriteLine("Podaj wiek pracownika"); string wiek = Console.ReadLine(); Console.WriteLine("Podaj pensje pracownika"); string pensja = Console.ReadLine(); Employee newEmployee = new Employee { id = Int32.Parse(numer), firstname = imie, surname = nazwisko, age = Int32.Parse(wiek), salary = Double.Parse(pensja) }; client.AddEmployee(newEmployee); Console.WriteLine("Dodano pracownika"); Console.WriteLine(client.ToString(newEmployee)); break; case 2: Console.WriteLine("Podaj numer pracownika do wyswietlenia."); string numerPr = Console.ReadLine(); Employee showEmployee = client.GetEmployee(Int32.Parse(numerPr)); Console.WriteLine(client.ToString(showEmployee)); break; case 3: Console.WriteLine("Podaj numer pracownika do usuniecia."); string numerUs = Console.ReadLine(); Employee deleteEmployee = client.GetEmployee(Int32.Parse(numerUs)); Console.WriteLine("\n" + client.ToString(deleteEmployee)); client.DeleteEmployee(Int32.Parse(numerUs)); Console.WriteLine("Usunieto pracownika"); break; case 4: Console.WriteLine("Podaj nazwisko pracownika do wyszukania"); string nazwiskoSz = Console.ReadLine(); List <Employee> employeefind = new List <Employee>(client.FindEmployeeBySurname(nazwiskoSz)); foreach (Employee e in employeefind) { Console.WriteLine(client.ToString(e)); } break; case 5: List <Employee> allEmployees = new List <Employee>(client.GetAllEmployees()); foreach (Employee e in allEmployees) { Console.WriteLine(client.ToString(e)); } break; case 6: client2.SumaPensjiAsync(); break; case 7: Stream stream = client.GetImage("image.jpg"); ZapiszPlik(stream, filePath); break; case 8: client.Close(); Console.WriteLine("Klient zakonczyl dzialanie"); return; default: Console.WriteLine("Niepoprawny numer opcji."); break; } Console.WriteLine("Podaj jaka jest kolejna funkcja"); } }