Asp.net源码专业站
首页->企业网站->中小企业网站系统前台源码(SmallBusinessStarterKit)>>App-Code/People/XmlPeopleProvider.cs>>源码在线查看
温馨提示:代码在线浏览功能只能做为源码浏览参考,如果想更进一步了解该代码请下载:中小企业网站系统前台源码(SmallBusinessStarterKit)
当前文件:文件类型 SmallBusinessStarterKit/App_Code/People/XmlPeopleProvider.cs[3K,2009-6-12 11:54:21]打开代码结构图
普通视图
		            
1using System; 2using System.Data; 3using System.Configuration; 4using System.Web; 5using System.Xml; 6using System.Xml.Schema; 7using System.IO; 8using System.Collections.Generic; 9/// <summary> 10/// 人员数据的XML数据提供者 11/// </summary> 12public class XmlPeopleProvider : PeopleProvider 13{ 14 private string _xmlFile; 15 private string _xsdFile; 16 /// <summary> 17 /// 公共构造函数,用于从Web.Config配置文件中获取Xml文件和Schema文件的路径 18 /// </summary> 19 public XmlPeopleProvider() 20 { 21 SmallBusinessDataProvidersSection sec = (ConfigurationManager.GetSection("SmallBusinessDataProviders")) as SmallBusinessDataProvidersSection; 22 string xmlFile = sec.PeopleProviders[sec.PeopleProviderName].Parameters["dataFile"]; 23 string xsdFile = sec.PeopleProviders[sec.PeopleProviderName].Parameters["schemaFile"]; 24 //将这两个文件的路径转换为相对路径并赋给私有变量_xmlFile和_xsdFile。 25 _xmlFile = HttpContext.Current.Request.MapPath("~/App_Data/" + xmlFile); 26 _xsdFile = HttpContext.Current.Request.MapPath("~/App_Data/schemas/" + xsdFile); 27 } 28 /// <summary> 29 /// 从XML文件中获取所有的人员数据列表。 30 /// </summary> 31 /// <returns></returns> 32 public override List<Person> GetAllPersons() 33 { 34 DataSet dataSet = Util.ReadAndValidateXml(_xmlFile, _xsdFile); 35 List<Person> personList = new List<Person>(); 36 //遍历数据表,用DataSet中的数据填充person实体对象。 37 foreach (DataTable t in dataSet.Tables) 38 { 39 foreach (DataRow r in t.Rows) 40 { 41 if (r["id"] is DBNull || r["visible"] is DBNull || r["firstName"] is DBNull || r["firstName"] is DBNull) 42 throw new InvalidOperationException(Messages.PersonRequiredAttributesMissing); 43 //(string)r["visible"] 44 Person curr = new Person((string)r["id"], (bool)r["visible"], (string)r["firstName"], (string)r["lastName"]); 45 curr.MiddleName = (r["middleName"] is DBNull) ? String.Empty : (string)r["middleName"]; 46 curr.Title = (r["title"] is DBNull) ? String.Empty : (string)r["title"]; 47 curr.Description = (r["description"] is DBNull) ? String.Empty : (string)r["description"]; 48 curr.Email = (r["email"] is DBNull) ? String.Empty : (string)r["email"]; 49 curr.Phone = (r["phone"] is DBNull) ? String.Empty : (string)r["phone"]; 50 curr.Fax = (r["fax"] is DBNull) ? String.Empty : (string)r["fax"]; 51 curr.StreetAddress = (r["streetAddress"] is DBNull) ? String.Empty : (string)r["streetAddress"]; 52 curr.City = (r["city"] is DBNull) ? String.Empty : (string)r["city"]; 53 curr.State = (r["state"] is DBNull) ? String.Empty : (string)r["state"]; 54 curr.PostalCode = (r["postalCode"] is DBNull) ? String.Empty : (string)r["postalCode"]; 55 curr.Country = (r["country"] is DBNull) ? String.Empty : (string)r["country"]; 56 curr.ImageUrl = (r["imageUrl"] is DBNull) ? String.Empty : (string)r["imageUrl"]; 57 curr.ImageAltText = (r["imageAltText"] is DBNull) ? String.Empty : (string)r["imageAltText"]; 58 //添加到泛型列表。 59 personList.Add(curr); 60 } 61 } 62 //返回该范型列表 63 return personList; 64 } 65} 66 67
还没有找到您心仪的内容?请用.net源码大搜捕
代码片断 打包下载该项目完整源码:中小企业网站系统前台源码(SmallBusinessStarterKit)
51Aspx.com 版权所有 CopyRight © 2006-2010. 京ICP备06046876号 本站法律顾问:ITlaw-庄毅雄律师
返回顶部
客户服务:点击这里进行客户咨询 业务合作:点击这里洽谈业务合作 合作热线:010-68880146