Ejemplo n.º 1
0
        private void DataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewCheckBoxCell dgcc = (DataGridViewCheckBoxCell)this.dataGridView2.Rows[e.RowIndex].Cells[0];
                Boolean flag = Convert.ToBoolean(dgcc.Value);
                dgcc.Value = flag == true ? false : true;
            }
            catch (Exception)
            {
            }

            if (e.RowIndex < 0)
            {
                return;
            }

            using (SqliteDbContext context = new SqliteDbContext())
            {
                richTextBox1.Clear();
                string   nickName = this.dataGridView2.Rows[e.RowIndex].Cells[0].Value as string;
                WxFriend friend   = context.WxFriends.FirstOrDefault(f => f.NickName == nickName); //仅查找一条数据
                if (friend == null)                                                                //如果没有找到
                {
                    return;
                }

                var messages = context.WxMessages //
                               .Where(m => m.WxId == friend.WxId)
                               .OrderBy(m => m.CreateTime)
                               .ToList();

                messages.ForEach(m =>
                {
                    if (m.IsSend == 1)
                    {
                        richTextBox1.SelectionAlignment = HorizontalAlignment.Right;
                        richTextBox1.SelectionColor     = Color.DimGray;
                        richTextBox1.AppendText($"{m.CreateTime}\n");
                        richTextBox1.SelectionColor = Color.Red;
                    }
                    else
                    {
                        richTextBox1.SelectionAlignment = HorizontalAlignment.Left;
                        richTextBox1.SelectionColor     = Color.DimGray;
                        richTextBox1.AppendText($"{m.CreateTime}\n");
                        richTextBox1.SelectionColor = Color.Blue;
                    }

                    richTextBox1.SelectionBackColor = Color.WhiteSmoke;
                    richTextBox1.AppendText($"{m.Content}\n\n");
                });
            }
        }
Ejemplo n.º 2
0
        private void DataGridView2_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                DataGridViewCheckBoxCell dgcc = (DataGridViewCheckBoxCell)this.dataGridView2.Rows[e.RowIndex].Cells[0];
                Boolean flag = Convert.ToBoolean(dgcc.Value);
                dgcc.Value = flag == true ? false : true;
            }
            catch (Exception)
            {
            }

            if (e.RowIndex < 0)
            {
                return;
            }

            using (SqliteDbContext context = new SqliteDbContext())
            {
                richTextBoxEx1.Clear();
                string    nickName = this.dataGridView2.Rows[e.RowIndex].Cells[0].Value as string;
                WxFriend  friend   = context.WxFriends.FirstOrDefault(f => f.NickName == nickName);//仅查找一条数据
                WxAccount account  = context.WxAccounts.FirstOrDefault(a => a.Id == 1);

                if (friend == null)//如果没有找到
                {
                    return;
                }
                if (Name == "聊天记录")
                {
                    //(treeView1.selectedNode.Name == “name1”)
                    var messages = context.WxMessages //
                                   .Where(m => m.WxId == friend.WxId)
                                   .OrderBy(m => m.CreateTime)
                                   .ToList();

                    messages.ForEach(m =>
                    {
                        if (m.IsSend == 1)
                        {
                            richTextBoxEx1.SelectionAlignment = HorizontalAlignment.Right;
                            richTextBoxEx1.SelectionColor     = Color.DimGray;
                            richTextBoxEx1.SelectionBackColor = Color.WhiteSmoke;
                            richTextBoxEx1.AppendText("(");
                            richTextBoxEx1.AppendText($"{account.NickName}");
                            richTextBoxEx1.AppendText(")");
                            richTextBoxEx1.AppendText($"{account.WxId}");
                            System.Drawing.Image img = System.Drawing.Image.FromFile(@"D:\UDisk\avator" + account.AvatarPath);
                            Bitmap bmp = new Bitmap(img, 25, 22);
                            Clipboard.SetDataObject(bmp);
                            DataFormats.Format dataFormat =
                                DataFormats.GetFormat(DataFormats.Bitmap);
                            if (richTextBoxEx1.CanPaste(dataFormat))
                            {
                                richTextBoxEx1.Paste(dataFormat);
                            }
                            richTextBoxEx1.AppendText("\n");
                            richTextBoxEx1.SelectionColor = Color.Red;
                        }
                        else
                        {
                            richTextBoxEx1.SelectionAlignment = HorizontalAlignment.Left;
                            richTextBoxEx1.SelectionColor     = Color.DimGray;
                            richTextBoxEx1.SelectionBackColor = Color.Blue;
                            System.Drawing.Image img          = System.Drawing.Image.FromFile(@"D:\UDisk\avator" + friend.AvatarPath);
                            Bitmap bmp = new Bitmap(img, 25, 22);
                            Clipboard.SetDataObject(bmp);
                            DataFormats.Format dataFormat =
                                DataFormats.GetFormat(DataFormats.Bitmap);
                            if (richTextBoxEx1.CanPaste(dataFormat))
                            {
                                richTextBoxEx1.Paste(dataFormat);
                            }
                            richTextBoxEx1.AppendText("(");
                            richTextBoxEx1.AppendText($"{friend.NickName}");
                            richTextBoxEx1.AppendText(")");
                            richTextBoxEx1.AppendText($"{m.WxId}\n");
                        }
                        //在sqlite的message表里面,有的对话的path字段含有空格,需要使用Replace进行去除
                        if (string.IsNullOrEmpty(m.Path.Replace(" ", "")))         //message是单纯的对话消息 或者 是含有url链接的消息
                        {
                            SelectUrl.print_msg_or_url(m.Content, richTextBoxEx1); //该方法在打印message内容的同时能够识别url
                            //Console.WriteLine("是对话或者链接:"+m.Content);
                        }
                        else//说明message是文件类型的消息,这时候应当能够点击链接并打开文件
                        {
                            //Console.WriteLine("文件类型:" + m.Content);
                            SelectUrl.print_file(m.Path, richTextBoxEx1);
                        }
                        richTextBoxEx1.AppendText($"{m.CreateTime}\n\n\n");
                    });
                }
                else if (Name == "朋友圈")
                {
                    var sns = context.WxSns
                              .Where(s => s.WxId == friend.WxId)
                              .OrderBy(s => s.CreateTime)
                              .ToList();

                    sns.ForEach(s =>
                    {
                        richTextBoxEx1.SelectionAlignment = HorizontalAlignment.Left;
                        richTextBoxEx1.SelectionColor     = Color.DimGray;
                        System.Drawing.Image img          = System.Drawing.Image.FromFile(@"D:\UDisk\avator" + friend.AvatarPath);
                        Bitmap bmp = new Bitmap(img, 25, 22);
                        Clipboard.SetDataObject(bmp);
                        DataFormats.Format dataFormat =
                            DataFormats.GetFormat(DataFormats.Bitmap);
                        if (richTextBoxEx1.CanPaste(dataFormat))
                        {
                            richTextBoxEx1.Paste(dataFormat);
                        }
                        richTextBoxEx1.AppendText("(");
                        richTextBoxEx1.AppendText($"{friend.NickName}");
                        richTextBoxEx1.AppendText(")");
                        richTextBoxEx1.AppendText($"{s.WxId}\n");

                        richTextBoxEx1.SelectionColor = Color.Blue;
                        richTextBoxEx1.AppendText($"{s.Content}\n");
                        richTextBoxEx1.AppendText($"{s.CreateTime}\n\n\n\n");


                        richTextBoxEx1.SelectionBackColor = Color.WhiteSmoke;
                    });
                }
            }
        }