常见代码编写规范(二)--详细数据的读与显示
来源:互联网 发布:链家端口费是什么 编辑:程序博客网 时间:2024/05/21 11:26
详细数据的读与显示是我们碰到的最多代码之一,这种代码分成二个阶段来完成:1.取到对应的对象,2.显示数据到界面上。显示数据的时候要好好组织,对于一个类聚合多个类时,每个类都要分成一个函数进行处理,每个处理函数要基本保证一条语句处理一个Porperty,对于需要转换的属性,使用一个函数进行转换。代码例子如下:
1.取相应的对象
private CPerson GetPerson()
{
Guid GuidPerson=new Guid(this.m_pGuid.Text);
CPerson person=CPerson .Load(GuidPerson);
}
2.显示相应的对象
显示Person
private void ShowPerson()
{
CPerson person=GetPerson()
if(person==null) return;
this.tb_name.Text=person.Name;
///当通过一个置值语句不能完成任务,或需要进行条件判断时,使用函数
SetGender(person.Gender);
this.tb_old.DateValue=person.BornDate;
ShowContactInfo(person.ContactInfo);
ShowApplyRecord(person.ApplyRecord);
this.tb_worktime.DateValue = person.StartWorkDate;
}
private void SetGender(bool bGender)
{
if(bGender)
this.rbMale.Checked = true;
else
this.rbFemale .Checked = true;
}
///显示其它对象,这里显示联系信息
private void ShowContactInfo(CContactInfo info)
{
if(info==null) return;
this.tb_phone.Text=info.Phone;
this.tbMobilePhone.Text = info.MobilePhoneNo ;
this.tbEmail.Text = info.EMail ;
}
///这里显示教育经历
private void ShowEducationHistory(CEducationHistory history)
{
if(history==null) return;
this.tb_school.Text=history.School;
this.tb_time.Value=history.StartDate.ToShortDateString();
this.tb_study.Text=history.Speciality;
this.ddlEducationalLevel.SelectedValue = history.EducationalLevel ;
this.ddlDegree.SelectedValue =history.Degree ;
}
private void InitApplyRecord(CApplyRecord apply)
{
if(apply==null) return;
this.tb_eng.SelectedValue =apply.EnglishLevel;
this.tb_jan.SelectedValue = apply.JanpaneseLevel ;
this.tb_other.SelectedValue = apply.OtherLanguageName ;
this.tbOtherLanguageLevel.Text = apply.OtherLanguageLevel ;
this.tb_work1.Text=apply.ApplyJob1;
this.tb_work2.Text=apply.ApplyJob2;
this.tb_work3.Text=apply.ApplyJob3;
this.applydate.Value=apply.ApplyDate.ToShortDateString();
InitEducationHistory(apply.EducationHistory);
}
结论:显示数据要清晰易懂,责任明确,每个哪个函数负责取对象,哪个函数负责显示哪个对象的数据,显示数据是要保持一条语句显示一个Porperty,做不到的使用函数来进行处理。
- 常见代码编写规范(二)--详细数据的读与显示
- 常见代码编写规范(二)--详细数据的读与显示
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码的编写规范(三)---对象的赋值与保存
- 常见代码的编写规范(四)---对象的保存与更新
- 常见的代码规范
- 项目文档编写规范与代码规范
- 代码编写规范说明书(c#.net与asp.net)
- 代码编写规范说明书(c#.net与asp.net)
- 代码编写规范说明书(c#与asp.net)
- 代码编写规范说明书(c#.net与asp.net)
- 代码编写规范说明书(c#.net与asp.net)
- 代码规范(二)
- IOS - 实时显示iOS编写UI代码效果(控件的懒加载和使用Plist文件将数据与代码分离),iosplist
- jsp分页显示的代码与详细步骤 复制代码
- 编程规范(二)—— 区分代码和数据
- 项目文档编写规范与代码规范(一)
- 实现接口5
- 实现接口6
- XP终端服务远程登录批处理(邪恶八进制blog)
- 20041208
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码编写规范(二)--详细数据的读与显示
- Session详解[郎云鹏]
- 網管必讀-常用網絡命令Windows 200x (转载)
- JasperReport在Spring上的应用
- 四大经济圈发展比较
- iBatis 学习 之二 事务处理
- ASP.Net请求处理模式
- J2SE5.0新特性之枚举类型
- J2SE5.0新特性之自动装箱解箱