2022年7月27日 星期三

Scriptcase Blank/Grid 應用 Bootstrap 的 Badges (徽章)

在 Scriptcase上應用 Bootstrap:

GRID:

1. 在 Events 的 onScriptInit 裡,加上 Bootstrap 的引入連結,可以在Bootstrap 官網上,複製過來即可:

<!-- CSS only -->
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.0/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-gH2yIJqKdNHPEq0n4Mqa/HGKIhSkIHeL5AyhkYV8i59U5AR6csBvApHHNl/vI1Bx" crossorigin="anonymous">



2. 在要顯示的欄位定義裡,套用Badges 的定義即可。

// Check for record
$check_sql = "SELECT count(*) "
   . " FROM orders"
   . " WHERE employeeid = " . {employeeid};
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]})) { //found
    $v_orders_count = {rs[0][0]};
} else {
    $v_orders_count = 0;
}

if ( $v_orders_count > 100 ) {
	{ordcount} = "" . $v_orders_count . "";
} else {
	{ordcount} = "" . $v_orders_count . "";
}

2022年7月10日 星期日

ScriptCase 的 DashBoard Application說明

 ScriptCase 的 DashBoard Application 作為一個主控台應用程式,可以同時將數個Application 放置在同一個面板上面。

DashBoard 可以安排兩種不同的 Widget(桌面小工具):

  • Link Widget :連結到現成的APP
  • Index Widget:建立一個直接抓取資料庫資料表的資料數值。



Index Widget

  • Table Name
  • Metric Field:公制欄位
  • Period Field:與公制欄位做比較的期間欄位。(這個翻譯還要再斟酌一下。)
目前測試,好像是:設定一個要觀測的資料,例如營業額,這就是 Metric Field
而 Period Field ,好像只能是日期欄位,然後可以設定與日期有關的格式,做比較。是成長、下降等!再研究一下!

2022年6月26日 星期日

整理一下SC裡面關於SQL的指令,自寫程式時使用

整理 SC 裡面,自訂程式時,如何使用 SC提供的SQL指令


一、關於 connection:

1. 使用SC Project 設定現成的 Connection

2. sc_connection_edit("Connetion_Name", $arr_conn)

1º Parameter: Connection name to be edited.

2º Parameter: Array of items containing the connection information to be edited. Check out the indices of the array:

Indice
DescriptionExample
['server']Database server (host)$arr_conn['server'] = "127.0.0.1"
['user']Database username$arr_conn['user'] = "root"
['password']Database password$arr_conn['password'] = "secretpass123"
['database']Database name used in the connection$arr_conn['database'] = "sc_samples"
['persistent']Defines if the connection is persistent or not$arr_conn['persistent'] = "Y" / "N"
['encoding']Configure the connection encoding$arr_conn['encoding'] = "utf8"

Note:Is not required to use all the indices in the array, we can pass only the required ones.

Example:

$arr_conn = array();

$arr_conn['user'] = "admin2";
$arr_conn['password'] = "admin2pass";
$arr_conn['database'] = "sc_samples2";

sc_connection_edit("sc_connection", $arr_conn);


3. sc_connection_new("Connection_Name", $arr_conn)

The new connection will only be available in the next application.

1º Parameter: Connection name.

Note: If there is a connection created within the Scriptcase with the same name, this macro has no effect. Connections created within the Scriptcase prevail. If you want to edit an existing connection, see the documentation for the macro sc_connection_edit.

2º Parameter: Array of items containing the connection information. Check out the indices of the array:

 

Indice
DescriptionExample
['drive']Driver of the database used for the connection (see table below)$arr_conn['drive'] = "oci8"
['server']Database server (host)$arr_conn['server'] = "127.0.0.1"
['user']Database username$arr_conn['user'] = "root"
['password']Database password$arr_conn['password'] = "secretpass123"
['database']Database name used in the connection$arr_conn['database'] = "sc_samples"
['persistent']Defines if the connection is persistent or not$arr_conn['persistent'] = "Y" / "N"
['encoding']Configure the connection encoding$arr_conn['encoding'] = "utf8"

