Esempio n. 1
0
        private void sendBtn_Click(object sender, EventArgs e)
        {
            string str = sendRichBox.Text;

            if (string.IsNullOrEmpty(str.Trim('\n').Trim('\t').Trim(' ')))
            {
                sendRichBox.Text = "";
                sendRichBox.Focus();
                MessageBox.Show("发送内容不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            DateTime    dt      = DateTime.Now;
            string      style   = null;
            string      content = ChatContent.GetStringByContent(str, fontDialog.Font, colorDialog.Color, dt, ref style);
            MessageType mt      = new MessageType(GlobalClass.CurrentUser.Id, DestUser.Id, content, 1);

            TCPUtil.socketSend.Send(mt.ToJsonBytes());
            recRichBox.AppendText(dt.ToString("yyyy-MM-dd HH:mm:ss") + " " + GlobalClass.CurrentUser.Name + "(" + GlobalClass.CurrentUser.Account + ")" + "\n");
            recRichBox.SelectionFont  = fontDialog.Font;
            recRichBox.SelectionColor = colorDialog.Color;
            recRichBox.AppendText(str + "\n");
            FormatChatText();
            sendRichBox.Text = "";
            UserChatRecord ur = new UserChatRecord()
            {
                MyId    = GlobalClass.CurrentUser.Id,
                UserId  = DestUser.Id,
                Time    = dt,
                Content = str,
                Style   = style,
                Role    = 0
            };

            UserChatRecordManager.AddRecord(ur);
        }
Esempio n. 2
0
        public static void AddRecord(UserChatRecord ur)
        {
            SQLiteConnection conn = new SQLiteConnection(connStr);

            try
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "INSERT INTO UserChatRecord (myid,userid,time,content,style,role)VALUES(@myid,@userid,@time,@content,@style,@role)";
                    cmd.Parameters.AddWithValue("@myid", ur.MyId);
                    cmd.Parameters.AddWithValue("@userid", ur.UserId);
                    cmd.Parameters.AddWithValue("@time", ur.Time);
                    cmd.Parameters.AddWithValue("@content", ur.Content);
                    cmd.Parameters.AddWithValue("@style", ur.Style);
                    cmd.Parameters.AddWithValue("@role", ur.Role);
                    cmd.ExecuteNonQuery();
                    cmd.Dispose();
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogManager.LOGERROR, "AddRecord:" + ex.ToString());
            }
            finally
            {
                conn.Close();
            }
        }
Esempio n. 3
0
        public static UserChatRecord GetUserChatRecordFromReader(SQLiteDataReader reader)
        {
            UserChatRecord ur = new UserChatRecord();

            ur.MyId    = reader.GetInt32(0);
            ur.UserId  = reader.GetInt32(1);
            ur.Time    = reader.GetDateTime(2);
            ur.Content = reader.GetString(3);
            ur.Style   = reader.GetString(4);
            ur.Role    = reader.GetInt32(5);
            return(ur);
        }
