Exemplo n.º 1
0
        private void AddItem(Topico t)
        {
            Label usr = new Label();//el label usuario

            usr.Font     = new Font("Arial", 12, FontStyle.Bold);
            usr.Text     = "Usuario: " + t.usuario;
            usr.AutoSize = true;
            Label txt = new Label();//el label texto

            txt.Text     = t.texto;
            txt.AutoSize = true;
            PanelTopicos.Controls.Add(txt, 0, PanelTopicos.RowCount - 1);//se agregan los dos labels al panel
            PanelTopicos.Controls.Add(usr, 0, PanelTopicos.RowCount - 1);
            PanelTopicos.RowCount++;
            //PanelTopicos.Controls.Add(pa, 0, PanelTopicos.RowCount - 1);//se agrega el panel en columna1
            if (t.imagen != "")
            {
                AddImage(t.imagen.Substring(2));
            }
        }
Exemplo n.º 2
0
        private void AddItem(Topico t)
        {
            Label tlt = new Label();//el label usuario

            tlt.Font     = new Font("Arial", 12, FontStyle.Bold);
            tlt.Text     = "Titulo: " + t.titulo.Trim();
            tlt.AutoSize = true;
            tlt.Margin   = new Padding(0, 16, 0, 0);
            Label usr = new Label();//el label usuario

            usr.Font     = new Font("Arial", 7, FontStyle.Bold);
            usr.Text     = "Usuario: " + t.usuario.Trim();
            usr.AutoSize = true;
            usr.Margin   = new Padding(4, 0, 0, 0);
            Label dt = new Label();//el label usuario

            dt.Font     = new Font("Arial", 5, FontStyle.Regular);
            dt.Text     = "Usuario: " + t.fecha.Trim();
            dt.AutoSize = true;
            dt.Margin   = new Padding(4, 0, 0, 0);
            Label txt = new Label();//el label texto

            txt.Text     = t.texto.Trim();
            txt.Font     = new Font("Arial", 12, FontStyle.Regular);
            txt.Margin   = new Padding(8, 8, 8, 8);
            txt.AutoSize = true;
            PanelTopicos.Controls.Add(dt, 0, PanelTopicos.RowCount - 1);
            PanelTopicos.Controls.Add(txt, 0, PanelTopicos.RowCount - 1);//se agregan los dos labels al panel
            PanelTopicos.Controls.Add(tlt, 0, PanelTopicos.RowCount - 1);
            PanelTopicos.Controls.Add(usr, 0, PanelTopicos.RowCount - 1);
            PanelTopicos.RowCount++;
            //PanelTopicos.Controls.Add(pa, 0, PanelTopicos.RowCount - 1);//se agrega el panel en columna1
            if (t.imagen != "")
            {
                AddImage(t.imagen.Substring(2));
            }
        }
Exemplo n.º 3
0
        private void agregar_Click(object sender, EventArgs e)
        {
            string[] fecha  = DateTime.Now.Date.ToString().Split(' ');
            Topico   _2Send = new Topico();

            _2Send.usuario = userName;
            _2Send.titulo  = tituloLabel.Text;
            _2Send.fecha   = fecha[0];
            _2Send.imagen  = (sourceFile != "")? "./imagesServer/" + fecha[0].Replace('/', '_') + '/' + Path.GetFileName(sourceFile): sourceFile;
            _2Send.texto   = mensajeSend.Text;
            string JsonToSend = JsonConvert.SerializeObject(_2Send);

            Console.WriteLine(JsonToSend);

            if (_2Send.titulo == "" && _2Send.texto == "")
            {
                MessageBox.Show("Campos vacíos");
            }
            else
            {
                Console.WriteLine("Connecting.....");
                try
                {
                    TcpClient tcpclnt = new TcpClient();
                    tcpclnt.Connect(ipAd, PortNumber);
                    NetworkStream stream = tcpclnt.GetStream();
                    Byte[]        data   = System.Text.Encoding.ASCII.GetBytes("1" + topic);
                    stream.Write(data, 0, data.Length);
                    Console.WriteLine("Se envio : " + "1" + topic);

                    data = new Byte[1024];
                    Int32  bytes        = stream.Read(data, 0, data.Length);
                    string responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                    Console.WriteLine("Received: {0}", responseData);

                    data = new Byte[4096];
                    data = System.Text.Encoding.UTF8.GetBytes(JsonToSend);
                    stream.Write(data, 0, data.Length);
                    data = new Byte[1024];

                    if (sourceFile != "")
                    {
                        byte[] imgeByArr  = ReadImageFile(sourceFile);
                        int    bufferSize = 1024;

                        // Send to server
                        int bytesSent = 0;
                        int bytesLeft = imgeByArr.Length;

                        while (bytesLeft > 0)
                        {
                            int curDataSize = Math.Min(bufferSize, bytesLeft);

                            stream.Write(imgeByArr, bytesSent, curDataSize);

                            bytesSent += curDataSize;
                            bytesLeft -= curDataSize;
                        }
                        Console.WriteLine("Done sending image: " + bytesSent);
                    }
                    data         = new Byte[1024];
                    bytes        = stream.Read(data, 0, data.Length);
                    responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes);
                    Console.WriteLine("Received: {0}", responseData);
                    // Close everything.
                    data = new Byte[256];
                    data = System.Text.Encoding.ASCII.GetBytes("3Salir");
                    stream.Write(data, 0, data.Length);
                    stream.Close();
                    tcpclnt.Close();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
            getNewPost();
            _2Send.titulo = "";
            _2Send.texto  = "";
            sourceFile    = "";
        }