Exemplo n.º 1
0
 /// <summary>
 /// 根据文章ID获取文章实体
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static Article GetArticle(int id)
 {
     using (var db = new SCenterEntities())
     {
         return db.Articles.Single(a => a.Aid == id);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// 添加人员
        /// </summary>
        /// <param name="name"></param>
        /// <param name="cid"></param>
        /// <param name="intro"></param>
        /// <param name="path">头像</param>
        /// <returns></returns>
        public static bool AddBStaff(string name, int cid, string intro, string path)
        {
            try
            {
                string sql = "insert into Member (Sid,Name,Introduction,Photo) values({0},{1},{2},{3})";

                using (var db = new SCenterEntities())
                {
                    db.ExecuteStoreCommand(sql, new object[] { cid, name, intro, path });

                    //Rank初始化
                    List<Member> list = db.Members.Where(m => m.Rank == null).ToList();
                    if (list != null && list.Count >0)
                    {
                        foreach (var item in list)
                        {
                            item.Rank = item.Mid;
                        }
                    }
                    db.SaveChanges();
                }

                return true;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 3
0
 /// <summary>
 /// 根据公告ID获取公告, 或者下载
 /// </summary>
 /// <param name="id"></param>
 /// <returns></returns>
 public static ArticleWithAthmt GetBulltin(int id)
 {
     using (var db = new SCenterEntities())
     {
         return db.ArticleWithAthmts.Single(a => a.Bid == id);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 添加新闻
        /// </summary>
        /// <param name="title"></param>
        /// <param name="cid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool AddNews(string title, int cid, string author, string source, DateTime date, string content, bool ispic, bool isloop, string path)
        {
            try
            {
                string sql = "insert into News (Sid,Title,Source,Author,Content,PostTime,IsPicNews,IsLoopPicNews,PicNewsPath) values({0},{1},{2},{3},{4},{5},{6},{7},{8})";

                using (var db = new SCenterEntities())
                {
                    db.ExecuteStoreCommand(sql, new object[] {cid, title, source, author, content, date, ispic, isloop, path});
                    //db.SaveChanges();

                    //初始化Rank为它的唯一标识
                    List<News> list = db.News.Where(n => n.Rank == null).ToList();
                    if (list != null && list.Count >0)
                    {
                        foreach (var item in list)
                        {
                            item.Rank = item.Nid;
                        }
                    }
                    db.SaveChanges();
                }

                return true;
            }
            catch
            {
                return false;
                throw;
            }
        }
Exemplo n.º 5
0
 public static Admin GetUser(int id)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             return db.Admins.Single(a => a.Userid == id);
         }
     }
     catch
     {
         return null;
     }
 }
Exemplo n.º 6
0
        public static List<Admin> GetUserList()
        {
            try
            {
                using (var db = new SCenterEntities())
                {
                    return db.Admins.OrderByDescending(a => a.Userid).ToList();
                }
            }
            catch
            {

            }
            return null;
        }
Exemplo n.º 7
0
 /// <summary>
 /// 删除公告下载
 /// </summary>
 /// <param name="id">文章ID</param>
 /// <returns>操作状态</returns>
 public static bool DelBulletin(int id)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             db.ArticleWithAthmts.DeleteObject(db.ArticleWithAthmts.Single(a => a.Bid == id));
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 8
0
 /// <summary>
 /// 删除文章
 /// </summary>
 /// <param name="id">文章ID</param>
 /// <returns>操作状态</returns>
 public static bool DelUser(int id)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             db.Admins.DeleteObject(db.Admins.Single(a => a.Userid == id));
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 9
0
 /// <summary>
 /// 删除人员
 /// </summary>
 /// <param name="id">人员ID</param>
 /// <returns>操作状态</returns>
 public static bool DelStaff(int id)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             db.Members.DeleteObject(db.Members.Single(a => a.Mid == id));
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// 删除新闻
 /// </summary>
 /// <param name="id">新闻ID</param>
 /// <returns>操作状态</returns>
 public static bool DelNews(int id)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             db.News.DeleteObject(db.News.Single(n => n.Nid == id));
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 11
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int id = Convert.ToInt32(RouteData.Values["id"]);
            post = BulletinHelper.GetBulltin(id);

            //bshare需要抓取的两个内容
            Page.Header.Title = post.Title;
            Page.Header.Description = post.Title;

            //更新统计数据
            using (var db = new SCenterEntities())
            {
                post.ClickCount += 1;
                db.Attach(post);
                db.ObjectStateManager.ChangeObjectState(post, System.Data.EntityState.Modified);
                db.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
            }
        }
Exemplo n.º 12
0
        protected void btnExec_onClick(object sender, EventArgs e)
        {
            string sql = @"alter table Article add Source varchar(255);
alter table Article add Author varchar(255);
alter table ArticleWithAthmt add Source varchar(255);
alter table ArticleWithAthmt add Author varchar(255);";
            try
            {
                using (var db = new SCenterEntities())
                {
                    db.ExecuteStoreCommand(sql, new object[] { });

                }
                this.lbShow.Text = "SUCCESS";
            }
            catch 
            {
                this.lbShow.Text = "FAILS";
            }
        }
Exemplo n.º 13
0
        protected void Page_Load(object sender, EventArgs e)
        {
            //获取要查看的新闻ID
            int id = Convert.ToInt32(RouteData.Values["id"]);

            Msg = ArtiHelper.GetArticle(id);

            //bshare需要抓取的两个内容
            Page.Header.Title = Msg.Title;
            Page.Header.Description = Msg.Title;

            //更新统计数据
            using (var db = new SCenterEntities())
            {
                Msg.ClickCount += 1;
                db.Attach(Msg);
                db.ObjectStateManager.ChangeObjectState(Msg, System.Data.EntityState.Modified);
                db.SaveChanges(System.Data.Objects.SaveOptions.AcceptAllChangesAfterSave);
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// 添加文章
        /// </summary>
        /// <param name="title"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public static bool AddUser(string username,  string password)
        {
            try
            {
                string sql = "insert into Admin (UserName,Password) values({0},{1})";

                using (var db = new SCenterEntities())
                {
                    db.ExecuteStoreCommand(sql, new object[] { username, FormsAuthentication.HashPasswordForStoringInConfigFile(password,"md5") });
                    db.SaveChanges();
                }

                return true;
            }
            catch
            {
                return false;
                throw;
            }
        }
Exemplo n.º 15
0
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username = this.txtUsername.Text;
            string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(this.txtPwd.Text, "md5");

            //判断用户是否已经登录
            if (AmIOnline(username, (Hashtable)Application["Online"]))
            {
                ClientScript.RegisterStartupScript(ClientScript.GetType(), "MyScript", "<script>repeat();</script>");
                return;
            }
            using (var db = new SCenterEntities())
            {
                var usr = db.Admins.SingleOrDefault(u => u.UserName == username);
                if (usr == null)
                {
                    ClientScript.RegisterStartupScript(ClientScript.GetType(), "MyScript", "<script>userError();</script>");
                    return;
                }
                else
                {

                    if (usr.Password != pwd)
                    {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(), "MyScript", "<script>pwdError();</script>");
                        return;
                    }

                    Hashtable h = (Hashtable)Application["Online"];
                    if (h == null)
                    {
                        h = new Hashtable();
                    }
                    h[Session.SessionID] = username;
                    Application["Online"] = h;

                    Session["username"] = username;
                    Response.Redirect("~/Admin/Index.aspx");
                }
            }
        }
Exemplo n.º 16
0
        /// <summary>
        /// 添加公告、下载
        /// </summary>
        /// <param name="title"></param>
        /// <param name="cid"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public static bool AddBulletin(string title, int cid, string content, string author, string source, DateTime date, string attachment, string filename)
        {
            DateTime Date = Convert.ToDateTime(date.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss.fff"));
            try
            {
                string sql = "insert into ArticleWithAthmt (Sid,Title,Content,Source,Author,PostTime,Attachment,AttachmentName) values({0},{1},{2},{3},{4},{5},{6},{7})";

                using (var db = new SCenterEntities())
                {
                    db.ExecuteStoreCommand(sql, new object[] { cid, title, content,source, author,Date, attachment, filename });
                    db.SaveChanges();
                }

                return true;
            }
            catch
            {
                return false;
                throw;
            }
        }
Exemplo n.º 17
0
        /// <summary>
        /// 分页获取公告信息
        /// </summary>
        /// <param name="pid">父类类别ID</param>
        /// <returns></returns>
        public static List<ArticleWithAthmt> GetTopItemsByParentId(int pid, int top)
        {
            using (var db = new SCenterEntities())
            {
                string strcid = "";
                var list = db.SystemCategories.Where(s => s.ParentNo == pid).ToList();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        strcid += item.Sid + ",";
                    }
                }
                if (strcid.Length > 0)
                {
                    strcid = strcid.Substring(0, strcid.Length - 1);
                }
                string sql = "select * from ArticleWithAthmt where Sid in (" + strcid + ") order by PostTIme desc";

                return db.ExecuteStoreQuery<ArticleWithAthmt>(sql, new object[] { }).Take(top).OrderByDescending(n => n.PostTime).ToList();
            }
        }
Exemplo n.º 18
0
 /// <summary>
 /// 所有新闻中,筛选出焦点图新闻、一般图片新闻
 /// </summary>
 /// <param name="cid">分类:0->焦点图新闻; other->图片新闻</param>
 /// <param name="top">选出的数目</param>
 /// <returns></returns>
 public static List<News> GetTopPicNews(int cid, int top)
 {
     List<News> news = new List<News>();
     using (var db = new SCenterEntities())
     {
         if (cid == 0)
         {
             news = db.News.Where(n => n.IsPicNews == true).OrderByDescending(n => n.Rank).Take(top).ToList();
         }
         else
         {
             news = db.News.Where(n => n.IsLoopPicNews == true).OrderByDescending(n => n.Rank).Take(top).ToList();
         }
     }
     return news;
 }
Exemplo n.º 19
0
 /// <summary>
 /// 所有新闻中,筛选出焦点图新闻、一般图片新闻
 /// </summary>
 /// <param name="top">选出的数目</param>
 /// <returns></returns>
 public static List<News> GetTopPicNews(int top)
 {
     List<News> news = new List<News>();
     using (var db = new SCenterEntities())
     {
         news = db.News.OrderByDescending(n => n.Rank).Take(top).ToList();
     }
     return news;
 }
Exemplo n.º 20
0
        /// <summary>
        /// 分页获取新闻信息
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="count">总条目</param>
        /// <returns></returns>
        public static List<News> GetPagedNews(int index, int pagesize, ref int count)
        {
            string sql = "select * from News order by Rank desc limit {0} offset {1}";

            using (var db = new SCenterEntities())
            {
                count = db.News.Count();
                return db.ExecuteStoreQuery<News>(sql, new object[] { pagesize, (index - 1) * pagesize }).OrderByDescending(n => n.Rank).ToList();
            }
        }
Exemplo n.º 21
0
 /// <summary>
 /// 根据ID获取新闻实体
 /// </summary>
 /// <param name="id">新闻ID</param>
 /// <returns></returns>
 public static News GetNews(int id)
 {
     using (var db = new SCenterEntities())
     {
         return db.News.Single(n => n.Nid == id);
     }
 }
Exemplo n.º 22
0
        /// <summary>
        /// 分页获取公告信息
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="cid">类别ID</param>
        /// <param name="count">总条目</param>
        /// <returns></returns>
        public static List<ArticleWithAthmt> GetPagedItems(int index, int pagesize, int cid, ref int count)
        {
            string sql = "select * from ArticleWithAthmt where Sid={0} order by PostTIme desc limit {1} offset {2}";

            using (var db = new SCenterEntities())
            {
                count = db.ArticleWithAthmts.Where(n => n.Sid == cid).Count();
                return db.ExecuteStoreQuery<ArticleWithAthmt>(sql, new object[] { cid, pagesize, (index - 1) * pagesize }).OrderByDescending(n => n.PostTime).ToList();
            }
        }
Exemplo n.º 23
0
 /// <summary>
 /// 修改文章
 /// </summary>
 /// <param name="id"></param>
 /// <param name="username"></param>
 /// <param name="password"></param>
 /// <returns></returns>
 public static bool UpdateUser(int id, string username, string password)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             var user = db.Admins.Single(a => a.Userid == id);
             user.UserName = username;
             user.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(password, "md5");
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// 分页获取公告信息
        /// </summary>
        /// <param name="index">页码</param>
        /// <param name="pagesize">页面大小</param>
        /// <param name="pid">父类类别ID</param>
        /// <param name="count">总条目</param>
        /// <returns></returns>
        public static List<ArticleWithAthmt> GetPagedItemsUsingParentType(int index, int pagesize, int pid, ref int count)
        {
            using (var db = new SCenterEntities())
            {
                string strcid = "";
                var list = db.SystemCategories.Where(s => s.ParentNo == pid).ToList();
                if (list.Count > 0)
                {
                    foreach (var item in list)
                    {
                        strcid += item.Sid + ",";
                        count += db.ArticleWithAthmts.Where(a => a.Sid == item.Sid).Count();
                    }
                }
                if (strcid.Length > 0)
                {
                    strcid = strcid.Substring(0, strcid.Length - 1);
                }
                string sql = "select * from ArticleWithAthmt where Sid in (" + strcid +") order by PostTIme desc limit {0} offset {1}";

                return db.ExecuteStoreQuery<ArticleWithAthmt>(sql, new object[] { pagesize, (index - 1) * pagesize }).OrderByDescending(n => n.PostTime).ToList();
            }
        }
Exemplo n.º 25
0
 public List<Post> GetTopDesc(int cid, int top)
 {
     List<Post> posts = new List<Post>();
     using (var db = new SCenterEntities())
     {
         var list = db.ArticleWithAthmts.Where(a => a.Sid == cid).OrderByDescending(n => n.PostTime).Take(top).ToList();
         if (list != null && list.Count > 0)
         {
             foreach (var item in list)
             {
                 posts.Add(new Post
                 {
                     Pid = item.Bid,
                     Title = item.Title,
                     PostTime = item.PostTime.ToString("yyyy-MM-dd")
                 });
             }
         }
         return posts;
     }
 }
Exemplo n.º 26
0
 /// <summary>
 /// 修改新闻
 /// </summary>
 /// <param name="id"></param>
 /// <param name="title"></param>
 /// <param name="cid"></param>
 /// <param name="content"></param>
 /// <param name="ispic"></param>
 /// <param name="isloop"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 public static bool UpdateNews(int id, string title, int cid, string author, string source, DateTime date, string content, bool ispic, bool isloop, string path)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             var news = db.News.Single(n => n.Nid == id);
             news.Title = title;
             news.Content = content;
             news.Sid = cid;
             news.Author = author;
             news.Source = source;
             news.PostTime = date;
             news.IsPicNews = ispic;
             news.IsLoopPicNews = isloop;
             news.PicNewsPath = path;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 27
0
 public List<Post> GetTopDesc(int cid, int top)
 {
     List<Post> posts = new List<Post>();
     using (var db = new SCenterEntities())
     {
         var list = db.News.Where(n => n.Sid == cid).OrderByDescending(n => n.Rank).Take(top).ToList();
         if (list != null && list.Count > 0)
         {
             foreach (var item in list)
             {
                 posts.Add(new Post
                 {
                     Pid = item.Nid,
                     Title = item.Title,
                     PostTime = item.PostTime.ToString("yyyy-MM-dd"),
                     PicPath = item.PicNewsPath
                 });
             }
         }
         return posts;
     }
 }
Exemplo n.º 28
0
 /// <summary>
 /// 通过分类ID与读取条数去取数据
 /// </summary>
 /// <param name="cid">分类ID,枚举Category</param>
 /// <param name="top">条目</param>
 /// <returns></returns>
 public static List<ArticleWithAthmt> SelectArticleAttached(int cid, int top)
 {
     using (var db = new SCenterEntities())
     {
         return db.ArticleWithAthmts.OrderByDescending(a => a.PostTime).Where(a => a.Sid == cid).Take(top).ToList();
     }
 }
Exemplo n.º 29
0
        /// <summary>
        /// rank down
        /// </summary>
        /// <param name="id">新闻的ID</param>
        /// <returns>修改是否成功</returns>
        public static bool DownNews(int id)
        {
            try
            {
                using (var db = new SCenterEntities())
                {
                    var m1 = db.News.Single(a => a.Nid == id);
                    if (m1.Rank == null)    //防止没有Rank的条目
                    {
                        m1.Rank = m1.Nid;
                    }

                    //找出此类列表
                    List<News> clist = db.News.Where(n => n.Sid == m1.Sid).OrderByDescending(a => a.Rank).ToList();
                    if (clist != null && clist.Count > 0)
                    {
                        News m2 = null;
                        try
                        {
                            m2 = clist[clist.LastIndexOf(m1) + 1];
                        }
                        catch
                        {
                        }
                        if (m2 != null)
                        {
                            var tmp = m1.Rank;
                            m1.Rank = m2.Rank;
                            m2.Rank = tmp;
                        }

                    }
                    //var m2 = db.News.SingleOrDefault(a => a.Rank == (m1.Rank - 1));

                    //if (m2 != null)
                    //{
                    //    m1.Rank -= 1;
                    //    m2.Rank += 1;
                    //}
                    db.SaveChanges();
                }
                return true;
            }
            catch
            {
                return false;
            }
        }
Exemplo n.º 30
0
 /// <summary>
 /// 修改文章
 /// </summary>
 /// <param name="id"></param>
 /// <param name="title"></param>
 /// <param name="cid"></param>
 /// <param name="content"></param>
 /// <param name="attachment"></param>
 /// <returns></returns>
 public static bool UpdateBulletin(int id, string title, int cid, string content, string author, string source, DateTime date, string attachment, string filename)
 {
     DateTime Date = Convert.ToDateTime(date.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss.fff"));
     try
     {
         using (var db = new SCenterEntities())
         {
             var bulletin = db.ArticleWithAthmts.Single(a => a.Bid == id);
             bulletin.Title = title;
             bulletin.Content = content;
             bulletin.Sid = cid;
             bulletin.Author = author;
             bulletin.Source = source;
             bulletin.PostTime = Date;
             bulletin.Attachment = attachment;
             bulletin.AttachmentName = filename;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }