top
Loading...
AppML 案例模型

<AppML> 案例研究 - 應用程序模型


此案例研究演示了如何構建一個完整的 <AppML> 互聯網應用程序,具有針對數據庫中的若干表進行信息列舉、編輯和搜索的功能。


應用程序模型

在本章中,我們將為數據庫中的 Customers 表建立一個完整的應用程序模型。


<AppML> 過濾器

如需允許過濾 <AppML> 數據,只需簡單地向模型添加一個 <filters> 元素:

實例:

<filters>
<query>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</query>
<order>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</order>
</filters>

如需全面了解,請參閱 <AppML> 參考手冊


<AppML> 更新

如需允許更新 <AppML> 數據,只需簡單地向模型添加一個 <update> 元素:

實例:

<update>
<item><name>LastName</name></item>
<item><name>FirstName</name></item>
<item><name>BirthDate</name></item>
<item><name>Photo</name></item>
<item><name>Notes</name></item>
</update>

且向 <database> 元素添加一個 <maintable> 和 <keyfield> 元素:

實例:

<maintable>Customers</maintable>
<keyfield>CustomerID</keyfield>

如需全面了解,請參閱 <AppML> 參考手冊


<AppML> 安全

您可以通過向 <AppML> 標籤添加一個 security 屬性來很容易地為 <AppML> 模型添加安全。

實例:

<appml security="admin">

在上面的實例中,只有用戶登錄成為用戶組 "admin" 的會員才能訪問模型。

如需為 <update> 元素設置安全,只需簡單地向 <update> 元素添加一個 security 屬性:

實例:

<update security="admin">
<item><name>LastName</name></item>
<item><name>FirstName</name></item>
<item><name>BirthDate</name></item>
<item><name>Photo</name></item>
<item><name>Notes</name></item>
</update>


完整的 Customers 模型

在本章中,我們將為數據庫中的每個表設立一個應用程序模型。

創建一個名為 Models 的新文件夾。在 Models 文件夾中,為每個應用程序創建一個模型。

模型:Customers.xml

<appml security="">

<datasource>
<database>
<connection>Demo</connection>
<maintable>Customers</maintable>
<keyfield>CustomerID</keyfield>
<sql>SELECT * FROM Customers</sql>
<orderby>CustomerName,City,Country</orderby>
</database>
</datasource>

<filters>
<query>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</query>
<order>
<field label="Customer">CustomerName</field>
<field>City</field>
<field>Country</field>
</order>
</filters>

<update security="admin">
<item><name>CustomerName</name></item>
<item><name>ContactName</name></item>
<item><name>Address</name></item>
<item><name>PostalCode</name></item>
<item><name>City</name></item>
<item><name>Country</name></item>
</update>

</appml>



模型視圖

創建一個模型視圖,把它保存為 Demo_Model.html,併嘗試一下:

視圖:Demo_Model.htm

<h1>Customers</h1>
<div id="List01"></div>

<script src="appml.js"></script>
<script>
customers=new AppML("appml.htmlx","Models/Customers");
customers.run("List01");
</script>

嘗試一下 »


現在把所有的合併在一起

然後,通過少量 JavaScript 編碼,為所有模型創建一個測試頁面:

Demo_Model_Views.htm

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="appml.css" />
</head>

<body>
<h1>Demo Applications</h1>

<button onclick='myOpen("Customers")'>Customers</button>
<button onclick='myOpen("Products")'>Products</button>
<button onclick='myOpen("Suppliers")'>Suppliers</button>
<button onclick='myOpen("Shippers")'>Shippers</button>
<button onclick='myOpen("Categories")'>Categories</button>
<button onclick='myOpen("Employees")'>Employees</button>
<button onclick='myOpen("Orders")'>Orders</button>
<button onclick='myOpen("OrderDetails")'>OrderDetails</button>
<br><br>

<div id="Place01"></div>

<script src="appml.js"></script>
<script>
function myOpen(pname)
{
var app_obj
app_obj=new AppML("appml.asp","Models/" + pname);
app_obj.run("Place01");
}
</script>

</body>
</html>



北斗有巢氏 有巢氏北斗