protected void Page_Load(object sender, EventArgs e) { using (DataEntities ent = new DataEntities()) { int id = WS.RequestInt("id"); Voodoo.Basement.Product p = (from l in ent.Product where l.ID == id select l).FirstOrDefault(); TemplateHelper Helper = new TemplateHelper(); Response.Clear(); Response.Write( Helper.CreateContentPage(p, p.GetClass())); } }
protected void Form_Save(object sender, DirectEventArgs e) { using (DataEntities ent = new DataEntities()) { var n = new Voodoo.Basement.Product(); try { int id = ID.Text.ToInt32(); n = (from l in ent.Product where l.ID == id select l).First(); } catch { } n.AddTime = AddTime.Value.ToDateTime(); n.ClassID = ClassID.SelectedItem.Value.ToInt32(); n.ClassName = ClassID.SelectedItem.Text; n.ClickCount = ClickCount.Value.ToInt32(); n.Contact = Contact.Text; n.Enable = Enable.Checked; //n.FaceImage = ""; n.Intro = Intro.Text; n.Name = Name.Text; n.OrderIndex = OrderIndex.Value.ToInt32(); n.Price = Price.Value.ToDecimal(); n.ProduceLocation = ProduceLocation.Text; n.SetTop = SetTop.Checked; n.Specification = Specification.Text; n.Tel = Tel.Text; n.Units = Units.Text; if (n.ID <= 0) { ent.AddToProduct(n); } ent.SaveChanges(); if (FaceImage.HasFile) { Class cls = (from l in ent.Class where l.ID == n.ClassID select l).First(); string fileName = string.Format("/u/products/{0}.jpg", n.ID); Voodoo.Basement.BasePage.UpLoadImage(FaceImage.PostedFile, fileName, cls.ImageWidth.ToInt32(), cls.ImageHeight.ToInt32());//194, 204 n.FaceImage = fileName; ent.SaveChanges(); } if (UpFile.HasFile) { var files = from l in ent.File where l.ItemID == n.ID select l; foreach (var f in files) { ent.DeleteObject(f); } string ext = UpFile.FileName.GetFileExtNameFromPath(); string fileName = string.Format("/u/products/{0}", UpFile.FileName); Voodoo.Basement.BasePage.UpLoadFile(UpFile.PostedFile, fileName); Voodoo.Basement.File file = new Voodoo.Basement.File(); file.ClassID = n.ClassID; file.FileDirectory = "/u/products/"; file.FileExtName = ext; file.FileName = UpFile.FileName; file.FilePath = fileName; file.FileSize = UpFile.PostedFile.ContentLength; file.FileType = 0; file.ItemID = n.ID; file.SmallPath = ""; file.UpTime = DateTime.Now; ent.AddToFile(file); ent.SaveChanges(); } this.GridPanel1.Store.Primary.CommitChanges(); this.BindData(); TabPanel1.SetActiveTab(0); FormPanel1.Title = "新增"; FormPanel1.Reset(); X.Msg.Notify("消息", "保存成功!").Show(); } }
/// <summary> /// 生成内容页--图片 /// </summary> /// <param name="album"></param> /// <param name="cls"></param> public string CreateContentPage(Product p, Class cls) { DataEntities ent = new DataEntities(); TemplateContent temp = GetContentTemplate(cls); string Content = temp.Content; Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplacePublicTemplate(Content); Content = ReplaceSystemSetting(Content); #region 替换内容 Content = ReplaceContent(Content, p, cls); #endregion Content = ReplaceTagContent(Content); //替换导航条 Content = Content.Replace("[!--newsnav--]", BuildClassNavString(cls)); return Content; }
public string ReplaceContent(string TempString, Product p, Class c) { return ReplaceContent(new TemplateList() { TimeFormat = "yyyy-MM-dd HH:mm:ss", CutTitle = 0 }, TempString, p, c); }
public string ReplaceContent(TemplateList temp, string TempString, Product p, Class c) { using (DataEntities ent = new DataEntities()) { string str_lst = TempString; str_lst = str_lst.Replace("[!--productaddtime.--]", p.AddTime.ToDateTime().ToString(temp.TimeFormat)); str_lst = str_lst.Replace("[!--product.classid--]", p.ClassID.ToS()); str_lst = str_lst.Replace("[!--product.classname--]", p.ClassName); str_lst = str_lst.Replace("[!--product.clickcount--]", p.ClickCount.ToS()); str_lst = str_lst.Replace("[!--product.contact--]", p.Contact); str_lst = str_lst.Replace("[!--product.enable--]", p.Enable.ToBoolean().ToChinese()); str_lst = str_lst.Replace("[!--product.faceimage--]", p.FaceImage); str_lst = str_lst.Replace("[!--product.id--]", p.ID.ToS()); str_lst = str_lst.Replace("[!--product.intro--]", p.Intro); str_lst = str_lst.Replace("[!--product.name--]", p.Name); str_lst = str_lst.Replace("[!--product.orderindex--]", p.OrderIndex.ToS()); str_lst = str_lst.Replace("[!--product.price-]", p.Price.ToDecimal().ToString("#.##")); str_lst = str_lst.Replace("[!--product.producelocation--]", p.ProduceLocation); str_lst = str_lst.Replace("[!--product.settop--]", p.SetTop.ToBoolean().ToChinese()); str_lst = str_lst.Replace("[!--product.specification--]", p.Specification); str_lst = str_lst.Replace("[!--product.tel--]", p.Tel); str_lst = str_lst.Replace("[!--product.units--]", p.Units); str_lst = str_lst.Replace("[!--product.url--]", BasePage.GetProductUrl(p, c)); var files = from l in ent.File where l.ItemID == p.ID select l; StringBuilder fileHtml=new StringBuilder();; foreach (var file in files) { string fTemp = string.Format("<a class=upfile href={0} target=_blank>{1}</a> <br/> ",file.FilePath,file.FileName); fileHtml.Append(fTemp); } str_lst = str_lst.Replace("[!--product.files--]", fileHtml.ToS()); return str_lst; } }