前一段时间,客户需要一个施工计划报表,要求能够直观的看到各个计划的实施时间,而且能够修改。琢磨着,决定用Silverlight搞定好了。效果如下:
用户可以通过右键菜单的【完成】选项来标记完成,左键选择单元格来设置时间段。那么数据是怎么带过来的呢?在这个Silverlight程序里面,定义了这么一个类:
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
|
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 ; }
}
} |
这个类,对每一小行(就是时间行)都做了精细的控制。比如是否只读,是否已编辑,是否允许为空(不选),是否允许撤销(当标记为完成时),允许标记的最大值、最小值以及是否允许结束时间超过当天。当然,这个类主要是对数据行的控制,整个报表还有些全局的控制。比如日期格式(day、week、month)(这点还需要完善),开始时间,日期列数,文本列列数,计划列头,日期列背景色等等。也就是这个计划自定义性是很强的,完全可以根据数据的需要来显示。
比如刚才这个测试的数据如下:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
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);
}
}
} |
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
|
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);
} |