⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formrecordmsgmisg.cs

📁 kuiMsg是一款用.net C# 开发的即时消息开源软件,适合.net即时消息软件开发者用。 主要功能: 支持文件传输(p2p); 支持GIF动画表情( 彻底消除闪屏 :) );
💻 CS
📖 第 1 页 / 共 2 页
字号:
                    sql = "select * from [" + DBtable + "] where ID in(select top " + this.pageSize.ToString() + " ID from [" + DBtable + "] where " + Qualification + "  ORDER BY ID DESC";
            }

            this.ButLast.Enabled = true;
            this.ButDown.Enabled = true;
            this.ButFirst.Enabled = true;
            this.ButUp.Enabled = true;
            this.ButDelRecord.Enabled = true;

            this.menuItemEditFirst.Enabled = true;
            this.menuItemEditFUp.Enabled = true;
            this.menuItemEditDown.Enabled = true;
            this.menuItemEditLast.Enabled = true;
            this.menuItemEditDelRecord.Enabled = true;

            if (this.CurrPage == this.PageCount)
            {
                this.ButLast.Enabled = false;
                this.ButDown.Enabled = false;
                this.menuItemEditDown.Enabled = false;
                this.menuItemEditLast.Enabled = false;

            }
            if (this.CurrPage == 1)
            {
                this.ButFirst.Enabled = false;
                this.ButUp.Enabled = false;
                this.menuItemEditFirst.Enabled = false;
                this.menuItemEditFUp.Enabled = false;
            }


            System.Data.OleDb.OleDbDataReader dr = IMLibrary.OleDb.DataAccess.ExSQLReDr(sql);

            UserInfo  sendUserInfo = FormAccess.selfInfo;

            int i = 0;
            bool IsSend = false;//标识此消息是否是对方发送的

            if (dr != null)
            {
                while (dr.Read())
                {
                    if (i == 0)
                        this.firstID = Convert.ToInt32(dr["ID"]);
                    i++;

                    IsSend = false;//标识此消息否是对方发送的

                    sendUserInfo = null;
                    IMLibrary.MyExtRichTextBox rich = new MyExtRichTextBox();
                    rich.ForeColor = Color.Blue;

                    sendUserInfo = FormAccess.findUser(Convert.ToString(dr["sendID"]).Trim()  );

                    if (sendUserInfo != null && sendUserInfo.UserID  == userID)
                    {
                        rich.ForeColor = Color.Red;
                        IsSend = true;//此消息为对方发送的
                    }

                    rich.AppendText(sendUserInfo.userName  + "(" + sendUserInfo.UserID  + ")" + Convert.ToString(dr["msgDateTime"]));
                    this.RTBRecord.AppendRtf(rich.Rtf);
                    rich.Clear();
                    rich.Dispose();

                    this.RTBRecord.AppendTextAsRtf("    ");

                    if (IsNotNotice)
                        textMsgToRich(Convert.ToString(dr["msgContent"]), Convert.ToString(dr["imageInfo"]), IsSend);
                    else
                        this.RTBRecord.AppendText(Convert.ToString(dr["msgContent"]) + "\n");


                    LastID = Convert.ToInt32(dr["ID"]);
                }
                dr.Close();
            }
            this.StatusLabelPage.Text = "第" + this.CurrPage.ToString() + "页(共" + this.PageCount.ToString() + "页)";

        }

        private void textMsgToRich(string msgContent, string ImageInfo, bool IsSend)//添加文本消息与图片到richBox
        {
      
            if ( ImageInfo != "")//如果消息中有图片,则添加图片
            {
                string[] imagePos =  ImageInfo.Split('|');
                int addPos = 0;//
                int currPos = 0;//当前正要添加的文本位置
                int textPos = 0;
                for (int i = 0; i < imagePos.Length - 1; i++)
                {
                    string[] imageContent = imagePos[i].Split(',');//获得图片所在的位置、图片名称、图片宽、高

                    currPos = Convert.ToInt32(imageContent[0]);

                    this.RTBRecord.AppendText(msgContent.Substring(textPos, currPos - addPos));
                    this.RTBRecord.SelectionStart = this.RTBRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos += currPos - addPos;
                    System.Drawing.Image image = (System.Drawing.Image)FormAccess.resourceManager.GetObject("ErrorImage"); 

                    IMLibrary.MyPicture pic = new MyPicture();
                    pic.BackColor = this.RTBRecord.BackColor;
                    pic.SizeMode = System.Windows.Forms.PictureBoxSizeMode.AutoSize; 
                    if (Convert.ToUInt32(imageContent[1]) < 96)
                        image = (System.Drawing.Image)FormAccess.resourceManager.GetObject("_" + imageContent[1]);
                    else
                    {
                        if (IsSend && new System.IO.FileInfo(Application.StartupPath + "\\ArrivalImage\\" + imageContent[1] + ".gif").Exists)
                            image = System.Drawing.Image.FromFile(Application.StartupPath + "\\ArrivalImage\\" + imageContent[1] + ".gif");
                        else if (!IsSend && new System.IO.FileInfo(Application.StartupPath + "\\sendImage\\" + imageContent[1] + ".gif").Exists)
                            image = System.Drawing.Image.FromFile(Application.StartupPath + "\\sendImage\\" + imageContent[1] + ".gif");
                    }

                    this.RTBRecord.InsertImage(image);

                    addPos++;
                }
                this.RTBRecord.AppendText(msgContent.Substring(textPos, msgContent.Length - textPos) + "\n");
            }
            else//如果消息中没有图片,则直接添加消息文本
            {
                this.RTBRecord.AppendText(msgContent + "\n");
            }
        }

        #region 工具栏单击事件 

        private void toolStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            bool t = false;
            //if (this.treeViewGroup.Nodes[1].IsSelected)t = false;

            switch (e.ClickedItem.ToolTipText)
            {
                case "第一页":
                    DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, true, false);
                    break;
                case "上一页":
                    DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, false, false);
                    break;
                case "下一页":
                    DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, true, false, false);
                    break;
                case "最后一页":
                    DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, false, true);
                    break;
                case "关闭":
                    this.Dispose();
                    break;
                case "删除记录":
                    delRecord(t);
                    break;
            }
        }
        #endregion

        #region 删除记录
        /// <summary>
        /// 删除记录
        /// </summary>
        /// <param name="IsNotNotice"></param>
        private void delRecord(bool IsNotNotice)
        {
            if (MessageBox.Show("确定要删除当前的所有对话记录吗?", "提示", System.Windows.Forms.MessageBoxButtons.YesNoCancel, System.Windows.Forms.MessageBoxIcon.Question) != System.Windows.Forms.DialogResult.Yes) return;
            string DBtable = "Notice";
            if (IsNotNotice)
            {
                DBtable = "MsgRecord";
            }
            string sql = "delete * from [" + DBtable + "] where (sendID='" + this.CurrUser + "' or ReceiveID='" + this.CurrUser + "')";
            IMLibrary.OleDb.DataAccess.ExSQL(sql);
            this.RTBRecord.Clear();
            this.ButDelRecord.Enabled = false;
        }
        #endregion

        private void menuItemEditFirst_Click(object sender, EventArgs e)
        {
            bool t = true;
            //if (this.TV_user.Nodes[1].IsSelected) t = false;

            DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, true, false);

        }

        private void menuItemEditFUp_Click(object sender, EventArgs e)
        {
            bool t = true;
           // if (this.TV_user.Nodes[1].IsSelected) t = false;

            DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, false, false);

        }

        private void menuItemEditDown_Click(object sender, EventArgs e)
        {
            bool t = true;
            //if (this.TV_user.Nodes[1].IsSelected) t = false;

            DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, true, false, false);
        }

        private void menuItemEditLast_Click(object sender, EventArgs e)
        {
            bool t = true;
            //if (this.TV_user.Nodes[1].IsSelected) t = false;

            DBRecordToRichTextBox(this.CurrUser, FormAccess.selfInfo.UserID, t, false, false, true);
        }

        private void contextMenuStrip_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            switch (e.ClickedItem.Name)
            {
                case "MenuItemCopy":
                    this.RTBRecord.Copy();
                    break;
                case "MenuItemPaset":
                    this.RTBRecord.Paste();
                    break;
                case "MenuItemCut":
                    this.RTBRecord.Cut();
                    break;
                case "MenuItemDel":
                    this.RTBRecord.SelectedText = "";
                    break;
                case "MenuItemSelAll":
                    this.Focus();
                    this.RTBRecord.SelectAll();
                    break;
            }
        }


    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -