Example #1
0
        /// <summary>
        /// 取得可能成为管理员的BBS用户
        /// </summary>
        /// <param name="id">BBS ID</param>
        /// <returns></returns>
        public List<CQGJ.passport.User> GetPotentialAdminByBBSID(int id)
        {
            BBSInfo BBSInformation = new BBSInfo();

            // 定义User,用于将班级学员转化为User对象
            List<CQGJ.passport.User> users = new List<CQGJ.passport.User>();

            try
            {
                // 获取BBS相关信息
                BBSInformation.BBS = (from bbs in CQGJ.BBS where bbs.BBSID == id select bbs).First();

                // 获取BBS当前管理员ID
                int BBSOwnerID = (int)(from b in CQGJ.BBS where b.BBSID == id select b.OwnerID).First();

                // 根据BBS当前管理员ID获取他在Passport数据库User表中的ID
                int PassportUserID = ToPassportUserID(BBSOwnerID);
                passport.CQGJPassport cqgjp = new CQGJ.passport.CQGJPassport();

                // 从Passport数据库中获取用户对象
                CQGJ.passport.User admin = cqgjp.GetCQGJUser(PassportUserID);

                // 获取该班级的所有学员, i 为该BBS对应班级的ID
                // (注意要另行定义int i,
                // 不能直接写成List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value select s.User.UserID).ToList();)
                // 否则会报错,原因未知
                int i = (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value;
                List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == i select s.User.UserID).ToList();

                // 将当前管理员添加到users对象中,作为潜在的管理员
                users.Add(admin);

                // 将班级学员添加到users对象中,作为潜在的管理员
                foreach (var studentId in sid)
                {
                    passport.CQGJPassport cqgjp2 = new CQGJ.passport.CQGJPassport();

                    int passportUserID = ToPassportUserID(studentId);

                    CQGJ.passport.User student = cqgjp2.GetCQGJUser(passportUserID);

                    // 判断当然管理是否是该班级,如果不是则添加,如果是就不添加
                    if (student.UserID != admin.UserID)
                    {
                        users.Add(student);

                    }

                }

            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }

            return users;
        }
Example #2
0
        /// <summary>
        /// 上传图标2
        /// </summary>
        public void IconUploadForBBSManagement2(int id)
        {
            // 获取上传的图片文件
            HttpPostedFile iconFile = HttpContext.Request.Files[0];

            // 定义图片路径
            string imgUrl = "";

            // 判断是否上传了图片
            if (!iconFile.FileName.Equals("") && iconFile.FileName != null)     // 上传图片
            {
                string strRelatePath = "/Content/UploadFiles/BBSFiles/Icon";
                string strAbsolutePath = this.HttpContext.Request.MapPath(@"../.." + strRelatePath);

                string fileName = FileUpload.SaveFile(iconFile, strAbsolutePath);

                imgUrl = strRelatePath + "/" + fileName;
            }
            else// 未上传图片
            {
                imgUrl = GetString("imgUrl");
            }

            // 定义临时BBS信息
            BBSInfo tempInfo = new BBSInfo();

            try
            {
                int bbsId = GetInt("bbsId");
                // 从修改后BBS信息
                tempInfo.BBS = (from bbs in CQGJ.BBS where bbs.BBSID == bbsId select bbs).First();
                tempInfo.BBS.ImageUrl = imgUrl;
                tempInfo.OwnerName = GetAdminByBBSID(id).Username;
                tempInfo.Oweners = GetPotentialAdminByBBSID(bbsId);
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message + "操作错误!");
            }

            RenderView("BBSInfoMagament", tempInfo);
        }
