当前位置:系统之家 > 技术开发教程 > 详细页面

DataWindow Style帮你格式化数据窗口样式

DataWindow Style帮你格式化数据窗口样式

更新时间:2024-04-12 文章作者:未知 信息来源:网络 阅读次数:

  在使用DataWindow时,通常我们都是手工在数据窗口画板中来调整数据窗口对象的样式(列宽、列高、标题、颜色等等)。但是在大型的应用中,往往会有众多的数据窗口,而反复的手工去调整这些数据窗口会给我们的开发工作带来极大的不便,即使耐心的一个一个地修改了数据窗口对象的样式,也难免不能做到精确的统一,这样即不符合功能复用的精神,也给系统的使用效果带来一定的影响。
      为了很好的解决这一问题,特提出了此解决方案,此方案是专门针对Grid类型的数据窗口的,在此基类中,通过代码遍历数据窗口的所有可视列,来改变列以及列标题的样式,以及改变拥有下拉子数据窗口的列中的数据窗口的样式,从而达到格式化数据窗口样式的目的。
      你可以在以下的图示中观察到这一功能的最终效果: 
 

DataWindow Style帮你格式化数据窗口样式

                图1.DataWindow Style效果示例
      实现机制:
      1.首先要有一个数据窗口的基类,作为以后封装各类数据窗口相关的特征代码的容器。
      2.所有要格式化的DWObject的属性均需设置为变量的形式,并为他们赋值。
      3.通过Describe("DataWindow.Column.Count") 函数来得到数据窗口的列数,并遍历列,使用Modify(" ")函数来实现改变DWObject其相关的属性(例如:执行Modify( "id_t .Font.Face=’宋体’" )来改变id_t的字体 )。
      4.重复3的过程,但不同的是,这次遍历的是子数据窗口的列,也就是DataWindowChild对象,注意:别忘记了先判断数据窗口是否拥有DataWindowChild,有的话记住先得到他们。
      5.也是最后一步,你是否需要保存数据窗口的样式呢?( 比如:保持同样的列宽,下次再打开此窗口时可以保持与上次调整的列宽一样。) 这里只是做了一个提醒,至于如何具体实现,本例中不做说明了,或许以后有专门讲解系统配置方面的专题中再加以说明吧。
      主要代码实现:
      1.变量的声明:
         private:
         integer                   ii_style =  1            //默认样式
         constant  integer    STYLE_DEFAULT = 1
         //STYLE_DEFAULT
         constant  string      colheader_fontcolor_default = "16777215"
         constant  string      colheader_bgcolor_default = "10040064"
         constant  string      col_bgcolor_default= "536870912~tif(mod(getrow(),2)=0,rgb(239,236,229),rgb(255,255,255))"
      2.主要函数:
      1)   integer of_getchild(ref datawindowchild adwc[])
            integer                  i, j, li_col_cnt
            integer                  li_ret
            string                    ls_col
            datawindowchild   ldwc_child[]
            li_col_cnt = integer( this.describe( "DataWindow.Column.Count" ) ) 
            if li_col_cnt < 1 then return -1
            for i = 1 to li_col_cnt 
                 ls_col = this.of_getcolumndisplayname( i )
                 li_ret = this.getchild( ls_col, ldwc_child[i] )
                 if li_ret = 1 then
                    j++
                    this.getchild( ls_col, adwc[j] )
                 end if
            next
            return j
      2)   string of_getcolumndisplayname(integer ai_colnumber)
            string ls_colname
            ls_colname = this.describe ("#" + string (ai_colnumber) + ".name")
            if ls_colname = " " or ls_colname = "!" then
               return "!"
            end if
            return of_getColumnDisplayName (ls_colname)
      3)   string of_getcolumndisplayname(string as_colname)
            string ls_coldisplayname
            ls_coldisplayname = this.describe (as_colname + ".name")
            return ls_coldisplayname
      4)   string of_getheadername(string as_column)
            string ls_defaultheadersuffix = "_t"
            string   ls_colhead
            ls_colhead = as_column + ls_defaultheadersuffix
            return ls_colhead
      5)   string of_getheadertext(string as_column)
            string ls_defaultheadersuffix = "_t"
            string   ls_colhead
            ls_colhead = this.describe ( as_column + ls_defaultheadersuffix + ".Text" )
            if ls_colhead = "!" then
              //No valid column header, use column name.
              ls_colhead = as_column
            end if 
            return ls_colhead
      6)   integer of_setstyle(integer ai_style)
            integer          i, j
            integer          li_column_cnt                  //列数
            string           ls_column_name               //列名
            string           ls_column_width               //列宽
            string           ls_child_column_name      //子数据窗口列名
            string           ls_column_headername     //列标题
            string           ls_colheader_fontcolor      //列标题字体颜色
            string           ls_colheader_bgcolor        //列标题背景颜色
            string           ls_col_bgcolor                  //列背景颜色
            datawindowchild  ldwc_child[]             //子数据窗口
            choose case ai_style
             case 1
              ls_colheader_fontcolor = colheader_fontcolor_default
              ls_colheader_bgcolor = colheader_bgcolor_default
              ls_col_bgcolor = col_bgcolor_default
             case else
              ls_colheader_fontcolor = colheader_fontcolor_default
              ls_colheader_bgcolor = colheader_bgcolor_default
              ls_col_bgcolor = col_bgcolor_default   
            end choose
            //禁止列移动
            this.modify("DataWindow.Grid.ColumnMove=No")
            //禁止鼠标全选择
            this.modify("DataWindow.Selected.Mouse=No")
            //调整列以及列标题
            li_column_cnt = integer( this.describe("DataWindow.Column.Count") )
            for i = 1 to li_column_cnt
              //调整列样式 
              ls_column_name = this.of_getcolumndisplayname( i )
              this.modify( ls_column_name + ".Font.Face=’宋体’" )
              this.modify( ls_column_name + ".Font.Height=’-9’" )
              this.modify( ls_column_name + ".Y=’4’" )
              this.modify( ls_column_name + ".Height=’56’")
              this.modify( ls_column_name + ".Background.Mode=’0’" )
              this.Modify( ls_column_name + ".Background.Color=’" + ls_col_bgcolor + "’" )
              //调整列标题样式
              ls_column_headername = this.of_getheadername( ls_column_name )
              this.modify( ls_column_headername + ".Color=’" + ls_colheader_fontcolor + "’" )
              this.modify( ls_column_headername + ".Font.Face=’Arial’" )
              this.modify( ls_column_headername + ".Font.Height=’-9’" )
              this.modify( ls_column_headername + ".Y=’0’" )
              this.modify( ls_column_headername + ".Height=’68’")
              this.modify( ls_column_headername + ".background.mode=’0’" )
              this.modify( ls_column_headername + ".Background.Color=’" + ls_colheader_bgcolor + "’")
            next
            //带区样式
            this.modify("DataWindow.Header.Height=’68’")
            this.modify("DataWindow.Detail.Height=’68’")
            this.modify("DataWindow.Footer.Height=’40’")
            //this.modify("DataWindow.Footer.Color= ’" + ls_colheader_bgcolor + "’")
            //调整datawindowchild样式
            this.of_getchild( ldwc_child[] )
            for i = 1 to upperbound( ldwc_child )
              if isvalid( ldwc_child[i] ) then
                 ldwc_child[i].settransobject( sqlca )
                 //禁止列移动
                 ldwc_child[i].modify("DataWindow.Grid.ColumnMove=No")
                 //禁止鼠标全选择
                 ldwc_child[i].modify("DataWindow.Selected.Mouse=No")
                 //调整表头高度为0
                 ldwc_child[i].modify("DataWindow.Header.Height=’0’")
                 //调整数据区高度
                 ldwc_child[i].modify("DataWindow.Detail.Height=’68’")
                 //datawindowchild的列数
                 li_column_cnt = integer( ldwc_child[1].describe("DataWindow.Column.Count") )
                 //调整datawindowchild的列样式
                 for j = 1 to li_column_cnt
                       //调整列样式 
                       ls_child_column_name = ldwc_child[i].describe ("#" + string (j) + ".name")
     
                       if ls_child_column_name = " " or ls_child_column_name = "!" then
                       ls_child_column_name = ’’
              else
                 ls_child_column_name = ldwc_child[i].describe ( ls_child_column_name + ".name" )
              end if
     
              ldwc_child[i].modify( ls_child_column_name + ".Font.Face=’宋体’" )
              ldwc_child[i].modify( ls_child_column_name + ".Font.Height=’-9’" )
              ldwc_child[i].modify( ls_child_column_name + ".Y=’4’" )
              ldwc_child[i].modify( ls_child_column_name + ".Height=’56’")
              ldwc_child[i].modify( ls_child_column_name + ".Background.Mode=’0’" )
             ldwc_child[i].Modify( ls_child_column_name + ".Background.Color=’" + ls_col_bgcolor + "’" ) 
            next
          end if
         next
         return 1

温馨提示:喜欢本站的话,请收藏一下本站!

本类教程下载

系统下载排行