ylbtech-SilverLight-DataControls-PagedCollectionView:The PagedCollectionView(分页的集合视图) 对象
  • 1.A, Building  a Data Object(创建一个数据对象)
  • 1.B, Sorting(排序)
  • 1.C, Filtering(过滤)
  • 1.D, Grouping(分组)
  • 1.E, Paging(分页)
1.A, Building  a Data Object(创建一个数据对象)返回顶部

/Access/Product.cs

  1. using System;
  2.  
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.ComponentModel.DataAnnotations;
  6. namespace SLYlbtechApp.Access
  7. {
  8. /// <summary>
  9. /// 产品类
  10. /// </summary>
  11. public class Product
  12. {
  13. int productId;
  14. /// <summary>
  15. /// 编号【PK】
  16. /// </summary>
  17. public int ProductId
  18. {
  19. get { return productId; }
  20. set { productId = value; }
  21. }
  22. string productName;
  23. /// <summary>
  24. /// 产品名称
  25. /// </summary>
  26. public string ProductName
  27. {
  28. get
  29. {
  30. return productName;
  31. }
  32. set
  33. {
  34. if (value=="") throw new ArgumentException("不能为空");
  35. productName = value;
  36. }
  37. }
  38. string quantityPerUnit;
  39. /// <summary>
  40. /// 产品规格
  41. /// </summary>
  42. public string QuantityPerUnit
  43. {
  44. get { return quantityPerUnit; }
  45. set { quantityPerUnit = value; }
  46. }
  47. /// <summary>
  48. /// 单位价格
  49. /// 注意 不要使用 decimal 类型,在 UserControl.Resounrce 资源绑定是引发类型转换异常
  50. /// </summary>
  51. double unitPrice;
  52. [Display(Name="价格",Description="价格不能小于0")]
  53. public double UnitPrice
  54. {
  55. get { return unitPrice; }
  56. set
  57. {
  58. if (value < ) throw new ArgumentException("不能小于0");
  59. unitPrice = value;
  60. }
  61. }
  62. string description;
  63. /// <summary>
  64. /// 描述
  65. /// </summary>
  66. public string Description
  67. {
  68. get { return description; }
  69. set { description = value; }
  70. }
  71. string productImagePath;
  72. /// <summary>
  73. /// 产品图片地址
  74. /// </summary>
  75. public string ProductImagePath
  76. {
  77. get { return productImagePath; }
  78. set { productImagePath = value; }
  79. }
  80. string categoryName;
  81. /// <summary>
  82. /// 类别名称
  83. /// </summary>
  84. public string CategoryName
  85. {
  86. get { return categoryName; }
  87. set { categoryName = value; }
  88. }
  89. DateTime addedDate;
  90. /// <summary>
  91. /// 添加日期
  92. /// </summary>
  93. public DateTime AddedDate
  94. {
  95. get { return addedDate; }
  96. set { addedDate = value; }
  97. }
  98.  
  99. /// <summary>
  100. /// 空参构造
  101. /// </summary>
  102. public Product()
  103. {
  104. AddedDate = new DateTime(, , ); //设置默认日期
  105. }
  106. /// <summary>
  107. /// 全参构造
  108. /// </summary>
  109. /// <param name="productId"></param>
  110. /// <param name="productName"></param>
  111. /// <param name="quantityPerUnit"></param>
  112. /// <param name="unitPrice"></param>
  113. /// <param name="description"></param>
  114. /// <param name="productImagePath"></param>
  115. /// <param name="categoryName"></param>
  116. public Product(int productId, string productName, string quantityPerUnit, double unitPrice, string description
  117. , string productImagePath, string categoryName)
  118. {
  119. ProductId = productId;
  120. ProductName=productName;
  121. QuantityPerUnit=quantityPerUnit;
  122. UnitPrice=unitPrice;
  123. Description=description;
  124.  
  125. ProductImagePath=productImagePath;
  126. CategoryName=categoryName;
  127. }
  128.  
  129. /// <summary>
  130. /// 获取全部产品
  131. /// </summary>
  132. /// <returns></returns>
  133. public static IList<Product> GetAll()
  134. {
  135. IList<Product> dals = new List<Product>();
  136. string categoryName = string.Empty;
  137. string productImagePath = string.Empty;
  138. string description = "嗟夫!草木无情,有时飘零。人为动物,惟物之灵。百忧感其心,万事劳其形,有动于中,必摇其精。而况思其力之所不及,忧其智之所不能,宜其渥然丹者为槁木,黟然黑者为星星。奈何以非金石之质,欲与草木而争荣?念谁为之戕贼,亦何恨乎秋声!";
  139. #region Add Product
  140.  
  141. #region 饮料
  142. categoryName = "饮料";
  143. productImagePath = "../Images/pencil.jpg";
  144.  
  145. dals.Add(new Product()
  146. {
  147. ProductId = ,
  148. ProductName = "啤酒",
  149. QuantityPerUnit = "1箱*6听",
  150. UnitPrice = 10d,
  151. CategoryName = categoryName
  152. ,
  153. ProductImagePath = productImagePath,
  154. Description = description
  155. });
  156.  
  157. dals.Add(new Product()
  158. {
  159. ProductId = ,
  160. ProductName = "绿茶",
  161. QuantityPerUnit = "500ml",
  162. UnitPrice = 3d,
  163. CategoryName = categoryName
  164. ,
  165. ProductImagePath = productImagePath,
  166. Description = description
  167. });
  168.  
  169. dals.Add(new Product()
  170. {
  171. ProductId = ,
  172. ProductName = "红茶",
  173. QuantityPerUnit = "500ml",
  174. UnitPrice = 3d,
  175. CategoryName = categoryName
  176. ,
  177. ProductImagePath = productImagePath,
  178. Description = description
  179. });
  180. dals.Add(new Product()
  181. {
  182. ProductId = ,
  183. ProductName = "纯净水",
  184. QuantityPerUnit = "500ml",
  185. UnitPrice = 1.5d,
  186. CategoryName = categoryName
  187. ,
  188. ProductImagePath = productImagePath,
  189. Description = description
  190. });
  191. #endregion
  192.  
  193. #region 零食
  194. categoryName = "零食";
  195. productImagePath = "../Images/pencil2.jpg";
  196.  
  197. dals.Add(new Product()
  198. {
  199. ProductId = ,
  200. ProductName = "奥利奥巧克力饼干",
  201. QuantityPerUnit = "10 boxes x 20 bags",
  202. UnitPrice = 30d,
  203. CategoryName = categoryName
  204. ,
  205. ProductImagePath = productImagePath,
  206. Description = description
  207. });
  208.  
  209. dals.Add(new Product()
  210. {
  211. ProductId = ,
  212. ProductName = "玻璃 海苔",
  213. QuantityPerUnit = "20g",
  214. UnitPrice = 13d,
  215. CategoryName = categoryName
  216. ,
  217. ProductImagePath = productImagePath,
  218. Description = description
  219. });
  220.  
  221. dals.Add(new Product()
  222. {
  223. ProductId = ,
  224. ProductName = "好丽友 薯片",
  225. QuantityPerUnit = "100g",
  226. UnitPrice = 3d,
  227. CategoryName = categoryName
  228. ,
  229. ProductImagePath = productImagePath,
  230. Description = description
  231. });
  232. dals.Add(new Product()
  233. {
  234. ProductId = ,
  235. ProductName = "统一 老坛酸菜面",
  236. QuantityPerUnit = "1 盒",
  237. UnitPrice = 8.5d,
  238. CategoryName = categoryName
  239. ,
  240. ProductImagePath = productImagePath,
  241. Description = description
  242. });
  243. #endregion
  244.  
  245. #endregion
  246. return dals;
  247. }
  248. /// <summary>
  249. /// GetModel
  250. /// </summary>
  251. /// <returns></returns>
  252. public static Product GetModel()
  253. {
  254. Product dal = null;
  255.  
  256. string categoryName = string.Empty;
  257. string productImagePath = string.Empty;
  258. string description = "嗟夫!草木无情,有时飘零。人为动物,惟物之灵。百忧感其心,万事劳其形,有动于中,必摇其精。而况思其力之所不及,忧其智之所不能,宜其渥然丹者为槁木,黟然黑者为星星。奈何以非金石之质,欲与草木而争荣?念谁为之戕贼,亦何恨乎秋声!";
  259.  
  260. categoryName = "饮料";
  261. productImagePath = "Images/pencil.jpg";
  262. dal = new Product()
  263. {
  264. ProductId = ,
  265. ProductName = "啤酒",
  266. QuantityPerUnit = "1箱*6听",
  267. UnitPrice=3.5,
  268. CategoryName = categoryName
  269. ,
  270. ProductImagePath = productImagePath,
  271. Description = description
  272. };
  273. //dal._unitPrice = 10d;
  274. return dal;
  275. }
  276. /// <summary>
  277. /// GetModel
  278. /// </summary>
  279. /// <param name="id">产品编号</param>
  280. /// <returns></returns>
  281. public static Product GetModel(int id)
  282. {
  283. Product dal = null;
  284. IList<Product> dals = GetAll();
  285. try
  286. {
  287. dal = dals.Single(p => p.ProductId == id);
  288. }
  289. catch { }
  290. finally
  291. {
  292. dals = null;
  293. }
  294. return dal;
  295. }
  296. }
  297. }