Note: It is required that all items are filled, with the exception of items ['persistent'] and ['encoding'].


Example:

$arr_conn = array();

$arr_conn['drive'] = "mysqlt";
$arr_conn['server'] = "127.0.0.1";
$arr_conn['user'] = "root";
$arr_conn['password'] = "pass123";
$arr_conn['database'] = "sc_samples";
$arr_conn['persistent'] = "Y";
$arr_conn['encoding'] = "utf8";

sc_connection_new("new_conn_mysql", $arr_conn);


二、SQL SELECT

sc_select (dataset, "SQL Command", "Connection")

sc_lookup (Dataset, "SQL Command", "Connection")


sc_select(dataset, "SQL Command", "Connection")

This macro executes the SQL commands passed as parameter and access the "dataset" in the command.

Different from sc_lookup macro, this macro doesn't manipulate the dataset (the user is responsible for all the manipulation).

If an error occurs in the sql command execution, the variable attributed to the database returns as "false" and the error message is available in the "dataset_error" variable.

The connection parameter is optional, use only if the command is executed in a data base different from the specified in the application. In this parameter it is not possible to use variables.


Ex. 1:

sc_select(my_data, "select clientId, clientName, limitecred from costumers");
if ({my_data} === false) {
    echo "Access error. Message =". {my_data_erro};
} else {
    while (!{my_data}->EOF) {
          {clientName} = {my_data}->fields[1];
          {my_data}->MoveNext();
     }
    {my_data}->Close();
}



Ex. 2: The SQL command can passed as application fields (local variables) or of global variables.
sc_select(dataset,"select price order from order where clientId = '{clientId}' and cod_Seller = [var_glo_seller]");

Note: The command must always be finished with semicolon";".


sc_lookup(Dataset, "SQL Command", "Connection")


This macro allows the user to execute SQL commands and returns the result to the "dataset" variable. The "dataset" structure is an array (line/column).

The "connection" parameter is optional. Use when the command is executed in a database different from that specified for the application.
Note: The connection parameter does not accept variable. You must enter the name of the connection that the SQL command will execute.


Ex. 1:
sc_lookup(dataset, "select customer_id, customer_name, credit_limit from customers" );

To have access to the first line (Dataset), use :
{customer_id} = {dataset[0][0]};
{customer_name} = {dataset[0][1]};
{credit_limit } = {dataset[0][2]};

To have access to the second line (Dataset), use:
{customer_id} = {dataset[1][0]};
{customer_name} = {dataset[1][1]};
{credit_limit} = {dataset[1][2]};

If occurs error in the execution of the SQL command, the variable attributed to the dataset will return as "false" and the error message will be available in the "dataset_error" variable. It is also important to verify the select returned data, to prevent access to non-existent variables, once the output array only will be created if the select command returns data.


Ex. 2:
sc_lookup(my_data, "select customer_id, customer_name, credit_limit from customers");
if ({my_data} === false)
{
echo "Access error. Message=". {my_data_error} ;
}
elseif (empty({my_data}))
{
echo "Select command didn't return data";
}
else
{
{customer_id} = {my_data[0][0]};
{customer_name} = {my_data[0][1]};
{credit_limit} = {my_data[0][2]};
}



Ex. 3: 
The SQL command also can be composed of application fields (local variables) or of global variables:
sc_lookup(dataset, "select order_value from orders where clientid = '{customer_id} ' and salesman_id = [var_glo_salesman]");

Note: The command must always be finished with a semicolon ";".

Note2: For a big result returned in the dataset we recommend the use of the macro sc_select instead of this one.



























sc_sql_injection ({My_Field}) or ($My_Variable)

sc_sql_protect (Value, "Type", "Connection")





Wordpress 的 Table 分析

由於有想要自己用SC設計一個取代(相容) WORDPRESS 的 CMS架站系統,所以,需要研究一下 WordPress 的資料庫結構。

