常见代码编写规范(二)--详细数据的读与显示
来源:互联网 发布:中世纪2优化9苏格兰 编辑:程序博客网 时间:2024/05/17 22:53
常见代码编写规范(二)--详细数据的读与显示
2004年12月8日
2.详细数据的读与显示
详细数据的读与显示是我们碰到的最多代码之一,这种代码分成二个阶段来完成: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分页显示的代码与详细步骤 复制代码
- 编程规范(二)—— 区分代码和数据
- 项目文档编写规范与代码规范(一)
- IRC下载TLF0day资源
- 撰写Blog的利器之一
- Language Oriented Programming
- 博客,文字的卡拉OK版
- 如何对待上级给的新任务
- 常见代码编写规范(二)--详细数据的读与显示
- linux block qq的办法
- Mysql的常用命令文摘一
- 面向对象的JavaScript编程(liuruhong(原作))
- 网络编程的练习2
- 使用SQLDMO控制 SQL Server
- JavaScript窗口功能指南之检查一个窗口是否存在
- 设计模式趣解
- 让肉鸡难逃五指山---精品后门程序及思路分板