public static List<Tag> GetHotTag() { List<Tag> tagList = new List<Tag>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_hot_tagResult> rs2 = dc.get_hot_tag(); foreach (get_hot_tagResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } return tagList; }
//List<Reservation> timeoutReservationList = new List<Reservation>(); //List<Delivery> timeoutDelivery = new List<Delivery>(); //Function: initiate the all the dishes, by query the configure information in db //从数据库吧dish信息读出来,dish是Admin通过adddish加的 public static void InitAllDish() { dishList = new List<Dish>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<select_all_dishResult> rs = dc.select_all_dish(); foreach (select_all_dishResult r in rs) { List<Tag> tagList = new List<Tag>(); List<Comment> commentList = new List<Comment>(); ISingleResult<get_tag_by_dishResult> rs2 = dc.get_tag_by_dish(r.name); foreach (get_tag_by_dishResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } ISingleResult<get_comment_by_dishResult> rs3 = dc.get_comment_by_dish(r.name); foreach (get_comment_by_dishResult r3 in rs3) { Comment comment = new Comment(r3.id,r3.content,r3.about_dish,r3.user_from); commentList.Add(comment); } Dish dish = new Dish( r.name, r.description, (double)r.price, r.pict_path, (int)r.popularity, tagList, commentList); dishList.Add(dish); } }
protected void Button1_Click(object sender, EventArgs e) { bool fileTypeOk = false; string fileExtension = ""; string virtualPath = System.Configuration.ConfigurationManager.AppSettings["ImageDish"]; string path = Server.MapPath(virtualPath); if (this.FileUpload1.HasFile) { fileExtension = System.IO.Path.GetExtension(this.FileUpload1.FileName).ToLower(); string[] allowExtension = { ".gif", ".png", ".jpeg", ".jpg" }; foreach (string extension in allowExtension) { if (fileExtension.Trim() == extension) { fileTypeOk = true; } } } if (fileTypeOk) { try { List<Tag> tagList = new List<Tag>(); Tag t1 = new Tag(); t1.name = TextBox4.Text; Tag t2 = new Tag(); t2.name = TextBox5.Text; Tag t3 = new Tag(); t3.name = TextBox6.Text; tagList.Add(t1); tagList.Add(t2); tagList.Add(t3); List<Comment> commentList = new List<Comment>(); string pictVirtualPath = virtualPath + TextBox1.Text + fileExtension; Dish dish = new Dish(TextBox1.Text, TextBox2.Text, Convert.ToDouble(TextBox3.Text), pictVirtualPath, 0, tagList, commentList); this.FileUpload1.SaveAs(path + dish.name.ToString() + fileExtension); bool isSucceed = admin.AddDish(dish); if (isSucceed) { this.SubmitInfoLabel.Text = "succeed to add the dish"; TextBox1.Text = ""; TextBox2.Text = ""; TextBox3.Text = ""; TextBox4.Text = ""; TextBox5.Text = ""; TextBox6.Text = ""; } else { SubmitInfoLabel.Text = "fail, the dish name exists"; } } catch (Exception ee) { SubmitInfoLabel.Text = "fail check the format of the image!"; } } //没有选择文件或者文件格式不正确 else { this.SubmitInfoLabel.Text = "fail no image is avalable, or format is not allowed!"; } this.SubmitInfoLabel.Visible = true; }
public List<Dish> SearchDishByKeyword(string pKeyword) { List<Dish> dishList = new List<Dish>(); DataContextDataContext dc = new DataContextDataContext(); ISingleResult<search_dish_by_keywordResult> rs = dc.search_dish_by_keyword(pKeyword); foreach (search_dish_by_keywordResult r in rs) { List<Tag> tagList = new List<Tag>(); ISingleResult<get_tag_by_dishResult> rs2 = dc.get_tag_by_dish(r.name); foreach (get_tag_by_dishResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } List<Comment> commentList = new List<Comment>(); ISingleResult<get_comment_by_dishResult> rs3 = dc.get_comment_by_dish(r.name); foreach (get_comment_by_dishResult r3 in rs3) { Comment comment = new Comment(r3.id, r3.content, r3.about_dish, r3.user_from); commentList.Add(comment); } Dish dish = new Dish(r.name, r.description, (double)r.price, r.pict_path, (int)r.popularity, tagList, commentList); dishList.Add(dish); } return dishList; }
public Dish GetDishByName(string pDishName) { Dish dish = null; DataContextDataContext dc = new DataContextDataContext(); ISingleResult<get_dish_by_nameResult> rs = dc.get_dish_by_name(pDishName); foreach (get_dish_by_nameResult r in rs) { List<Tag> tagList = new List<Tag>(); List<Comment> commentList = new List<Comment>(); ISingleResult<get_tag_by_dishResult> rs2 = dc.get_tag_by_dish(r.name); foreach (get_tag_by_dishResult r2 in rs2) { Tag tag = new Tag(r2.name, (int)r2.popularity); tagList.Add(tag); } ISingleResult<get_comment_by_dishResult> rs3 = dc.get_comment_by_dish(r.name); foreach (get_comment_by_dishResult r3 in rs3) { Comment comment = new Comment(r3.id, r3.content, r3.about_dish, r3.user_from); commentList.Add(comment); } dish = new Dish( r.name, r.description, (double)r.price, r.pict_path, (int)r.popularity, tagList, commentList); } return dish; }