Пример #1
0
        /// <summary>
        /// 当用户状态发生更改时,更改图标
        /// </summary>
        /// <param name="sender"></param>
        private void user_UserShowTypeChanged(object sender)
        {
            exUser user = sender as exUser;

            if (user != null)
            {
                foreach (ListViewItem item in listView1.Items)
                {
                    if ((item.Tag as exUser).UserID == user.UserID)
                    {
                        if ((item.Tag as exUser).ShowType >= IMLibrary3.Enmu.ShowType.Invisible)
                        {
                            item.ImageIndex = 0;
                        }
                        else
                        {
                            item.ImageIndex = 1;
                        }

                        listView1.Refresh();
                        SetGroupCount();
                        return;
                    }
                }
            }
        }
Пример #2
0
 private void listView1_MouseDoubleClick(object sender, MouseEventArgs e)
 {
     if (listView1.SelectedItems.Count > 0 && listView1.SelectedItems[0].Tag is exUser)
     {
         exUser user = listView1.SelectedItems[0].Tag as exUser;
         if (CreateFormTalkUser != null)
         {
             CreateFormTalkUser(this, user);
         }
     }
 }
Пример #3
0
 private void butOK_Click(object sender, EventArgs e)
 {
     foreach (ListViewItem item in listView1.Items)
     {
         exUser user = item.Tag as exUser;
         if (user != null)
         {
             Users.Add(user);
         }
     }
     this.Close();
 }
Пример #4
0
        private void treeView_Organization_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
        {
            if (e.Node.Tag is exUser)
            {
                foreach (ListViewItem tempItem in listView1.Items)
                {
                    if (tempItem.Tag == e.Node.Tag)
                    {
                        return;
                    }
                }
                exUser user = e.Node.Tag as  exUser;

                ListViewItem item = new ListViewItem(user.UserName + "(" + user.UserID + ")");
                item.ImageIndex = 0;
                item.Tag        = e.Node.Tag;
                listView1.Items.Add(item);
                setSelUsersCount();
            }
        }
Пример #5
0
        /// <summary>
        /// 树图节点选中后事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void treeView_Organization_AfterSelect(object sender, TreeViewEventArgs e)
        {
            this.txtRecord.Clear();

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

            this.PageCount = 0;
            this.CurrPage  = 0;

            if (e.Node.Tag is exUser)
            {
                exUser user = e.Node.Tag as exUser;
                this.SelectUserID = user.UserID;
                this.MessageType  = IMLibrary3.Enmu.MessageType.User;
            }
            else if (e.Node.Tag is exRoom)
            {
                exRoom room = e.Node.Tag as exRoom;
                this.SelectUserID = room.RoomID;
                this.MessageType  = IMLibrary3.Enmu.MessageType.Group;
            }
            else if (e.Node.ImageIndex == 17)
            {
                this.MessageType = IMLibrary3.Enmu.MessageType.Notice;
            }

            this.PageCount = GetPageCount(this.SelectUserID);
            if (this.PageCount > 0)
            {
                DBRecordToRichTextBox(1);
            }

            this.TextBoxPage.Text = this.CurrPage.ToString() + "/" + this.PageCount.ToString();
        }
Пример #6
0
        /// <summary>
        /// 获得所有用户集合
        /// </summary>
        public static List <exUser> GetUsers()
        {
            List <exUser> Users = new List <exUser>();
            string        sql   = "select * from Users order by orderID";

            System.Data.SQLite.SQLiteDataReader dr = SQLiteDBHelper.ExecuteReader(sql, null);
            if (dr != null)
            {
                while (dr.Read())
                {
                    exUser user = new exUser();
                    {
                        user.UserID   = Convert.ToString(dr["UserID"]);
                        user.UserName = Convert.ToString(dr["UserName"]);
                        user.GroupID  = Convert.ToString(dr["GroupID"]);
                        user.OrderID  = Convert.ToInt32(dr["OrderID"]);
                    }
                    Users.Add(user);
                }
                dr.Close();
            }
            dr.Dispose();
            return(Users);
        }
