Example #1
0
        private void readmessages()
        {
            MessageRead.Clear();
            MessageRead.ScrollToCaret();
            string Read_Query = "select * from comments where Sender_ID = '" + sendertext + "' and Reciver_ID = '" + recivertext + "' or Sender_ID = '" + recivertext + "' and Reciver_ID = '" + sendertext + "' ";

            connection.Open();
            MySqlCommand    cmd = new MySqlCommand(Read_Query, connection);
            MySqlDataReader dr  = cmd.ExecuteReader();


            DateTime today = DateTime.Now;


            string text;

            while (dr.Read())
            {
                DateTime date_sent = (DateTime)dr["Date_sent"];
                MessageRead.Text += date_sent.ToString("dddd HH:mm");
                MessageRead.Text += ": ";
                MessageRead.Text += dr["Sender_ID"].ToString();
                MessageRead.Text += ": ";
                if (dr["Important"].ToString() == "1")
                {
                    MessageRead.Text += "<<<IMPORTANT>>>";
                }
                string message = dr["message"].ToString();



                using (Aes myAes = Aes.Create())
                {
                    text = SendClass.Decrypt(message);
                }

                MessageRead.Text += text.ToString();

                if (dr["Important"].ToString() == "1")
                {
                    MessageRead.Text += "<<<IMPORTANT>>>";
                }
                MessageRead.Text += (Environment.NewLine);
            }

            connection.Close();
        }
Example #2
0
        private void Send_button_Click(object sender, EventArgs e)
        {
            DateTime today    = DateTime.Now;
            int      checkbox = 0;
            string   encrypted_message;
            string   message = textBox1.Text;

            using (Aes myAes = Aes.Create())
            {
                encrypted_message = SendClass.Encrypt(message);
            }


            string strtoday = today.ToString("yyyy-MM-dd HH:mm:ss tt");

            if (FlagBox.Checked)
            {
                checkbox = 1;
            }

            if (string.IsNullOrEmpty(this.textBox1.Text))
            {
                MessageBox.Show("Can't send nothing!");
            }


            else
            {
                connection.Open();
                MySqlCommand comm = connection.CreateCommand();
                comm.CommandText = "INSERT INTO comments(Sender_ID,Reciver_ID, Message,Important ,Date_sent) VALUES(?sendertext, ?recivertext, ?encrypted_message, ?checkbox, ?date)";
                comm.Parameters.AddWithValue("?sendertext", sendertext);
                comm.Parameters.AddWithValue("?recivertext", recivertext);
                comm.Parameters.AddWithValue("?encrypted_message", encrypted_message);

                comm.Parameters.AddWithValue("?checkbox", checkbox);
                comm.Parameters.AddWithValue("?date", strtoday);
                comm.ExecuteNonQuery();

                connection.Close();
            }

            FlagBox.Checked = false;
            textBox1.Clear();
            readmessages();
        }