Example #3
0
        /// <summary>
        /// 根据BBSID获取BBS相关信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public BBSInfo GetBBSInfo(int id)
        {
            BBSInfo BBSInformation = new BBSInfo();

            try
            {
                // 获取BBS相关信息
                BBSInformation.BBS = (from bbs in CQGJ.BBS where bbs.BBSID == id select bbs).First();
                // 获取BBS内发帖的条数
                BBSInformation.BBSItemsNbr = (from bi in CQGJ.BBSItem where bi.BBS.BBSID == id && bi.ParentID == -1 select bi).Count();

                // 获取BBS当前管理员ID
                int BBSOwnerID = (int)(from b in CQGJ.BBS where b.BBSID == id select b.OwnerID).First();

                // 根据BBS当前管理员ID获取他在Passport数据库User表中的ID
                int PassportUserID = ToPassportUserID(BBSOwnerID);
                passport.CQGJPassport cqgjp = new CQGJ.passport.CQGJPassport();

                // 从Passport数据库中获取用户对象,并取得管理员名字
                CQGJ.passport.User admin = cqgjp.GetCQGJUser(PassportUserID);
                BBSInformation.OwnerName = admin.Username;

                // 获取该班级的所有学员, i 为该BBS对应班级的ID
                // (注意要另行定义int i,
                // 不能直接写成List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value select s.User.UserID).ToList();)
                // 否则会报错,原因未知
                int i = (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value;
                List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == i select s.User.UserID).ToList();

                // 定义User,用于将班级学员转化为User对象
                List<CQGJ.passport.User> users = new List<CQGJ.passport.User>();

                // 定义用户姓名的数组
                List<string> names = new List<string>();
                List<int> ownerIds = new List<int>();

                // 将当前管理员添加到users对象中,作为潜在的管理员
                users.Add(admin);
                // 添加管理员的名字
                names.Add(admin.Username);
                ownerIds.Add(admin.UserID);

                // 将班级学员添加到users对象中,作为潜在的管理员
                foreach (var studentId in sid)
                {
                    passport.CQGJPassport cqgjp2 = new CQGJ.passport.CQGJPassport();

                    int passportUserID = ToPassportUserID(studentId);

                    CQGJ.passport.User student = cqgjp2.GetCQGJUser(passportUserID);

                    // 判断当然管理是否是该班级,如果不是则添加,如果是就不添加
                    if (student.UserID != admin.UserID)
                    {
                        users.Add(student);
                        names.Add(student.Username);
                        ownerIds.Add(student.UserID);
                    }

                }

                BBSInformation.Oweners = users;
                BBSInformation.OwernNames = names;
                BBSInformation.OwernIDs = ownerIds;
            }
            catch (Exception ex)
            {

            }

            return BBSInformation;
        }
Example #4
0
        /// <summary>
        /// 在BBS管理页面中修改BBS管理员
        /// </summary>
        /// <param name="id"></param>
        public void ModifyBBSInAdminPage(int id)
        {
            // 定义临时BBS信息
            BBSInfo tempInfo = new BBSInfo();

            try
            {
                // 修改管理员
                ModifyBBSAdmin(id, GetInt("ownerId"));

                // 从修改后BBS信息
                tempInfo.BBS = (from bbs in CQGJ.BBS where bbs.BBSID == id select bbs).First();
                tempInfo.OwnerName = GetAdminByBBSID(id).Username;
                tempInfo.Oweners = GetPotentialAdminByBBSID(id);
            }
            catch(Exception ex)
            {
                Response.Write(ex.Message);
            }

            RenderView("BBSInfoMagamentPage", tempInfo);
        }
Example #5
0
        /// <summary>
        /// 获得公共BBS及其相关内容
        /// </summary>
        public PublicBBSViewData ListPublicBBS()
        {
            PublicBBSViewData publicBBS = new PublicBBSViewData();

            // ? 有必要判断数据库中是否存在5条这样的数据,如果不存在,怎么办????
            publicBBS.HotBBSItemsList = (from bbsItems in CQGJ.BBSItem
                                         where bbsItems.ParentID == -1 && bbsItems.BBS.BBSID == 1
                                         orderby bbsItems.ViewCount descending
                                         select bbsItems).ToList();

            // ?????????问题同上
            publicBBS.RecentBBSItemsList = (from bbsItems in CQGJ.BBSItem
                                            where bbsItems.ParentID == -1 && bbsItems.BBS.BBSID == 1 && bbsItems.BBS.BBSID == 1
                                            orderby bbsItems.SubmitTime descending
                                            select bbsItems).ToList();

            // 匿名对象a用来保存BBS相关的信息
            var a = (from b in CQGJ.BBS
                     join bi in CQGJ.BBSItem on b.BBSID equals bi.BBS.BBSID
                         into c
                     orderby c.Count() descending
                     select new { b, count = c.Count() }).ToList();

            publicBBS.BBSInfoList = new List<BBSInfo>();

            foreach (var element in a)
            {
                BBSInfo BBSInfoData = new BBSInfo
                {
                    BBS = element.b,
                    BBSItemsNbr = element.count
                };

                publicBBS.BBSInfoList.Add(BBSInfoData);

            }

            return publicBBS;
        }
