C#Web realizes multi-data list write storage

By clicking the add button, add the data
Insert picture description here
after adding it as shown in the
Insert picture description here
View interface code
Insert picture description here

Insert picture description here
//Add bad phenomenon button trigger event
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("");
                    }
                }   
    }

数据存储点击提交按钮
Insert picture description here
代码
//叫修数据提交
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;

    }
}

Data logic processing
Insert picture description here
//storage call repair order method
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)
{ varg now = sDefect_Desc_Pluss) { varg now = sDefect_Desc_Pluss; "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;

Return to the interface after successful addition
Insert picture description here

When the front-end page temporarily stores the List storage value, multiple data and different types are written into the data table
Insert picture description here

Insert picture description here
Divide first and then take the value to convert and write the data
Insert picture description here

Guess you like

Origin blog.csdn.net/caoguanghui0804/article/details/110430980