//保存盘点单 public JsonResult SaveCheck(T_StockInfoEX model) { try { if (string.IsNullOrEmpty(model.WarehouseNo)) { return(Json(new { state = false }, JsonRequestBehavior.AllowGet)); } T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); string StrongHoldCode = ""; string StrongHoldCodeName = ""; TWareHouseDB.GetStrongholdcode(model.WarehouseNo, ref StrongHoldCode, ref StrongHoldCodeName); Check_DB checkdb = new Check_DB(); string ErrorMsg = ""; if (!checkdb.CheckIsSvae(model.MaterialNo, model.WarehouseNo, ref ErrorMsg)) { return(Json(new { state = false, ErrMsg = "待发或者待收库区有该物料不能生成盘点单!【" + ErrorMsg + "】" }, JsonRequestBehavior.AllowGet)); } string strErrMsg = string.Empty; List <T_StockInfoEX> lsttask = new List <T_StockInfoEX>(); Query_DB db = new Query_DB(); if (!db.GetStockCombineInfo2(model, ref lsttask, ref strErrMsg)) { return(Json(new { Result = 0, ErrMsg = strErrMsg }, JsonRequestBehavior.AllowGet)); } if (model.Check == "0") { //检验WMS库存和U9是否一致 T_Material_Batch_Func FUNC = new T_Material_Batch_Func(); List <U9Stock> erp_stock = FUNC.GetStockInfo(model.WarehouseNo, StrongHoldCode, model.MaterialNo); bool isOk = true; lsttask.ForEach(itemWMS => { if (erp_stock.FindAll(itemerp => { return(itemerp.MaterialNo == itemWMS.MaterialNo && itemerp.BatchNo == itemWMS.BatchNo && itemerp.Qty == itemWMS.Qty); }).Count != 1) { isOk = false; } }); if (!isOk) { return(Json(new { state = false, ErrMsg = "WMS库存和U9不匹配不能生成盘点单!" }, JsonRequestBehavior.AllowGet)); } } Check_Model cm = new Check_Model(); //cm.REMARKS = strremark + txt_remarkD.Text + txt_remark.Text; cm.CHECKSTATUS = "新建"; cm.CREATER = currentUser.UserNo; cm.CHECKDESC = "明盘"; string ErrMsg = ""; if (checkdb.SaveCheck2(cm, lsttask, ref ErrMsg)) { return(Json(new { state = true }, JsonRequestBehavior.AllowGet)); } return(Json(new { state = false }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { state = false, ErrMsg = ex.ToString() }, JsonRequestBehavior.AllowGet)); } }
// 获取盘点库存信息 public JsonResult GetCheckStock(DividPage page, T_StockInfoEX model) { try { if (string.IsNullOrEmpty(model.WarehouseNo)) { return(Json(new { Result = 0, ResultValue = "仓库不能为空!" }, JsonRequestBehavior.AllowGet)); } T_WareHouse_DB TWareHouseDB = new T_WareHouse_DB(); string StrongHoldCode = ""; string StrongHoldCodeName = ""; TWareHouseDB.GetStrongholdcode(model.WarehouseNo, ref StrongHoldCode, ref StrongHoldCodeName); string strErrMsg = string.Empty; List <T_StockInfoEX> wms_stock = new List <T_StockInfoEX>(); Query_DB db = new Query_DB(); if (db.GetStockCombineInfo2(model, ref wms_stock, ref strErrMsg)) { if (wms_stock == null || wms_stock.Count == 0) { return(Json(new { Result = 0, ResultValue = "查询库存为空!" }, JsonRequestBehavior.AllowGet)); } T_Material_Batch_Func FUNC = new T_Material_Batch_Func(); List <U9Stock> erp_stock = FUNC.GetStockInfo(model.WarehouseNo, StrongHoldCode, model.MaterialNo); //wms数据和erp数据对账 for (int i = 0; i < wms_stock.Count; i++) { if (erp_stock != null && erp_stock.Count > 0) { for (int j = 0; j < erp_stock.Count; j++) { if (wms_stock[i].MaterialNo == erp_stock[j].MaterialNo && wms_stock[i].BatchNo == erp_stock[j].BatchNo) { wms_stock[i].U9MaterialNo = erp_stock[i].MaterialNo; wms_stock[i].U9BatchNo = erp_stock[i].BatchNo; wms_stock[i].U9Qty = erp_stock[j].Qty; erp_stock[j].IsAmount = 1; } } } } if (erp_stock != null && erp_stock.Count > 0) { //没匹配的u9数据 for (int i = 0; i < erp_stock.Count; i++) { if (erp_stock[i].IsAmount != 1) { wms_stock.Add(new T_StockInfoEX() { U9MaterialNo = erp_stock[i].MaterialNo, U9BatchNo = erp_stock[i].BatchNo, U9Qty = erp_stock[i].Qty, Qty = 0 }); } } } return(Json(new { Result = 1, Data = wms_stock }, JsonRequestBehavior.AllowGet)); } return(Json(new { Result = 0, ResultValue = strErrMsg }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { Result = 0, ResultValue = ex.ToString() }, JsonRequestBehavior.AllowGet)); } }