简单快速开发C\S架构程序用最简单的不分层最快的效率达到功能要求的例子程序FrmCommentEdit 编辑评论的功能实现
2012-09-02 18:45 通用C#系统架构 阅读(658) 评论(0) 编辑 收藏 举报评论编辑时,用了最少的参数Id,来定位唯一评论,同时界面上显示了,谁创建的评论,谁最后修改的评论,进行责任明确。同时加了一个已处理标志来实现,这个事情是否已经搞定处理好了?还是还没处理好?还需要其他人员沟通协调的,还是这个评论是在代办事列里?这个评论是否被其他人修改过等等。
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 /// FrmCommentEdit.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 FrmCommentEdit : BaseForm
30 {
31 public FrmCommentEdit()
32 {
33 InitializeComponent();
34 }
35
36 public FrmCommentEdit(string id)
37 : this()
38 {
39 this.EntityId = id;
40 }
41
42 #region public override void ShowEntity() 显示内容
43 /// <summary>
44 /// 显示内容
45 /// </summary>
46 public override void ShowEntity()
47 {
48 // 获取数据
49 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
50 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
51 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.EntityId);
52 DataTable dtComment = sqlBuilder.EndSelect();
53 // 显示信息
54 BaseCommentEntity commentEntity = new BaseCommentEntity(dtComment);
55 this.txtComment.Text = commentEntity.Contents;
56 this.chkWorked.Checked = commentEntity.Worked == 1;
57 this.txtCreateBy.Text = commentEntity.CreateBy;
58 if (commentEntity.CreateOn.HasValue)
59 {
60 this.txtCreateOn.Text = ((DateTime)commentEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat);
61 }
62 if (!string.IsNullOrEmpty(commentEntity.ModifiedBy))
63 {
64 this.txtModifiedBy.Text = commentEntity.ModifiedBy;
65 if (commentEntity.ModifiedOn.HasValue)
66 {
67 this.txtModifiedOn.Text = ((DateTime)commentEntity.ModifiedOn).ToString(BaseSystemInfo.DateTimeFormat);
68 }
69 }
70 }
71 #endregion
72
73 #region public override void FormOnLoad() 加载窗体
74 /// <summary>
75 /// 加载窗体
76 /// </summary>
77 public override void FormOnLoad()
78 {
79 // 显示实体
80 this.ShowEntity();
81 }
82 #endregion
83
84 #region public override bool SaveEntity() 保存
85 /// <summary>
86 /// 保存
87 /// </summary>
88 /// <returns>保存成功</returns>
89 public override bool SaveEntity()
90 {
91 bool returnValue = false;
92 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
93 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
94 sqlBuilder.SetValue(BaseCommentEntity.FieldContents, this.txtComment.Text);
95 sqlBuilder.SetValue(BaseCommentEntity.FieldWorked, this.chkWorked.Checked ? 1 : 0);
96 sqlBuilder.SetValue(BaseCommentEntity.FieldModifiedUserId, this.UserInfo.Id);
97 sqlBuilder.SetValue(BaseCommentEntity.FieldModifiedBy, this.UserInfo.RealName);
98 sqlBuilder.SetDBNow(BaseCommentEntity.FieldModifiedOn);
99 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.EntityId);
100 returnValue = sqlBuilder.EndUpdate() > 0;
101 return returnValue;
102 }
103 #endregion
104
105 #region public override bool CheckInput() 检查输入的有效性
106 /// <summary>
107 /// 检查输入的有效性
108 /// </summary>
109 /// <returns>有效</returns>
110 public override bool CheckInput()
111 {
112 bool returnValue = true;
113 this.txtComment.Text = this.txtComment.Text.TrimEnd();
114 if (string.IsNullOrEmpty(this.txtComment.Text))
115 {
116 MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9984), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
117 this.txtComment.Focus();
118 return false;
119 }
120 return returnValue;
121 }
122 #endregion
123
124 #region private void ClearForm()
125 /// <summary>
126 /// 清除窗体
127 /// </summary>
128 private void ClearForm()
129 {
130 this.txtComment.Text = string.Empty;
131 this.txtComment.Focus();
132 }
133 #endregion
134
135 #region private void AddComment(bool close)
136 /// <summary>
137 /// 保存评论
138 /// </summary>
139 /// <param name="close">关闭窗体</param>
140 private void AddComment(bool close)
141 {
142 // 检查输入的有效性
143 if (this.CheckInput())
144 {
145 // 设置鼠标繁忙状态,并保留原先的状态
146 Cursor holdCursor = this.Cursor;
147 this.Cursor = Cursors.WaitCursor;
148 try
149 {
150 if (this.SaveEntity())
151 {
152 // 数据发生了变化
153 this.Changed = true;
154 if (close)
155 {
156 this.DialogResult = DialogResult.OK;
157 // 关闭窗口
158 this.Close();
159 }
160 else
161 {
162 this.ClearForm();
163 }
164 }
165 }
166 catch (Exception ex)
167 {
168 this.ProcessException(ex);
169 }
170 finally
171 {
172 // 设置鼠标默认状态,原来的光标状态
173 this.Cursor = holdCursor;
174 }
175 }
176 }
177 #endregion
178
179 private void btnSave_Click(object sender, EventArgs e)
180 {
181 this.AddComment(true);
182 }
183 }
184 }
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 /// FrmCommentEdit.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 FrmCommentEdit : BaseForm
30 {
31 public FrmCommentEdit()
32 {
33 InitializeComponent();
34 }
35
36 public FrmCommentEdit(string id)
37 : this()
38 {
39 this.EntityId = id;
40 }
41
42 #region public override void ShowEntity() 显示内容
43 /// <summary>
44 /// 显示内容
45 /// </summary>
46 public override void ShowEntity()
47 {
48 // 获取数据
49 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
50 sqlBuilder.BeginSelect(BaseCommentEntity.TableName);
51 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.EntityId);
52 DataTable dtComment = sqlBuilder.EndSelect();
53 // 显示信息
54 BaseCommentEntity commentEntity = new BaseCommentEntity(dtComment);
55 this.txtComment.Text = commentEntity.Contents;
56 this.chkWorked.Checked = commentEntity.Worked == 1;
57 this.txtCreateBy.Text = commentEntity.CreateBy;
58 if (commentEntity.CreateOn.HasValue)
59 {
60 this.txtCreateOn.Text = ((DateTime)commentEntity.CreateOn).ToString(BaseSystemInfo.DateTimeFormat);
61 }
62 if (!string.IsNullOrEmpty(commentEntity.ModifiedBy))
63 {
64 this.txtModifiedBy.Text = commentEntity.ModifiedBy;
65 if (commentEntity.ModifiedOn.HasValue)
66 {
67 this.txtModifiedOn.Text = ((DateTime)commentEntity.ModifiedOn).ToString(BaseSystemInfo.DateTimeFormat);
68 }
69 }
70 }
71 #endregion
72
73 #region public override void FormOnLoad() 加载窗体
74 /// <summary>
75 /// 加载窗体
76 /// </summary>
77 public override void FormOnLoad()
78 {
79 // 显示实体
80 this.ShowEntity();
81 }
82 #endregion
83
84 #region public override bool SaveEntity() 保存
85 /// <summary>
86 /// 保存
87 /// </summary>
88 /// <returns>保存成功</returns>
89 public override bool SaveEntity()
90 {
91 bool returnValue = false;
92 SQLBuilder sqlBuilder = new SQLBuilder(this.UserCenterDbHelper);
93 sqlBuilder.BeginUpdate(BaseCommentEntity.TableName);
94 sqlBuilder.SetValue(BaseCommentEntity.FieldContents, this.txtComment.Text);
95 sqlBuilder.SetValue(BaseCommentEntity.FieldWorked, this.chkWorked.Checked ? 1 : 0);
96 sqlBuilder.SetValue(BaseCommentEntity.FieldModifiedUserId, this.UserInfo.Id);
97 sqlBuilder.SetValue(BaseCommentEntity.FieldModifiedBy, this.UserInfo.RealName);
98 sqlBuilder.SetDBNow(BaseCommentEntity.FieldModifiedOn);
99 sqlBuilder.SetWhere(BaseCommentEntity.FieldId, this.EntityId);
100 returnValue = sqlBuilder.EndUpdate() > 0;
101 return returnValue;
102 }
103 #endregion
104
105 #region public override bool CheckInput() 检查输入的有效性
106 /// <summary>
107 /// 检查输入的有效性
108 /// </summary>
109 /// <returns>有效</returns>
110 public override bool CheckInput()
111 {
112 bool returnValue = true;
113 this.txtComment.Text = this.txtComment.Text.TrimEnd();
114 if (string.IsNullOrEmpty(this.txtComment.Text))
115 {
116 MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9984), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
117 this.txtComment.Focus();
118 return false;
119 }
120 return returnValue;
121 }
122 #endregion
123
124 #region private void ClearForm()
125 /// <summary>
126 /// 清除窗体
127 /// </summary>
128 private void ClearForm()
129 {
130 this.txtComment.Text = string.Empty;
131 this.txtComment.Focus();
132 }
133 #endregion
134
135 #region private void AddComment(bool close)
136 /// <summary>
137 /// 保存评论
138 /// </summary>
139 /// <param name="close">关闭窗体</param>
140 private void AddComment(bool close)
141 {
142 // 检查输入的有效性
143 if (this.CheckInput())
144 {
145 // 设置鼠标繁忙状态,并保留原先的状态
146 Cursor holdCursor = this.Cursor;
147 this.Cursor = Cursors.WaitCursor;
148 try
149 {
150 if (this.SaveEntity())
151 {
152 // 数据发生了变化
153 this.Changed = true;
154 if (close)
155 {
156 this.DialogResult = DialogResult.OK;
157 // 关闭窗口
158 this.Close();
159 }
160 else
161 {
162 this.ClearForm();
163 }
164 }
165 }
166 catch (Exception ex)
167 {
168 this.ProcessException(ex);
169 }
170 finally
171 {
172 // 设置鼠标默认状态,原来的光标状态
173 this.Cursor = holdCursor;
174 }
175 }
176 }
177 #endregion
178
179 private void btnSave_Click(object sender, EventArgs e)
180 {
181 this.AddComment(true);
182 }
183 }
184 }
将权限管理、工作流管理做到我能力的极致,一个人只能做好那么很少的几件事情。