示例#1
0
        // Show conversation when first pressed on the button
        private void show_conversation(object sender, EventArgs e)
        {
            msg_chat_box.Enabled = true;
            bool @checked = false;

            ready_to_send = true;
            string from_employee_number;

            from_employee_number = parse_emp_number(sender.ToString());
            #region Get Conversation
            to_conversation = ""; from_conversation = "";
            msg_id          = 0; last_id = 0;
            conversation    = new string[255, 6];
            string query = "select top 10 fromemp, fromname, toemp, toname, msg, cast(msgtime as smalldatetime) as time from d_msgtable where (fromemp = '" +
                           from_employee_number + "' and toemp = '" + this.employeenumber + "') or (toemp = '" +
                           from_employee_number + "' and fromemp = '" + this.employeenumber + "') order by msgtime desc";

            ExcoODBC       database = ExcoODBC.Instance;
            OdbcDataReader reader;
            database.Open(Database.DECADE_MARKHAM);
            reader = database.RunQuery(query);
            while (reader.Read())
            {
                conversation[msg_id, 0] = reader[0].ToString().Trim(); //from employee NUMBER
                conversation[msg_id, 1] = reader[1].ToString().Trim(); //from employee NAME
                conversation[msg_id, 2] = reader[2].ToString().Trim(); //to employee NUMBER
                conversation[msg_id, 3] = reader[3].ToString().Trim(); //to employee NAME

                // Decrypt
                Encrypter en        = new Encrypter();
                string    encrypted = reader[4].ToString().Trim();
                conversation[msg_id, 4] = en.Decrypt(encrypted);       //message

                conversation[msg_id, 5] = reader[5].ToString().Trim(); //message TIME
                if (reader[0].ToString().Trim() == from_employee_number && !@checked)
                {
                    last_id  = msg_id;
                    @checked = true;
                }
                msg_id++;
            }
            reader.Close();
            @checked = false;
            #endregion

            from_employee_name_g   = get_name(from_employee_number);
            from_employee_number_g = from_employee_number;
            groupBox1.Text         = from_employee_name_g;
            string[] wrap = new string[2];
            lastmsgrec_box.Text = "Last message recieved at: " + conversation[last_id, 5];

            if (conversation.Length > 0)
            {
                for (int i = msg_id - 1; i >= 0; i--)//for (int i = 0; i < msg_id; i++)
                {
                    if (conversation[i, 0] == from_employee_number)
                    {
                        wrap = format_conversation(conversation[i, 4]);
                        from_conversation = from_conversation + wrap[0];
                        to_conversation   = to_conversation + blank_lines(Convert.ToInt32(wrap[1]));
                    }
                    else
                    {
                        wrap              = format_conversation(conversation[i, 4]);
                        to_conversation   = to_conversation + wrap[0];
                        from_conversation = from_conversation + blank_lines(Convert.ToInt32(wrap[1]));
                    }
                }
                tobox.Clear();
                frombox.Clear();

                tobox.Text   = to_conversation;
                frombox.Text = from_conversation;
            }

            // Active/inactive toggle
            if (is_active())
            {
                active_text.Text      = "Active";
                active_text.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(10)))), ((int)(((byte)(200)))), ((int)(((byte)(10)))));
                active_text.Visible   = true;
            }
            else
            {
                active_text.Text      = "Inactive";
                active_text.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(10)))), ((int)(((byte)(10)))));
                active_text.Visible   = true;
            }
        }
