/// <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; } }
/// <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; } }
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"; } }
/// <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; } }
/// <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; } }