简单快速开发C\S架构程序用最简单的不分层最快的效率达到功能要求的例子程序FrmCommentAdd 添加评论的功能实现

2012-09-02 18:42        by         通用信息化建设平台,         340         阅读,         0         评论,         收藏,         编辑

2012090201.jpg

其实系统里的所有的对象,就是加100个字段1000个字段,也是有描述不完的功能需要描述的,这时候我们其实还是希望有个可以对任何系统里的对象都可以进行评论的一个功能,这样任何想说明的,都能随时加个评论就可以了。这样方便系统里的多个用户之间沟通交流。其实很早就想做个这样的功能,但是由于一直没时间,就等到最近空了,才做了这个评论功能,打算对系统的所有的窗体都实现可以进行评论的功能改进。

程序里就用了SQLBuilder工具类的功能,代码编写简单,同时能支持多数据库的支持,将来有需要更换数据库时就不会头疼了。

复制代码
 1 // --------------------------------------------------------------------
 2 // All Rights Reserved , Copyright (C) 2012 , Hairihan TECH, Ltd.
 3 // --------------------------------------------------------------------
 4
 5 using System;
 6 using System.Windows.Forms;
 7
 8 namespace DotNet.WinForm
 9 {
10 using DotNet.Business;
11 using DotNet.Utilities;
12
13 /// <summary>
14 /// FrmCommentAdd.cs
15 /// 添加评论
16 ///
17 /// 修改记录
18 ///
19 ///     2012.08.26 版本:1.0 JiRiGaLa  添加功能页面编写。
20 ///
21 /// 版本:1.0
22 ///
23 /// <author>
24 /// <name> JiRiGaLa </name>
25 /// <date> 2012.08.26 </date>
26 /// </author>
27 /// </summary>
28 public partial class FrmCommentAdd : BaseForm
29     {
30 public FrmCommentAdd()
31         {
32             InitializeComponent();
33         }
34
35 public FrmCommentAdd( string categoryCode, string objectId)
36             : this()
37         {
38 this.CategoryCode = categoryCode;
39 this.ObjectId = objectId;
40         }
41
42 private string categoryCode = string.Empty;
43 /// <summary>
44 /// 分类
45 /// </summary>
46 public string CategoryCode
47         {
48 get
49             {
50 return categoryCode;
51             }
52 set
53             {
54                 categoryCode = value;
55             }
56         }
57
58 private string objectId = string.Empty;
59 /// <summary>
60 /// 实体主键
61 /// </summary>
62 public string ObjectId
63         {
64 get
65             {
66 return objectId;
67             }
68 set
69             {
70                 objectId = value;
71             }
72         }
73
74 #region public override bool SaveEntity() 保存
75 /// <summary>
76 /// 保存
77 /// </summary>
78 /// <returns> 保存成功 </returns>
79 public override bool SaveEntity()
80         {
81 bool returnValue = false;
82             SQLBuilder sqlBuilder = new SQLBuilder( this.UserCenterDbHelper);
83             sqlBuilder.BeginInsert(BaseCommentEntity.TableName);
84             sqlBuilder.SetValue(BaseCommentEntity.FieldCategoryCode, this.CategoryCode);
85             sqlBuilder.SetValue(BaseCommentEntity.FieldObjectId, this.ObjectId);
86             sqlBuilder.SetValue(BaseCommentEntity.FieldContents, this.txtComment.Text);
87             sqlBuilder.SetValue(BaseCommentEntity.FieldWorked, this.chkWorked.Checked ? 1 : 0);
88             sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentId, this.UserInfo.DepartmentId);
89             sqlBuilder.SetValue(BaseCommentEntity.FieldDepartmentName, this.UserInfo.DepartmentName);
90             sqlBuilder.SetValue(BaseCommentEntity.FieldCreateUserId, this.UserInfo.Id);
91             sqlBuilder.SetValue(BaseCommentEntity.FieldCreateBy, this.UserInfo.RealName);
92             sqlBuilder.SetDBNow(BaseCommentEntity.FieldCreateOn);
93             sqlBuilder.SetValue(BaseCommentEntity.FieldIPAddress, this.UserInfo.IPAddress);
94             sqlBuilder.SetValue(BaseCommentEntity.FieldEnabled, 1);
95             sqlBuilder.SetValue(BaseCommentEntity.FieldDeletionStateCode, 0);
96             returnValue = sqlBuilder.EndInsert() > 0;
97 return returnValue;
98         }
99 #endregion
100
101 #region public override bool CheckInput() 检查输入的有效性
102 /// <summary>
103 /// 检查输入的有效性
104 /// </summary>
105 /// <returns> 有效 </returns>
106 public override bool CheckInput()
107         {
108 bool returnValue = true;
109 this.txtComment.Text = this.txtComment.Text.TrimEnd();
110 if ( string.IsNullOrEmpty( this.txtComment.Text))
111             {
112                 MessageBox.Show(AppMessage.Format(AppMessage.MSG0007, AppMessage.MSG9984), AppMessage.MSG0000, MessageBoxButtons.OK, MessageBoxIcon.Information);
113 this.txtComment.Focus();
114 return false;
115             }
116 return returnValue;
117         }
118 #endregion
119
120 #region private void ClearForm()
121 /// <summary>
122 /// 清除窗体
123 /// </summary>
124 private void ClearForm()
125         {
126 this.txtComment.Text = string.Empty;
127 this.txtComment.Focus();
128         }
129 #endregion
130
131 #region private void AddComment(bool close)
132 /// <summary>
133 /// 保存评论
134 /// </summary>
135 /// <param name="close"> 关闭窗体 </param>
136 private void AddComment( bool close)
137         {
138 // 检查输入的有效性
139 if ( this.CheckInput())
140             {
141 // 设置鼠标繁忙状态,并保留原先的状态
142                Cursor holdCursor = this.Cursor;
143 this.Cursor = Cursors.WaitCursor;
144 try
145                 {
146 if ( this.SaveEntity())
147                     {
148 // 数据发生了变化
149 this.Changed = true;
150 if (close)
151                         {
152 this.DialogResult = DialogResult.OK;
153 // 关闭窗口
154 this.Close();
155                         }
156 else
157                         {
158 this.ClearForm();
159                         }
160                     }
161                 }
162 catch (Exception ex)
163                 {
164 this.ProcessException(ex);
165                 }
166 finally
167                 {
168 // 设置鼠标默认状态,原来的光标状态
169 this.Cursor = holdCursor;
170                 }
171             }
172         }
173 #endregion
174
175 private void btnAdd_Click( object sender, EventArgs e)
176         {
177 this.AddComment( false);
178         }
179
180 private void btnSave_Click( object sender, EventArgs e)
181         {
182 this.AddComment( true);
183         }
184     }
185 }
复制代码