Esempio n. 4
0
        public static List <UserChatRecord> GetChatRecordList(int userid, int page, int size, string content, int myid)
        {
            SQLiteConnection      conn = new SQLiteConnection(connStr);
            List <UserChatRecord> list = new List <UserChatRecord>();

            try
            {
                conn.Open();
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection  = conn;
                    cmd.CommandText = "SELECT * FROM UserChatRecord WHERE myid=@myid AND userid = @userid";
                    if (!string.IsNullOrEmpty(content))
                    {
                        cmd.CommandText += " AND content LIKE '%" + content + "%'";
                    }
                    cmd.CommandText += " ORDER BY time ASC LIMIT @page,@size";
                    cmd.Parameters.AddWithValue("@myid", myid);
                    cmd.Parameters.AddWithValue("@userid", userid);
                    cmd.Parameters.AddWithValue("@page", (page - 1) * size);
                    cmd.Parameters.AddWithValue("@size", size);
                    SQLiteDataReader reader = cmd.ExecuteReader();
                    if (reader.HasRows)
                    {
                        while (reader.Read())
                        {
                            UserChatRecord ur = GetUserChatRecordFromReader(reader);
                            list.Add(ur);
                        }
                    }
                    reader.Close();
                    cmd.Dispose();
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogManager.LOGERROR, "GetChatRecordList:" + ex.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(list);
        }
Esempio n. 5
0
        public static List <List <UserChatRecord> > GetAllRecord(int id, List <User> userList)
        {
            SQLiteConnection conn = new SQLiteConnection(connStr);
            List <List <UserChatRecord> > list = new List <List <UserChatRecord> >();

            try
            {
                conn.Open();
                foreach (User user in userList)
                {
                    List <UserChatRecord> recordList = new List <UserChatRecord>();
                    using (SQLiteCommand cmd = new SQLiteCommand())
                    {
                        cmd.Connection  = conn;
                        cmd.CommandText = "SELECT * FROM UserChatRecord WHERE myid=@myid AND userid = @userid";
                        cmd.Parameters.AddWithValue("@myid", id);
                        cmd.Parameters.AddWithValue("@userid", user.Id);
                        SQLiteDataReader reader = cmd.ExecuteReader();
                        if (reader.HasRows)
                        {
                            while (reader.Read())
                            {
                                UserChatRecord ur = GetUserChatRecordFromReader(reader);
                                recordList.Add(ur);
                            }
                        }
                        reader.Close();
                        cmd.Dispose();
                        list.Add(recordList);
                    }
                }
            }
            catch (Exception ex)
            {
                LogManager.WriteLog(LogManager.LOGERROR, "GetAllRecord:" + ex.ToString());
            }
            finally
            {
                conn.Close();
            }
            return(list);
        }
 private void FillRichBox(List <UserChatRecord> list)
 {
     foreach (UserChatRecord ur in list)
     {
         string fromWho;
         if (ur.Role == 1)
         {
             fromWho = listView.FocusedItem.Text;
         }
         else
         {
             fromWho = GlobalClass.CurrentUser.Name + "(" + GlobalClass.CurrentUser.Account + ")";
         }
         recordRichTB.AppendText(fromWho + " " + ur.Time.ToString("yyyy-MM-dd HH:mm:ss") + "\n");
         Tuple <Font, Color> tuple = UserChatRecord.GetStyle(ur.Style);
         recordRichTB.SelectionColor = tuple.Item2;
         recordRichTB.SelectionFont  = tuple.Item1;
         recordRichTB.AppendText(ur.Content + "\n");
     }
 }
Esempio n. 7
0
 public void InitChatText(List <MessageType> list)
 {
     foreach (MessageType mt in list)
     {
         string      style = null;
         ChatContent cc    = ChatContent.GetChatContentByStr(mt.Content, ref style);
         recRichBox.AppendText(cc.Time.ToString("yyyy-MM-dd HH:mm:ss") + " " + DestUser.Name + "(" + DestUser.Account + ")" + "\n");
         recRichBox.SelectionColor = cc.Color;
         recRichBox.SelectionFont  = new Font(cc.FontFamily, cc.Size, cc.FontStyle);
         recRichBox.AppendText(cc.Content + "\n");
         FormatChatText();
         UserChatRecord ur = new UserChatRecord()
         {
             MyId    = GlobalClass.CurrentUser.Id,
             UserId  = DestUser.Id,
             Time    = cc.Time,
             Content = cc.Content,
             Style   = style,
             Role    = 1
         };
         UserChatRecordManager.AddRecord(ur);
     }
 }
Esempio n. 8
0
        public void ReceiveMsg(string str)
        {
            string style = null;

            recRichBox.AppendText(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " " + DestUser.Name + "(" + DestUser.Account + ")" + "\n");
            ChatContent cc = ChatContent.GetChatContentByStr(str, ref style);

            recRichBox.SelectionColor = cc.Color;
            recRichBox.SelectionFont  = new Font(cc.FontFamily, cc.Size, cc.FontStyle);
            recRichBox.AppendText(cc.Content + "\n");
            FormatChatText();
            UserChatRecord ur = new UserChatRecord()
            {
                MyId    = GlobalClass.CurrentUser.Id,
                UserId  = DestUser.Id,
                Time    = cc.Time,
                Content = cc.Content,
                Style   = style,
                Role    = 1
            };

            UserChatRecordManager.AddRecord(ur);
        }