2014年9月2日 星期二

Code Charge 的 Form Templates (表單模板)

Form Templates 表單模板是Code Charge 設計來給  Builder 用的。
Code Charge 自己內訂一組模版,放在安裝目錄下的 /Templates 裡面。
可以根據自己的想法,修改之。
可以改的有:

  1. Authentication (i.e. Login form), 
  2. Editable Grid (i.e. Grid and Search forms), 
  3. Grid and Record (i.e. Grid, Record and Search forms), 
  4. Gallery (Gallery form), 
  5. Grid (i.e. Grid and Search forms), 
  6. Record, and Search. 

  • 大致來說,一個 From Template 也是一個 Code Charge Page,有 .ccp 及 .html。這兩個一組,如果要copy放到另一個目錄,一定要一起copy過去。
  • html 檔案裡面只能有三種東西:
    • template block (<!-- BEGIN Error -->  xxxxx  <!-- END Error -->)
    • template variable ({ControlTitle}之類的)
    • html 
  • 絕對不能在裡面加上 Code Charge 的 Component,會亂掉。

HELP裡面的 Example  很清楚的範例,值得參考照著實作一次就大致知道了。




Code Charge 的 Builder 當掉

一個開發中的專案,當然碰到一大堆問題,慢慢的克服,今天下午,突然要跑 Builder 時掛了!

試過各種的 Builder ,都當! Grid、Record 、Report、Editable Grid、Grid/Record等,都當!

是我的 Code Charge出問題嗎?

開另一個專案,跑 Builder,可以!那就表示 Code Charge沒有問題,是專案的設定有問題。

試了很多方法,因為之前有經驗,就是一個page remove designs時,會錯亂掉!所以我也懷疑Code Charge 的 .ccp 、.ccs 會不會可能也會錯亂?!如果 .ccs 或 .ccp錯亂了,可能導致AP跑起來當掉的。但是,正確的 .ccs/.ccp是怎樣?我還不是很清楚,也不知如何判斷,打開 .ccs/.ccp也看不出哪裡有問題?!

最後,想要會不會是 DBConnection 設定的問題,所以,又把 Connection 重新設定一次,重心存檔,在一次執行產生專案碼。再重試一次 Builder 就好了!

摸索了半天,Code Charge 還真煩人啊!

我想 Code Charge 還是還有很多小問題,如果不是很懂他的規則,總是會誤觸地雷,然後,就 GG ......了!

建議,經常性的備份,萬一掛掉時,還有回到之前狀態的機會。

code charge 的資料庫中文亂碼

今天建立一個新的專案,因為想說只有中文而已,因此,在專案設定上,server/script 上 Charset 設定為 utf8,Locales & Encodings 裡面的 File Encoding: Unicode(UTF-8)、Default HTML Encoding : Unicode(UTF-8)、Site Locales: Chinese (Default),點進去看內容,Output Encoding  也是 Unicode(UTF-8)。想說這樣該設的都設了,Connection 部分找不到有設定 encoding 的地方,所以就把帳號密碼設設就以為好了。

結果,使用 builder 一建立一個 AP 出來一看,我的媽唉!中文全成了 "???????"!

關於資料庫中文 "??????"的問題,php+mySQL其實早有經驗了,只是好奇,為什麼之前一樣用 Code Charge 都沒有問題的,為什麼此時會有問題?!

因為,我的資料庫是原本就建立好的,而且之前用別的程式做抓資料都沒有問題,我也特別檢查一下我的資料庫,該是"utf"原本就都設了,沒有改變。那麼問題應該還是在 Code Charge 上面了。

弄了半天,只好試試在該程式頁的起始之後,寫了一小段 "SET NAMES 'UTF8'",用程式強制mySQL用UTF8編碼,結果就正常了!

可是,Code Charge的問題ˋ出在哪裡呢?

請出全文搜索工具,尋找"UTF8",其他正常的專案可以顯示中文,新的專案顯示不了中文,肯定是有不一樣的地方。果然,找到 Common.php 中有不一樣的地方。新專案的 $CCConnectionSettings = array() 設定沒有 Encoding "UTF8" ,成功顯示中文的有。

那是哪裡的設定出問題呢?

後來試了試,原來是在 Locales & Encodings 裡。只要新增一個English語系,也設成UTF8 ,原本的Chinese也給他設設(本來就有的),這樣以後, common.php裡面,就自動產生了 Encoding "UTF8" 程式了!

