發表文章

coldfusion query buildin functions

Method Signiture Return Type Method Signiture Description void queryName.first() jump to the first row of a query void queryName.last() jump to the last row of a query boolean queryName.isFirst() true if we are positioned at the first row boolean queryName.isLast() true if we are positioned at the first row boolean queryName.next() go to the next row, return true if there is a next row boolean queryName.previous() go to the previous row, return true if there is a previous row int queryName.findColumn(String name) get the internal zero based Column ID by name void sort(int columnID, boolean ascending) sort by a column, use findColumn to get the column id String getColumnTypeName(int columnID) gets the data type of a column, this one didn't work properly when I tested it, it would return NUMERIC for a field that was a varchar. There is a method called guessColumnType that was probably used to determine it, it guessed wrong. 資料參考來源

sort query in coldfusion

當我們需要用 coldfusion 查詢資料庫時會使用 cfquery 執行SQL指令 <cfquery name="allEmployee" datasource="myDB">  Select employee_no,employee_name,employee.duty  From employee  Where employee_retired = 'N' </cfquery> 當然,資料排序可以直接下 SQL 的 ORDER BY 來完成 但是,如果有特殊需求需要在 coldfusion 內(in memory)才排序的話 有兩種方式可以完成: 1、使用 cfquery 對已經存在的 query 再處理 <cfquery name="sortedEmployee" dbtype="query">  Select *  From allEmployee  Order By employee_name ASC </cfquery> 2、使用query專用指令 <cfset allEmployee.sort(allEmployee.findColumn("employee_name"),true)> 對於第2種用法,可能要非常小心 因為,adobe的 coldfusion 服務器與 Railo 的服務器有不同的使用法 (注意,我測試的adobe coldfusion 是 MX7,可能新的版本有變) 指令 Adobe Coldfusion MX7 Railo QueryName.sort(QueryName.findColumn("ColumnName"),true) 可 不可 QueryName.sort(2,true) 可 不可 QueryName.sort("ColumnName",true) 不可 可 QueryName.sort("2",true) 不可 不可

Operating the HTML table like Powerbuilder's DataWindow chapter 0

圖片
發想來自我接觸最久的程式語言 Powerbuilder,說真的跳通到其他語言時,會非常懷念它的DataWindow 物件。原因不外乎,它讓資料操作變得很簡單,甚至讓程式設計師變懶了。 但如果開始使用其他語言時,例如現在幾乎都要用網頁來工作,就發現網頁要操作資料真的不是那麼容易,尤其使用AJAX技術時,針對頁面的操作,每個工程師寫出來的方式大相逕庭,閱讀理解就變得重重。 有鑑於此,只好將自己理解datawidnow的部份,將其方法(method)實現到javascript裡面來。 盡力讓畫面表單操作變得簡單一些。 這樣的好處是,使用相同套件,程式碼閱讀起來清爽也易懂,比較容易除錯。 下面簡單介紹一下操作原理,與表格架構,DataWindow會用DW簡稱: 1、原則上一個類DW的架構如下: <div id="objid">  <table width="100">   <tr>    <th width="48" cn="field1">欄1標題</th>    <th width="18" cn="field2">欄2標題</th>    <th width="28" cn="field3">欄3標題</th>   </tr>  <table> </div> 這是一個標準table外面包著一個div層,而這個div層的id就是這個datawindow的名稱(datawindow name),一個DW結構(div)裡面只能有一個table存在。 這個結構很重要,因為接下來所有的操作都會參考這個結構的定義。 2、TH屬性的定義: cn :欄位名稱,必要的,英數字,其值就是代表了這個欄位的column name。 edit :編輯模式,選擇性,此屬性表示生成的資料可以編輯,其值(編輯模式)有:text / password / date / ddw / lbox。 key :關鍵欄,選擇性,其值為yes / no,yes=開啟編

使用coldfusion將HTML表格輸出成EXCEL檔案(使用者下載)

Coldfusion 的檔案輸出控制,主要有下面兩個指令 <cfcontent><cfheader> cfcontent 用來告訴瀏覽器等一下要輸出的內容是甚麼格式 cfheader 用來宣告傳輸資料的相關資訊 簡單的輸出測試  saveFileTest.cfm: <cfsetting enablecfoutputonly= "Yes" > <cfcontent type= "application/vnd.ms-excel; charset=big5" > <cfheader name= "Content-Disposition" value= "attachment;filename=ODR10001234567.xls" > <!--- office Excel Format Structure---> <cfoutput> <html xmlns:x= "urn:schemas-microsoft-com:office:excel" > <head> <meta http-equiv= "Content-Type" content= "text/html;charset=big5" > <!--[if gte mso 9]> <xml> <x:ExcelWorkbook> <x:ExcelWorksheets> <x:ExcelWorksheet> <!--- this line names the worksheet ---> <x:Name>訂單狀態</x:Name> <x:WorksheetOptions> <!--- these 2 lines are what works the magic ---> <x:Panes> </x:Panes> </x:WorksheetOptions>

a problem Read & ReadEx in Powerbuilder 10

