Ejemplo n.º 1
0
        /// <summary>
        /// 获得群信息
        /// </summary>
        /// <param name="room"></param>
        private void onOrgRooms(Room room)
        {
            exRoom exroom = new exRoom();
            exroom.RoomID = room.RoomID;
            exroom.RoomName = room.RoomName;
            exroom.Notice = room.Notice;
            exroom.UserIDs = room.UserIDs;
            exroom.CreateUserID = room.CreateUserID;
            Rooms.Add(exroom);

            if (frmOrg != null && !frmOrg.IsDisposed)
            {
                frmOrg.Times = 0;
                frmOrg.Value = this.Rooms.Count;
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 群信息更新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="Room"></param>
        private void fs_UpdateRoom(object sender,exRoom Room)
        {
            if (this.UpdateRoom != null)
                this.UpdateRoom(this, Room);

        }
Ejemplo n.º 3
0
        /// <summary>
        /// 创建或添加群成功后操作
        /// </summary>
        /// <param name="Room"></param>
        private void CreateOrAddGroup(exRoom Room)
        {
            exRoom group = findRoom(Room.RoomID);//查找群组 

            if (group == null)
            {
                group = Room;//获取群组信息

                this.Rooms.Add(group);//内存中添加群组

                TreeNode node = new TreeNode();
                node.Text = group.RoomID + "(" + group.RoomID + ")";
                node.Tag = group;
                group.TreeNode = node;
                treeView_Rooms.Nodes.Add(node);
            }
             OpeRecordDB.UpdateRooms(group);//数据库中保存群组资料
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获得群对话框
        /// </summary>
        /// <param name="room"></param>
        private FormTalkRoom GetRoomMsgForm(exRoom room)
        {
            FormTalkRoom fs = null;
            try
            {
                fs = room.Tag as FormTalkRoom;
                if (fs == null || fs.IsDisposed)
                {
                    fs = new FormTalkRoom();//发送消息对话框根据需要替换
                    room.Tag = fs;

                    ///群中创建用户对话窗口事件发生时
                    fs.CreateFormTalkUser += delegate(object sender, exUser user)
                    {
                        FormTalkUser fTalkUser = GetUserMsgForm(user);// 获得用户消息对话框
                        fTalkUser.Show();
                        fTalkUser.Activate();
                    };

                    //更新群事件发生时
                    fs.UpdateRoom += delegate(object sender, exRoom updateRoom)
                    {
                        ChangeRoom changeRoom = new ChangeRoom();
                        changeRoom.type = type.set;
                        changeRoom.RoomID = updateRoom.RoomID;
                        changeRoom.RoomName = updateRoom.RoomName;
                        changeRoom.UserIDs = updateRoom.UserIDs;
                        changeRoom.Notice = updateRoom.Notice;
                        SendMessageToServer(changeRoom);
                        //向服务器请求更新群组资料 
                    };


                    ///当在群里发送消息事件发生时
                    fs.SendMsgToGroup += delegate(IMLibrary3.Protocol.Element e, exRoom Room)
                    {
                        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; room.Tag = null; };

                    fs.Room = room;
                    fs.myUserID = MyAuth.UserID ;
                    fs.myUserName = MyAuth.UserName;
                }
            }
            catch (Exception ex)
            {
                IMLibrary3.Global.MsgShow(ex.Message);
            }
            return fs;
        }
Ejemplo n.º 5
0
        private void onChangeRoom(ChangeRoom changeRoom)
        {
            #region 创建临时群
            exRoom room = new exRoom();
            room.RoomID = changeRoom.RoomID;
            room.RoomName = changeRoom.RoomName;
            room.Notice = changeRoom.Notice;
            room.CreateUserID = changeRoom.CreateUserID;
            room.UserIDs = changeRoom.UserIDs;
            if(room.UserIDs !=null)
            foreach (string userID in  room.UserIDs.Split(';'))
            {
                User user = findUser(userID);
                if (user != null)
                    room.Users.Add(user.UserID, user);
            }
            #endregion

            exRoom exroom = findRoom(changeRoom.RoomID);//查找群是否已经存在

            if (changeRoom.CreateUserID == MyAuth.UserID)//如果是自己创建的群
            {
                if (changeRoom.type == type.New)//如果创建群成功,更新群成功
                {
                    if (this.frmCreateGroup != null && !this.frmCreateGroup.IsDisposed)//如果创建群窗口已经加载
                    {
                        this.frmCreateGroup.Room = room;
                        this.frmCreateGroup.isUpdateSuccess = true;
                    }
                    if (exroom == null)//如果群不存在,则添加群
                    {
                        this.Rooms.Add(room);
                        List<exRoom> rooms = new List<exRoom>();
                        rooms.Add(room);
                        treeViewAddRooms(rooms);
                    }
                }
                else if (changeRoom.type == type.set)//如果是自己更新群信息
                {
                    if (exroom != null)//如果群存在,则更新群信息即可
                    {
                        exroom.Notice = room.Notice;
                        exroom.UserIDs = room.UserIDs;
                        exroom.RoomName = room.RoomName;
                        exroom.Users = room.Users;
                        FormTalkRoom frmGroup = exroom.Tag as FormTalkRoom;
                        if (frmGroup != null)
                            frmGroup.Room = exroom;

                        OurMsg.FormCreateRoom frm = (exroom.FormData as FormCreateRoom);
                        if (frm != null && !frm.IsDisposed)
                        {
                            frm.Room = room;
                            frm.isUpdateSuccess = true;
                        }
                    }
                }
            }
            else//如果群信息发生改变
            {
                if (changeRoom.type == type.New || changeRoom.type == type.set)//如果加入群 
                {
                    if (exroom == null)//如果群不存在,则添加群
                    {
                        this.Rooms.Add(room);
                        List<exRoom> rooms = new List<exRoom>();
                        rooms.Add(room);
                        treeViewAddRooms(rooms);
                    }
                    else//如果群存在,则更新信息
                    {
                        exroom.Notice = room.Notice;
                        exroom.UserIDs = room.UserIDs;
                        exroom.RoomName = room.RoomName;
                        exroom.Users = room.Users;

                        FormTalkRoom frmGroup = exroom.Tag as FormTalkRoom;
                        if (frmGroup != null)
                            frmGroup.Room = exroom;
                    }
                }
                else if (changeRoom.type == type.delete)//如果退出群
                {
                    if (exroom != null)
                    {
                        Form frm = exroom.Tag as Form;
                        if (frm != null && !frm.IsDisposed)
                            frm.Close();

                        frm = exroom.FormData as Form;
                        if (frm != null && !frm.IsDisposed)
                            frm.Close();
                         
                        TreeNode node = (exroom.TreeNode as TreeNode);
                        if (node != null) node.Remove();
                         
                        this.Rooms.Remove(exroom);
                    }
                }
            }
        }
Ejemplo n.º 6
0
 /// <summary>
 /// 获得所有群
 /// </summary>
 public static List<exRoom> GetRooms()
 {
     List<exRoom> Rooms = new List<exRoom>();
     string sql = "select * from Rooms";
     System.Data.SQLite.SQLiteDataReader dr = SQLiteDBHelper.ExecuteReader(sql, null);
     if (dr != null)
     {
         while (dr.Read())
         {
             exRoom Room = new exRoom();
             {
                 Room.RoomID = Convert.ToString(dr["RoomID"]);
                 Room.RoomName = Convert.ToString(dr["RoomName"]);
                 Room.Notice = Convert.ToString(dr["Notice"]);
                 Room.UserIDs = Convert.ToString(dr["Users"]);
                 Room.OrderID = Convert.ToInt32(dr["OrderID"]);
                 Room.CreateUserID = Convert.ToString(dr["CreateUserID"]);
             }
             Rooms.Add(Room);
         }
         dr.Close();
     }
     dr.Dispose();
     return Rooms;
 }
Ejemplo n.º 7
0
        /// <summary>
        ///  添加或更新一个群信息
        /// </summary>
        /// <param name="Groups"></param>
        public static void UpdateRooms(exRoom room)
        {
            #region 单次插入数据
            string sql = "insert into Rooms(RoomID,RoomName,Users, Notice,CreateUserID) values(@RoomID,@RoomName,@Users,@Notice,@CreateUserID)";
              System.Data.SQLite.SQLiteParameter[] parameters = new System.Data.SQLite.SQLiteParameter[]{   
                     new System.Data.SQLite.SQLiteParameter("@RoomID",room.RoomID ),   
                     new System.Data.SQLite.SQLiteParameter("@RoomName",room.RoomName ),   
                     new System.Data.SQLite.SQLiteParameter("@Users",room.UserIDs),   
                     new System.Data.SQLite.SQLiteParameter("@Notice",room.Notice ),   
                     new System.Data.SQLite.SQLiteParameter("@CreateUserID",room.CreateUserID ),   
                                       };
            try
            {
                SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
            }

            catch 
            {
                try
                {
                    sql = "update Rooms set RoomName=@RoomName,Users=@Users,Notice=@Notice,CreateUserID=@CreateUserID where  RoomID=@RoomID";

                    SQLiteDBHelper.ExecuteNonQuery(sql, parameters);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Source + ex.Message);
                }
            }
            #endregion

            #region 一次性事务添加
            //SQLiteConnection con = new SQLiteConnection(); //创建连接
            //SQLiteCommand cmd = null;
            //con.ConnectionString = conStr;
            //try
            //{
            //    con.Open();
            //    using (SQLiteTransaction dbTrans = con.BeginTransaction()) //使用事务
            //    {
            //        using (cmd = con.CreateCommand())
            //        {
            //            cmd.CommandText = "insert into Groups(GroupID,GroupName,SuperiorID,orderID) values(?,?,?,?)";
            //            SQLiteParameter Field1 = cmd.CreateParameter();   //添加字段
            //            SQLiteParameter Field2 = cmd.CreateParameter();
            //            SQLiteParameter Field3 = cmd.CreateParameter();
            //            SQLiteParameter Field4 = cmd.CreateParameter();
            //            cmd.Parameters.Add(Field1);
            //            cmd.Parameters.Add(Field2);
            //            cmd.Parameters.Add(Field3);
            //            cmd.Parameters.Add(Field4);
            //            foreach (OurMsg.Organization.exGroup group in Groups)
            //            {
            //                Field1.Value = group.GroupID; //字符赋值
            //                Field2.Value = group.GroupName;
            //                Field3.Value = group.SuperiorID;
            //                Field4.Value = group.OrderID;
            //                cmd.ExecuteNonQuery();
            //            }
            //        }
            //        dbTrans.Commit();     //提交事务执行
            //    }
            //}
            //catch (Exception ex)
            //{
            //    MessageBox.Show(ex.Source + ex.Message);
            //}
            //finally
            //{
            //    con.Close();
            //}
            #endregion
        }
Ejemplo n.º 8
0
        private void butOK_Click(object sender, EventArgs e)
        {
            if (!IsCreate && myUserID  != textBoxCreateUser.Text)
            {
                this.Close();
                return;
            }

            if (this.textBoxGroupName.Text.Trim() == "")
            {
                MessageBox.Show("组名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBoxGroupName.Focus();
                return;
            } 
            this.butOK.Enabled = false;
            this.isUpdateSuccess = false;

           exRoom NewRoom = new exRoom();
            NewRoom.UserIDs = "";
            NewRoom.RoomID= this.textBoxGroupID.Text;//组编号
            NewRoom.CreateUserID = this.textBoxCreateUser.Text;//群组创建用户编号
            NewRoom.RoomName = this.textBoxGroupName.Text;//群组名称
            NewRoom.Notice = this.textBoxGroupNotice.Text;//群组通知

            foreach (ListViewItem item in this.listViewGroupUsers.Items)
                NewRoom.UserIDs += item.Text + ";";

            string newVersion = NewRoom.RoomName.Trim() + NewRoom.Notice.Trim() + NewRoom.UserIDs;

            if (newVersion == oldVersion)//如果未做修改,则退出
            {
                this.Close();
                return;
            }

            if (this.UpdateRoom != null)
                this.UpdateRoom(this, NewRoom);

            this.timer1.Enabled = true;//启动检测更新
        }
Ejemplo n.º 9
0
        private void butCreateGroup_Click(object sender, EventArgs e)
        {  
            if (this.textBoxGroupName.Text.Trim() == "")
            {
                MessageBox.Show("组名不能为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.textBoxGroupName.Focus();
                return;
            }

            this.butCreateGroup.Enabled = false;
            this.isUpdateSuccess = false;

           exRoom NewRoom = new exRoom();
            NewRoom.RoomID = this.textBoxGroupID.Text.Trim();
            NewRoom.UserIDs = "";
            NewRoom.CreateUserID = this.textBoxCreateUser.Text;//群组创建用户编号
            NewRoom.RoomName = this.textBoxGroupName.Text;//群组名称
            NewRoom.Notice = this.textBoxGroupNotice.Text;//群组通知

            foreach (ListViewItem item in this.listViewGroupUsers.Items)
                NewRoom.UserIDs += item.Text + ";";

            if (CreateRoom != null)
                CreateRoom(this, NewRoom);

            this.timer1.Enabled = true;//启动检测更新
        }