Exemple #1
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);
        }
Exemple #2
0
        private void onUserVcard(UserVcard  card)
        {
            if (frmUserVcard != null && !frmUserVcard.IsDisposed  && card.type == type.New)
                frmUserVcard.isUpdateSuccess = true;

            exUser user = findUser(card.UserID);//查找本地用户是否存在操作用户

            if (card.type == type.New && user == null)
            {
                user = new exUser();
                user.UserID = card.UserID;
                user.GroupID = card.GroupID;
                Users.Add(user);
                addUserTreeNode(user);//将用户节点添加到树
                user.UserName = card.UserName;
                OpeRecordDB.UpdateUserVcard(card);//添加到本地数据库
            }
            else if (card.type == type.delete && user != null)
            {
                TreeNode node = user.TreeNode as TreeNode;
                if (node != null && node.Parent != null)
                {
                    if (user.ShowType != IMLibrary3.Enmu.ShowType.Offline)
                        user.Group.OnLineUserCount -= 1;

                    user.Group.UserCount -= 1;

                    node.Parent.Nodes.Remove(node);//删除用户树节点
                    Form frm = user.Tag as Form;
                    if (frm != null && !frm.IsDisposed) { frm.Close(); frm.Dispose(); }//关闭用户对话窗口
                    Users.Remove(user);//删除用户
                    OpeRecordDB.DeleteUser(card.UserID);//本地数据库中删除
                }
            }
            else if (user != null)
            {
                FormUserVcard frm = getUserVcardForm(card.UserID);
                if (frm != null && !frm.IsDisposed)
                    if (card.type != type.set)
                        frm.UserVcard = card;
                    else
                        frm.isUpdateSuccess = true;
                user.UserName = card.UserName;
                OpeRecordDB.UpdateUserVcard(card);//更新本地数据库
            }
        }
Exemple #3
0
        /// <summary>
        /// 获得用户信息
        /// </summary>
        /// <param name="user"></param>
        private void onOrgUsers(User user)
        {
            exUser exuser = new exUser();
            exuser.UserID = user.UserID;
            exuser.UserName = user.UserName;
            exuser.GroupID = user.GroupID;
            exuser.OrderID = user.OrderID;
            Users.Add(exuser);

            if (frmOrg != null && !frmOrg.IsDisposed)
            {
                frmOrg.Times = 0;
                frmOrg.Value = this.Users.Count;
            }
        }
Exemple #4
0
        /// <summary>
        /// 获得用户消息对话框
        /// </summary>
        /// <param name="user"></param>
        private FormTalkUser GetUserMsgForm(exUser user)
        {
            FormTalkUser fs = null;
            try
            {
                fs = user.Tag as FormTalkUser;
                if (fs == null || fs.IsDisposed)
                {
                    fs = new FormTalkUser(user );//发送消息对话框根据需要替换
                    user.Tag = fs;
                    fs.myUserID = MyAuth.UserID;
                    fs.myUserName = MyAuth.UserName;

                    fs.Text = "与 " + user.UserName + "(" + user.UserID + ") 对话";

                    ///消息发送事件代理
                    fs.SendMsgToUser += delegate(IMLibrary3.Protocol.Element e, IMLibrary3.Organization.User User)
                    {
                        e.from = MyAuth.UserID;
                        e.to = User.UserID; 
                        SendMessageToServer(e);

                        if (e is IMLibrary3.Protocol.Message)
                            OpeRecordDB.AddMsg(e as IMLibrary3.Protocol.Message);//将消息添加到数据库
                    };
                    fs.FormClosed += delegate(object sender, FormClosedEventArgs e)
                                    { fs.Dispose(); fs = null; user.Tag = null; };
                
                }
            }
            catch (Exception ex)
            {
                IMLibrary3.Global.MsgShow(ex.Message);
            }
            return fs;
        }
