常见代码编写规范(二)--详细数据的读与显示
2005-02-21 09:50
656 查看
常见代码编写规范(二)--详细数据的读与显示
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,做不到的使用函数来进行处理。
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,做不到的使用函数来进行处理。
相关文章推荐
- 常见代码编写规范(二)--详细数据的读与显示
- 常见代码编写规范(二)--详细数据的读与显示
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码的编写规范(一)---列表数据的显示
- 常见代码的编写规范(三)---对象的赋值与保存
- 常见代码的编写规范(三)---对象的赋值与保存
- 常见代码的编写规范(四)---对象的保存与更新
- 常见代码的编写规范(四)---对象的保存与更新
- Control Study -> 主表和子表数据同时在绑定控件显示(示例代码下载)
- 编写高质量的CSS代码,规范建议
- 实时显示iOS编写UI代码效果
- JQuery读取XML文件数据并显示的实现代码
- asp textbox获取显示mysql数据示例代码
- 03_MyBatis基本查询,mapper文件的定义,测试代码的编写,resultMap配置返回值,sql片段配置,select标签标签中的内容介绍,配置使用二级缓存,使用别名的数据类型,条件查询ma
- Android代码编写规范
- OpenCv学习笔记(三)---OpenCv中基本数据类型--Point,Size,Rect,Scalar,Vec3b类类型的详细解释及其OpenCv中源代码的详细分析
- J2EE项目代码编写规范
- python中常见编写代码的陷阱
- 【POJ1182】食物链,思路+数据+代码,可能是史上关于这道题最详细的解题报告