4,

1.B, Sorting(排序)返回顶部
1,
2,
2.1/3,
  1. xmlns:data="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"

2.2/3,

  1. <Grid x:Name="LayoutRoot" Background="White">
  2. <Grid.RowDefinitions>
  3. <RowDefinition Height="*"></RowDefinition>
  4. <RowDefinition Height="30"></RowDefinition>
  5. </Grid.RowDefinitions>
  6. <data:DataGrid Grid.Row="0" x:Name="gridList" AutoGenerateColumns="False">
  7. <data:DataGrid.Columns>
  8. <data:DataGridTextColumn Header="Category Name" Binding="{Binding CategoryName}"></data:DataGridTextColumn>
  9. <data:DataGridTextColumn Header="Product Id" Binding="{Binding ProductId}"></data:DataGridTextColumn>
  10. <data:DataGridTextColumn Header="Product Name" Binding="{Binding ProductName}"></data:DataGridTextColumn>
  11. <data:DataGridTextColumn Header="UnitPrice" Binding="{Binding UnitPrice}" CanUserReorder="True"></data:DataGridTextColumn>
  12. <data:DataGridTextColumn Header="Added Date" Binding="{Binding AddedDate}"></data:DataGridTextColumn>
  13. </data:DataGrid.Columns>
  14. </data:DataGrid>
  15. </Grid>

