其他分享
首页 > 其他分享> > layui表格数据返回自定义数据

layui表格数据返回自定义数据

作者:互联网

function AddWaer() {

var tabledata1 = layui.table.cache['tabmessage'];

var Form = $("#layui-form").serializeArray();

var json = {};

var commodityID = [];

var SL = [];

for (var i = 0; i < Form.length; i++) {

json[Form[i].name] = Form[i].value;

}

for (var i = 0; i < tabledata1.length; i++) {

commodityID.push(tabledata1[i].CommodityID);

$("#CommodityID").val(tabledata1[i].CommodityID);

}

for (var i = 0; i < tabledata1.length; i++) {

SL.push(tabledata1[i].SL);

$("#SL").val(tabledata1[i].SL);//layui自定义数据

}

var form = new FormData(document.getElementById("layui-form"));

form.append("commodityID", commodityID);

form.append("SL", SL);

var strUrl = "/Inventory/InventoryDB/AddInventory";

//加载层

var index = layer.load();

console.log(form);

//发送请求

$.ajax({

url: strUrl,

type: "post",

data: form,、

dataType: "json",

success: function (rtMsg) {

//关闭加载层

layer.close(index);

layer.alert(rtMsg.Text, { icon: 1, skin: 'layui-layer-molv' }, function (rtIndex) {

layer.close(rtIndex);

if (rtMsg.State) {

window.location.href = "/Inventory/InventoryDB/Index";

}

});

}

});

}

public ActionResult AddInventory(SYS_Allocating allocating, string commodityID, string SL)

{

ReturnJson returnJson = new ReturnJson();

int alloc = Convert.ToInt32(allocating.WareExport);

if (allocating.WareExport != allocating.WareFold)

{

SYS_Warehouse Ware = myModel.SYS_Warehouse.Single(o => o.WarehouseID == alloc);

if (Ware.CheckState != true)

{

if (commodityID != "")

{

int Sl = 0;

string comName = "";

string[] strArr = commodityID.Split(',');

string[] strSL = SL.Split(',');

if (strArr.Length > 0)

{ 

int allCount = myModel.SYS_Allocating.Count(o => o.AllocatingID == allocating.AllocatingID);

if (allCount == 0)

{

myModel.SYS_Allocating.Add(allocating);

if (myModel.SaveChanges() > 0)

{

int allId = allocating.AllocatingID;

for (int i = 0; i < strArr.Length; i++)

{

int adw = Convert.ToInt32(strArr[i]);

int sl = Convert.ToInt32(strSL[i]);

SYS_Commodity commodity = myModel.SYS_Commodity.Single(m => m.CommodityID == adw);

comName += commodity.CommodityName + ',';

SYS_Inventory inventory = myModel.SYS_Inventory.Single(o => o.CommodityID == commodity.CommodityID);

inventory.InventorySl -= sl;

}

for (int i = 0; i < strSL.Length; i++)

{

int sl = Convert.ToInt32(strSL[i]);

Sl += sl;

}

allocating.Storage = Sl;

allocating.ComAllocating = comName;

allocating.DeliveryState = false;

allocating.StorageState = false;

allocating.YW = "调拨";

myModel.Entry(allocating).State System.Data.Entity.EntityState.Modified;

if (myModel.SaveChanges() > 0)

{

returnJson.State = true;

returnJson.Text = "新增成功!";

}

else

returnJson.Text = "保存盘点失败!";

}

else

returnJson.Text = "保存盘点失败!";

}

else

returnJson.Text = "该仓库正在盘点!";

}

}

else

{

returnJson.Text = "请选择商品!";

}

}

else

{

returnJson.Text = "该出库仓库正在盘点中,请使用其他仓库!";

}

}

else

{

returnJson.Text = "出库仓库不能和入库仓库一样!";

}

return Json(returnJson, JsonRequestBehavior.AllowGet);

}

标签:定义数据,表格,int,layui,SYS,SL,var,allocating,returnJson
来源: https://blog.csdn.net/a13828603242/article/details/123607391