1,给页面中的标签增加css的样式
2,使用jsrender 进行页面渲染 前台页面写法
1
- 2
3,后台常用分页
1 #region 替换指定的字符串 2 ///3 /// 替换指定的字符串 4 /// 5 /// 原字符串 6 /// 旧字符串 7 /// 新字符串 8 ///9 public static string ReplaceStr(string originalStr, string oldStr, string newStr) 10 { 11 if (string.IsNullOrEmpty(oldStr)) 12 { 13 return ""; 14 } 15 return originalStr.Replace(oldStr, newStr); 16 } 17 #endregion 18 19 20 21 22 23 /// 返回分页页码 24 /// 25 /// 页面大小 26 /// 当前页 27 /// 总记录数 28 /// 链接地址,__id__代表页码 29 /// 中间页码数量 30 /// 31 public static string OutPageList2(int pageSize, int pageIndex, int totalCount, string linkUrl, int centSize) 32 { 33 //计算页数 34 if (totalCount < 1 || pageSize < 1) 35 { 36 return ""; 37 } 38 int pageCount = totalCount / pageSize; 39 if (pageCount < 1) 40 { 41 return ""; 42 } 43 if (totalCount % pageSize > 0) 44 { 45 pageCount += 1; 46 } 47 if (pageCount <= 1) 48 { 49 return ""; 50 } 51 StringBuilder pageStr = new StringBuilder(); 52 string pageId = "__id__"; 53 string firstBtn = "«上一页"; 54 string lastBtn = "下一页»"; 55 string firstStr = "1"; 56 string lastStr = "" + pageCount.ToString() + ""; 57 58 if (pageIndex <= 1) 59 { 60 firstBtn = "«上一页"; 61 } 62 if (pageIndex >= pageCount) 63 { 64 lastBtn = "下一页»"; 65 } 66 if (pageIndex == 1) 67 { 68 firstStr = "1"; 69 } 70 if (pageIndex == pageCount) 71 { 72 lastStr = "" + pageCount.ToString() + ""; 73 } 74 int firstNum = pageIndex - (centSize / 2); //中间开始的页码 75 if (pageIndex < centSize) 76 firstNum = 2; 77 int lastNum = pageIndex + centSize - ((centSize / 2) + 1); //中间结束的页码 78 if (lastNum >= pageCount) 79 lastNum = pageCount - 1; 80 pageStr.Append("共" + totalCount + "记录"); 81 pageStr.Append(firstBtn + firstStr); 82 if (pageIndex >= centSize) 83 { 84 pageStr.Append("...\n"); 85 } 86 for (int i = firstNum; i <= lastNum; i++) 87 { 88 if (i == pageIndex) 89 { 90 pageStr.Append("" + i + ""); 91 } 92 else 93 { 94 pageStr.Append("" + i + ""); 95 } 96 } 97 if (pageCount - pageIndex > centSize - ((centSize / 2))) 98 { 99 pageStr.Append("...");100 }101 pageStr.Append(lastStr + lastBtn);102 103 return " " + pageStr.ToString()+"";104 }105 #endregion
4,dtcms 后台,加载详情页,可以写你想要的任何的东西,之后前台绑定
1 /// 显示房源详情 2 /// 3 public partial class house_show : Web.UI.BasePage 4 { 5 protected string id; 6 protected string house_type = "0"; 7 ///8 /// 热门搜索 9 /// 10 /// 11 12 13 protected Listhot_words = new List (); 14 15 protected EFModel.trm_f_house model = new EFModel.trm_f_house(); 16 protected EFModel.tsm_b_estate_dict dict = new EFModel.tsm_b_estate_dict(); 17 /// 18 /// 图片列表 19 /// 20 protected Listpic_paths = new List (); 21 /// 22 /// 房源标签 23 /// 24 protected Listsell_points = new List (); 25 /// 26 /// 房屋配套 27 /// 28 protected Listhouse_matchings = new List (); 29 /// 30 /// 同小区房源 31 /// 32 protected Listestate_houses = new List (); 33 /// 34 /// 小区成交历史 35 /// 36 protected Listdealed_houses = new List (); 37 /// 38 /// 浏览过的房源 39 /// 40 protected Listbrowsed_houses = new List (); 41 /// 42 /// 猜您喜欢的房源 43 /// 44 protected Listlike_houses = new List (); 45 46 protected override void ShowPage() 47 { 48 id = DTRequest.GetString("id"); 49 id = id.Replace("_", "-"); 50 EFModel.ChlWebEntities ent = new EFModel.ChlWebEntities(); 51 52 model = ent.trm_f_house.SingleOrDefault(w => w.HOUSE_CODE == id && w.STATUS == "A"); 53 if (model == null) 54 { 55 HttpContext.Current.Response.Redirect(linkurl("error", "?msg=" + Utils.UrlEncode("出错啦,您要浏览的房源不存在或已删除!"))); 56 return; 57 } 58 else 59 { 60 ChlWebEntities efmodel = new ChlWebEntities(); 61 62 63 64 //model 的看过的次数加一 65 if (model.HOUSE_CLICK_NUM == null) 66 { 67 model.HOUSE_CLICK_NUM = 1; 68 } 69 else 70 { 71 model.HOUSE_CLICK_NUM += 1; 72 } 73 74 // efmodel.Attach(model); 75 //efmodel.ObjectStateManager.ChangeObjectState(model, EntityState.Modified); 76 efmodel.SaveChanges(); 77 78 79 } 80 81 82 //增加点击量 HOUSE_CLICK_NUM 83 //保存用户查看记录trm_f_house_view 用于统计用户浏览量及喜欢的房源 84 //记录用户查看的房源的关键信息trm_f_cust_like,用于统计用户浏览量及喜欢的房源 85 86 //列出热门搜索 87 hot_words = ent.tsm_b_keywrod.Where(w => w.HOUSE_TYPE == "1").OrderByDescending(w => w.SEARCH_SUM).Select(w => w.KEYWORDS).Take(3).ToList(); 88 89 //列出房源的图片列表 90 var list = from r in ent.tpm_s_pic_rel 91 join p in ent.tpm_s_pic 92 on r.PICTURE_CODE equals p.PICTURE_CODE 93 where r.STATUS == "A" && p.STATUS == "A" && r.CODE == model.HOUSE_CODE 94 select new 95 { 96 PIC_PATH = p.PICTURE_PATH 97 }; 98 pic_paths = list.Select(w => w.PIC_PATH).ToList (); 99 100 //列出房源的卖点特色101 string[] arrs = null;102 if (!String.IsNullOrEmpty(model.SELL_POINTS))103 {104 arrs = model.SELL_POINTS.Split(new char[] { ',' });105 if (arrs != null)106 {107 foreach (string item in arrs)108 {109 var pmodel = ent.tpm_s_param.SingleOrDefault(w => w.TAB_NAME == "TRM_F_HOUSE" && w.COL_CODE == "SELL_POINTS" && w.COL_VALUE_CODE == item);110 if (pmodel != null)111 sell_points.Add(pmodel.COL_VALUE_NAME);112 if (sell_points.Count > 4)113 break;114 }115 }116 }117 //列出房源的配套118 if (!String.IsNullOrEmpty(model.HOUSE_MATCHING))119 {120 arrs = model.HOUSE_MATCHING.Split(new char[] { ',' });121 if (arrs != null)122 {123 foreach (string item in arrs)124 {125 var pmodel = ent.tpm_s_param.SingleOrDefault(w => w.TAB_NAME == "TRM_F_HOUSE" && w.COL_CODE == "HOUSE_MATCHING" && w.COL_VALUE_CODE == item);126 if (pmodel != null)127 house_matchings.Add(pmodel.COL_VALUE_NAME);128 if (house_matchings.Count > 5)129 break;130 }131 }132 }133 //列出同小区房源(除本身外)134 if (!String.IsNullOrEmpty(model.ESTATE_CODE))135 {136 dict = ent.tsm_b_estate_dict.SingleOrDefault(w => w.ESTATE_CODE == model.ESTATE_CODE);137 estate_houses = ent.trm_f_house.Where(w => w.ESTATE_CODE == model.ESTATE_CODE && w.STATUS == "A" && w.HOUSE_TYPE == "1" && w.PIC_SHOW_PATH != "" && w.HOUSE_CODE != model.HOUSE_CODE).OrderByDescending(w => w.UPDATE_TIME).Take(5).ToList();138 }139 //列出已成交房源140 dealed_houses = ent.trm_f_house.Where(w => w.ESTATE_CODE == model.ESTATE_CODE && w.HOUSE_STATUS == "2" && w.HOUSE_TYPE == "1").OrderByDescending(w => w.UPDATE_TIME).Take(12).ToList();141 //浏览过的房源(需要处理)142 browsed_houses = estate_houses;143 //喜欢的房源144 like_houses = estate_houses;145 }146 }147 }
5,dtcms 前台数据绑定
{model.AREA_CODESTR}
<!--foreach循环标签--> <%foreach(string pic_pathitem in pic_paths)%> <div class="item"> <img src="{pic_pathitem}" /></div> <%/foreach%>