知识大全 网购系统——用户界面层公共函数集WebUtility
Posted 函数
篇首语:业无高卑志当坚,男儿有求安得闲?本文由小常识网(cha138.com)小编为大家整理,主要介绍了知识大全 网购系统——用户界面层公共函数集WebUtility相关的知识,希望对你有一定的参考价值。
网购系统——用户界面层公共函数集WebUtility 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
频繁的数据库操作 需要一个公共的数据库操作函数集(DBUtility中的SQLHelper cs) 频繁的用户界面操作 也需要一个公共函数集WebUtility cs 因为频繁 这个类及类中的函数 也做成了静态的 一 App_Code中添加类WebUtility cs 并在类中添加函数GetCategoryName() [csharp] using System; using System Configuration; using System Web; using System Web Caching; using WestGarden DAL; namespace WestGarden Web public static class WebUtility private const string CATEGORY_NAME_KEY = category_name_ ; private static readonly bool enableCaching = bool Parse(ConfigurationManager AppSettings[ EnableCaching ]) public static string GetCategoryName(string categoryId) Category category = new Category() if (!enableCaching) return category GetCategory(categoryId) Name; string cacheKey = string Format(CATEGORY_NAME_KEY categoryId) string data = (string)HttpRuntime Cache[cacheKey]; if (data == null) int cacheDuration = int Parse(ConfigurationManager AppSettings[ CategoryCacheDuration ]) data = category GetCategory(categoryId) Name; HttpRuntime Cache Add(cacheKey data null DateTime Now AddHours(cacheDuration) Cache NoSlidingExpiration CacheItemPriority High null) return data; using System; using System Configuration; using System Web; using System Web Caching; using WestGarden DAL; namespace WestGarden Web public static class WebUtility private const string CATEGORY_NAME_KEY = category_name_ ; private static readonly bool enableCaching = bool Parse(ConfigurationManager AppSettings[ EnableCaching ]) public static string GetCategoryName(string categoryId) Category category = new Category() if (!enableCaching) return category GetCategory(categoryId) Name; string cacheKey = string Format(CATEGORY_NAME_KEY categoryId) string data = (string)HttpRuntime Cache[cacheKey]; if (data == null) int cacheDuration = int Parse(ConfigurationManager AppSettings[ CategoryCacheDuration ]) data = category GetCategory(categoryId) Name; HttpRuntime Cache Add(cacheKey data null DateTime Now AddHours(cacheDuration) Cache NoSlidingExpiration CacheItemPriority High null) return data; 这个函数功能是获取类别名称 获取类别需要进行一下判断 如果允许Cache缓存 就从Cache中获取 如果不允许 就从数据库中查询 因些 使用这个函数需要在nfig中添加两个设置 是否允许Cache以及Cache的生命期 [csharp] <add key= EnableCaching value= true /> <add key= CategoryCacheDuration value= /> <add key= EnableCaching value= true /> <add key= CategoryCacheDuration value= /> 这个函数如果从数据库进行查询 需要调用DAL中的GetCategory()函数 为此 需要在Category cs中添加函数GetCategory() [csharp] public CategoryInfo GetCategory(string categoryId) CategoryInfo category = null; SqlParameter parm = new SqlParameter(Parm_CATEGORY_ID SqlDbType VarChar ) parm Value = categoryId; using (SqlDataReader rdr = SqlHelper ExecuteReader(SqlHelper ConnectionStringLocalTransaction CommandType Text SQL_SELECT_CATEGORIES parm)) if (rdr Read()) category = new CategoryInfo(rdr GetString( ) rdr GetString( ) rdr GetString( )) else category = new CategoryInfo() return category; public CategoryInfo GetCategory(string categoryId) CategoryInfo category = null; SqlParameter parm = new SqlParameter(Parm_CATEGORY_ID SqlDbType VarChar ) parm Value = categoryId; using (SqlDataReader rdr = SqlHelper ExecuteReader(SqlHelper ConnectionStringLocalTransaction CommandType Text SQL_SELECT_CATEGORIES parm)) if (rdr Read()) category = new CategoryInfo(rdr GetString( ) rdr GetString( ) rdr GetString( )) else category = new CategoryInfo() return category; 二 Web添加母版MasterPage master 窗体页代码 [] <%@ Master Language= C# AutoEventWireup= true CodeFile= MasterPage master cs Inherits= WestGarden Web MasterPage %> <%@ Register Src= Controls/NavigationControl ascx TagName= NavigationControl TagPrefix= WestGardenControl %> <!DOCTYPE PUBLIC //W C//DTD XHTML //EN > < xmlns= > <head runat= server > <title>The NET Pet Shop</title> </head> <body> <form id= form runat= server > <asp:Panel ID= panFocus runat= server DefaultButton= btnSearch > <table align= center border= cellpadding= cellspacing= width= > <tr valign= top > <td rowspan= > <img src= Images/Comm_Images/Logo_home jpg alt= home /></td> <td class= homeBgSearch height= width= > <asp:TextBox ID= txtSearch runat= server CssClass= homeSearchBox Width= px ></asp:TextBox></td> <td class= homeBgSearch width= > <asp:ImageButton ID= btnSearch runat= server AlternateText= Search CausesValidation= false CssClass= paddingSearchicon ImageUrl= Images/Comm_Images/button search gif /></td> <td class= homeBgSearch width= > <asp:LoginStatus ID= lgnStatus runat= server CssClass= homeLink LoginText= 登 录 LogoutAction= Redirect LogoutPageUrl= ~/Default aspx LogoutText= 退 出 /> </td> <td width= > </td> </tr> <tr> <td colspan= > <img src= Images/Comm_Images/KFC JPG /></td> <td width= > </td> </tr> </table> </asp:Panel> <table align= center border= cellpadding= cellspacing= width= > <tr> <td colspan= > <img src= Images/Comm_Images/spacer gif height= /></td> </tr> <tr> <td > </td> <td width= > </td> <td width= > </td> <td width= > </td> </tr> <tr> <td > </td> <td> </td> <td class= pageHeader > <asp:Literal ID= ltlHeader runat= server ></asp:Literal> </td> <td> </td> </tr> <tr> <td > </td> <td > </td> <td class= dottedLine > </td> <td > </td> </tr> <tr> <td valign= top > </td> <td valign= top > <WestGardenControl:NavigationControl ID= Categories runat= server ></WestGardenControl:NavigationControl> </td> <td bgcolor= #FFFFFF valign= top > <asp:ContentPlaceHolder ID= cphPage runat= server > </asp:ContentPlaceHolder> </td> <td height= > </td> </tr> <tr> <td > </td> <td> </td> <td class= footer > <table width= % > <tr> <td > <td align= right > <a _blank > </tr> </table> </td> <td> </td> </tr> </table> </form> </body> </> <%@ Master Language= C# AutoEventWireup= true CodeFile= MasterPage master cs Inherits= WestGarden Web MasterPage %> <%@ Register Src= Controls/NavigationControl ascx TagName= NavigationControl TagPrefix= WestGardenControl %> <!DOCTYPE PUBLIC //W C//DTD XHTML //EN > < xmlns= > <head runat= server > <title>The NET Pet Shop</title> </head> <body> <form id= form runat= server > <asp:Panel ID= panFocus runat= server DefaultButton= btnSearch > <table align= center border= cellpadding= cellspacing= width= > <tr valign= top > <td rowspan= > <img src= Images/Comm_Images/Logo_home jpg alt= home /></td> <td class= homeBgSearch height= width= > <asp:TextBox ID= txtSearch runat= server CssClass= homeSearchBox Width= px ></asp:TextBox></td> <td class= homeBgSearch width= > <asp:ImageButton ID= btnSearch runat= server AlternateText= Search CausesValidation= false CssClass= paddingSearchicon ImageUrl= Images/Comm_Images/button search gif /></td> <td class= homeBgSearch width= > <asp:LoginStatus ID= lgnStatus runat= server CssClass= homeLink LoginText= 登 录 LogoutAction= Redirect LogoutPageUrl= ~/Default aspx LogoutText= 退 出 /> </td> <td width= > </td> </tr> <tr> <td colspan= > <img src= Images/Comm_Images/KFC JPG /></td> <td width= > </td> </tr> </table> </asp:Panel> <table align= center border= cellpadding= cellspacing= width= > <tr> <td colspan= > <img src= Images/Comm_Images/spacer gif height= /></td> </tr> <tr> <td > </td> <td width= > </td> <td width= > </td> <td width= > </td> </tr> <tr> <td > </td> <td> </td> <td class= pageHeader > <asp:Literal ID= ltlHeader runat= server ></asp:Literal> </td> <td> </td> </tr> <tr> <td > </td> <td > </td> <td class= dottedLine > </td> <td > </td> </tr> <tr> <td valign= top > </td> <td valign= top > <WestGardenControl:NavigationControl ID= Categories runat= server ></WestGardenControl:NavigationControl> </td> <td bgcolor= #FFFFFF valign= top > <asp:ContentPlaceHolder ID= cphPage runat= server > </asp:ContentPlaceHolder> </td> <td height= > </td> </tr> <tr> <td > </td> <td> </td> <td class= footer > <table width= % > <tr> <td > <td align= right > <a _blank > </tr> </table> </td> <td> </td> </tr> </table> </form> </body> </> 代码页代码 [csharp] using System; using System Web; using System Web UI WebControls; namespace WestGarden Web public partial class MasterPage : System Web UI MasterPage private const string HEADER_PREFIX = 肯德基订餐系统 西园工作室 :: ; protected void Page_PreRender(object sender EventArgs e) ltlHeader Text = Page Header Title; Page Header Title = string Format(HEADER_PREFIX Page Header Title) using System; using System Web; using System Web UI WebControls; namespace WestGarden Web public partial class MasterPage : System Web UI MasterPage private const string HEADER_PREFIX = 肯德基订餐系统 西园工作室 :: ; protected void Page_PreRender(object sender EventArgs e) ltlHeader Text = Page Header Title; Page Header Title = string Format(HEADER_PREFIX Page Header Title) 三 为已建窗体Items aspx应用母版 并在后台添加代码 设置窗体标题 应用母版代码 [] <%@ Page Language= C# MasterPageFile= ~/MasterPage master AutoEventWireup= true CodeFile= Items aspx cs Inherits= WestGarden Web Items %> <%@ Register Src= Controls/ItemssControl ascx TagName= ItemsControl TagPrefix= WestGardenControl %> <asp:Content ID= cntPage ContentPlaceHolderID= cphPage runat= Server EnableViewState= false > <WestGardenControl:ItemsControl ID= ItemsControl runat= server /> </asp:Content> <%@ Page Language= C# MasterPageFile= ~/MasterPage master AutoEventWireup= true CodeFile= Items aspx cs Inherits= WestGarden Web Items %> <%@ Register Src= Controls/ItemssControl ascx TagName= ItemsControl TagPrefix= WestGardenControl %> <asp:Content ID= cntPage ContentPlaceHolderID= cphPage runat= Server EnableViewState= false > <WestGardenControl:ItemsControl ID= ItemsControl runat= server /> </asp:Content> 设置窗体标题代码 [csharp] using WestGarden DAL; namespace WestGarden Web public partial class Items : System Web UI Page protected void Page_Load(object sender EventArgs e) Page Title = WebUtility GetCategoryName(Request QueryString[ categoryId ]) cha138/Article/program/net/201311/13079相关参考
PHP取得用户浏览器和系统函数 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! //操作系统fun
近年来,我国网上购物市场日趋繁荣。目前我国网购用户已达1,61亿,交易总额超过5000亿元,网购带动了仓储、快递等相关产
近年来,我国网上购物市场日趋繁荣。目前我国网购用户已达1,61亿,交易总额超过5000亿元,网购带动了仓储、快递等相关产业的迅速发展,这表明:_____A、居民的消费结构不断改善B、居民的消费心理发生
.NET中三层构架开发实例-用户注册系统 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!下面是用户注
Asp文件操作函数集 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! <%=========
DateTime数字型 SystemDateTimecurrentTime=newSystemDateTime(); 取当前年月日时分秒 currentTime=SystemDateTi
C#.NET常用的小函数方法集 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧! DateTime
ASP.NET中经常用到的27个函数集 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!第一种方法
DateTime 数字型 SystemDateTimecurrentTime=newSy
PHPWeb开发学习实录:用户自定义函数实例描述 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!
PHPWeb开发学习实录:用户自定义函数实例应用 以下文字资料是由(全榜网网www.cha138.com)小编为大家搜集整理后发布的内容,让我们赶快一起来看一下吧!