示例#2
0
        // Refresh the current conversation
        private void refresh_conversation(string from_employee_number, string to_employee_number)
        {
            to_conversation = ""; from_conversation = "";
            msg_id          = 0;
            conversation    = new string[255, 6];
            string query = "select top 10 fromemp, fromname, toemp, toname, msg, cast(msgtime as smalldatetime) as time from d_msgtable where (fromemp = '" +
                           from_employee_number + "' and toemp = '" + to_employee_number + "') or (toemp = '" +
                           from_employee_number + "' and fromemp = '" + to_employee_number + "') order by msgtime desc";
            ExcoODBC       database = ExcoODBC.Instance;
            OdbcDataReader reader;

            database.Open(Database.DECADE_MARKHAM);
            reader = database.RunQuery(query);
            while (reader.Read())
            {
                conversation[msg_id, 0] = reader[0].ToString().Trim(); //from employee NUMBER
                conversation[msg_id, 1] = reader[1].ToString().Trim(); //from employee NAME
                conversation[msg_id, 2] = reader[2].ToString().Trim(); //to employee NUMBER
                conversation[msg_id, 3] = reader[3].ToString().Trim(); //to employee NAME

                // Decrypt
                Encrypter en        = new Encrypter();
                string    encrypted = reader[4].ToString().Trim();
                conversation[msg_id, 4] = en.Decrypt(encrypted);       //message

                conversation[msg_id, 5] = reader[5].ToString().Trim(); //message TIME
                msg_id++;
            }

            reader.Close();
            query    = "select firstname from d_user where employeenumber = '" + from_employee_number + "'";
            database = ExcoODBC.Instance;
            database.Open(Database.DECADE_MARKHAM);
            reader = database.RunQuery(query);
            reader.Read();
            from_employee_name_g = reader[0].ToString().Trim();;
            reader.Close();
            from_employee_number_g = from_employee_number;
            groupBox1.Text         = from_employee_name_g;
            string[] wrap = new string[2];
            lastmsgrec_box.Text = "Last message recieved at: " + conversation[last_id, 5];

            if (conversation.Length > 0)
            {
                for (int i = msg_id - 1; i >= 0; i--)
                {
                    if (conversation[i, 0] == from_employee_number)
                    {
                        wrap = format_conversation(conversation[i, 4]);
                        from_conversation = from_conversation + wrap[0];
                        to_conversation   = to_conversation + blank_lines(Convert.ToInt32(wrap[1]));
                    }
                    else
                    {
                        wrap              = format_conversation(conversation[i, 4]);
                        to_conversation   = to_conversation + wrap[0];
                        from_conversation = from_conversation + blank_lines(Convert.ToInt32(wrap[1]));
                    }
                }
                tobox.Clear();
                frombox.Clear();

                tobox.Text   = to_conversation;
                frombox.Text = from_conversation;
            }
        }
示例#3
0
        private void send_button_Click(object sender, EventArgs e)
        {
            if (to_text.Text.Length > 3)
            {
                get_email_list(to_text.Text);
                if (Email_List.Count > 0)
                {
                    string         query    = "select * from d_active where employeenumber = '" + this.current_employeenumber + "'";
                    ExcoODBC       database = ExcoODBC.Instance;
                    OdbcDataReader reader;
                    database.Open(Database.DECADE_MARKHAM);
                    reader = database.RunQuery(query);
                    try
                    {
                        reader.Read();
                        Encrypter @str         = new Encrypter();
                        string    my_email     = @str.Decrypt(reader[3].ToString().Trim());
                        string    my_pw        = @str.Decrypt(reader[4].ToString().Trim());
                        string    my_smtp      = reader[5].ToString().Trim();
                        int       my_smtp_port = Convert.ToInt32(reader[7].ToString().Trim());
                        string    my_sig       = @str.Decrypt(reader[9].ToString().Trim());
                        foreach (string email in Email_List)
                        {
                            if (email.Contains("@") && email.Contains("."))
                            {
                                mailmsg.To.Add(email);
                            }
                        }
                        reader.Close();
                        MailAddress from = new MailAddress(my_email);
                        mailmsg.From    = from;
                        mailmsg.Subject = subject_text.Text;
                        mailmsg.Body    = message_text.Text + "\r\n\r\n" + my_sig;
                        SmtpClient        client     = new SmtpClient(my_smtp, my_smtp_port);
                        NetworkCredential credential = new NetworkCredential(my_email, my_pw);
                        client.Credentials = credential;

                        bool hasSend = false;
                        while (!hasSend)
                        {
                            try
                            {
                                client.Send(mailmsg);
                                hasSend = true;
                            }
                            catch
                            {
                                hasSend = false;
                            }
                        }
                        AlertBox alert = new AlertBox("Message sent.", "");
                        alert.Show();
                        alert.HideButton();
                        Visible = false;
                        Dispose();
                        Close();
                    }
                    catch
                    {
                        reader.Close();
                    }
                }
            }
        }