顯示具有 Insert 標籤的文章。 顯示所有文章
顯示具有 Insert 標籤的文章。 顯示所有文章

2023年8月14日 星期一

V120401 - 按[存檔]鈕 - 未觸發後端的 Update() , Insert() 函式

 目的: V120401 - 按[存檔]鈕 - 未觸發後端的 Update()  , Insert() 函式

處理說明: 1> 按[存檔]鈕 , 會執行  beforeEdit  & beforeInsert 函式, 
                    所以必需設定  beforeEdit & beforeInsert 函式,以便執行後端 Update() & Insert() 函式
                       Ext.getCmp('btn_save').beforeEdit = function () {
                                isCheck = S_DB.doSave('Update');
                                return isCheck;
                       }
                             

1>*.js
               var S_DB = Ext.create('S_DB', {
                                   apiName: 'V120401'
                 });

                       //修改的存檔
                         Ext.getCmp('btn_save').beforeEdit = function () {
                         isCheck = S_DB.doSave('Update');
                         return isCheck;
                         };

                      //新增的存檔
                        Ext.getCmp('btn_save').beforeInsert = function () {
                        isCheck = S_DB.doSave('Insert');
                        return isCheck;
                         };

                      //刪除 - 資料庫刪除資料
                        Ext.getCmp('btn_del').afterDel = function () {
                        return S_DB.afterDel();
                        };


2>*.cs
 public class V120401APIController : BaseAPIController
    {
        string funId = "V120401";
        public V120401APIController()
        {
            DBTable = "AMM_TMDWG";
            setParam(DBTable);
        }

[HttpPost]
        public string[] getPK()
        {
            return base.getPK();
        }
        
        [HttpPost]
        public void Insert()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            excuteInsert(nvc, DBTable);
        }

        [HttpPost]
        public void Update()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            string[] arrCondition = getPK();
            excuteUpdate(nvc, DBTable, arrCondition);
        }

        [HttpPost]
        public void Delete()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            //string[] arrCondition = new string[] { "" };
            string[] arrCondition = getPK();
            excuteDelete(nvc, DBTable, arrCondition);
        }

-->更新時, 自動 Assign 建檔人員 & 建檔日期
        [HttpPost]
        public void Update()
        {
            var c = System.Web.HttpContext.Current;
            NameValueCollection nvc = c.Request.Form;
            NameValueCollection nvc1 = new NameValueCollection();
            foreach (string k in nvc.Keys)
            {
                nvc1[k] = nvc[k];
            }            
            nvc1["MKER"] =User.Identity.Name;
            nvc1["MKDT"] = DateTime.Now.ToString("yyyy/MM/dd");
            string[] arrCondition = getPK();            
            excuteUpdate(nvc1, DBTable, arrCondition);
        }