MVC中View与后台多次交互操作

1.MVC中View和Controller多次交互的操作。

前台有数据Table和操作按钮【取消】,选中某行数据,点击取消,提交到Controller中,验证选中的数据行是否满足取消的条件,如果不满足返回不满足原因显示到界面上;如果满足取消的验证条件(如数据状态等),在前台提示:是否确定要 取消该数据?。

前台继续操作,如果点击否,那么结束操作,如果点击是,那么继续操作,对该行数据进行取消操作。

   

   
      
   
 
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   
   

过程:

 

代码:前台代码

数据Table代码:

Grid:

<div id="vertical" class="fullscreen">

    <div id="grid"></div>

    <div id="horizontal">

        <div>

            <div id="gridNotJoinOrder" class="bottom_left"></div>

        </div>

        <div class="middle">

            <div class="content">

                <button id="btnRightAll" class="glyphicon glyphicon-chevron-right"><span></span></button>

                <button id="btnRight" class="glyphicon glyphicon-arrow-right"></button>

 

                <button id="btnLeft" class="glyphicon glyphicon-arrow-left"></button>

                <button id="btnLeftAll" class="glyphicon glyphicon-chevron-left"></button>

            </div>

        </div>

        <div>

            <div id="gridHasJoinOrder" class="bottom_right"></div>

        </div>

    </div>

</div>

 

 

@*查询*@

<script type="text/x-kendo-template" id="gridTransPlan_search">

    <div class="toolbar">

        <div>

            <a class="k-button k-grid-myCancel" href="javascript:void(0);"><span class="k-icon k-i-hbars"></span>取消</a>

        </div>

    </div>

</script>

 

加载数据:

    LoadingKendoGrid({

        id: "#grid",

        dataSource: dataSource_TransPlan,

        toolbar: [

            { template: kendo.template($("#gridTransPlan_search").html()) }

        ],

        columns: [

            { field: "rowNumber", title: "序号", width: 50, template: "<span class='row-number'></span>", attributes: { style: "white-space:nowrap;" }, filterable: false },

            {

                command: [

                    {

                        name: "myEdit",

                        text: "<span class='k-icon k-edit' style='margin-right:-2px' title='编辑' ></span>",

                        click: function (e) {

                            var tr = $(e.target).closest("tr");

                            var data = this.dataItem(tr);

                            UID = data.uid;

                            Edit(data);

                        }

                    },

                    {

                        name: "myDestroy",

                        text: "<span class='k-icon k-delete' style='margin-right:-2px' title='删除' ></span>",

                        click: function (e) {

                            var tr = $(e.target).closest("tr");

                            var data = this.dataItem(tr);

                            //校验通过后,再提示是否删除;

                            $.post("/H3CDMS/TransPlan/CheckDeleteTransPlan", { TransNo: data.TRANSNO }, function (result) {

                                if (result.code == CheckSuccess) {

                                    ShowConfirm({

                                        info: "确定删除该条数据吗?",

                                        confirm: function () {

                                            $.post("/H3CDMS/TransPlan/DeleteTransPlan", { TransNo: data.TRANSNO }, function (result) {

                                                ShowInfo(result.msg);

                                                if (result.code == DeleteSuccess) {

                                                    $("#grid").data("kendoGrid").dataSource.read();

                                                }

                                            });

                                        }

                                    });

                                } else {

                                    ShowInfo(result.msg);

                                }

                            });

                        }

                    }

                ],

                title: "操作",

                width: 66

            },

            {

                field: "TRANSNO", title: "计划货运单号", width: 120, attributes: { style: "white-space:nowrap;" }, filterable: true,

                filterable: {

                    operators: {

                        string: {

                            eq: "包含"

                        }

                    },

                    ui: function (element) {

                        element[0].setAttribute("data-name", "TRANSNO");

                        element.kendoMaskedTextBox({});

                    },

                    messages: {

                        info: "计划货运单号"

                    }

                }

            },

            { field: "TRANSNOTE", title: "备注", attributes: { style: "white-space:nowrap;" }, filterable: false },

        ],

        dataBound: function (e) {

            var rows = this.items();

            var page = this.pager.page() - 1;

            var pagesize = this.pager.pageSize();

            $(rows).each(function () {

                var index = $(this).index() + 1 + page * pagesize;

                var rowLabel = $(this).find(".row-number");

                $(rowLabel).html(index);

            });

            //按钮权限控制

            CheakUserAction();

        },

        height: "100%",

        selectable: "row",

        change: function (e) {

            $("#gridHasJoinOrder").data("kendoGrid").dataSource.read();

        }

    });

 

按钮的点击事件:

    $(".k-grid-myCancel").click(function (e) {

        debugger;

        var tr = $(".k-state-selected");

        if (tr) {

            var transno = $(tr).find('td').eq(2).text();

            $.post("/H3CDMS/TransPlan/CheckPlan", { TRANSNO: transno }, function (rtnData) {

 

                if (rtnData.code == checkSuccess) {

                    ShowConfirm({

                        info: "你确认要取消当前运输计划?",

                        confirm: function () {

                            $.post("/H3CDMS/TransPlan/UpdatePlanStatus", { TRANSNO: transno }, function (result) {

                                ShowInfo(result.msg);

                                if (result.code == CancelPlanSuccess) {

                                    $("#grid").data("kendoGrid").dataSource.read();

                                }

                            });

                        }

                    });

                }

                else{

                    ShowInfo(rtnData.msg, false,0);

                }

            });         

 

            }

});

 

 

