public static string Set_LessonData(string id, article.Lesson item) { Lesson ItemData = new Lesson(); ItemData = item; HttpContext.Current.Session["LessonData"] = ItemData; string result = ""; return(result);; }
public static dynamic Set_data(string kind, string Id, string[] Category , string Subject, string SubTitle, string Contents, string Pic, string PostDay, string Recommend , string[] Tags, string Author, string Keywords, string Status, article.Lesson Lesson , string YoutubeUrl, string NextRead, string Viewcount, string flag) { //如果用dynamic 傳,就會有LIST postdata = postdata[0]; string result = ""; List <Category> ItemData = new List <Category>();; foreach (string s in Category) { NameValueCollection nvc = new NameValueCollection(); string strsql = @"SELECT categoryid, title as name, kind FROM tbl_category where categoryid=@id "; nvc.Add("id", s); DataTable dt = DbControl.Data_Get(strsql, nvc); int i = 0; for (i = 0; i < dt.Rows.Count; i++) { ItemData.Add(new Category { Id = 0, CategoryId = (int)dt.Rows[i]["categoryid"], Name = dt.Rows[i]["name"].ToString(), Kind = dt.Rows[i]["Kind"].ToString(), }); } dt.Dispose(); } MainData MainData = new MainData { Id = int.Parse(Id), Subject = Subject, SubTitle = SubTitle, Contents = Contents, Pic = classlib.GetImgNmae(Pic), PostDay = DateTime.Parse(PostDay), Status = Status, Viewcount = int.Parse(Viewcount), Keywords = Keywords, Tags = Tags, Category = ItemData, Author = Author, Lesson = Lesson, Recommend = Recommend, kind = kind, Tempid = HttpContext.Current.Session["uploadid"].ToString(), YoutubeUrl = YoutubeUrl, NextRead = NextRead, Flag = flag // Category = postdata["Category"] , // Lesson = postdata.Lesson , }; HttpContext.Current.Session["MainData"] = MainData; return(result); }
public static MainData Get_article(int id) { MainData MainData = new MainData(); string strsql = @"select * FROM tbl_article LEFT OUTER JOIN tbl_lesson ON tbl_article.articleId = tbl_lesson.articleId where tbl_article.articleid =@id"; NameValueCollection nvc = new NameValueCollection { { "id", id.ToString() } }; DataTable dt = DbControl.Data_Get(strsql, nvc); string[] tags; List <Category> categoryid = new List <Category>(); string[] Lecturer; if (dt.Rows.Count > 0) { MainData.Id = id; MainData.Subject = dt.Rows[0]["Subject"].ToString(); MainData.SubTitle = dt.Rows[0]["SubTitle"].ToString(); MainData.Contents = dt.Rows[0]["Contents"].ToString().Replace("\r", "").Replace("\n", ""); MainData.Pic = "/webimages/article/" + dt.Rows[0]["pic"].ToString(); MainData.PostDay = DateTime.Parse(dt.Rows[0]["PostDay"].ToString()); MainData.Status = dt.Rows[0]["Status"].ToString(); MainData.Keywords = dt.Rows[0]["Keywords"].ToString(); MainData.Author = dt.Rows[0]["Author"].ToString(); MainData.Viewcount = (int)dt.Rows[0]["Viewcount"]; MainData.kind = dt.Rows[0]["kind"].ToString(); MainData.Recommend = dt.Rows[0]["Recommend"].ToString(); MainData.YoutubeUrl = dt.Rows[0]["YoutubeUrl"].ToString(); MainData.NextRead = dt.Rows[0]["NextRead"].ToString(); MainData.Flag = dt.Rows[0]["flag"].ToString(); //if (MainData.YoutubeUrl != "") //{ // string v = MainData.YoutubeUrl.Substring(MainData.YoutubeUrl.IndexOf("?v=") +3, MainData.YoutubeUrl.Length - MainData.YoutubeUrl.IndexOf("?v=")-3); // MainData.Pic = "http://img.youtube.com/vi/" + v + "/maxresdefault.jpg"; //} } dt.Dispose(); nvc.Clear(); List <string> termsList = new List <string>(); strsql = "select * from tbl_article_tag where articleid =@id and unitid=13"; nvc.Add("id", id.ToString()); dt = DbControl.Data_Get(strsql, nvc); int i = 0; for (i = 0; i < dt.Rows.Count; i++) { termsList.Add(dt.Rows[i]["tagid"].ToString()); } tags = termsList.ToArray(); termsList.Clear(); MainData.Tags = tags; nvc.Clear(); dt.Dispose(); //取目錄 MainData.Category = Get_article_category(id); dt.Dispose(); nvc.Clear(); //取課程 Lesson lesson = new Lesson(); List <LessonDetail> lessondetail = new List <LessonDetail>(); strsql = @"select * from tbl_lesson where articleid =@id"; nvc.Add("id", id.ToString()); dt = DbControl.Data_Get(strsql, nvc); if (dt.Rows.Count > 0) { //lesson.Add(new Lesson //{ lesson.Address = dt.Rows[0]["address"].ToString(); lesson.Lessontime = dt.Rows[0]["Lessontime"].ToString(); lesson.StartDay = dt.Rows[0]["StartDay"].ToString() == "" ? DateTime.Today : DateTime.Parse(dt.Rows[0]["StartDay"].ToString()); lesson.EndDay = dt.Rows[0]["EndDay"].ToString() == "" ? DateTime.Today : DateTime.Parse(dt.Rows[0]["EndDay"].ToString()); lesson.Id = id; //}); } strsql = @"select * from tbl_lesson_class where articleid =@id"; dt = DbControl.Data_Get(strsql, nvc); for (int idx = 0; idx < dt.Rows.Count; idx++) { lessondetail.Add(new LessonDetail { LessonId = (int)dt.Rows[idx]["LessonId"], Sellprice = (int)dt.Rows[idx]["Sellprice"], Price = (int)dt.Rows[idx]["price"], Description = (string)dt.Rows[idx]["description"], Limitnum = (int)dt.Rows[idx]["Limitnum"], Sort = (int)dt.Rows[idx]["sort"], Strdat = (DateTime)dt.Rows [idx]["strdat"], Enddat = (DateTime)dt.Rows[idx]["enddat"], Flag = (string )dt.Rows[idx]["Flag"] }); } dt.Dispose(); nvc.Clear(); lesson.LessonDetail = lessondetail; //取講師 termsList.Clear(); strsql = "select * from tbl_article_tag where articleid =@id and unitid=14"; nvc.Add("id", id.ToString()); dt = DbControl.Data_Get(strsql, nvc); for (i = 0; i < dt.Rows.Count; i++) { termsList.Add(dt.Rows[i]["tagid"].ToString()); } Lecturer = termsList.ToArray(); termsList.Clear(); //bool exists = lesson.Exists(p => p.Id == id); //if (exists) //{ // var L = lesson.Find(p => p.Id == id); // L.LessonDetail = lessondetail; // L.Lecturer = Lecturer; //} nvc.Clear(); dt.Dispose(); MainData.Lesson = lesson; return(MainData); }