按照功能大致分為五類:
用戶資訊 : wp_users , wp_usermeta
鏈接資訊 : wp_links
文章及評論 : wp_posts , wp_postmeta , wp_comments
分類,鏈接分類,標籤管理 : wp_term , wp_term_relationships , wp_term_taxonomy
全局設置 : wp_options

wp_commentmeta:評論的其他資訊
wp_comments:留言回覆
wp_links:友情鏈接(Blogroll)
wp_options:儲存 WordPress 系統選項和插件、主題配置
wp_postmeta: 存儲文章(包括頁面、上傳文件、修訂)的其他資訊
wp_posts:儲存文章(包括頁面、上傳文件、修訂)
wp_terms:儲存每個目錄、標籤
wp_term_relationships:儲存每個文章、鏈接和對應分類的關係
wp_term_taxonomy:儲存每個目錄、標籤所對應的分類
wp_usermeta:儲存用戶的其他資訊
wp_users:用戶資訊


2022年6月24日 星期五

SC GRID 的 SAVE GRID "儲存檢視格式"的功能

 SAVE GRID 這個功能是儲存檢視格式的功能,不是儲存GRID資料值到資料庫的功能。

GRID 是一個報表顯示、展示、檢視的應用程式,並不是編輯資料用的,因此,沒有儲存資料的必要性。(編輯然後儲存資料的功能是 FORM)

所以,這裡的 SAVE GRID 就是儲存檢視格式的功能的意思。這是要釐清概念一下的地方。

使用 ScriptCase 的 GRID-User Defined 設計一個產品頁/部落格文章頁等

ScriptCase 的 GRID Application裡面有四種型態的GRID,其中一個 User Defined 可以使用 HTML Template (定義在 Layout->HTML Template )裡面,也就是可以自行設計一個 HTML 模板,裡面再來放置 資料欄位值,然後,配合 GRID其他屬性的設定,而顯示頁面出來。

SC提供的範例,是 CARD ,一頁可以顯示所有的 CARD,或是依照 GRID 參數的設定,而一次顯示一筆或多筆均可。

如果一次一頁只顯示一筆,也就是商城單一產品展示頁的功能,或是 部落格單一文章展示頁的功能。

要一次只讀取一筆資料,可以在  SQL 地方,增加一個 WHERE productid=[v_productid],再來處理 [v_productid] 可以是 GET/POST 的方式給予值,這樣這個GRID 就只有一筆特定ID的資料頁了。

要把GRID 內定的依些顯示資料,例如格子底部的 幾筆之幾筆 的信息隱藏起來,就在 onScriptInit Event 裡面,加上 將該 CSS ID 設成 display: none; 這樣就可以了!

其他要怎麼顯示的格式,就在  HTML Template 裡面去設計即可。

GRID 的 layout 的 header/footer 也可以依據需要,設定顯示或不顯示。



** 註:

ScriptCase 的 GRID Application裡面有四種型態的GRID:

  • 橫式:一般橫式表格橫列的方式呈現資料,等於是一個 表格 報表
  • 直式:直式方式,一筆資料是一直行
  • SLIDE:投影片式,也就是運用SC提供的 現有Layout 功能,製作顯示頁面,一次一頁一筆
  • User Defined自定義,也就是 HTML Template

ScriptCase 修改SC的CSS設定值

可以在 Application 的 Events 裡面的 onScriptInit 裡面添加 CSS 的定義,就可以修改掉 原本 SC的CSS設定,例如:希望將 GRID 的表格底部的訊息隱藏起來,不要出現,可以使用 網頁檢查 的方式,查到該信息的 ID 為:sc_grid_sumario

那段 html 為:

<tr id="sc_grid_sumario"> .....</tr>

所以,就可以在 onScriptInit 這個 Event 裡面,這樣改:

?>
<style>
#sc_grid_sumario {
  display: none;
}
</style>
<?php


註:

onScriptInit 會加在 <HTML><HEAD>............[加在這裡]</HEAD>  

onApplicationInit 會加在 [加在這裡]<HTML<HEAD>............</HEAD>

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

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