后台Controller

 

        /// <summary>

        /// 校验 取消运输计划

        /// </summary>

        /// <param name="TRANSNO"></param>

        /// <param name="USER_ID"></param>

        /// <returns></returns>

          public JsonResult CheckPlan(string TRANSNO)

          {

              string Api_Address = Api_CheckTransportPlan + string.Format("?TRANSNO={0}&USER_ID={1}",TRANSNO,DataHelper.UserID.ToString());

              string result = helper.HttpGetMethod(Api_Address);

              ResultInfo resultinfo = JsonConvert.DeserializeObject(result, typeof(ResultInfo)) as ResultInfo;

              return Json(resultinfo, JsonRequestBehavior.AllowGet);   

          }

          /// <summary>

          /// 更新实体

          /// </summary>

          public class UpdateTransNo

          {

              public string TRANSNO { set; get; }

          }

        /// <summary>

        /// 取消运输计划

        /// </summary>

        /// <param name="TRANSNO"></param>

        /// <returns></returns>

          public JsonResult UpdatePlanStatus(string TRANSNO)

          {

              UpdateTransNo model = new UpdateTransNo()

              {

                  TRANSNO = TRANSNO

              };

              string jsonString = JsonConvert.SerializeObject(model);

              HttpClient client = new HttpClient();

              HttpContent httpContent = new StringContent(jsonString);

              httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/json");

              HttpResponseMessage response = client.PostAsync(Api_UpdatePlanStatus,httpContent).Result;

              string Result = response.Content.ReadAsStringAsync().Result;

              ResultInfo obj = JsonConvert.DeserializeObject(Result, typeof(ResultInfo)) as ResultInfo;

              if (obj != null)

              {

                  LogHelper.WriteLog("运输计划", LogHelper.OperateType.Update, Api_UpdatePlanStatus, obj.msg, "货运单取消", TRANSNO);

                  resultInfo = obj;

              }

              else

              {

                  resultInfo.ResultConnectError();

              }

              return Json(resultInfo, JsonRequestBehavior.AllowGet);

          }

        #endregion

 

API层

        #region 取消确认

        /// <summary>

        /// 运输计划取消校验信息

        /// </summary>

        /// <param name="TRANSNO"></param>

        /// <param name="User_id"></param>

        /// <returns></returns>

        [HttpGet]

        public ResultInfo GetCheckPlan(string TRANSNO, string USER_ID)

        {

            MTL_SHIPPLAN_INFO mtl_Shipplan_Info = db.MTL_SHIPPLAN_INFO.Find(TRANSNO);

            if (mtl_Shipplan_Info != null)

            {

                if (mtl_Shipplan_Info.REGISTER_MAN != USER_ID)

                {

                    return new ResultInfo().CheckPlanFailed2();

                }

                if (mtl_Shipplan_Info.TRANSSTATUS != 20)

                {

                    return new ResultInfo().CheckPlanFailed2();

                }

                int count = db.MTL_ORDERHEADERS.Where(x => x.TRANSNO.Equals(TRANSNO) && x.TRANS_STATUS == 30).Count();

                if (count > 0)

                {

                    return new ResultInfo().CheckPlanFailed3();

                }

                return new ResultInfo().CheckPlanSuccess();

            }

            else

            {

                return new ResultInfo().CheckPlanNotExist();

            }

        }

        #endregion

 

        #region 取消执行计划-更新状态

        /// <summary>

        /// 更新实体

        /// </summary>

        public class UpdateTransNo

        {

            public string TRANSNO { set; get; }

        }

        /// <summary>

        ///

        /// </summary>

        /// <param name="TRANSNO"></param>

        /// <param name="USER_ID"></param>

        /// <returns></returns>

        [HttpPost]

        public ResultInfo UpdatePlanStatus(UpdateTransNo model)

        {

            MTL_SHIPPLAN_INFO model1 = db.MTL_SHIPPLAN_INFO.Find(model.TRANSNO);

            if (model1 != null)

            {

                model1.TRANSSTATUS = 10;

                shipplan_business.UpdateModel(model1);

            }

            MTL_ORDERHEADERS model2 = db.MTL_ORDERHEADERS.Where(x => x.TRANSNO.Equals(model.TRANSNO)).FirstOrDefault();

            if (model2 != null)

            {

                model2.TRANS_STATUS = 10;

                orderheaders_business.UpdateModel(model2);

            }

            MTL_SHIPPLAN_DETAIL model3 = db.MTL_SHIPPLAN_DETAIL.Where(x => x.TRANSNO.Equals(model.TRANSNO)).FirstOrDefault();

            if (model3 != null)

            {

                model3.STATUS = 10;

                shipplan_detail_business.UpdateModel(model3);

            }

            return new ResultInfo().CancelPlanSuccess();

 

        }

        #endregion

}

 

底层的DAO,Business,Model就不展示了

前端页面:                        

MVC层Controller:

API层Controller:

API层Business,Dao,Model:

ResultInfo:

 

 

先进行黑色路线再进行红色路线

转载于:https://www.cnblogs.com/CoChe/p/6349265.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值