---
# System prepended metadata

title: doQuOther
tags: [實習筆記]

---

# doQuOther

::: danger
就是不使用模組化的crud，改成自己新增Buttonc或是使用onchange或是onblur事件來執行程式
:::
## cshtml
```htmlmixed=
<button type="button"  class="btn btn-main" ng-click="GET_Date()" />
```
* ng-click() 點擊事件
* ng-change() 欄位變更事件
* ng-blur() 欄位變更完的事件


## 沒有傳回值的QuOther
### JS
```javascript=
$scope.GET_Date = function () {              
    if ($scope.editRow.NAME != NULL) {
    //宣告一個QuOther的物件叫l_delta
    var l_delta = newDeltaQuOther();

    l_delta.name = "GETDate";
    //將值傳入l_delta裡面
    l_delta.oldRow.NAME = $scope.editRow.NAME;
    ////執行QuOther，並將l_delta傳入，回傳的值會放入a_result
    $scope.doQuOther(l_delta).then(function (a_result) { });
    }
}
```


### Controller
``` csharp=
[System.Web.Http.HttpPost]
public IHttpActionResult QuOther(DeltaQuOther a_delta)
{

    //將a_delta的oldRow放入l_searchData裡
    Dictionary<string, object> l_searchData = a_delta.oldRow;

    if (a_delta.name == "GETDate")
    {
        //宣告一個hashtable存放要加入sql的參數
        Hashtable ht = new Hashtable();
        //建立一個dbcontroller(資料庫連線器)
        DBController dbc = new DBController();
        //將ht清空
        ht.Clear();
        //放入sql語法所需參數
        ht.Add("@NAME", new StructureSQLParameter
        (l_searchData["NAME"], SqlDbType.NVarChar));
        //放入需要執行的sql
        string GET_IDDate_Select = 
        "INSERT INTO DEMOMI VALUES (@NAME,1,'2020-07-01 00:00:00.000'
        ,'2020-07-15 00:00:00.000')";
        //DbExecuteScalar_Str會將執行結果變為一個字串回傳回來
        //資料庫連線器.執行的型態(看需求來選擇)(sql,ht)
        string GET_IDDateSelect = dbc.DbExecuteScalar_Str
        (GET_IDDate_Select, ht);

    }
    return this.doQuOther();
}
```
* Controller 加入 Quther Function
* 在改寫sql


## 有傳回值的QuOther
### JS
```javascript=
$scope.GET_Date = function () {              
    if ($scope.editRow.NAME != NULL) {
    //宣告一個QuOther的物件叫l_delta
    var l_delta = newDeltaQuOther();

    l_delta.name = "GETDate";
    //將值傳入l_delta裡面
    l_delta.oldRow.NAME = $scope.editRow.NAME;
    ////執行QuOther，並將l_delta傳入，回傳的值會放入a_result
    $scope.doQuOther(l_delta).then(function (a_result) 
        {
            if (a_result.NAME == "")
            {
                 swal("資料庫內無資料", "", "warning").catch(swal.noop);
            }
            else
            {
                 swal("查詢資料:"+a_result.NAME, "", "success").catch(swal.noop);
            }
        });
    }
}
```
* 回傳的值會放入a_result
### Controller
``` csharp=
[System.Web.Http.HttpPost]
public IHttpActionResult QuOther(DeltaQuOther a_delta)
{

    //將a_delta的oldRow放入l_searchData裡
    Dictionary<string, object> l_searchData = a_delta.oldRow;

    if (a_delta.name == "GETDate")
    {
        //宣告一個hashtable存放要加入sql的參數
        Hashtable ht = new Hashtable();
        //建立一個dbcontroller(資料庫連線器)
        DBController dbc = new DBController();
        //將ht清空
        ht.Clear();
        //放入sql語法所需參數
        ht.Add("@NAME", new StructureSQLParameter
        (l_searchData["NAME"], SqlDbType.NVarChar));
        //放入需要執行的sql
        string GET_IDDate_Select = 
        "Select abank_name from fnxabank where abank_name like '%'+@NAME+'%'";
        string GET_IDDateSelect = dbc.DbExecuteScalar_Str(GET_IDDate_Select, ht);
        l_searchData["NAME"] = GET_IDDateSelect;
        return new OkNegotiatedContentResult<Dictionary<string, object>>
        (l_searchData, this);   
    }
    return this.doQuOther();
}
```
* OkNegotiatedContentResult<Dictionary<string, object>>(l_searchData, this);用他來回傳資料去前端 

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