2.3/3,

  1. using System.Windows.Controls;
  2.  
  3. using SLYlbtechApp.Access;
  4. using System.Windows.Data;
  5. namespace SLYlbtechApp.ThePagedCollectionView
  6. {
  7. public partial class Sorting : UserControl
  8. {
  9. public Sorting()
  10. {
  11. InitializeComponent();
  12.  
  13. PagedCollectionView view = new PagedCollectionView(Product.GetAll());
  14. //排序
  15. view.SortDescriptions.Add(new System.ComponentModel.SortDescription("UnitPrice"
  16. , System.ComponentModel.ListSortDirection.Ascending));
  17. view.SortDescriptions.Add(new System.ComponentModel.SortDescription("ProductId"
  18. , System.ComponentModel.ListSortDirection.Ascending)); //二次排序
  19. this.gridList.ItemsSource = view;
  20. }
  21. }
  22. }

3,

4,
1.C, Filtering(过滤)返回顶部
1,
2,
2.1/3, 同上文 B.2.1/3
2.2/3, 同上文 B.2.2/3
2.3/3,

  1. using System.Windows.Controls;
  2.  
  3. using SLYlbtechApp.Access;
  4. using System.Windows.Data;
  5. namespace SLYlbtechApp.ThePagedCollectionView
  6. {
  7. public partial class Filtering : UserControl
  8. {
  9. public Filtering()
  10. {
  11. InitializeComponent();
  12. PagedCollectionView view = new PagedCollectionView(Product.GetAll());
  13. //过滤集合
  14. view.Filter = delegate(object filterObject)
  15. {
  16. Product product = (Product)filterObject;
  17. return (product.CategoryName == "饮料"); //只显示 类别名称等于“饮料”的商品
  18. };
  19. this.gridList.ItemsSource = view;
  20. }
  21. }
  22. }

3,

4,
1.D Grouping(分组)返回顶部
1,
1.1/2, 一次分组
1.2/2,二次分组
2,
2.1/3, 同上文 B.2.1/3
2.2/3, 同上文 B.2.2/3
2.3/3,
  1. using System.Windows.Controls;
  2.  
  3. using SLYlbtechApp.Access;
  4. using System.Windows.Data;
  5. namespace SLYlbtechApp.ThePagedCollectionView
  6. {
  7. public partial class Grouping : UserControl
  8. {
  9. public Grouping()
  10. {
  11. InitializeComponent();
  12.  
  13. PagedCollectionView paged = new PagedCollectionView(Product.GetAll());
  14. //分组
  15. paged.GroupDescriptions.Add(new PropertyGroupDescription("CategoryName"));
  16. //paged.GroupDescriptions.Add(new System.Windows.Data.PropertyGroupDescription("UnitPrice")); //二次分组
  17. this.gridList.ItemsSource = paged;
  18. }
  19. }
  20. }

3,

