public void CreateTestPosts() { for (int i = 0; i < 10; i++) { int a = rnd.Next(0, TestTitles.Length); Post newpost = new Post(0, rnd.Next(1, 6), TestTitles[a], TestTeachers[rnd.Next(0, TestTeachers.Length)], TestTexts[a], rnd.Next(1, 31).ToString() + "." + rnd.Next(1, 12).ToString() + ".2017"); PostLine postLine = new PostLine(newpost, PostControlls[PostControlls.Count - 1] != null ? PostControlls[PostControlls.Count - 1].Location.Y + 50 : 50, this); Posts.Add(newpost); PostControlls.Add(postLine); } }
/* * * МОИ МЕТОДЫ! * */ public void GetAllPosts() { Client = new TcpClient(); try { Client.Connect(IPAddress.Parse(Ip), Port); } catch (Exception ex) { MessageBox.Show(ex.ToString()); return; } NetworkStream stream = Client.GetStream(); byte[] data = Encoding.UTF8.GetBytes("2"); stream.Write(data, 0, data.Length); Thread.Sleep(600); data = new byte[1024]; StringBuilder str = new StringBuilder(); if (stream.DataAvailable) { do { int bytes = stream.Read(data, 0, data.Length); str.Append(Encoding.UTF8.GetString(data, 0, bytes)); } while (stream.DataAvailable); } stream.Close(); Client.Close(); str.Append("&"); if (str.ToString() != "&") { StringBuilder cId = new StringBuilder(); StringBuilder cTitle = new StringBuilder(); StringBuilder cDate = new StringBuilder(); StringBuilder cImportant = new StringBuilder(); StringBuilder cText = new StringBuilder(); int counter = 0; for (int i = 1; i < str.Length; i++) { if (str[i].ToString() != "/" && str[i].ToString() != "&") { switch (counter) { case 0: cId.Append(str[i].ToString()); break; case 1: cTitle.Append(str[i].ToString()); break; case 2: cImportant.Append(str[i].ToString()); break; case 3: cDate.Append(str[i].ToString()); break; case 4: cText.Append(str[i].ToString()); break; } } else { if (str[i].ToString() == "/") { counter++; } if (str[i].ToString() == "&" || i == str.Length - 1) { counter = 0; Post newpost = new Post(0, Convert.ToInt32(cImportant.ToString()), cTitle.ToString(), "Jame James", cText.ToString(), cDate.ToString()); PostLine postLine = new PostLine(newpost, PostControlls[PostControlls.Count - 1] != null ? PostControlls[PostControlls.Count - 1].Location.Y + 50 : 50, this); Posts.Add(newpost); PostControlls.Add(postLine); cText.Clear(); cTitle.Clear(); cDate.Clear(); cImportant.Clear(); cId.Clear(); } } } } }