简单快速开发C\S架构程序用最简单的不分层最快的效率达到功能要求的例子程序FrmCommnets 显示某个对象的评论列表的功能实现
2012-09-02 18:52 通用C#系统架构 阅读(738) 评论(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 /// FrmCommnets.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 FrmCommnets : BaseForm
30 {
31 public FrmCommnets()
32 {
33 InitializeComponent();
34 }
35
36 public FrmCommnets(string categoryCode, string objectId)
37 : this()
38 {
39 this.CategoryCode = categoryCode;
40 this.ObjectId = objectId;
41 }
42
43 #region public override string EntityId 主键
44 /// <summary>
45 /// 主键
46 /// </summary>
47 public override string EntityId
48 {
49 get
50 {
51 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldId);
52 }
53 }
54 #endregion
55
56 private string categoryCode = string.Empty;
57 /// <summary>
58 /// 分类
59 /// </summary>
60 public string CategoryCode
61 {
62 get
63 {
64 return categoryCode;
65 }
66 set
67 {
68 categoryCode = value;
69 }
70 }
71
72 private string objectId = string.Empty;
73 /// <summary>
74 /// 实体主键
75 /// </summary>
76 public string ObjectId
77 {
78 get
79 {
80 return objectId;
81 }
82 set
83 {
84 objectId = value;
85 }
86 }
87
88 #region public override void FormOnLoad() 加载窗体
89 /// <summary>
90 /// 加载窗体
91 /// </summary>
92 public override void FormOnLoad()
93 {
94 // 表格显示序号的处理部分
95 this.DataGridViewOnLoad(this.grdComment);
96 // 获得列表
97 this.GetList();
98 }
99 #endregion
100
101 #region public override void GetList() 获取列表
102 /// <summary>
103 /// 获取列表
104 /// </summary>
105 public override void GetList()
106 {
107 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
108 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
109 sqlBuilder.SetWhere(BaseCommentEntity.FieldCategoryCode, this.CategoryCode);
110 sqlBuilder.SetWhere(BaseCommentEntity.FieldObjectId, this.ObjectId);
111 sqlBuilder.SetWhere(BaseCommentEntity.FieldDeletionStateCode, 0);
112 DataTable dtComment = sqlBuilder.EndSelect();
113 dtComment.DefaultView.Sort = BaseCommentEntity.FieldCreateOn + " DESC";
114 this.grdComment.AutoGenerateColumns = false;
115 this.grdComment.DataSource = dtComment.DefaultView;
116 }
117 #endregion
118
119 #region public override void SetControlState() 设置控件状态
120 /// <summary>
121 /// 设置控件状态
122 /// </summary>
123 public override void SetControlState()
124 {
125 this.btnAdd.Enabled = true;
126 this.btnEdit.Enabled = false;
127 this.btnBatchDelete.Enabled = false;
128 this.btnSelectAll.Enabled = false;
129 this.btnInvertSelect.Enabled = false;
130
131 if ((this.grdComment.RowCount >= 1))
132 {
133 this.btnSelectAll.Enabled = true;
134 this.btnInvertSelect.Enabled = true;
135 this.btnEdit.Enabled = true;
136 this.btnBatchDelete.Enabled = true;
137 }
138 }
139 #endregion
140
141 private void grdComment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
142 {
143 this.btnEdit.PerformClick();
144 }
145
146 private void btnSelectAll_Click(object sender, EventArgs e)
147 {
148 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
149 {
150 dataGridViewRow.Cells["colSelected"].Value = true;
151 }
152 }
153
154 private void btnInvertSelect_Click(object sender, EventArgs e)
155 {
156 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
157 {
158 dataGridViewRow.Cells["colSelected"].Value = !(System.Boolean)(dataGridViewRow.Cells["colSelected"].Value ?? false);
159 }
160 }
161
162 private void btnAdd_Click(object sender, EventArgs e)
163 {
164 FrmCommentAdd frmCommentAdd = new FrmCommentAdd(this.CategoryCode, this.ObjectId);
165 if (frmCommentAdd.ShowDialog(this) == DialogResult.OK || frmCommentAdd.Changed)
166 {
167 // 获得角色列表
168 this.GetList();
169 // 设置按钮状态
170 this.SetControlState();
171 }
172 }
173
174 private void btnEdit_Click(object sender, EventArgs e)
175 {
176 FrmCommentEdit frmCommentEdit = new FrmCommentEdit(this.EntityId);
177 if (frmCommentEdit.ShowDialog(this) == DialogResult.OK)
178 {
179 // 获得角色列表
180 this.GetList();
181 // 设置按钮状态
182 this.SetControlState();
183 }
184 }
185
186 #region private string[] GetSelecteIds() 获得已被选择的主键数组
187 /// <summary>
188 /// 获得已被选择的主键数组
189 /// </summary>
190 /// <returns>主键数组</returns>
191 private string[] GetSelecteIds()
192 {
193 return BaseInterfaceLogic.GetSelecteIds(this.grdComment, BaseRoleEntity.FieldId, "colSelected", true);
194 }
195 #endregion
196
197 #region public override int BatchDelete() 批量删除
198 /// <summary>
199 /// 批量删除
200 /// </summary>
201 /// <returns>影响行数</returns>
202 public override int BatchDelete()
203 {
204 int returnValue = 0;
205 // 这个是只打上删除标记的方法
206 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
207 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
208 sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 1);
209 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
210 returnValue = sqlBuilder.EndUpdate();
211 // 这里是真删除的方法
212 // sqlBuilder.BeginDelete(BaseCommentEntity.TableName);
213 // sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
214 // returnValue = sqlBuilder.EndDelete();
215 return returnValue;
216 }
217 #endregion
218
219 /// <summary>
220 /// 删除数据
221 /// </summary>
222 public int Delete()
223 {
224 int returnValue = 0;
225 // 检查至少要选择一个?
226 if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdComment, "colSelected"))
227 {
228 return returnValue;
229 }
230 // 是否确认删除了?
231 if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
232 {
233 return returnValue;
234 }
235 // 设置鼠标繁忙状态,并保留原先的状态
236 Cursor holdCursor = this.Cursor;
237 this.Cursor = Cursors.WaitCursor;
238 try
239 {
240 this.btnBatchDelete.Enabled = false;
241 returnValue = this.BatchDelete();
242 // 重新加载数据,先刷新屏幕,再显示提示信息
243 this.FormOnLoad();
244 this.SetControlState();
245 // 是否需要有提示信息?
246 if (BaseSystemInfo.ShowInformation)
247 {
248 // 批量保存,进行提示
249 MessageBox.Show(AppMessage.Format(AppMessage.MSG0077, returnValue.ToString()), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
250 }
251 }
252 catch (Exception ex)
253 {
254 this.ProcessException(ex);
255 }
256 finally
257 {
258 // 设置鼠标默认状态,原来的光标状态
259 this.Cursor = holdCursor;
260 }
261 return returnValue;
262 }
263
264 private void btnBatchDelete_Click(object sender, EventArgs e)
265 {
266 // 删除数据
267 this.Delete();
268 }
269 }
270 }
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 /// FrmCommnets.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 FrmCommnets : BaseForm
30 {
31 public FrmCommnets()
32 {
33 InitializeComponent();
34 }
35
36 public FrmCommnets(string categoryCode, string objectId)
37 : this()
38 {
39 this.CategoryCode = categoryCode;
40 this.ObjectId = objectId;
41 }
42
43 #region public override string EntityId 主键
44 /// <summary>
45 /// 主键
46 /// </summary>
47 public override string EntityId
48 {
49 get
50 {
51 return BaseInterfaceLogic.GetDataGridViewEntityId(this.grdComment, BaseCommentEntity.FieldId);
52 }
53 }
54 #endregion
55
56 private string categoryCode = string.Empty;
57 /// <summary>
58 /// 分类
59 /// </summary>
60 public string CategoryCode
61 {
62 get
63 {
64 return categoryCode;
65 }
66 set
67 {
68 categoryCode = value;
69 }
70 }
71
72 private string objectId = string.Empty;
73 /// <summary>
74 /// 实体主键
75 /// </summary>
76 public string ObjectId
77 {
78 get
79 {
80 return objectId;
81 }
82 set
83 {
84 objectId = value;
85 }
86 }
87
88 #region public override void FormOnLoad() 加载窗体
89 /// <summary>
90 /// 加载窗体
91 /// </summary>
92 public override void FormOnLoad()
93 {
94 // 表格显示序号的处理部分
95 this.DataGridViewOnLoad(this.grdComment);
96 // 获得列表
97 this.GetList();
98 }
99 #endregion
100
101 #region public override void GetList() 获取列表
102 /// <summary>
103 /// 获取列表
104 /// </summary>
105 public override void GetList()
106 {
107 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
108 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
109 sqlBuilder.SetWhere(BaseCommentEntity.FieldCategoryCode, this.CategoryCode);
110 sqlBuilder.SetWhere(BaseCommentEntity.FieldObjectId, this.ObjectId);
111 sqlBuilder.SetWhere(BaseCommentEntity.FieldDeletionStateCode, 0);
112 DataTable dtComment = sqlBuilder.EndSelect();
113 dtComment.DefaultView.Sort = BaseCommentEntity.FieldCreateOn + " DESC";
114 this.grdComment.AutoGenerateColumns = false;
115 this.grdComment.DataSource = dtComment.DefaultView;
116 }
117 #endregion
118
119 #region public override void SetControlState() 设置控件状态
120 /// <summary>
121 /// 设置控件状态
122 /// </summary>
123 public override void SetControlState()
124 {
125 this.btnAdd.Enabled = true;
126 this.btnEdit.Enabled = false;
127 this.btnBatchDelete.Enabled = false;
128 this.btnSelectAll.Enabled = false;
129 this.btnInvertSelect.Enabled = false;
130
131 if ((this.grdComment.RowCount >= 1))
132 {
133 this.btnSelectAll.Enabled = true;
134 this.btnInvertSelect.Enabled = true;
135 this.btnEdit.Enabled = true;
136 this.btnBatchDelete.Enabled = true;
137 }
138 }
139 #endregion
140
141 private void grdComment_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
142 {
143 this.btnEdit.PerformClick();
144 }
145
146 private void btnSelectAll_Click(object sender, EventArgs e)
147 {
148 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
149 {
150 dataGridViewRow.Cells["colSelected"].Value = true;
151 }
152 }
153
154 private void btnInvertSelect_Click(object sender, EventArgs e)
155 {
156 foreach (DataGridViewRow dataGridViewRow in this.grdComment.Rows)
157 {
158 dataGridViewRow.Cells["colSelected"].Value = !(System.Boolean)(dataGridViewRow.Cells["colSelected"].Value ?? false);
159 }
160 }
161
162 private void btnAdd_Click(object sender, EventArgs e)
163 {
164 FrmCommentAdd frmCommentAdd = new FrmCommentAdd(this.CategoryCode, this.ObjectId);
165 if (frmCommentAdd.ShowDialog(this) == DialogResult.OK || frmCommentAdd.Changed)
166 {
167 // 获得角色列表
168 this.GetList();
169 // 设置按钮状态
170 this.SetControlState();
171 }
172 }
173
174 private void btnEdit_Click(object sender, EventArgs e)
175 {
176 FrmCommentEdit frmCommentEdit = new FrmCommentEdit(this.EntityId);
177 if (frmCommentEdit.ShowDialog(this) == DialogResult.OK)
178 {
179 // 获得角色列表
180 this.GetList();
181 // 设置按钮状态
182 this.SetControlState();
183 }
184 }
185
186 #region private string[] GetSelecteIds() 获得已被选择的主键数组
187 /// <summary>
188 /// 获得已被选择的主键数组
189 /// </summary>
190 /// <returns>主键数组</returns>
191 private string[] GetSelecteIds()
192 {
193 return BaseInterfaceLogic.GetSelecteIds(this.grdComment, BaseRoleEntity.FieldId, "colSelected", true);
194 }
195 #endregion
196
197 #region public override int BatchDelete() 批量删除
198 /// <summary>
199 /// 批量删除
200 /// </summary>
201 /// <returns>影响行数</returns>
202 public override int BatchDelete()
203 {
204 int returnValue = 0;
205 // 这个是只打上删除标记的方法
206 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
207 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
208 sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 1);
209 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
210 returnValue = sqlBuilder.EndUpdate();
211 // 这里是真删除的方法
212 // sqlBuilder.BeginDelete(BaseCommentEntity.TableName);
213 // sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.GetSelecteIds());
214 // returnValue = sqlBuilder.EndDelete();
215 return returnValue;
216 }
217 #endregion
218
219 /// <summary>
220 /// 删除数据
221 /// </summary>
222 public int Delete()
223 {
224 int returnValue = 0;
225 // 检查至少要选择一个?
226 if (!BaseInterfaceLogic.CheckInputSelectAnyOne(this.grdComment, "colSelected"))
227 {
228 return returnValue;
229 }
230 // 是否确认删除了?
231 if (MessageBox.Show(AppMessage.MSG0015, AppMessage.MSG0000, MessageBoxButtons.OKCancel, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2) != DialogResult.OK)
232 {
233 return returnValue;
234 }
235 // 设置鼠标繁忙状态,并保留原先的状态
236 Cursor holdCursor = this.Cursor;
237 this.Cursor = Cursors.WaitCursor;
238 try
239 {
240 this.btnBatchDelete.Enabled = false;
241 returnValue = this.BatchDelete();
242 // 重新加载数据,先刷新屏幕,再显示提示信息
243 this.FormOnLoad();
244 this.SetControlState();
245 // 是否需要有提示信息?
246 if (BaseSystemInfo.ShowInformation)
247 {
248 // 批量保存,进行提示
249 MessageBox.Show(AppMessage.Format(AppMessage.MSG0077, returnValue.ToString()), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
250 }
251 }
252 catch (Exception ex)
253 {
254 this.ProcessException(ex);
255 }
256 finally
257 {
258 // 设置鼠标默认状态,原来的光标状态
259 this.Cursor = holdCursor;
260 }
261 return returnValue;
262 }
263
264 private void btnBatchDelete_Click(object sender, EventArgs e)
265 {
266 // 删除数据
267 this.Delete();
268 }
269 }
270 }
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。