Пример #7
0
        /// <summary>
        /// 将用户对话消息加入 RichTextBox 控件
        /// </summary>
        /// <param name="msg">消息类</param>
        /// <param name="IsSend">标记是发送消息还是收到消息</param>
        public void MsgToRichTextBox(IMLibrary3.Protocol.Message msg, exUser user) //将发送的消息加入历史rich
        {
            int iniPos = txtRecord.TextLength;                                     //获得当前记录richBox中最后的位置

            if (msg.Title != "")
            {
                #region 添加标题
                txtRecord.AppendText(msg.Title);
                txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
                txtRecord.SelectionFont      = new Font("宋体", 18);
                txtRecord.SelectionColor     = msg.Color;
                txtRecord.SelectionAlignment = HorizontalAlignment.Center;
                txtRecord.AppendText("\n\n");
                #endregion
            }

            #region 添加内容
            iniPos = txtRecord.TextLength; //获得当前记录richBox中最后的位置

            #region                        //如果消息中有图片,则添加图片
            if (msg.ImageInfo != "")       //如果消息中有图片,则添加图片
            {
                string[] imagePos = msg.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.txtRecord.AppendText(msg.Content.Substring(textPos, currPos - addPos));
                    this.txtRecord.SelectionStart = this.txtRecord.TextLength;

                    textPos += currPos - addPos;
                    addPos  += currPos - addPos;

                    Image image;

                    if (this.txtRecord.GetPicture(imageContent[1]) == null)
                    {
                        image = System.Drawing.Image.FromFile(Application.StartupPath + @"\face\" + imageContent[1] + ".gif");
                    }
                    else
                    {
                        image = this.txtRecord.GetPicture(imageContent[1]).Image;
                    }

                    this.txtRecord.addGifControl(imageContent[1], image);
                    addPos++;
                }
                this.txtRecord.AppendText(msg.Content.Substring(textPos, msg.Content.Length - textPos) + "  \n");
            }
            #endregion
            #region  //如果消息中没有图片,则直接添加消息文本
            else//如果消息中没有图片,则直接添加消息文本
            {
                txtRecord.AppendText(msg.Content + "\n");
            }
            #endregion
            txtRecord.Select(iniPos, this.txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont      = msg.Font;
            txtRecord.SelectionColor     = msg.Color;
            txtRecord.SelectionAlignment = HorizontalAlignment.Left;
            #endregion

            if (msg.remark != "")
            {
                #region 添加落款
                iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置
                txtRecord.AppendText("\n" + msg.remark);
                txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
                txtRecord.SelectionFont      = new Font("宋体", 13);
                txtRecord.SelectionColor     = msg.Color;
                txtRecord.SelectionAlignment = HorizontalAlignment.Right;
                txtRecord.AppendText("\n  ");
                #endregion
            }


            iniPos = txtRecord.TextLength;//获得当前记录richBox中最后的位置
            txtRecord.AppendText("\n发送用户:" + user.UserName + "(" + user.UserID + ")\n");
            txtRecord.AppendText("发送时间:" + System.DateTime.Now.ToString() + "\n");
            txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
            txtRecord.SelectionFont      = txtRecord.Font;
            txtRecord.SelectionAlignment = HorizontalAlignment.Left;

            txtRecord.Select(this.txtRecord.TextLength, 0);
        }
Пример #8
0
        private void DBRecordToRichTextBox(int Page)
        {
            if (Page > PageCount)
            {
                return;                  //如果页数超过当前页数,则退出
            }
            if (Page <= 0)
            {
                return;           //如果页数为负数,则退出
            }
            this.txtRecord.Clear();
            this.CurrPage = Page;

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


            if (Page == this.PageCount)
            {
                this.ButLast.Enabled = false;
                this.ButDown.Enabled = false;
            }
            if (Page == 1)
            {
                this.ButFirst.Enabled = false;
                this.ButUp.Enabled    = false;
            }
            this.TextBoxPage.Text = Page.ToString() + "/" + this.PageCount.ToString();

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

            #region sql表达式
            string sql = "";
            switch (this.MessageType)
            {
            case IMLibrary3.Enmu.MessageType.User:
                sql = string.Format("select *  from [MsgRecord] where ((froms='{0}' and tos='{1}') or (froms='{1}' and tos='{0}')) And MessageType={2}  ORDER BY DateTime DESC limit " + (Page - 1) * pageSize + "," + pageSize, SelectUserID, myUserID, (byte)this.MessageType);
                break;

            case IMLibrary3.Enmu.MessageType.Group:
                sql = string.Format("select *  from [MsgRecord] where tos='{0}' and MessageType={1} ORDER BY DateTime DESC limit " + (Page - 1) * pageSize + "," + pageSize, SelectUserID, (byte)this.MessageType);
                break;

            case IMLibrary3.Enmu.MessageType.Notice:
                sql = string.Format("select *  from [MsgRecord] where MessageType={0} ORDER BY DateTime DESC limit " + (Page - 1) * pageSize + "," + pageSize, (byte)this.MessageType);
                break;
            }
            #endregion

            try
            {
                SQLiteDataReader dr = SQLiteDBHelper.ExecuteReader(sql, null);
                if (dr == null)
                {
                    return;
                }
                while (dr.Read())
                {
                    IsSend = false;//标识此消息否是对方发送的

                    #region 获得消息类
                    Msg = OpeRecordDB.GetDrMsg(dr);
                    if (Msg == null)
                    {
                        continue;
                    }
                    #endregion

                    exUser sendUserInfo = findUser(Msg.from, Users);
                    if (sendUserInfo == null)
                    {
                        return;
                    }

                    if (sendUserInfo.UserID == this.myUserID)//此消息为对方发送的
                    {
                        IsSend = true;
                    }

                    int    iniPos     = txtRecord.TextLength;//获得当前记录richBox中最后的位置
                    string title      = sendUserInfo.UserName + "(" + sendUserInfo.UserID + ")" + Msg.DateTime;
                    Color  titleColor = Color.Red;
                    if (!IsSend)//如果是收到消息
                    {
                        titleColor = Color.Blue;
                    }

                    txtRecord.AppendText(title);
                    txtRecord.Select(iniPos, txtRecord.TextLength - iniPos);
                    txtRecord.SelectionFont  = new Font("宋体", 10);
                    txtRecord.SelectionColor = titleColor;
                    txtRecord.AppendText("\n  ");

                    textMsgToRich(Msg, IsSend);
                }
                dr.Close(); dr.Dispose();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Source + ex.Message);
            }
        }