4,
1.E, Paging(分页)返回顶部
1,
2,
2.1/3, 同上文 B.2.1/3
2.2/3,
  1. <Grid x:Name="LayoutRoot" ShowGridLines="True" Background="White">
  2. <Grid.RowDefinitions>
  3. <RowDefinition/>
  4. <RowDefinition Height="30"/>
  5. <RowDefinition Height="30"/>
  6. <RowDefinition Height="30"/>
  7. <RowDefinition Height="30"/>
  8. <RowDefinition Height="30"/>
  9. <RowDefinition Height="30"/>
  10. </Grid.RowDefinitions>
  11. <data:DataGrid x:Name="gridList" AutoGenerateColumns="False" Margin="3">
  12. <data:DataGrid.Columns>
  13. <data:DataGridTextColumn Header="Category Name" Binding="{Binding CategoryName}"></data:DataGridTextColumn>
  14. <data:DataGridTextColumn Header="Product Id" Binding="{Binding ProductId}"></data:DataGridTextColumn>
  15. <data:DataGridTextColumn Header="Product Name" Binding="{Binding ProductName}"></data:DataGridTextColumn>
  16. <data:DataGridTextColumn Header="UnitPrice" Binding="{Binding UnitPrice}" CanUserReorder="True"></data:DataGridTextColumn>
  17. <data:DataGridTextColumn Header="Added Date" Binding="{Binding AddedDate}"></data:DataGridTextColumn>
  18. </data:DataGrid.Columns>
  19. </data:DataGrid>
  20. <data:DataPager x:Name="pager" Grid.Row="1" Margin="3" IsTotalItemCountFixed="True"
  21. PageSize="5" DisplayMode="FirstLastNumeric" Source="{Binding ItemsSource, ElementName=gridList}"/>
  22. <data:DataPager x:Name="pager2" Grid.Row="2" Margin="3" IsTotalItemCountFixed="True"
  23. PageSize="5" Source="{Binding ItemsSource, ElementName=gridList}"/>
  24. <data:DataPager x:Name="pager3" Grid.Row="3" Margin="3" IsTotalItemCountFixed="True"
  25. PageSize="5" DisplayMode="FirstLastPreviousNextNumeric" Source="{Binding ItemsSource, ElementName=gridList}"/>
  26. <data:DataPager x:Name="pager4" Grid.Row="4" Margin="3" IsTotalItemCountFixed="True"
  27. PageSize="5" DisplayMode="Numeric" Source="{Binding ItemsSource, ElementName=gridList}"/>
  28. <data:DataPager x:Name="pager5" Grid.Row="5" Margin="3" IsTotalItemCountFixed="True"
  29. PageSize="5" DisplayMode="PreviousNext" Source="{Binding ItemsSource, ElementName=gridList}"/>
  30. <data:DataPager x:Name="pager6" Grid.Row="6" Margin="3" IsTotalItemCountFixed="True"
  31. PageSize="5" DisplayMode="PreviousNextNumeric" Source="{Binding ItemsSource, ElementName=gridList}"/>
  32. </Grid>

2.3/3,

  1. using System.Windows.Controls;
  2.  
  3. using SLYlbtechApp.Access;
  4. using System.Windows.Data;
  5. namespace SLYlbtechApp.ThePagedCollectionView
  6. {
  7. public partial class Paging : UserControl
  8. {
  9. public Paging()
  10. {
  11. InitializeComponent();
  12. //分页
  13. PagedCollectionView view = new PagedCollectionView(Product.GetAll());
  14. this.gridList.ItemsSource = view;
  15. }
  16. }
  17. }

3,

4,
1.F,返回顶部
 
作者:ylbtech
出处:http://ylbtech.cnblogs.com/
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

