常见代码的编写规范(一)---列表数据的显示

类别:Java 点击:0 评论:0 推荐:


常见代码的编写规范(一)---列表数据的显示

2004年12月7日     


最近检查代码,发现很多问题,为此整理了一下常见代码的编写规范,以提高代码质量与效率。
      1.列表数据的显示
            列表数据显示分三个功能来完成,组织条件、取数据、展示数据,例子如下:
            A:组织条件
                private void PerpareSearchCondition()
                {    
                    DateTime dtStart = new DateTime(2000,1,1);
                   DateTime dtEnd=DateTime.Now ;
                   int iState = -1;
                   if(this.DropDownList4.SelectedValue!="")
                        iState=System.Convert.ToInt16(this.DropDownList4.SelectedValue) ;
                   int iWorkAge =0;
                   if( dd_workyear.SelectedValue!="")
                        iWorkAge=System.Convert.ToInt16(this.dd_workyear.SelectedValue) ;

                   if(this.startdate.Value!="")
                        dtStart = this.startdate.DateValue ;
                   if(this.enddate.Value !="")
                        dtEnd=this.enddate.DateValue ;
            }
           B:取数据
                     IList list = BusinessService.CHRService.GetApplyer(tb_applywork.Text,
                        dd_degree.SelectedItem.Text , iWorkAge,dtStart ,dtEnd ,iState );
            C:显示数据
              private void AddApplierToGrid(IList list)
              {
                   this.uwgApplyList.Rows.Clear();
                   foreach(IList listItem in list)
                   {
                        string[] sItem = GetItemData(listItem);
                        UltraGridRow r=new UltraGridRow(sItem);
                        uwgApplyList.Rows.Add(r) ;
                   }
              }
           private string[] GetItemData(IDictionary listItem)
          {
               string[] sItem = new string[9];
               if(listItem==null) return sItem;
   
               sItem[0]=NHibernateHelper.GetString(listItem["DeptName"]);
               sItem[1]=NHibernateHelper.GetString(listItem["Name"]);
               sItem[2]=NHibernateHelper.GetString(listItem["PositionName"]);
               sItem[3]=NHibernateHelper.GetString(listItem["ProbationershipMonth"]);
               sItem[4]=NHibernateHelper.GetString(listItem["ProbationershipSalary"]);
               sItem[5]=NHibernateHelper.GetShortDateString(listItem["OnDutyDate"]); 
               sItem[6]=NHibernateHelper.GetString(listItem["Phone"])+";"+NHibernateHelper.GetString(listItem["MobilePhone"]) ; 
               sItem[7]=NHibernateHelper.GetString(listItem["Email"]); 
               sItem[8]=NHibernateHelper.GetString(listItem["GuidPerson"]); 
               return sItem;  
          }
         
            主程序:
                   private  void Search()
                    {
                            PerpareSearchCondition();
                            IList list = BusinessService.CHRService.GetApplyer(tb_applywork.Text,
                        dd_degree.SelectedItem.Text , iWorkAge,dtStart ,dtEnd ,iState );
                            AddApplierToGrid(list);
                    }
        

本文地址:http://com.8s8s.com/it/it12784.htm