這應該是 Code Charge 的 bug吧!理論上,Locales & Encoding 已經設了 Chinese UTF8 了,他還是把它當成一般的無 UTF8 的編碼,必需有新增一個 UTF8 的 Locales ,Code Charge才建立 UTF8的編碼起來。


2014年8月29日 星期五

CCS 動態產生 Data Source 資料來源

動態產生

一、動態產生 ListBox 的"List Of Values"
ListBox 裡面的值是成對的,透過 BeforeShow 可以將成對的值,以array(),送進去。

function Tasks_BeforeShow(& $sender) {
global $Tasks;
 
$Tasks->Status->Values = array(array("1", "High"),array("2", "Normal"), array("3", "Low"));

}



二、









CCS 使用筆記

修改物件屬性,要重新產生程式碼

CCS 修改物件的屬性以後,直接存檔,然後產生頁面程式,結果發現,沒改!跑出來的結果根本就是舊的屬性資料,不是新的。
幾經研究發現,原來,正確的程序,如果是修改物件的屬性,應該是讓CCS重新產生程式碼,然後再存檔,產生程式碼。

操作方法是:


  1. 切換到 "Code" 格;
  2. 確認是在 xxxxx.php 而不是 xxxxx_Event.php,按 Ctrl+A,選擇全部,然後 Delete 掉,再切換到 "Html" 格,再切換回 "Code"格,強迫CCS重新依據新的屬性記錄(記錄在.ccp檔案裡)重新產生程式碼。
  3. 存檔。產生頁面程式碼。完成。


CCS 把所有頁面裡面的物件,都儲存在 .ccp檔案中,.ccp其實是一個 xml 檔案,用文字編輯器就可以打開來看,你一看就會懂的。那就是這些物件的所有屬性資料的記錄檔案。

CCS 就是根據這個物件的屬性資料檔案來產生相對的程式碼。

CCS 程式中如何取得翻譯文字?

主要關鍵在於
global $CCSLocales;

然後,就可以這樣用:

$CCSLocales->GetText("CCS_Today");


function Label1_BeforeShow(& $sender) {
global $CCSLocales;
  $Component->SetValue($CCSLocales->GetText("CCS_Today"));
}

2014年8月26日 星期二

CCS 如何引用物件(referencing objects)?

在CCS中如何引用一個物件?

引用物件(Referencing Objects)

由CCS產生的應用程式的物件,可以有很多種引用的方法。
要引用一個物件,你應該要知道這個物件存在網頁程式中的階層位置。舉例來說:你必須弄清楚,這個物件是直接位於頁上的,還是頁裡的表單裡的物件。頁-page是一個物件、表單-Form也是一個物件。


PHP

在PHP裡面,你可以直接使用 $Component 來指引到發出該事件的元件, $Container 則是指引到存放該 $Component 的物件,也就是說 $Component 的上一層級物件。
使用 $Component 及 $Container 這個方法建議使用在可以重複使用的程式碼上,因為它並沒有直接使用名稱指引,所以,可以被重複利用。
另一個方法,就是直接使用廣域變數名稱來指引要該物件,例如:使用 $MyGrid 來指引到 "MyGrid" 這個grid 物件。


各種指引到物件的例子 語  法
頁面裡面的表單物件Form object placed on a page 頁面事件
Page Events
$Component->form->visible = false;
表單事件
Form Events
$Component->Visible = false;
表單裡面的控制項物件
Control object placed within a form
頁面事件
Page Events
$Component->form->control->SetValue($Component->form->PageNumber);
表單事件
Form Events
$Component->control->SetValue($Component->PageNumber);
控制項物件事件
Control Events
$Component->SetValue($Container->PageNumber);
頁面物件裡面的控制項物件
Control object placed on a page
頁面事件
Page Events
$Component->control->SetValue("ABC");
控制項事件
Control Events
$Component->SetValue("ABC");
在"包含頁面"(included page)物件裡面的控制項物件
Control object placed on an included page
主頁面事件
Main Page Events
$Component->page->control->Visible = false;
包含頁面事件
Includable Page  Events
$Component->control->Visible = false;
控制項物件事件
Control Events
$Component->Visible = false;
在"包含頁面"裡面的表單物件
Form object placed on an included page
主頁面事件
Main Page Events
$Component->page->form->Visible = false;
包含頁事件
Includable Page  Events
$Component->form->Visible = false;
表單事件
Form Events
$Component->Visible = false;
存在包含頁裡面的表單裡的控制項物件
Control object placed in a form within an  included page 
主頁面事件
Main Page Events
$Component->page->form->control->Visible = false;
包含頁事件
Includable Page  Events
$Component->form->control->Visible = false;
表單事件
Form Events
$Component->control->Visible = false;
控制項事件
Control Events
$Component->Visible = false;