SilverLight-DataControls:四、The PagedCollectionView(分页的集合视图) 对象的更多相关文章

  1. 集合视图控制器(CollectionViewController) 、 标签控制器(TabBarController) 、 高级控件介绍

    1 创建集合视图,设置相关属性以满足要求 1.1 问题 集合视图控制器UIConllectionViewController是一个展示大量数据的控制器,系统默认管理着一个集合视图UICollectio ...

  2. UICollectionView 集合视图 的使用

    直接上代码: // // RootViewController.m // // #import "RootViewController.h" #import "Colle ...

  3. SQL Server -- 回忆笔记(四):case函数,索引,子查询,分页查询,视图,存储过程

    SQL Server知识点回忆篇(四):case函数,索引,子查询,分页查询,视图,存储过程 1. CASE函数(相当于C#中的Switch) then '未成年人' else '成年人' end f ...

  4. 【转载】MDX Step by Step 读书笔记(四) - Working with Sets (使用集合)

    1. Set  - 元组的集合,在 Set 中的元组用逗号分开,Set 以花括号括起来,例如: { ([Product].[Category].[Accessories]), ([Product].[ ...

  5. C# List 集合 交集、并集、差集、去重, 对象集合、 对象、引用类型、交并差补、List<T>

    关键词:C#  List 集合 交集.并集.差集.去重, 对象集合. 对象.引用类型.交并差.List<T> 有时候看官网文档是最高效的学习方式! 一.简单集合 Intersect 交集, ...

  6. day 68 django 之api操作 | jQueryset集合与对象

    我们的orm里面分为: jQueryset集合, 还有对象, 我们的jqueryset集合里面可以有多个对象,这句话的意思就是我们的对象是最小的单位,不可以再拆分了,我们的jQueryset集合就相当 ...

  7. 对象转型、迭代器Iterator、Set集合、装箱与拆箱、基本数据类型与字符串的转换、TreeSet集合与对象

      包的声明与定义 需要注意的是,包的声明只能位于Java源文件的第一行. 在实际程序开发过程中,定义的类都是含有包名的: 如果没有显式地声明package语句,创建的类则处于默认包下: 在实际开发中 ...

  8. Java基础 - Map接口的实现类 : HashedMap / LinkedHashMap /TreeMap 的构造/修改/遍历/ 集合视图方法/双向迭代输出

    Map笔记: import java.util.*; /**一:Collection接口的 * Map接口: HashMap(主要实现类) : HashedMap / LinkedHashMap /T ...

  9. UICollectionView(集合视图)以及自定义集合视图

    一.UICollectionView集合视图           其继承自UIScrollView.         UICollectionView类是iOS6新引进的API,用于展示集合视图,布局 ...

随机推荐

  1. 装饰器与lambda

    装饰器 实际上理解装饰器的作用很简单,在看core python相关章节的时候大概就是这种感觉.只是在实际应用的时候,发现自己很难靠直觉决定如何使用装饰器,特别是带参数的装饰器,于是摊开来思考了一番, ...

  2. activity-alias

    activity-alias标签,它有一个属性叫android:targetActivity,这个属性就是用来为该标签设置目标Activity的,或者说它就是这个目标Activity的别名.至此我们已 ...

  3. 安装python包

    开始--cmd pip install pymongo 直到最后给出提示successfull install pymongo-**(版本号,最新的)

  4. 合并Excel工作薄中成绩表的VBA代码,非常适合教育一线的朋友_python

    这时候还需要把各个工作表合并到一起来形成一个汇总表.这时候比较麻烦也比较容易出错,因为各个表的学号不一定都是一致的.对齐的.因为可能会有人缺考,有人会考号涂错等等.特奉献以下代码,用于合并学生成绩表或 ...

  5. Jeddict:怎样在window系统下,成功打包Angular

    在Jeddict的应用过程中,发现了一个问题.如果前端视图选择Angular(具体版本,需要根据插件版本确定.此处理解为非Angular JS),那么在自动构建的过程中,会发现,每当在安装NodeJS ...

  6. Jeddict研究过程中的总结

    一.与作者交流的总结 说来也是惭愧,没有太多的经验,先给大家贴两张图,看看大家能不能发现问题: 在最开始的时候,都处于Gaurav Gupta让我给材料的过程,因为我不是缺这个就是缺那个,根本说不清楚 ...

  7. 【转】PhpStorm 提交代码到远程GitHub仓库

    转载地址:http://my.oschina.net/lujianing/blog/180728 1.下载github for window http://windows.github.com/ 2. ...

  8. [luoguP3302] [SDOI2013]森林(主席树 + 启发式合并 + lca)

    传送门 显然树上第k大直接主席树 如果连边的话,我们重构小的那一棵,连到另一棵上. 说起来简单,调了我一晚上. 总的来说3个错误: 1.离散化写错位置写到了后面 2."="写成了& ...

  9. BZOJ1227 [SDOI2009]虔诚的墓主人 【树状数组】

    题目 小W 是一片新造公墓的管理人.公墓可以看成一块N×M 的矩形,矩形的每个格点,要么种着一棵常青树,要么是一块还没有归属的墓地.当地的居民都是非常虔诚的基督徒,他们愿意提前为自己找一块合适墓地.为 ...

  10. JS实现并集,交集和差集

    var set1 = new Set([1,2,3]);var set2 = new Set([2,3,4]); 并集let union = new Set([...set1, ...set2]); ...