private void UpdateEmp(EmployeeDTO emp) { TcpClient client = new TcpClient("127.0.0.1", 2020); data = Encoding.UTF8.GetBytes("UpdEmp"); using (NetworkStream stream = client.GetStream()) { stream.Write(data, 0, data.Length); XmlSerializer serializer = new XmlSerializer(emp.GetType()); serializer.Serialize(stream, emp); } client.Close(); }
private async void WorkWithServer(string dataType) { client = new TcpClient("127.0.0.1", 2020); Byte[] data = Encoding.UTF8.GetBytes(dataType); NetworkStream stream = client.GetStream(); XmlSerializer serializer; try { switch (dataType) { case "Emp": await Task.Run(() => { stream.Write(data, 0, data.Length); serializer = new XmlSerializer(typeof(List <EmployeeDTO>)); employees = (List <EmployeeDTO>)serializer.Deserialize(stream); }); break; case "Adr": await Task.Run(() => { stream.Write(data, 0, data.Length); serializer = new XmlSerializer(typeof(ObservableCollection <AddressDTO>)); addresses = (ObservableCollection <AddressDTO>)serializer.Deserialize(stream); }); break; case "Rep": await Task.Run(() => { stream.Write(data, 0, data.Length); serializer = new XmlSerializer(typeof(ObservableCollection <ReportDTO>)); reports = (ObservableCollection <ReportDTO>)serializer.Deserialize(stream); }); break; case "DelEmp": await Task.Run(() => { stream.Write(data, 0, data.Length); serializer = new XmlSerializer(emp.GetType()); serializer.Serialize(stream, emp); }); break; default: break; } lbEmploy.ItemsSource = employees; lbEmploy.Items.Refresh(); spiner.Visibility = Visibility.Hidden; } finally { client.Close(); stream.Close(); } }