Silverlight——施工计划日报表(二)
近来一直在加班,基本上没有个人时间。所以更新不会很即时。
长话短说,先从界面代码开始吧。界面代码很简单,如下所示:
<UserControl xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" x:Class="PlansView.ShowPlans"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:BubbleCremeTheme="System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.BubbleCremeTheme"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="400" Loaded="UserControl_Loaded">
<toolkit:BubbleCremeTheme>
<StackPanel Name="stackPanel1" FlowDirection="LeftToRight" HorizontalAlignment="Left">
<StackPanel Orientation="Vertical">
<TextBlock Height="23" Name="txtTitle" HorizontalAlignment="Center" Text="标题" FontSize="18" FontWeight="Bold" Opacity="0.7" RenderTransformOrigin="0.5,0.5" >
<TextBlock.RenderTransform>
<CompositeTransform/>
</TextBlock.RenderTransform>
<TextBlock.Foreground>
<LinearGradientBrush EndPoint="0.5,1" MappingMode="RelativeToBoundingBox" StartPoint="0.5,0">
<GradientStop Color="Black" Offset="1"/>
<GradientStop Color="#FFE49C9C"/>
</LinearGradientBrush>
</TextBlock.Foreground>
</TextBlock>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right"> <Button Content="一键标记为完成" Name="btnFilishAll" Width="130" Margin="5,0,5,0" Click="btnFilishAll_Click" />
<Button Content="全屏" Name="BtnFullScreen" Width="100" Margin="5,0,5,0" Click="BtnFullScreen_Click" />
<Button Content="提交" Name="btnSubmit" Width="100" Click="Button_Click" Margin="5,0,5,0"/>
</StackPanel>
<ScrollViewer HorizontalContentAlignment="Left" HorizontalAlignment="Left" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" MaxHeight="513">
<ScrollViewer.BorderBrush>
<LinearGradientBrush EndPoint="0.5,1.5" StartPoint="0.5,0">
<GradientStop Color="#FFE0E3BC"/>
<GradientStop Color="#FF6C6C5C" Offset="1"/>
</LinearGradientBrush>
</ScrollViewer.BorderBrush>
<Border BorderBrush="#FF333333" BorderThickness="2" Background="#FFC1C1C1" >
<Grid x:Name="gdPlans" Background="#FFC1C1C1" MouseRightButtonDown="gdPlans_MouseRightButtonDown"> </Grid>
</Border>
</ScrollViewer>
</StackPanel>
</StackPanel>
</toolkit:BubbleCremeTheme>
</UserControl>
值得注意的是,这里用到了Silverlight 4.0工具包里面的BubbleCremeTheme主题。在使用的时候,注意引用,如“xmlns:BubbleCremeTheme="System.Windows.Controls.Theming;assembly=System.Windows.Controls.Theming.BubbleCremeTheme"”。然后需要注意的是,使用了ScrollViewer 实现滚动条,在ScrollViewer 里面放了一个Border 控件,用于绘制边框。在Border 控件里面,用到了Grid 控件。所有的数据都是基于Grid 控件生成的。
界面元素定义好了。接下来如下公共属性:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
#region 公共属性 /// <summary> /// 日期格式(day、week、month) /// </summary> public string DateType { get; set; } /// <summary> /// 行号 /// </summary> public int RowIndex { get; set; } /// <summary> /// 开始时间 /// </summary> public DateTime StartDate { get; set; } /// <summary> /// 设置日期列数 /// </summary> public int DateColCount { get; set; } /// <summary> /// 文本列列数 /// </summary> public int NameColumns { get; set; } /// <summary> /// 计划列头 /// </summary> public string[] PlanHeads { get; set; } /// <summary> /// 日期列背景色 /// </summary> public Color DayBackGroundColor { get; set; } /// <summary> /// 数据 /// </summary> List<PlansData> LstPlansData { get; set; } /// <summary> /// 是否已经显示设置完成的提示 /// </summary> public bool HasShowSetFilishTip { get; set; } Dictionary<string, string> dicInitParams; //行背景(用于时间段) private static List<ImageBrush> RowBackGroundLst; private ImageBrush FilishImageBrush; /// <summary> /// 周的日数(默认7) /// </summary> int _weekDayCount; #endregion |
|
1
|
属性定义好了,那么这些值是怎么传递过来的呢?使用的是InitParams。如下面代码: |
|
1
|
|
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
public ShowPlans(){ try { InitializeComponent(); SetInitialValue(); #region 设置显示的时间段 if (DateType == "day" && txtTitle.Text.Length > 0) { txtTitle.Text += string.Format("({0}~{1})", StartDate.ToShortDateString(), StartDate.AddDays(DateColCount).ToShortDateString()); } #endregion } catch (Exception ex) { MessageBox.Show("参数初始化出错:" + ex.Message, "错误", MessageBoxButton.OK); }}#region 参数初始化/// <summary>/// 数据初始化/// StartDate:开始日期,默认为当前时间/// DateType:日期类型,可选值为(day、week、month),默认为day/// DateColCount:日期列数,day默认为30,week默认为10,month默认为12/// Title:标题/// PlanHeads:文字标头,多列需用“;”分隔。值需用Url编码。/// Data:数据。格式为Json,需用Url编码。映射的类为PlansData。/// DayBackGroundColor:日期列背景色/// WeekDayCount:周涵盖的天数(默认7)/// OnlyResponseHasEdit:仅仅只输出编辑项/// </summary>private void SetInitialValue(){ RowIndex = 0; #region 设置默认值 StartDate = DateTime.Now; DateColCount = 30; DateType = "day"; NameColumns = 1; DayBackGroundColor = Colors.White; HasShowSetFilishTip = false; #region 图片画刷 RowBackGroundLst = new List<ImageBrush>() { new ImageBrush() { ImageSource=new BitmapImage(new Uri("plink.png", UriKind.Relative)) }, new ImageBrush() { ImageSource=new BitmapImage(new Uri("blue.png", UriKind.Relative)) }, new ImageBrush() { ImageSource=new BitmapImage(new Uri("red.png", UriKind.Relative)) }, new ImageBrush() { ImageSource=new BitmapImage(new Uri("green.png", UriKind.Relative)) }, }; FilishImageBrush = new ImageBrush() { ImageSource = new BitmapImage(new Uri("red.png", UriKind.Relative)) }; #endregion #endregion #region 设置初始化参数 dicInitParams = App.Current.Host.InitParams as Dictionary<string, string>; if (dicInitParams != null && dicInitParams.Count > 0) { //标题 if (dicInitParams.ContainsKey("Title")) txtTitle.Text = dicInitParams["Title"] ?? string.Empty; else txtTitle.Visibility = Visibility.Collapsed; //设置开始日期 if (dicInitParams.ContainsKey("StartDate")) StartDate = Convert.ToDateTime(dicInitParams["StartDate"]); //周涵盖天数(仅当DateType=week时启用) _weekDayCount = 7; //日期列背景色 if (dicInitParams.ContainsKey("DayBackGroundColor")) DayBackGroundColor = ReturnColorFromString(dicInitParams["DayBackGroundColor"]); //日期类型 if (dicInitParams.ContainsKey("DateType")) { DateType = dicInitParams["DateType"]; if (DateType == "week") { if (!dicInitParams.ContainsKey("DateColCount")) { DateColCount = 10; } if (dicInitParams.ContainsKey("WeekDayCount")) { _weekDayCount = Convert.ToInt32(dicInitParams["WeekDayCount"]); } } else if (DateType == "month") { if (!dicInitParams.ContainsKey("DateColCount")) { DateColCount = 12; } } } //日期列列数 if (dicInitParams.ContainsKey("DateColCount")) DateColCount = Convert.ToInt32(dicInitParams["DateColCount"]); //文本列列头 if (dicInitParams.ContainsKey("PlanHeads")) { PlanHeads = HttpUtility.UrlDecode(dicInitParams["PlanHeads"]).Split(';'); NameColumns = PlanHeads.Length; } #endregion } else { MessageBox.Show("启动参数未设置"); }}#endregion |
参数设置好了,但是数据还没有呢?在上一篇——《Silverlight——施工计划日报表(一)》中介绍过数据类了。首先在Silverlight项目中定义PlansData类,具体属性如下:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
|
using System;using System.Collections.Generic;namespace PlansView{ /// <summary> /// 数据 /// </summary> public class PlansData { public List<Plan> LstPlan { get; set; } /// <summary> /// 计划时间集合 /// </summary> public List<PlanDate> LstPlanDate { get; set; } } /// <summary> /// 计划 /// </summary> public class Plan { /// <summary> /// 计划名称 /// </summary> public string PlanName { get; set; } } /// <summary> /// 计划日期 /// </summary> public class PlanDate { /// <summary> /// 说明 /// </summary> public string Explain { get; set; } /// <summary> /// 开始时间 /// </summary> public DateTime? StartDate { get; set; } /// <summary> /// 结束时间 /// </summary> public DateTime? EndDate { get; set; } /// <summary> /// 允许的最小值 /// </summary> public DateTime? MinDate { get; set; } /// <summary> /// 允许的最大值 /// </summary> public DateTime? MaxDate { get; set; } /// <summary> /// 是否只读 /// </summary> public bool IsReadOnly { get; set; } /// <summary> /// 是否允许超过当前时间 /// </summary> public bool CanGreaterThanNow { get; set; } /// <summary> /// 是否已编辑 /// </summary> public bool HasEdit { get; set; } /// <summary> /// 是否已完成 /// </summary> public bool IsFlish { get; set; } /// <summary> /// 是否允许撤销 /// </summary> public bool AllowCancel { get; set; } /// <summary> /// 是否允许为空(必填情况下,无法提交数据) /// </summary> public bool AllowBlank { get; set; } /// <summary> /// 自定义标记 /// </summary> public string Tag { get; set; } }} |
这个类是用来控制数据行的。开始时间和结束时间控制显示的条状的长度。接下来,需要使用JSON.NET组件(http://james.newtonking.com/projects/json-net.aspx)。
下载好该组件后,引用Json.Silverlight(Silverlight的JSON组件用起来不方便)。这样我们就可以很方便的将JSON字符串反序列化成对象了,也可以将对象序列化成JSON字符串。于是,只需要在InitParams传入JSON字符串,然后反序列话即可。如下所示:
|
1
2
3
4
5
6
7
|
#region 设置数据private void LoadData(){ if (dicInitParams != null && dicInitParams.ContainsKey("Data")) LstPlansData = JsonConvert.DeserializeObject<List<PlansData>>(HttpUtility.UrlDecode(dicInitParams["Data"]));}#endregion |
那么InitParams如何设置呢,测试页(.aspx页面)页面元素如下:
<form id="form1" runat="server" style="height:100%">
<div id="silverlightControlHost">
<object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%">
<param name="source" value="ClientBin/PlansView.xap"/>
<param name="onError" value="onSilverlightError" />
<param name="background" value="white" />
<param name="minRuntimeVersion" value="4.0.50826.0" />
<param name="autoUpgrade" value="true" />
<param name="initParams" value='<%=InitParams %>' />
<a href="http://go.microsoft.com/fwlink/?LinkID=149156&v=4.0.50826.0" style="text-decoration:none">
<img src="http://go.microsoft.com/fwlink/?LinkId=161376" alt="获取 Microsoft Silverlight" style="border-style:none"/>
</a>
</object><iframe id="_sl_historyFrame" style="visibility:hidden;height:0px;width:0px;border:0px"></iframe></div>
</form>
在后来代码中,InitParams 如此定义:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
public string InitParams { get; set; }protected void Page_Load(object sender, EventArgs e){ if (!IsPostBack) { try { InitParams = "Title=施工计划,DateColCount=80,PlanHeads=工程名称,Data="; List<PlansData> _lstPlansData = new List<PlansData>(); LoadData(_lstPlansData); InitParams += HttpUtility.UrlEncode(JsonConvert.SerializeObject(_lstPlansData, Formatting.Indented)); //LogManager.WriteTraceLog(JsonConvert.SerializeObject(_lstPlansData, Formatting.Indented)); } catch (Exception ex) { LogManager.WriteErrorLog(ex); } }}private static void LoadData(List<PlansData> _lstPlansData){ PlansData _planData1 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="木工轻钢割断墙"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now,EndDate=DateTime.Now.AddDays(3),Explain="基准时间",IsReadOnly=true}, new PlanDate(){StartDate=DateTime.Now.AddDays(1),EndDate=DateTime.Now.AddDays(4),Explain="计划时间",CanGreaterThanNow=true}, new PlanDate(){StartDate=DateTime.Now.AddDays(2),EndDate=DateTime.Now.AddDays(5),Explain="实际时间",IsFlish=true,AllowBlank=false} } }; _lstPlansData.Add(_planData1); PlansData _planData2 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="贴文化石,刷漆"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now.AddDays(5),EndDate=DateTime.Now.AddDays(16),Explain="计划时间",CanGreaterThanNow=true}, new PlanDate(){StartDate=DateTime.Now.AddDays(4),EndDate=DateTime.Now.AddDays(15),Explain="实际时间"} } }; _lstPlansData.Add(_planData2); PlansData _planData3 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="石膏板吊棚"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now.AddDays(5),EndDate=DateTime.Now.AddDays(18),Explain="基准时间",IsReadOnly=true,CanGreaterThanNow=true}, new PlanDate(){StartDate=DateTime.Now.AddDays(8),EndDate=DateTime.Now.AddDays(12),Explain="计划时间"}, } }; _lstPlansData.Add(_planData3); PlansData _planData4 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="大白乳胶漆"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now.AddDays(15),EndDate=DateTime.Now.AddDays(18),Explain="基准时间",IsReadOnly=true}, new PlanDate(){StartDate=DateTime.Now.AddDays(19),EndDate=DateTime.Now.AddDays(25),Explain="计划时间"}, new PlanDate(){StartDate=DateTime.Now,EndDate=DateTime.Now.AddDays(5),Explain="实际时间"} } }; _lstPlansData.Add(_planData4); PlansData _planData5 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="铺地板"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now.AddDays(3),EndDate=DateTime.Now.AddDays(5),Explain="基准时间"}, new PlanDate(){StartDate=DateTime.Now.AddDays(6),EndDate=DateTime.Now.AddDays(15),Explain="计划时间"}, new PlanDate(){StartDate=DateTime.Now.AddDays(7),EndDate=DateTime.Now.AddDays(19),Explain="实际时间"} } }; _lstPlansData.Add(_planData5); PlansData _planData6 = new PlansData() { LstPlan = new List<Plan>() { new Plan(){PlanName="测试1"} }, LstPlanDate = new List<PlanDate>() { new PlanDate(){StartDate=DateTime.Now,EndDate=DateTime.Now,Explain="基准时间"}, new PlanDate(){StartDate=DateTime.Now.AddDays(6),EndDate=DateTime.Now.AddDays(15),Explain="计划时间"}, new PlanDate(){StartDate=DateTime.Now.AddDays(79),EndDate=DateTime.Now.AddDays(79),Explain="实际时间"} } }; _lstPlansData.Add(_planData6); |
|
1
|
} |
先写到这里吧。本文是按初学者的角度来写的,如果你是老手,那么有些内容就可以直接略过了,如果有不当之处,请指教;
如果你是初学者,还有不明白的,那么可以说明。
Silverlight我也只是入门而已,一直在加班,从未停歇过。仅仅只是地铁上看完了风云的书,然后花3天时间做了这个,待完善处还很多。
希望此文能够对大家有所帮助。
有时间我会继续写完的。
Silverlight——施工计划日报表(二)的更多相关文章
- Silverlight——施工计划日报表(一)
前一段时间,客户需要一个施工计划报表,要求能够直观的看到各个计划的实施时间,而且能够修改.琢磨着,决定用Silverlight搞定好了.效果如下: 用户可以通过右键菜单的[完成]选项来标记完成,左键选 ...
- 解析大型.NET ERP系统 窗体、查询、报表二次开发
详细介绍Enterprise Solution 二次开发的流程步骤,主要包括数据输入窗体(Entry Form),查询(Query/Enquiry),报表(Report)三个重要的二次开发项目. 数据 ...
- 基于WebForm+EasyUI的业务管理系统形成之旅 -- 施工计划查询(Ⅷ)
上篇<基于WebForm+EasyUI的业务管理系统形成之旅 -- 施工计划安排>,主要介绍整个施工计划列表与编辑界面. 下面看看施工计划查询(ⅠⅡⅢ ⅣⅤⅥ Ⅶ Ⅷ) 一.施工计划查询 ...
- ABAP 分货日报表
*&---------------------------------------------------------------------* *& Report ZSDR031 ...
- 基于WebForm+EasyUI的业务管理系统形成之旅 -- 施工计划安排(Ⅶ)
上篇<基于WebForm+EasyUI的业务管理系统形成之旅 -- 首页Portal界面拖拽>,主要介绍首页随客户喜好安排区块位置,更好的实现用户体验. 这两天将项目中施工计划管理归纳总结 ...
- 在Silverlight中动态绑定页面报表(PageReport)的数据源
ActiveReports 7中引入了一种新的报表模型——PageReport(页面布局报表),这种报表模型又细分了两种具体显示形式: o 固定页面布局报表模型(FPL)是ActiveRepor ...
- ACM 第十一届 河南省省赛A题 计划日
一.题目描述如下: 二.思路分析 其实这个如果是一个填空题,可以直接用Excel快速计算出来,反而用代码比较麻烦 说一下我的代码的思路: 1.如果N大于本月剩下的天数,就先从N天里减去本月剩下的天数, ...
- MyBatis mysal 日报表,月,年报表的统计
mysql 按日.周.月.年统计sql语句整理,实现报表统计可视化 原文地址:http://blog.csdn.net/u010543785/article/details/52354957 最近在做 ...
- RS报表从按月图表追溯到按日报表
相信很多COGNOS开发人员看到这个标题就会感觉很轻松,追溯无非是COGNOS自带的一个下钻的功能,但是这里却是固定的条件: 要求1:A报表显示按月的图表B报表显示按日的明细 2:追溯到B的时候B的开 ...
随机推荐
- [图形学] Chp17 OpenGL光照和表面绘制函数
这章学了基本光照模型,物体的显示受到以下效果影响:全局环境光,点光源(环境光漫反射分量,点光源漫反射分量,点光源镜面反射分量),材质系数(漫反射系数,镜面反射系数),自身发光,雾气效果等.其中点光源有 ...
- 【亲测】Appium测试Android混合应用时,第二次切换到WebView失败
要解决的问题:Appium测试Android混合应用时,第二次切换到WebView时失败 原因分析:在用Appium测试Android混合应用时,当程序第一次切换到WebView时,可以正常进行自动化 ...
- 容器_JDK源码分析_自己简单实现ArrayList容器
这几天仔细研究下关于ArrayList容器的jdk源码,感觉收获颇多,以前自己只知道用它,但它里面具体是怎样实现的就完全不清楚了.于是自己尝试模拟写下java的ArrayList容器,简单了实现的Ar ...
- php 极简框架ES发布(代码总和不到 400 行)
ES 框架简介 ES 是一款 极简,灵活, 高性能,扩建性强 的php 框架. 未开源之前在商业公司 经历数年,数个高并发网站 实践使用! 框架结构 整个框架核心四个文件,所有文件加起来放在一起总行数 ...
- Java之面向对象例子(三) 多态,重写,重载,equals()方法和toString()方法的重写
重写(继承关系) 子类得成员方法和父类的成员方法,方法名,参数类型,参数个数完全相同,这就是子类的方法重写了父类的方法. 重载 在一个类里有两个方法,方法名是完全一样的,参数类型或参数个数不同. 例子 ...
- javascript之数组快速排序
快速排序思想其实还是挺简单的,分三步走: 1.在数组中找到基准点,其他数与之比较. 2.建立两个数组,小于基准点的数存储在左边数组,大于基准点的数存储在右边数组. 3.拼接数组,然后左边数组与右边数组 ...
- iOS App内存优化之 解决UIImagePickerController的图片对象占用RAM过高问题
这个坑会在特定的情况下特别明显: 类似朋友圈的添加多张本地选择\拍照 的图片 并在界面上做一个预览功能 由于没有特别的相机\相册需求,则直接使用系统自带的UIImagePickerController ...
- 介绍CSS的相关知识
以下是我跟大家分享的有关CSS的相关知识点: ①什么是CSS? css(Cascading Style Sheets)是层叠样式表 ②css的三种样式使用方法: 1,内联样式表:直接在html标签属性 ...
- 【PHP】数组用法(转)
摘要: 说明数组遍历方法foreach,while,for,推荐使用foreach(PHP内部实现,简单速度最快,还可以遍历类属性).以及一些常用方法current,prev,next,end,key ...
- JStorm与Storm源码分析(三)--Scheduler,调度器
Scheduler作为Storm的调度器,负责为Topology分配可用资源. Storm提供了IScheduler接口,用户可以通过实现该接口来自定义Scheduler. 其定义如下: public ...