A. 26~30 規劃撰寫程式入下列表:
功能 | 程式名稱 | 目錄 |
---|---|---|
列表(List) | StockCode_L.aspx | WEB介面設計-列表 List (26) |
新增(Create) | StockCode_C.aspx | WEB介面設計-新增 Create (27) |
讀取(Read) | StockCode_R.aspx | WEB介面設計-修改 Update (28) |
更新(Update) | StockCode_U.aspx | WEB介面設計-刪除 Delete (29) |
刪除(Delete) | StockCode_D.aspx | WEB介面設計-查詢 Read (30) |
1.UI設計
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="StockCode_L.aspx.cs" Inherits="Web.LStockCode_L" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<table style="width: 100%;">
<tr>
<td>List StockCode</td>
</tr>
<tr>
<td>
<asp:GridView ID="gvStockCodes" runat="server">
</asp:GridView>
</td>
</tr>
</table>
</form>
</body>
</html>
2.內部設計
using Model;
using MongoDB.Driver;
using System;
using System.Collections.Generic;
namespace Web
{
public partial class LStockCode_L : System.Web.UI.Page
{
private MongoDatabase myDB;
protected void Page_Load(object sender, EventArgs e)
{
List<MongoStockCode> StockCodes = new List<MongoStockCode>();
// 產生 MongoClient 物件
string Link = "mongodb://10.10.10.234:27017";
MongoClient _client = new MongoClient(Link);
//_client.GetServer().Connect();
// 取得 MongoServer 物件
#pragma warning disable CS0618
MongoServer server = _client.GetServer();
// 取得 MongoDatabase 物件
myDB = server.GetDatabase("dbs");
// 取得 Collection
MongoCollection<MongoStockCode> _StockCodes = myDB.GetCollection<MongoStockCode>("StockCode");
foreach (MongoStockCode StockCode in _StockCodes.FindAll())
{
StockCodes.Add(StockCode);
}
gvStockCodes.DataSource = StockCodes;
gvStockCodes.DataBind();
}
}
}
3.執行狀況