Example #6
0
        /// <summary>
        /// 显示出所有的BBS
        /// </summary>
        public void ListBBS()
        {
            // 定义BBS列表BBSListViewData,用于保存从数据库中读取到的所有的BBS
            BBSListViewData BBSListViewData = new BBSListViewData();

            try
            {
                // 从数据库中读取到的所有的BBS
                BBSListViewData.BBSList = (from bbsList in CQGJ.BBS select bbsList).ToList();

                // 取出本论坛最新贴子
                //BBSListViewData.LastBBSItem = (from bbsItem in CQGJ.BBSItem
                //orderby bbsItem.SubmitTime select bbsItem).First();

                BBSListViewData.BBSInfo = new List<BBSInfo>();

                foreach (var a in BBSListViewData.BBSList)
                {
                    // 初始化参数
                    BBSInfo tempInfo = new BBSInfo();
                    tempInfo.BBS = new BBS();
                    tempInfo.BBSItemsNbr = 0;
                    tempInfo.LastBBSItem = new BBSItem();
                    tempInfo.OwnerName = "no one";

                    // 查询赋值
                    tempInfo.BBS = a;

                    var tempBBSItem = from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID orderby bi.SubmitTime descending select bi;

                    if (tempBBSItem.Count() > 0)
                    {
                        tempInfo.LastBBSItem = (from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID orderby bi.SubmitTime descending select bi).First();
                    }

                    tempInfo.BBSItemsNbr = (from bi in CQGJ.BBSItem where bi.BBS.BBSID == a.BBSID select bi).Count();

                    BBSListViewData.BBSInfo.Add(tempInfo);
                }

                // 将BBS列表以BBSListViewData对象的形式绑定到ListBBS.aspx页面
                RenderView("ListBBS", BBSListViewData);
            }
            catch (ArgumentNullException)
            {
                Response.Write("目前不存在BBS论坛!");
            }
        }
Example #7
0
        /// <summary>
        /// 取得可能成为管理员的BBS用户
        /// </summary>
        /// <param name="id">BBS ID</param>
        /// <returns></returns>
        public List<User> GetPotentialAdminByBBSID(int id)
        {
            BBSInfo BBSInformation = new BBSInfo();

            // 定义User,用于将班级学员转化为User对象
            List<User> users = new List<User>();

            try
            {
                // 获取BBS相关信息
                BBSInformation.BBS = (from bbs in CQGJ.BBS where bbs.BBSID == id select bbs).First();

                // 获取BBS当前管理员ID
                //int BBSOwnerID = (int)(from b in CQGJ.BBS where b.BBSID == id select b.OwnerID).First();

                User admin = (from b in CQGJ.BBS
                              from u in CQGJ.User
                              where b.BBSID == id && u.UserID == b.OwnerID
                              select u).First();

                // 获取该班级的所有学员, i 为该BBS对应班级的ID
                // (注意要另行定义int i,
                // 不能直接写成List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value select s.User.UserID).ToList();)
                // 否则会报错,原因未知
                int i = (int)BBSInformation.BBS.ClassesReference.EntityKey.EntityKeyValues[0].Value;
                List<int> sid = (from s in CQGJ.Student where s.Classes.ClassID == i select s.User.UserID).ToList();

                // 将当前管理员添加到users对象中,作为潜在的管理员
                users.Add(admin);

                // 将班级学员添加到users对象中,作为潜在的管理员
                foreach (var studentId in sid)
                {
                    User student = (from u in CQGJ.User
                                    where u.UserID == studentId
                                    select u).First();

                    // 判断当然管理是否是该班级,如果不是则添加,如果是就不添加
                    if (student.UserID != admin.UserID)
                    {
                        users.Add(student);
                    }
                }
            }
            catch (Exception ex)
            {
                Response.Write(ex.Message);
            }
            return users;
        }