在使用DataWindow時(shí),通常我們都是手工在數(shù)據(jù)窗口畫板中來調(diào)整數(shù)據(jù)窗口對(duì)象的樣式(列寬、列高、標(biāo)題、顏色等等)。但是在大型的應(yīng)用中,往往會(huì)有眾多的數(shù)據(jù)窗口,而反復(fù)的手工去調(diào)整這些數(shù)據(jù)窗口會(huì)給我們的開發(fā)工作帶來極大的不便,即使耐心的一個(gè)一個(gè)地修改了數(shù)據(jù)窗口對(duì)象的樣式,也難免不能做到精確的統(tǒng)一,這樣即不符合功能復(fù)用的精神,也給系統(tǒng)的使用效果帶來一定的影響。 實(shí)現(xiàn)機(jī)制: 1.首先要有一個(gè)數(shù)據(jù)窗口的基類,作為以后封裝各類數(shù)據(jù)窗口相關(guān)的特征代碼的容器。 2.所有要格式化的DWObject的屬性均需設(shè)置為變量的形式,并為他們賦值。 3.通過Describe("DataWindow.Column.Count") 函數(shù)來得到數(shù)據(jù)窗口的列數(shù),并遍歷列,使用Modify(" ")函數(shù)來實(shí)現(xiàn)改變DWObject其相關(guān)的屬性(例如:執(zhí)行Modify( "id_t .Font.Face=’宋體’" )來改變id_t的字體 )。 4.重復(fù)3的過程,但不同的是,這次遍歷的是子數(shù)據(jù)窗口的列,也就是DataWindowChild對(duì)象,注意:別忘記了先判斷數(shù)據(jù)窗口是否擁有DataWindowChild,有的話記住先得到他們。 5.也是最后一步,你是否需要保存數(shù)據(jù)窗口的樣式呢?( 比如:保持同樣的列寬,下次再打開此窗口時(shí)可以保持與上次調(diào)整的列寬一樣。) 這里只是做了一個(gè)提醒,至于如何具體實(shí)現(xiàn),本例中不做說明了,或許以后有專門講解系統(tǒng)配置方面的專題中再加以說明吧。 主要代碼實(shí)現(xiàn): 1.變量的聲明: private: integer ii_style = 1 //默認(rèn)樣式 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.主要函數(shù): 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 //列數(shù) string ls_column_name //列名 string ls_column_width //列寬 string ls_child_column_name //子數(shù)據(jù)窗口列名 string ls_column_headername //列標(biāo)題 string ls_colheader_fontcolor //列標(biāo)題字體顏色 string ls_colheader_bgcolor //列標(biāo)題背景顏色 string ls_col_bgcolor //列背景顏色 datawindowchild ldwc_child[] //子數(shù)據(jù)窗口 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 //禁止列移動(dòng) this.modify("DataWindow.Grid.ColumnMove=No") //禁止鼠標(biāo)全選擇 this.modify("DataWindow.Selected.Mouse=No") //調(diào)整列以及列標(biāo)題 li_column_cnt = integer( this.describe("DataWindow.Column.Count") ) for i = 1 to li_column_cnt //調(diào)整列樣式 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 + "’" ) //調(diào)整列標(biāo)題樣式 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 //帶區(qū)樣式 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 + "’") //調(diào)整datawindowchild樣式 this.of_getchild( ldwc_child[] ) for i = 1 to upperbound( ldwc_child ) if isvalid( ldwc_child[i] ) then ldwc_child[i].settransobject( sqlca ) //禁止列移動(dòng) ldwc_child[i].modify("DataWindow.Grid.ColumnMove=No") //禁止鼠標(biāo)全選擇 ldwc_child[i].modify("DataWindow.Selected.Mouse=No") //調(diào)整表頭高度為0 ldwc_child[i].modify("DataWindow.Header.Height=’0’") //調(diào)整數(shù)據(jù)區(qū)高度 ldwc_child[i].modify("DataWindow.Detail.Height=’68’") //datawindowchild的列數(shù) li_column_cnt = integer( ldwc_child[1].describe("DataWindow.Column.Count") ) //調(diào)整datawindowchild的列樣式 for j = 1 to li_column_cnt //調(diào)整列樣式 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 |
溫馨提示:喜歡本站的話,請(qǐng)收藏一下本站!