简单快速开发C\S架构程序用最简单的不分层最快的效率达到功能要求的例子程序FrmCommnetList 所有评论列表的功能实现
2012-09-02 18:48 通用C#系统架构 阅读(733) 评论(0) 编辑 收藏 举报这个是系统里列出所有评论的功能页面,这个页面列出系统里的所有对象的评论,并且最新的评论显示在最前面,还能标识出是否已处理的功能标志。这个是方便系统的多个管理人员之间互相沟通协调,就算是一个系统管理员,也方便记录系统地各个备忘录。方便日常管理维护。
1 //--------------------------------------------------------------------
2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3 //--------------------------------------------------------------------
4
5 using System;
6 using System.Data;
7 using System.Windows.Forms;
8
9 namespace DotNet.WinForm
10 {
11 using DotNet.Business;
12 using DotNet.Utilities;
13
14 /// <summary>
15 /// FrmCommnetList.cs
16 /// 评论列表
17 ///
18 /// 修改记录
19 ///
20 /// 2012.08.26 版本:1.0 JiRiGaLa 列表功能页面编写。
21 ///
22 /// 版本:1.0
23 ///
24 /// <author>
25 /// <name>JiRiGaLa</name>
26 /// <date>2012.08.26</date>
27 /// </author>
28 /// </summary>
29 public partial class FrmCommnetList : BaseForm
30 {
31 public FrmCommnetList()
32 {
33 InitializeComponent();
34 }
35
36 #region public override string EntityId 主键
37 /// <summary>
38 /// 主键
39 /// </summary>
40 public override string EntityId
41 {
42 get
43 {
44 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldId);
45 }
46 }
47 #endregion
48
49 #region public override string CategoryCode 分类
50 /// <summary>
51 /// 分类
52 /// </summary>
53 public string CategoryCode
54 {
55 get
56 {
57 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldCategoryCode);
58 }
59 }
60 #endregion
61
62 #region public override string ObjectId 实体主键
63 /// <summary>
64 /// 实体主键
65 /// </summary>
66 public string ObjectId
67 {
68 get
69 {
70 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldObjectId);
71 }
72 }
73 #endregion
74
75 #region public override void FormOnLoad() 加载窗体
76 /// <summary>
77 /// 加载窗体
78 /// </summary>
79 public override void FormOnLoad()
80 {
81 // 表格显示序号的处理部分
82 this.DataGridViewOnLoad(this.grdComment);
83 // 获得列表
84 this.GetList();
85 }
86 #endregion
87
88 #region public override void GetList() 获取列表
89 /// <summary>
90 /// 获取列表
91 /// </summary>
92 public override void GetList()
93 {
94 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
95 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
96 sqlBuilder.SetWhere(BaseCommentEntity.FieldDeletionStateCode, 0);
97 DataTable dtComment = sqlBuilder.EndSelect();
98 dtComment.DefaultView.Sort = BaseCommentEntity.FieldCreateOn + " DESC";
99 this.grdComment.AutoGenerateColumns = false;
100 this.grdComment.DataSource = dtComment.DefaultView;
101 }
102 #endregion
103
104 #region public override void SetControlState() 设置控件状态
105 /// <summary>
106 /// 设置控件状态
107 /// </summary>
108 public override void SetControlState()
109 {
110 this.btnView.Enabled = false;
111 this.btnEdit.Enabled = false;
112 this.btnBatchDelete.Enabled = false;
113 this.btnSelectAll.Enabled = false;
114 this.btnInvertSelect.Enabled = false;
115
116 if ((this.grdComment.RowCount >= 1))
117 {
118 this.btnSelectAll.Enabled = true;
119 this.btnInvertSelect.Enabled = true;
120 this.btnView.Enabled = true;
121 this.btnEdit.Enabled = true;
122 this.btnBatchDelete.Enabled = true;
123 }
124 }
125 #endregion
126
127 private void grdComment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
128 {
129 this.btnView.PerformClick();
130 }
131
132 private void btnSelectAll_Click(object sender, EventArgs e)
133 {
134 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
135 {
136 dataGridViewRow.Cells["colSelected"].Value = true;
137 }
138 }
139
140 private void btnInvertSelect_Click(object sender, EventArgs e)
141 {
142 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
143 {
144 dataGridViewRow.Cells["colSelected"].Value = !(System.Boolean)(dataGridViewRow.Cells["colSelected"].Value ?? false);
145 }
146 }
147
148 private void btnView_Click(object sender, EventArgs e)
149 {
150 Type assemblyType = CacheManager.Instance.GetType("DotNet.WinForm", this.CategoryCode);
151 Form frmObject = (Form)Activator.CreateInstance(assemblyType, this.ObjectId);
152 frmObject.ShowDialog(this);
153 }
154
155 private void btnEdit_Click(object sender, EventArgs e)
156 {
157 FrmCommentEdit frmCommentEdit = new FrmCommentEdit(this.EntityId);
158 if (frmCommentEdit.ShowDialog(this) == DialogResult.OK)
159 {
160 // 获得角色列表
161 this.GetList();
162 // 设置按钮状态
163 this.SetControlState();
164 }
165 }
166
167 #region private string[] GetSelecteIds() 获得已被选择的主键数组
168 /// <summary>
169 /// 获得已被选择的主键数组
170 /// </summary>
171 /// <returns>主键数组</returns>
172 private string[] GetSelecteIds()
173 {
174 return BaseInterfaceLogic.GetSelecteIds(this.grdComment, BaseRoleEntity.FieldId, "colSelected", true);
175 }
176 #endregion
177
178 #region public override int BatchDelete() 批量删除
179 /// <summary>
180 /// 批量删除
181 /// </summary>
182 /// <returns>影响行数</returns>
183 public override int BatchDelete()
184 {
185 int returnValue = 0;
186 // 这个是只打上删除标记的方法
187 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
188 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
189 sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 1);
190 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
191 returnValue = sqlBuilder.EndUpdate();
192 // 这里是真删除的方法
193 // sqlBuilder.BeginDelete(BaseCommentEntity.TableName);
194 // sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
195 // returnValue = sqlBuilder.EndDelete();
196 return returnValue;
197 }
198 #endregion
199
200 /// <summary>
201 /// 删除数据
202 /// </summary>
203 public int Delete()
204 {
205 int returnValue = 0;
206 // 检查至少要选择一个?
207 if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdComment, "colSelected"))
208 {
209 return returnValue;
210 }
211 // 是否确认删除了?
212 if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
213 {
214 return returnValue;
215 }
216 // 设置鼠标繁忙状态,并保留原先的状态
217 Cursor holdCursor = this.Cursor;
218 this.Cursor = Cursors.WaitCursor;
219 try
220 {
221 this.btnBatchDelete.Enabled = false;
222 returnValue = this.BatchDelete();
223 // 重新加载数据,先刷新屏幕,再显示提示信息
224 this.FormOnLoad();
225 this.SetControlState();
226 // 是否需要有提示信息?
227 if (BaseSystemInfo.ShowInformation)
228 {
229 // 批量保存,进行提示
230 MessageBox.Show(AppMessage.Format(AppMessage.MSG0077, returnValue.ToString()), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
231 }
232 }
233 catch (Exception ex)
234 {
235 this.ProcessException(ex);
236 }
237 finally
238 {
239 // 设置鼠标默认状态,原来的光标状态
240 this.Cursor = holdCursor;
241 }
242 return returnValue;
243 }
244
245 private void btnBatchDelete_Click(object sender, EventArgs e)
246 {
247 // 删除数据
248 this.Delete();
249 }
250
251 private void btnClose_Click(object sender, EventArgs e)
252 {
253 this.Close();
254 }
255 }
256 }
2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
3 //--------------------------------------------------------------------
4
5 using System;
6 using System.Data;
7 using System.Windows.Forms;
8
9 namespace DotNet.WinForm
10 {
11 using DotNet.Business;
12 using DotNet.Utilities;
13
14 /// <summary>
15 /// FrmCommnetList.cs
16 /// 评论列表
17 ///
18 /// 修改记录
19 ///
20 /// 2012.08.26 版本:1.0 JiRiGaLa 列表功能页面编写。
21 ///
22 /// 版本:1.0
23 ///
24 /// <author>
25 /// <name>JiRiGaLa</name>
26 /// <date>2012.08.26</date>
27 /// </author>
28 /// </summary>
29 public partial class FrmCommnetList : BaseForm
30 {
31 public FrmCommnetList()
32 {
33 InitializeComponent();
34 }
35
36 #region public override string EntityId 主键
37 /// <summary>
38 /// 主键
39 /// </summary>
40 public override string EntityId
41 {
42 get
43 {
44 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldId);
45 }
46 }
47 #endregion
48
49 #region public override string CategoryCode 分类
50 /// <summary>
51 /// 分类
52 /// </summary>
53 public string CategoryCode
54 {
55 get
56 {
57 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldCategoryCode);
58 }
59 }
60 #endregion
61
62 #region public override string ObjectId 实体主键
63 /// <summary>
64 /// 实体主键
65 /// </summary>
66 public string ObjectId
67 {
68 get
69 {
70 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldObjectId);
71 }
72 }
73 #endregion
74
75 #region public override void FormOnLoad() 加载窗体
76 /// <summary>
77 /// 加载窗体
78 /// </summary>
79 public override void FormOnLoad()
80 {
81 // 表格显示序号的处理部分
82 this.DataGridViewOnLoad(this.grdComment);
83 // 获得列表
84 this.GetList();
85 }
86 #endregion
87
88 #region public override void GetList() 获取列表
89 /// <summary>
90 /// 获取列表
91 /// </summary>
92 public override void GetList()
93 {
94 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
95 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
96 sqlBuilder.SetWhere(BaseCommentEntity.FieldDeletionStateCode, 0);
97 DataTable dtComment = sqlBuilder.EndSelect();
98 dtComment.DefaultView.Sort = BaseCommentEntity.FieldCreateOn + " DESC";
99 this.grdComment.AutoGenerateColumns = false;
100 this.grdComment.DataSource = dtComment.DefaultView;
101 }
102 #endregion
103
104 #region public override void SetControlState() 设置控件状态
105 /// <summary>
106 /// 设置控件状态
107 /// </summary>
108 public override void SetControlState()
109 {
110 this.btnView.Enabled = false;
111 this.btnEdit.Enabled = false;
112 this.btnBatchDelete.Enabled = false;
113 this.btnSelectAll.Enabled = false;
114 this.btnInvertSelect.Enabled = false;
115
116 if ((this.grdComment.RowCount >= 1))
117 {
118 this.btnSelectAll.Enabled = true;
119 this.btnInvertSelect.Enabled = true;
120 this.btnView.Enabled = true;
121 this.btnEdit.Enabled = true;
122 this.btnBatchDelete.Enabled = true;
123 }
124 }
125 #endregion
126
127 private void grdComment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
128 {
129 this.btnView.PerformClick();
130 }
131
132 private void btnSelectAll_Click(object sender, EventArgs e)
133 {
134 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
135 {
136 dataGridViewRow.Cells["colSelected"].Value = true;
137 }
138 }
139
140 private void btnInvertSelect_Click(object sender, EventArgs e)
141 {
142 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
143 {
144 dataGridViewRow.Cells["colSelected"].Value = !(System.Boolean)(dataGridViewRow.Cells["colSelected"].Value ?? false);
145 }
146 }
147
148 private void btnView_Click(object sender, EventArgs e)
149 {
150 Type assemblyType = CacheManager.Instance.GetType("DotNet.WinForm", this.CategoryCode);
151 Form frmObject = (Form)Activator.CreateInstance(assemblyType, this.ObjectId);
152 frmObject.ShowDialog(this);
153 }
154
155 private void btnEdit_Click(object sender, EventArgs e)
156 {
157 FrmCommentEdit frmCommentEdit = new FrmCommentEdit(this.EntityId);
158 if (frmCommentEdit.ShowDialog(this) == DialogResult.OK)
159 {
160 // 获得角色列表
161 this.GetList();
162 // 设置按钮状态
163 this.SetControlState();
164 }
165 }
166
167 #region private string[] GetSelecteIds() 获得已被选择的主键数组
168 /// <summary>
169 /// 获得已被选择的主键数组
170 /// </summary>
171 /// <returns>主键数组</returns>
172 private string[] GetSelecteIds()
173 {
174 return BaseInterfaceLogic.GetSelecteIds(this.grdComment, BaseRoleEntity.FieldId, "colSelected", true);
175 }
176 #endregion
177
178 #region public override int BatchDelete() 批量删除
179 /// <summary>
180 /// 批量删除
181 /// </summary>
182 /// <returns>影响行数</returns>
183 public override int BatchDelete()
184 {
185 int returnValue = 0;
186 // 这个是只打上删除标记的方法
187 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
188 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
189 sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 1);
190 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
191 returnValue = sqlBuilder.EndUpdate();
192 // 这里是真删除的方法
193 // sqlBuilder.BeginDelete(BaseCommentEntity.TableName);
194 // sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
195 // returnValue = sqlBuilder.EndDelete();
196 return returnValue;
197 }
198 #endregion
199
200 /// <summary>
201 /// 删除数据
202 /// </summary>
203 public int Delete()
204 {
205 int returnValue = 0;
206 // 检查至少要选择一个?
207 if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdComment, "colSelected"))
208 {
209 return returnValue;
210 }
211 // 是否确认删除了?
212 if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
213 {
214 return returnValue;
215 }
216 // 设置鼠标繁忙状态,并保留原先的状态
217 Cursor holdCursor = this.Cursor;
218 this.Cursor = Cursors.WaitCursor;
219 try
220 {
221 this.btnBatchDelete.Enabled = false;
222 returnValue = this.BatchDelete();
223 // 重新加载数据,先刷新屏幕,再显示提示信息
224 this.FormOnLoad();
225 this.SetControlState();
226 // 是否需要有提示信息?
227 if (BaseSystemInfo.ShowInformation)
228 {
229 // 批量保存,进行提示
230 MessageBox.Show(AppMessage.Format(AppMessage.MSG0077, returnValue.ToString()), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
231 }
232 }
233 catch (Exception ex)
234 {
235 this.ProcessException(ex);
236 }
237 finally
238 {
239 // 设置鼠标默认状态,原来的光标状态
240 this.Cursor = holdCursor;
241 }
242 return returnValue;
243 }
244
245 private void btnBatchDelete_Click(object sender, EventArgs e)
246 {
247 // 删除数据
248 this.Delete();
249 }
250
251 private void btnClose_Click(object sender, EventArgs e)
252 {
253 this.Close();
254 }
255 }
256 }
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。