C#Web实现多数据列表写入存储

通过点击添加按钮,将数据添加
在这里插入图片描述
添加后如图
在这里插入图片描述
View界面代码
在这里插入图片描述

在这里插入图片描述
//添加不良现象 按钮触发事件
function AddPart() {

    var sDefect_Type = $("#Defect_Type").val().trim();
   

    var sDefect_Desc_Plus = $("#Defect_Desc_Plus").val().trim();
    
    if ((sDefect_Type == undefined || sDefect_Type == null || sDefect_Type == "") && (sDefect_Desc_Plus == undefined || sDefect_Desc_Plus == null || sDefect_Desc_Plus == "")) {
        alert('不良现象、不良现象补充不能同时为空');
        return;
    }
    if (sDefect_Type != null && sDefect_Type != "" ) {          
                    var c_bAdd = true;
                    var row_count = $("#PartNumList-grid").data("kendoGrid").dataSource.data().length;
                    //if (row_count == 2) {
                    //    $("#PartNumList-grid").data("kendoGrid").dataSource.read();
                    //    //$("#PartNumList-grid").data("kendoGrid").refresh();
                    //}
                    for (var i = 0; i < row_count; i++) {
                        var sODefect_Type = $("#PartNumList-grid").data('kendoGrid').dataSource.at(i).Defect_Type;
                   
                        var sODefect_Desc_Plus = $("#PartNumList-grid").data('kendoGrid').dataSource.at(i).Defect_Desc_Plus;
                        if (sDefect_Type == sODefect_Type && sDefect_Desc_Plus == sODefect_Desc_Plus) {
                            c_bAdd = false;
                            break;
                        }
                    }
                    if (c_bAdd == true) {
                        var newRow = {
                            row: row_count + 1,
                            Defect_Type: sDefect_Type,
                           // Defect_Type_Name: Defect_Type_Name,
                            Defect_Desc_Plus: sDefect_Desc_Plus                
                        };
                        $("#PartNumList-grid").data("kendoGrid").dataSource.add(newRow);
                        $("#Defect_Type").val("");
                        $("#Defect_Type_Name").val("");
                        $("#Defect_Desc_Plus").val("");
                    }
                }   
    }

数据存储点击提交按钮
在这里插入图片描述
代码
//叫修数据提交
function CallRepairSubmit() {
var row_count = $("#PartNumList-grid").data(“kendoGrid”).dataSource.data().length;
var sDefect_Type = “”;
var sDefect_Desc_Plus = “”;
for (var i = 0; i < row_count; i++) {
var defect_Type = $("#PartNumList-grid").data(“kendoGrid”).dataSource.at(i).Defect_Type;
if (defect_Type == null || defect_Type == undefined) {
defect_Type = “”;
}
var defect_Desc_Plus = $("#PartNumList-grid").data(“kendoGrid”).dataSource.at(i).Defect_Desc_Plus;
if (defect_Desc_Plus == null || defect_Desc_Plus == undefined) {
defect_Desc_Plus = “”;
}
if (sDefect_Type == “” && sDefect_Desc_Plus == “”) {
sDefect_Type = defect_Type;
sDefect_Desc_Plus = defect_Desc_Plus;

        } else {
            sDefect_Type += "," + defect_Type;
            sDefect_Desc_Plus += "|" + defect_Desc_Plus;
        }
    }

    $.ajax({        
        type: "post",
        url: "/Repair/CallRepairSubmit",
        data:
        {
            sRepair_Type: $("#Repair_Type").val(),
            sCallRepairNo: $("#Call_Repair_No").val(),
            sLine_Id: $("#Line_Id").val(),
            sCall_Location: $("#Call_Location").val(),
            sMachineNo: $("#MachineNo").val(),
            sMachine_Name: $("#Machine_Name").val(),
            sDefect_Types: sDefect_Type,
            sDefect_Desc_Pluss: sDefect_Desc_Plus,
        },
        success: function (data) {
            debugger;
            if (data == "OK") {
                window.location.href = "@Url.Action("Index")";
            }
            else {
                alert(data);
            }
        },
        error: function () {
            alert("ERROR:界面数据类型不对!");
        }
    });
}



   控制器代码

    //存储叫修单(新增保存)
    public string CallRepairSubmit(string sRepair_Type, string sCallRepairNo, int sLine_Id, string sCall_Location, string sMachineNo, string sMachine_Name, string sDefect_Types, string sDefect_Desc_Pluss)
    {
        string sRetMsg = "OK";
        var handler = new RepairHandler();
        sCallRepairNo = handler.GetNew_TLId();
        var result = handler.CallRepairSubmit(sRepair_Type, sCallRepairNo, sLine_Id, sCall_Location, sMachineNo, sMachine_Name, sDefect_Types, sDefect_Desc_Pluss);

        if (result != "OK")
            sRetMsg = result;

        return sRetMsg;

    }
}

