コード例 #1
0
 public static bool LoadClients()
 {
     try
     {
         ClientsList.Clear();
         using (var sr = new StreamReader(FilePath))
         {
             var deSerializer  = new XmlSerializer(typeof(ObservableCollection <Client>));
             var tmpCollection =
                 (ObservableCollection <Client>)deSerializer.Deserialize(sr);
             foreach (var item in tmpCollection)
             {
                 ClientsList.Add(item);
             }
             return(true);
         }
     }
     catch (Exception ex)
     {
         if (ex is FileNotFoundException)
         {
             var sw = new StreamWriter(FilePath);
         }
         MessageBox.Show(ex.Message);
         return(false);
     }
 }
コード例 #2
0
        public void FindClientFunc(object obj)
        {
            try
            {
                if (_searchText != "")
                {
                    string task;
                    if (radio2 == true)
                    {
                        task = $"findClientByProject#{_searchText}";
                    }
                    else
                    {
                        task = $"findClientByClient#{_searchText}";
                    }

                    client = new TcpClient();
                    client.Connect(ep);

                    NetworkStream ns = client.GetStream();
                    StreamWriter  sw = new StreamWriter(ns);
                    sw.WriteLine(task);
                    sw.Flush();


                    byte[] data  = new byte[50000];
                    int    bytes = ns.Read(data, 0, data.Length);
                    ObservableCollection <ClassesLibaryBilling.Client> cl = new ObservableCollection <ClassesLibaryBilling.Client>();
                    cl = FromByteArray <ObservableCollection <ClassesLibaryBilling.Client> >(data);
                    ClientsList.Clear();

                    foreach (var item in cl)
                    {
                        ClientsList.Add(item);
                    }

                    sw.Close();
                    ns.Close();
                    client.Close();
                }
                else
                {
                    MessageBox.Show("Введите текст для поиска");
                }
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }
コード例 #3
0
        public void LoadClients()
        {
            try
            {
                ClientsList.Clear();

                string task = "loadClients";

                client = new TcpClient();
                client.Connect(ep);

                NetworkStream ns = client.GetStream();
                StreamWriter  sw = new StreamWriter(ns);
                sw.WriteLine(task);
                sw.Flush();

                byte[] data  = new byte[50000];
                int    bytes = ns.Read(data, 0, data.Length);
                ObservableCollection <ClassesLibaryBilling.Client> cl = new ObservableCollection <ClassesLibaryBilling.Client>();
                cl = FromByteArray <ObservableCollection <ClassesLibaryBilling.Client> >(data);


                foreach (var item in cl)
                {
                    ClientsList.Add(item);
                }

                sw.Close();
                ns.Close();
                client.Close();
            }

            catch (Exception)
            {
                MessageBox.Show("Сервер выключен либо отсутствует соидинение с интеренетом");
            }
        }