Powerbuilder 10 (含)以後的版本,檔案的讀取分為 Read 與 ReadEx 兩個指令,按照說明文件的用法 ReadEx 支援 StreamMode! 讀取每次可以超過 32767 個位元組,並且支援 TextMode! 的讀取模式,算是很好用的;但是這次的問題卻出在使用 LineMode! 開啟檔案 時 PB10 的 Read 這個指令上: 先看看這段程式碼哪裡出了問題,我有純文字一份文件 A.txt (ANSI編碼)內容為: 數據窗口揭秘:未公開的數據窗口事件 (作者:Mark Brown) 到目前為止,PB的數據窗口控件仍是PB眾多控件中功能最強大,最複雜的控件。 數據窗口固有的行為 然後利用下面這段程式碼讀取內容並顯示在 mle_1(MultiLine Editor)上面 integer li_fn string ls_str mle_1.text = "" li_fn = FileOpen("A.txt",LineMode!,Read!) if li_fn > 0 then //逐行讀取並顯示在mle_1上面 do while FileRead (li_fn , ls_str) >= 0 mle_1.text += ls_str +"~r~n" loop FileClose(li_fn) end if mle_1物件上的顯示內容: 數據窗口揭秘:未公開的數據窗口事件 的數據窗口事件 事件 (作者:Mark Brown) ) 到目前為止,PB的數據窗口控件仍是PB眾多控件中功能最強大,最複雜的控件。 件中功能最強大,最複雜的控件。 複雜的控件。 鞳C 數據窗口固有的行為 的行為 發現了嗎?讀取出的內容怪怪的,幾乎每一行後段文字都重複被讀出,導致整個內容大亂。 但是,這段程式碼如果放在 PB6、PB7、PB8、PB9 執行,卻一點問題就沒有。 整個詭異到不行。 但是如果是英數文內容的檔案,不管哪個版本 PB6 or PB10 就完全不會有問題,測試檔案內容如下: calculate the height of the element and divid

powerbuilder 的邏輯運算函數

powerbuilder 的位元運算能力幾乎同等『沒有』。 但是使用 windows API 又常常遇到許多變數需要邏輯運算過,但是看看目前的 PFC 的邏輯運算效能也不好。 因此突發奇想,把原本 PFC 的邏輯運算改一改,發現也蠻好用的,效能上也有改善。 Function名稱: f_bitoperator 回傳值: unsignedlong 傳遞參數: aul_s1 [unsignedlong][value]、aul_s2 [unsignedlong][value]、as_operator [string][value] /* PFC簡易版兩組數字做邏輯運算 輸入來源:aul_s1 [uLong],aul_s2 [uLong],as_operator [String] as_operator為邏輯運算描述如:"and" , "or" , "xor" , "not"只需要第一組(aul_s1)輸入, aul_s2放0就可以了 返回:運算結果[Long],當參數錯誤返回NULL */ uLong ll_ret boolean lb_s1[32] , lb_s2[32] , lb_u integer li_bit as_operator = lower(trim(as_operator)) //參數檢查 if isnull(aul_s1) or isnull(aul_s2) or isnull(as_operator) then setnull(ll_ret) Return ll_ret end if if as_operator = "" then setnull(ll_ret) Return ll_ret end if //位元轉換 for li_bit = 32 to 1 step -1 if mod(aul_s1 , 2) = 1 then lb_s1[li_bit] = true else lb_s1[li_bit] = false end if aul_s1 = truncate(aul_s1 /

匯入 EDI 檔案到 DataStore

在台灣寫程式常常會需要使用到其他公司的資料交換,而大部份的合作夥伴都很多都會使用EDI檔案傳遞,因此處理EDI檔案就成了家常便飯,但有時候又不想要遇到一個專案就要再寫一次,所以幾乎都將它轉成PFC來使用。 上一次提到了 EDI 轉出 Function ,所以這次來看看轉入EDI檔案的 Function怎麼做吧。 Function 名稱: f_edi2ds 回傳值: Long 傳遞參數: ads_dest[datastore][refrence]、as_file[string][readonly]、as_error[string][refrence] /* 將ED文字檔(as_file)I匯入到 DataStore(ads_dest) EDI切割模式依照 dataObject 的 column.limit 訂定的長度 */ Integer li_ColCount,li_Pos,li_Col,li_file Long ll_collimit[],ll_rc,ll_totl,ll_cc,ll_new String ls_colname[],ls_coltype[],ls_data,ls_val,ls_date,ls_time Datetime ldt_1 boolean lb_fin //檔案存在否? IF not FileExists(as_file) THEN Return -1 //DataStore存在否? IF isnull(ads_dest) OR not isValid(ads_dest) THEN Return -1 END IF //欄位存在否? li_ColCount = integer(ads_dest.Describe("datawindow.column.count")) IF li_ColCount <= 0 THEN Return -1 ll_totl = 0 //取得欄位屬性 FOR li_Col=1 TO li_ColCount ls_colname[li_Col] = ads_dest.Describe("#" + string(li_Col) + ".Name") ll_collimit[li_Col]