Exemplo n.º 1
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.º 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>
 /// 删除公告下载
 /// </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.º 4
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.º 5
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.º 6
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.º 7
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.º 8
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.º 9
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.º 10
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.º 11
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.º 12
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;
     }
 }
Exemplo n.º 13
0
 /// <summary>
 /// 修改人员
 /// </summary>
 /// <param name="id"></param>
 /// <param name="name"></param>
 /// <param name="cid"></param>
 /// <param name="intro"></param>
 /// <param name="path"></param>
 /// <returns></returns>
 public static bool UpdateStaff(int id, string name, int cid, string intro, string path)
 {
     try
     {
         using (var db = new SCenterEntities())
         {
             var staff = db.Members.Single(a => a.Mid == id);
             staff.Name = name;
             staff.Introduction = intro;
             staff.Sid = cid;
             staff.Photo = path;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }
Exemplo n.º 14
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.º 15
0
        /// <summary>
        /// rank down
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public static bool DownStaff(int id)
        {
            try
            {
                using (var db = new SCenterEntities())
                {
                    var m1 = db.Members.Single(a => a.Mid == id);
                    if (m1.Rank == null)
                    {
                        m1.Rank = m1.Mid;
                    }
                    var m2 = db.Members.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.º 16
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.º 17
0
 /// <summary>
 /// 修改文章
 /// </summary>
 /// <param name="id"></param>
 /// <param name="title"></param>
 /// <param name="cid"></param>
 /// <param name="content"></param>
 /// <returns></returns>
 public static bool UpdateArticle(int id, string title, int cid, string author, string source, DateTime date, string content)
 {
     DateTime Date = Convert.ToDateTime(date.ToString("yyyy-MM-dd") + " " + DateTime.Now.ToString("HH:mm:ss.fff"));
     try
     {
         using (var db = new SCenterEntities())
         {
             var news = db.Articles.Single(a => a.Aid == id);
             news.Title = title;
             news.Content = content;
             news.Sid = cid;
             news.Author = author;
             news.Source = source;
             news.PostTime = Date;
             db.SaveChanges();
         }
         return true;
     }
     catch
     {
         return false;
     }
 }