数据逻辑处理
在这里插入图片描述
//存储叫修单的方法
public string CallRepairSubmit(string sRepair_Type, string sCallRepairNo, int sLine_Id, string sCall_Location, string sMachineNo, string sMachine_Name, string sDefect_Types, string sDefect_Desc_Pluss)
{
var now = DateTime.Now;
string sRetMsg = “OK”;

        try
        {

            #region Insert叫修单号基本信息
            var masterData = new EMS_R_CALL()
            {
                ID = GetMaxId("EMS_R_CALL") + 1,
                CALL_REPAIR_NO = sCallRepairNo,
                REPAIR_TYPE = sRepair_Type,
                PLANT_ID = UserSession.Plant.Id,
                LINE_ID = sLine_Id,
                CALL_LOCATION = sCall_Location,
                CALL_BY = UserSession.Account.Id,
                CALL_TIME = now,
                STATUS = 1,
                UPDATE_BY = UserSession.Account.Id,
                UPDATE_TIME = now,
                DEFECT_TYPE = "D"
            };
            db.EMS_R_CALL.Add(masterData);
            db.SaveChanges();
            #endregion

            #region Insert 绑定的不良现象
            string[] sArrDefect_Type = sDefect_Types.Split(',');
            string[] sArrDefect_Desc_Plus = sDefect_Desc_Pluss.Split('|');
            
            for (int i = 0; i < sArrDefect_Type.Length; i++)
            {
              
                var UseNO_PartData = new CommonResource.Models.EMS_R_CALL_DEFECT()
                {
      
                    ID = GetMaxId("EMS_R_CALL_DEFECT") + 1,
                    CALL_REPAIR_NO = sCallRepairNo,
                    MACHINE_ID = db.MACHINE.Where(t => t.CUSTODYNO == sMachineNo).Select(t => t.ID).FirstOrDefault(),                     
                    DEFECT_ID = Convert.ToDecimal(sArrDefect_Type[i]),
                    //DEFECT_ID = db.TROUBLES.Where(t => t.NAME == sArrDefect_Type.ToString()).Select(t => t.ID).FirstOrDefault(),
                    //DEFECT_ID = sArrDefect_Type[i].ToString().Trim() == "" ? null : sArrDefect_Type[i]0.ToString().Trim(),                  
                    DEFECT_DESC_PLUS = sArrDefect_Desc_Plus[i].ToString().Trim() == "" ? null : sArrDefect_Desc_Plus[i].ToString().Trim(),
                    UPDATE_BY = UserSession.Account.Id,
                    UPDATE_TIME = now
                };
            db.EMS_R_CALL_DEFECT.Add(UseNO_PartData);
            db.SaveChanges();
        }
            #endregion


            #region Insert叫修UpdateMachine基本信息
            var machineModel = getMachineCount( sCallRepairNo, sMachineNo).Where(x => x.CUSTODYNO == sMachineNo).SingleOrDefault();
            {
                machineModel.R_STATUS = (int)RepairCallStatus.叫修 ;
            };
            db.SaveChanges();

            #endregion
            var Result = "";
        if (Result == null)
        {
            sRetMsg = "NG:料号异常";
        }

    }
        catch (Exception ex)
        {
            sRetMsg = "NG:Insert data异常" + ex.Message;
        }
        return sRetMsg;

添加成功后返回界面
在这里插入图片描述

前端页面临时存放List存储值时多数据不同类型写入到数据表中
在这里插入图片描述

在这里插入图片描述
先分割后再取值转换写入数据
在这里插入图片描述

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值