用通用權限管理系統元件開發一個簡易的日積月累功能的代碼實作,運作效果如下效果,很多通用的小功能系統元件自動都實作了,那開發應用程式會變得又快又簡單了。
具體代碼參考如下:
1//--------------------------------------------------------------------
2// All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3//--------------------------------------------------------------------
4
5using System;
6using System.Data;
7using System.Windows.Forms;
8
9namespace DotNet.WinForm
10 {
11using DotNet.Business;
12using DotNet.Utilities;
13
14///<summary>
15/// FrmKnowledge.cs
16/// 日積月累
17///
18/// 修改記錄
19///
20/// 2012.09.03 版本:1.0 JiRiGaLa 修改功能頁面編寫。
21///
22/// 版本:1.0
23///
24///<author>
25///<name>JiRiGaLa</name>
26///<date>2012.09.03</date>
27///</author>
28///</summary>
29publicpartialclass FrmKnowledge : BaseForm
30 {
31public FrmKnowledge()
32 {
33 InitializeComponent();
34 }
35
36///<summary>
37/// 日積月累的知識庫
38///</summary>
39 DataTable dtKnowledge = null;
40
41///<summary>
42/// 目前顯示第幾條
43///</summary>
44int CurrentIndex = 0;
45
46#region public override void ShowEntity() 顯示内容
47///<summary>
48/// 顯示内容
49///</summary>
50publicoverridevoid ShowEntity()
51 {
52// 顯示資訊
53 BaseCommentEntity commentEntity = new BaseCommentEntity(dtKnowledge.Rows[this.CurrentIndex]);
54this.txtContents.Text = commentEntity.Contents;
55 }
56#endregion
57
58publicoverridevoid SetControlState()
59 {
60if (this.dtKnowledge != null && this.dtKnowledge.Rows.Count > 0)
61 {
62this.btnNext.Enabled = true;
63if (this.CurrentIndex == this.dtKnowledge.Rows.Count - 1)
64 {
65this.btnNext.Enabled = false;
66 }
67this.btnPrevious.Enabled = true;
68if (this.CurrentIndex == 0)
69 {
70this.btnPrevious.Enabled = false;
71 }
72 }
73 }
74
75#region public override void FormOnLoad() 加載窗體
76///<summary>
77/// 加載窗體
78///</summary>
79publicoverridevoid FormOnLoad()
80 {
81// 擷取資料
82 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
83 sqlBuilder.BeginSelect("BaseKnowledge");
84// 隻擷取前200個資料就可以了,減小網絡傳遞資料的網絡帶寬。
85 sqlBuilder.SelectTop(200);
86if (!string.IsNullOrEmpty(this.EntityId))
87 {
88 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.EntityId);
89 }
90// 這裡是為了每次顯示的資料都是亂序的,資料測循序是被打亂的。
91 sqlBuilder.SetOrderBy( " NEWID() ");
92 dtKnowledge = sqlBuilder.EndSelect();
93if (dtKnowledge.Rows.Count > 1)
94 {
95this.CurrentIndex = new Random().Next(0, dtKnowledge.Rows.Count - 1);
96 }
97// 顯示實體
98this.ShowEntity();
99
100// 顯示日積月累
101string showKnowledge = DotNetService.Instance.ParameterService.GetParameter(BaseSystemInfo.UserInfo, "User", "ShowKnowledg", "Show");
102if (!string.IsNullOrEmpty(showKnowledge))
103 {
104this.chkShowKnowledge.Checked = showKnowledge.Equals(true.ToString());
105 }
106 }
107#endregion
108
109privatevoid chkShowKnowledge_CheckedChanged(object sender, EventArgs e)
110 {
111if (this.FormLoaded)
112 {
113 DotNetService.Instance.ParameterService.SetParameter(BaseSystemInfo.UserInfo, "User", "ShowKnowledg", "Show", this.chkShowKnowledge.Checked.ToString());
114 }
115 }
116
117privatevoid btnPrevious_Click(object sender, EventArgs e)
118 {
119if (this.CurrentIndex > 0)
120 {
121this.CurrentIndex--;
122this.ShowEntity();
123 }
124this.SetControlState();
125 }
126
127privatevoid btnNext_Click(object sender, EventArgs e)
128 {
129if (this.CurrentIndex < this.dtKnowledge.Rows.Count -1)
130 {
131this.CurrentIndex++;
132this.ShowEntity();
133 }
134this.SetControlState();
135 }
136
137privatevoid btnColse_Click(object sender, EventArgs e)
138 {
139this.Close();
140 }
141 }
142 }
本文轉自 jirigala 51CTO部落格,原文連結:http://blog.51cto.com/2347979/1196196,如需轉載請自行聯系原作者