---
# System prepended metadata

title: 單檔(M)
tags: [實習筆記]

---

# 單檔(M)
### 要繼承IApiController.==M==
## Controller
```csharp=
 public override MasterClass getMaster()
{
//SQL只要跟查詢有關的都要有1=1 是因為模組一經寫好了 
//模組有一部分是根據1=1來去做修改 
//SQL必須加入1=1條件
StringBuilder l_SQL = new StringBuilder();
l_SQL.Append(@" Select M.* From DEMOMI M 
Where 1=1 order by m.id ");
return new MasterClass()
{
    tableName = "DEMOMI",
    //程式第一次載入時是否有資料
    isNoDataFirstLoad = false, 
    //SQL轉成大寫
    sQL = l_SQL.ToString().ToUpper(), 
    //string[1] 後面1就寫1 2就寫2
    keyField = new string[1] { "ID" },
    //不可空白欄位
    notNullField = new string[2] { "NAME", "SEX" },
    //不可編輯,但可新增欄位
    noEditButInsertField = new string[0] { },
    //不可編輯欄位 
    noEditField = new string[1] { "ID" }, 
    //查詢條件預設值
    searchData = new SearchClass() { NAME = "", SEX = "" }
    };
}
```
* tableName 表名稱
* l_SQL.Append(sql語法);
* keyField 主鍵
* notNullField 不可NULL
* string[1] 後面1就寫1 2就寫2

## cshtml
**擁有兩種表單:Master From 和 Serach From**

### Master From(是新增跟修改的頁面)
```htmlmixed=
@section panelMaster {
<form name="masterForm" class="form-horizontal" role="form">
    <div class="form-group">
        <div class="control-title col-xs-6 col-sm-2 col-md-2 col-lg-2">
            <label for="txtID" class="control-label" ng-class="isRequiredClass('ID')">
                <span class="error-block">
                    <i class="glyphicon glyphicon-warning-sign error-icon" ng-show="masterForm.txtID.$error.required" data-toggle="tooltip" data-placement="right" data-title="【編號】不可空白!"></i>
                </span>
                編號
            </label>
        </div>
        <div class="col-xs-6 col-sm-4 col-md-4 col-lg-4">
            <input name="txtID" id="txtID" type="text" class="form-control " ng-model="editRow.ID" ng-required="isRequired('ID')" ng-disabled="isReadOnly('ID')">
        </div>
    </div>

    <div class="form-group">
        <div class="control-title col-xs-6 col-sm-2 col-md-2 col-lg-2">
            <label for="txtNAME" class="control-label" ng-class="isRequiredClass('NAME')">
                <span class="error-block">
                    <i class="glyphicon glyphicon-warning-sign error-icon" ng-show="masterForm.txtNAME.$error.required" data-toggle="tooltip" data-placement="right" data-title="【姓名】不可空白!"></i>
                </span>
                姓名
            </label>
        </div>
        <div class="col-xs-6 col-sm-4 col-md-4 col-lg-4">
            <input name="txtNAME" id="txtNAME" type="text" class="form-control " ng-model="editRow.NAME" ng-required="isRequired('NAME')" ng-disabled="isReadOnly('NAME')" max-length="10">
        </div>
    </div>
</form>
}
```
* MasterFrom ng-model => editRow.參數

### Serach From(查詢頁面)
:::danger
查詢模組
:::
```htmlmixed=
<form name="searchForm" class="form-horizontal" role="form">
    <div class="form-group">
        <label for="txtID_S" class="col-xs-4 control-label">編號</label>
        <div class="col-xs-4">
            <select name="txtID_S" class="form-control" ng-model="searchData.ID" 
            ng-options=" m.DESC as m.DESC for m in opData.MEB_ID">
                <option value=""></option>
            </select>
        </div>
    </div>      
</form>
```
* SearchFrom ng-model => searchData.參數
 
## JS
```javascript=
@section Scripts {
    <script type="text/javascript">
        var myApp = angular.module('myApp', ['ngGrid', 'ksijs']);
        //controller
        myApp.controller('MCtrl', ['$scope', '$window', 'ksiEnum', 'ksiLib', '$compile', '$filter',
            function ($scope, $window, Enum, myLib, $compile, $filter) {
                //程式代碼
                $scope.progNo = 'M';
                //--初始化initializing ----取得程式初始設定，放入Master物件(傳入參數)//Resource.action([parameters], [success], [error])
                myLib.init($scope, myLib);

                //定義Grid欄位內容(放在後面init)
                //在這裡宣告需要顯示的欄位
                $scope.gridMaster.columnDefs = [];
                $scope.gridMaster.columnDefs.push({ field: 'ID', displayName: '代碼', width: '100px', pinnable: true });
                $scope.gridMaster.columnDefs.push({ field: 'NAME', displayName: '名稱', width: '300px', pinnable: true });
                $scope.gridMaster.columnDefs.push({ field: 'SEX', displayName: '性別 ', width: '100px', pinnable: true });
                $scope.gridMaster.columnDefs.push({ field: 'DATE1', displayName: '起始日期', width: '300px', pinnable: true });
                $scope.gridMaster.columnDefs.push({ field: 'DATE2', displayName: '結束日期', width: '300px', pinnable: true });
```
* $scope.progNo = '==M=='; M是放要連動的Controller的名字
* $scope.gridMaster.columnDefs.push 是寫入想要呈現的欄位

###### tags: `實習筆記`