Exemple #5
0
        /// <summary>
        /// 创建用户树节点
        /// </summary>
        /// <param name="user"></param>
        private void addUserTreeNode(exUser user)
        {
            exGroup group = findGroup(user.GroupID);
            if (group != null && group.TreeNode != null)
            {
                TreeNode node = new TreeNode();
                node.Text = user.UserName;
                node.ToolTipText = user.UserName;
                node.ImageIndex = 0;
                node.SelectedImageIndex = 0;
                node.Tag = user;
                user.TreeNode = node;
                TreeNode groupNode = group.TreeNode as TreeNode;
                if (groupNode != null)
                    groupNode.Nodes.Add(node);

                user.Group = group;
                user.Group.UserCount++;
            }
        }
Exemple #6
0
        /// <summary>
        /// 显示用户资料窗口
        /// </summary>
        /// <param name="user"></param>
        public void ShowUserVcard(exUser user)
        {
            FormUserVcard frm = getUserVcardForm(user.UserID);
            if (frm == null)
            {
                frm = new FormUserVcard();
                frmUserVcards.Add(user.UserID, frm);

                if (MyAuth.isAdmin)//如果是管理员,则添加更新事件
                    frm.UpdateVcard += delegate(object sender1, UserVcard userVcard)//更新事件
                    {
                        UpdateUser(userVcard);//更新用户资料
                    };
                else//如果不是管理员,则添加刷新事件
                    frm.RefreshVcard += delegate(object sender1, UserVcard userVcard)//刷新事件
                    {
                        //向服务器请求获得用户最新资料
                        userVcard.type = type.get;
                        SendMessageToServer(userVcard);
                    };

                frm.FormClosed += delegate(object sender1, FormClosedEventArgs e1)//窗口关闭事件
                {
                    frm.Dispose();
                    frmUserVcards.Remove(user.UserID);
                };

                frm.ChanagePassword += delegate(object sender2, ChangePassword e2)//密码修改事件
                {
                    if (!frm.isAdmin && e2.OldPassword != myPassword)
                    {
                        IMLibrary3.Global.MsgShow("旧密码不正确,请重新输入");
                        return;
                    }
                    SendMessageToServer((object)e2);
                };

                UserVcard card = OpeRecordDB.GetUserVcard(user.UserID);
                if (card == null)
                {
                    card = new UserVcard();
                    card.UserID = user.UserID;
                    card.UserName = user.UserName;
                    card.GroupID = user.GroupID;
                    card.OrderID = user.OrderID;

                    //向服务器请求获得用户最新资料
                    card.type = type.get;
                    SendMessageToServer(card);
                }
                frm.UserVcard = card;
            }

            if (MyAuth.isAdmin)//如果是管理员
                frm.Text = "修改 " + user.UserName + "(" + user.UserID + ")的资料";
            else
                frm.Text = "查看 " + user.UserName + "(" + user.UserID + ")的资料";

            frm.myUserID = MyAuth.UserID;
            frm.isAdmin = MyAuth.isAdmin;
            frm.IsCreate = false;
            frm.Show();
            frm.Activate ();
        }
Exemple #7
0
        /// <summary>
        /// 收到群组对话消息
        /// </summary>
        private void OnGroupTalk(IMLibrary3.Protocol.Message Msg, exUser user)
        { 
            exRoom room = findRoom(Msg.to);//获得消息接收群
            if (room == null) return;

            FormTalkRoom fs = GetRoomMsgForm(room);
            fs.MsgToRichTextBox(Msg, false, user.UserName + "(" + user.UserID + ")");
            fs.Show();
        }
Exemple #8
0
 /// <summary>
 /// 收到用户对话消息
 /// </summary>
 private void OnUserMessage(IMLibrary3.Protocol.Message msg,exUser user)
 {
     FormTalkUser fs = GetUserMsgForm(user);
     fs.MsgToRichTextBox(msg, false);
     fs.Show();
     fs.Activate();
 }
Exemple #9
0
        /// <summary>
        /// 收到通知消息
        /// </summary>
        private void OnNoticeMsg(IMLibrary3.Protocol.Message msg,exUser user)
        {
            FormNotice fs = new FormNotice();
            fs.MsgToRichTextBox(msg, user);
            fs.Show();
          

        }
Exemple #10
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;
        }