private static string GetRealItemInfo(Jia_Item item, Jia_Template temp, string type) { Jia_ImgService imgDal = new Jia_ImgService(); Jia_ImgCustomerService cimgDal = new Jia_ImgCustomerService(); string tempHtml = ""; if (type == "1") { tempHtml = temp.TplHtml; } if (type == "0") { tempHtml = temp.UglyTplHtml; } IList <Jia_Img> imgList = imgDal.GetAllJia_Img(temp.TplId); IList <Jia_ImgCustomer> cimgList = cimgDal.GetAllJia_ImgCustomer(item.ItemId); //替换图片 foreach (Jia_Img jimg in imgList) { tempHtml = tempHtml.Replace(jimg.Tag, jimg.JiaImg); } foreach (Jia_ImgCustomer jcimg in cimgList) { tempHtml = tempHtml.Replace(jcimg.Tag, jcimg.JiaImg); } //替换chartext string chartext = item.CharText.Substring(1, item.CharText.Length - 2); //剔除{} Dictionary <string, string> dic = new Dictionary <string, string>(); string[] chars = Regex.Split(chartext, "{,}"); foreach (string s in chars) { dic.Add(s.Substring(0, s.IndexOf(':')), s.Substring(s.IndexOf(':') + 1, s.Length - s.IndexOf(':') - 1)); } foreach (KeyValuePair <string, string> kvp in dic) { tempHtml = tempHtml.Replace("{" + kvp.Key + "}", kvp.Value); } //替换PropertyText string propertyText = item.PropertyText.Substring(1, item.PropertyText.Length - 2); //剔除{} string loop = tempHtml.Substring(tempHtml.IndexOf("{loop}") + 6, tempHtml.IndexOf("{/loop}") - tempHtml.IndexOf("{loop}") - 6); chars = Regex.Split(propertyText, "{,}"); string realpropertyText = ""; foreach (string s in chars) { realpropertyText += loop.Replace("{left}", s.Substring(0, s.IndexOf(':'))).Replace("{right}", s.Substring(s.IndexOf(':') + 1, s.Length - s.IndexOf(':') - 1)); } Regex regex = new Regex("{loop}.*?{/loop}"); tempHtml = regex.Replace(tempHtml, realpropertyText); return(tempHtml); }