写这篇文章也源于我和新员工的一些谈话心得,一些基础比较薄弱的技术人员,看起来有点像没有思想和灵魂的程序员。你可能也会觉得国内有很多小企业出来的人或者刚毕业的人,会的最多也是CRUD和拖拉控件。我也接触过一些技术人员,他们告诉我他们再也不想搞技术了,因为技术是在太无聊了,特别年纪稍大一点的,想的最多的就是转行。曾经我非常惊讶于这样的状况,事实上,写程序是一件很有创造力的事情,但为何很多人都会觉得无聊呢。
控件关系映射的发明源自于我在参与一款MIS系统的设计,该系统是一个钢管管理系统,每一个钢管的信息有很多很多的属性,我记得钢管厂给我们的数据说明书里面,一个管子的信息有惊人的380多列。因此,我们在查询、修改、添加记录的时候,总是会有类似以下成片成片的代码。
2 ......
3 var para1 = new SqlParameter("@a1", SqlDbType.String, a1.Text.Trim();
4 var para2 = new SqlParameter("@a2", SqlDbType.String, a1.Text.Trim();
5 ......
6 var paraN = new SqlParameter("@aN", SqlDbType.String, a1.Text.Trim();
2 <CrmMappings Class="HumanDispSolution.login" >
3 <MappingSQL GenType="None" Name="Login" Value="select UID,Name,Sys_User.RID,Role from Sys_User,Sys_Role where Sys_User.RID=Sys_Role.RID AND UID=@UID AND Password = @PWD" SqlOpType="SELECT" CmdType="Text" >
4 <SqlParams >
5 <SqlParam Name="@UID" ControlID="UID" ParamType="String" IsFile="False" >
6 </SqlParam>
7 <SqlParam Name="@PWD" ControlID="PWD" ParamType="String" IsFile="False" >
8 </SqlParam>
9 </SqlParams>
10 <SqlResults >
11 <SqlResult Field="Name" MemberID="UserName" IsStatic="True" AssemblyName="HumanDispSolution" StaticTypeName="HumanDispSolution.UserConfig" >
12 </SqlResult>
13 <SqlResult Field="UID" MemberID="UserID" IsStatic="True" AssemblyName="HumanDispSolution" StaticTypeName="HumanDispSolution.UserConfig" >
14 </SqlResult>
15 <SqlResult Field="RID" MemberID="RID" IsStatic="True" AssemblyName="HumanDispSolution" StaticTypeName="HumanDispSolution.UserConfig" >
16 </SqlResult>
17 <SqlResult Field="Role" MemberID="Role" IsStatic="True" AssemblyName="HumanDispSolution" StaticTypeName="HumanDispSolution.UserConfig" >
18 </SqlResult>
19 <SqlResult InvokeMethod="Log" IsStatic="True" AssemblyName="HumanDispSolution" StaticTypeName="HumanDispSolution.Logger" >
20 <InvokeParam Value="登入系统" >
21 </InvokeParam>
22 </SqlResult>
23 </SqlResults>
24 </MappingSQL>
25 </CrmMappings>
2 {
3 public class login : CrmPage
4 {
5 private void btnLogin_Click(object sender, System.EventArgs e)
6 {
7 DataSet ds = this.ExecuteMapping("Login") as DataSet;
8 if(ds.Tables[0].Rows.Count > 0) //登入
9 {
10 System.Web.Security.FormsAuthentication.RedirectFromLoginPage(UID.Text,false);
11 }
12 else
13 this.lAlert.Text = "<script language='javascript'>alert('登录失败,请重新输入帐户信息!');</script>";
14 }
15 }
16 }
2、我是如何发明了通用窗体框架
每一个开发人员只需要编写类似以下的配置文件就可以集成了:
2 <MainForm>
3 <Menus Name="菜单">
4 <Menu Name="系统(S)" LeftIndex="3" TopIndex="1" Command="" Class="">
5 <Menu Name="登录管理" LeftIndex="1" TopIndex="1" Command="" Class=""/>
6 <Menu Name="欢迎" LeftIndex="2" TopIndex="2" Command="" Class="CZB.Framework.WelcomeForm"/>
7 <Menu Name="退出" LeftIndex="3" TopIndex="3" Command="Close" Class=""/>
8 </Menu>
9
10 <Menu Name="数据导出(B)" LeftIndex="2" TopIndex="3" Command="" Class="">
11 <Menu Name="导出Excel" LeftIndex="2" TopIndex="2" Command="" Class="SalaryManagement.UI.frmExport"/>
12 </Menu>
13 </Menus>
14
15 <ToolButtons Name="工具栏">
16 <ToolButton Name="工具栏名称" Index="1" ImageIndex="1" Visible="true" Roles="" Command="HideOrShow" Class="工具栏名称" />
17 <ToolButton Name="工具栏名称1" Index="2" ImageIndex="2" Visible="false" Roles="" Command="" Class="工具栏名称1" />
18 </ToolButtons>
19 </MainForm>
ORM对于一些小型应用感觉有点庞大,但是对于大型应用,我想是一个比较总要的组件了。在我们使用ORM组件时,也经常会写以下代码。
2 user.Name = NameTextBox.Text.Trim();
3 user.Password = PasswordTextBox.Text.Trim();
4 ......
5 OrmFactory.Save(user);
6 ----------------------------------------------
7 var user = OrmFactory.QueryScalar(...);
8 NameTextBox.Text = user.Name;
9 ......
2 {
3 ……
4 [Member]
5 public int Age;
6 [Control]
7 public string Name
8 {
9 get { return this._Name; }
10 set { this._Name = value; }
11 }
12 [Control("CardNo.Text")]
13 public string CardNo
14 {
15 get { return this._CardNo; }
16 set { this._CardNo = value; }
17 }
18 ……
19 }
20
21 public class EmployeeEntity
22 {
23 ……
24 [Reference(typeof(UserEntity))]
25 public UserEntity User
26 {
27 get { return this._User; }
28 set { this._User = value; }
29 }
30 [Control]
31 public float PostSalary
32 {
33 get { return this._PostSalary; }
34 set { this._PostSalary = value; }
35 }
36 ……
37 }
2 {
3 this.o = CZB.ObjectMapper.ObjectEngine.Map(this,typeof(EmployeeEntity)) as EmployeeEntity;
4 }
2 {
3 this.o.User.Name = "c.z.b in";
4 this.o.User.Age = 19;
5 this.o.CompoInsurance = 0;
6 CZB.ObjectMapper.ObjectEngine.InverseMap(this,o);
7 }
我不是什么老鸟,希望我们在如此多的技术的世界中能够多多交流,共同进步。解决这些问题,不仅增加了编程的乐趣,更是增加了自己的见识,从而避免自己成为一个没有思想的程序员!我也知道,我们可以找到很多理由来反驳文中提到的做法和观点,但是,提高自己才是最重要的,不要去着急的否定一些什么,并给自己找借口。