private void mButtonShowConversation_Click(object sender, EventArgs e)
        {
            string connectionString = @"Data Source=.;Initial Catalog=Chat;Integrated Security=True";

            using (SqlConnection conn = new SqlConnection(connectionString))
            {
                // mesaje.Clear();
                conn.Open();
                string command = "SELECT * FROM Chat";
                PullData(dataTable);

                using (SqlCommand cmdd = new SqlCommand(command, conn))
                {
                    bool check = u.ReturinVerificare();
                    if (check == true)
                    {
                        foreach (DataRow row in dataTable.Rows)
                        {
                            string nume1 = row["nume1"].ToString().Trim();
                            string nume2 = row["nume2"].ToString().Trim();
                            if (nume1 == u.getThisUser().Trim() & nume2 == u.getPersoana().Trim())
                            {
                                mesajHASH = String.Empty;
                                aoleu     = string.Empty;
                                aoleu     = row["mesaj"].ToString().Trim();
                                //  mesajHASH = Decrypt(aoleu, password);
                                richTextBox1.Text += u.getThisUser().Trim() + ":" + aoleu + "\r\n";
                            }
                            else if (nume2 == u.getThisUser().Trim() & nume1 == u.getPersoana().Trim())
                            {
                                mesajHASH = String.Empty;
                                aoleu     = string.Empty;
                                //    mesajHASH = Decrypt(row["mesaj"].ToString(), password);
                                aoleu              = row["mesaj"].ToString().Trim();
                                richTextBox1.Text += u.getPersoana().Trim() + ":" + aoleu + "\r\n";
                            }
                        }
                    }
                    else if (check == false)
                    {
                        foreach (DataRow row in dataTable.Rows)
                        {
                            string nume1 = row["nume1"].ToString().Trim();
                            string nume2 = row["nume2"].ToString().Trim();
                            if (nume1 == u.getThisUser().Trim() & nume2 == u.getUserForPChat().Trim())
                            {
                                richTextBox1.Text += u.getThisUser().Trim() + ":" + row["mesaj"].ToString() + "\r\n";
                                // mesaje.Add(pChat.getThisUser().Trim() + ":" + row["mesaj"].ToString());
                            }
                            else if (nume2 == u.getThisUser().Trim() & nume1 == u.getUserForPChat().Trim())
                            {
                                richTextBox1.Text += u.getUserForPChat().Trim() + ":" + row["mesaj"].ToString() + "\r\n";
                                //   mesaje.Add(pChat.getUserForPChat().Trim() + ":" + row["mesaj"].ToString());
                            }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        protected override void OnLoad(EventArgs e)
        {
            //    //if (formLogin.getCkeck() == true)
            //    //{

            base.OnLoad(e);

            prop = this.MyProperty;
            ala  = this.Text;
            bool check = pChat.ReturinVerificare();

            Ticker();
            //  MessageBox.Show(prop);
            //    // Client.Connected += Client_Connected;
            //    //Client.Connect(ip, 2014);
            //    //Client.Send("Connect|" + userName + "|connected");
            //    //Client.Received += _client_Received;
            //    //Client.Disconnected += Client_Disconnected;
            if (check == true)
            {
                mesajPtServer = String.Empty;
                mesajPtServer = mTextSendTextBox.Text;
                pChat.getMesajDeCriptat(mesajPtServer, prop.Trim(), pChat.getPersoana().Trim());
                pChat.formLogin.Client.Send("cheie|" + pChat.getThisUser().Trim() + "|" + pChat.getPersoana().Trim() + "|" + prop.Trim());


                // mTextBoxMessageReceived.Text += "eu" + ": " + mesajPtServer + "\r\n";
                mTextSendTextBox.Text = string.Empty;

                //tu ai fost contactat
            }
            else
            {
                mesajPtServer = String.Empty;
                mesajPtServer = mTextSendTextBox.Text;
                pChat.getMesajDeCriptat(mesajPtServer, prop.Trim(), pChat.getUserForPChat().Trim());
                pChat.formLogin.Client.Send("cheie|" + pChat.getThisUser().Trim() + "|" + pChat.getUserForPChat().Trim() + "|" + prop.Trim());


                //  mTextBoxMessageReceived.Text += "eu" + ": " + mesajPtServer + "\r\n";
                mTextSendTextBox.Text = string.Empty;

                //tu ai deschis comunicatia
            }

            // Ticker2();
            //  Ticker3();
            formLogin.Client.Received     += _client_Received;
            formLogin.Client.Disconnected += Client_Disconnected;
            // pChat.formLogin.Client.Send("publicKey|" + pChat.getThisUser().Trim() + "|" + pChat.getPersoana().Trim() + "|" + privateKey.Trim() + "|" + prop.Trim());
            // Text = "TCP Chat ";
            //  formLogin.ShowDialog();

            //    //loginForm.ShowDialog();
            //    //  }
            //    // else Application.Exit();
        }