使用廣域變數名稱的例子 語法
頁面裡的表單物件
Form object placed on a page
$form->Visible = false;
表單裡的控制項物件
Control object placed within a form
$form->control->SetValue("123");
頁面裡的控制項物件
Control object placed on a page
$control->SetValue("ABC");
包含頁裡的控制項物件
Control object placed on an included page
$page->control->Visible = false;
包含頁裡的表單物件
Form object placed on an included page
$page->form->Visible = false;
包含頁裡的表單裡的控制項物件
Control object placed in a form within an  included page 
$page->form->control->Visible = false;

Perl

Examples of working with objects Syntax
Form object placed on a page $<form>->{Visible} = 0;
Control object placed within a form $<form>->{<control>}->SetValue("123");
Control object placed on a page $<control>->SetValue("ABC");
Control object placed on an included page $<page>->{<control>}->{Visible} = 0;
Form object placed on an included page $<page>->{<form>}->{Visible} = 0;
Control object placed in a form within an included page  $<page>->{<form>}->{<control>}->{Visible} = 0;
Assigning an object to a variable $<variable> = $<object>;

Java

Examples of working with objects Syntax
Form object placed on a page Page Events e.getPage().getComponent("<form>").setVisible(false);
Form Events e.getComponent().setVisible(false);
Control object placed within a form Page Events e.getPage().getComponent("<form>").getControl("<control>").setValue("123");
Form Events e.getComponent().getControl("<control>").setValue("123");
Control Events e.getControl().setValue("123");
Control object placed on a page Page Events e.getPage().getControl("<control>").setValue("ABC");
Control Events e.getControl().setValue("ABC");
Assigning an object to a variable <variable> = <object>;
Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

C#

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = false;
Record Events <form>Holder.Visible = false;
Directory and Path Events <form>.Visible = false;
Control object placed within a Record form <form><control>.Visible = false;
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = false;
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = false;
Assigning an object to a variable <variable> = <object>;
Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

VB.Net

Examples of working with objects Syntax
Form object placed on a page Grid and Editable Grid Events <form>Repeater.Visible = False
Record Events <form>Holder.Visible = False
Directory and Path Events <form>.Visible = False
Control object placed within a Record form <form><control>.Visible = False
Control object placed within a Grid, Editable Grid, Directory and Path form Control's Before Show Event <form><control>.Visible = False
Form's Before Show and Before Show Row Event Object reference should be retrieved from the FormControls collection.
See the ItemDataBound Event MSDN example.
Control object placed on a page <control>.Visible = False
Assigning an object to a variable <variable> = <object>
Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above. The syntax for accessing objects in an included page from events within the including page is not supported. The syntax for accessing objects in the including page from events within the included page is also not supported.

ColdFusion

Examples of working with objects Syntax
Form variable placed on a page or within a form <CFSET blnReadAllowed<form>=false>
Control variable placed within a form or a page <CFSET fld<control> = "abc">
Note: The syntax for accessing objects in an included page from events within the same included page is the same as specified above.


如果引用的物件是在於一個Panel裡面,似乎有問題了。 如果一個物件存在於一個Panel裡面,文件上寫說 Panel 是透通的,也就是說引用物件的階層上, Panel是透明的,可以不管,可是,實際上卻發現不行! 在相同的 Panel 裡面,可以很輕易的引用到其他物件,但在 Panel 外面,或其他的 Panel 就會引用不到物件! 例如: members record -obj1 -obj2 -panel1 --obj3 --obj4 -panel2 --obj5 --obj6 在panel1裡面的 obj3 可以使用 members->obj4->getvalue() 引用到物件 可是 obj3 裡面使用 members->obj1->getvalue() 卻引用不到 在 obj1 可以使用 members->obj2->getvalue(), members->obj5->getvalue() 都可以引用到! 換句話說:在panel外面的物件,panel 就是透明的,可以引用到panel裡面的物件 而在panel裡面的物件,panel就不是透明的了,可以引用同層的物件,無法引用到panel外面的物件! 此時,只好變通一下了 在 panel 外面而裡面要用到的,重複一個hidden 的物件到裡面去! 只好這樣了!

如何判斷現在FORM是在 insert mode? 還是 update mode?

只要用  if (empty({primary_key})) 就可以知道是否為新增模式了。 如果 {promary_key} 是空白的,那麼就是在新增模式;反之,就是更新模式。 以上。