public RedirectToRouteResult SyncInventory(WWInventoryItem item) { try { var user = System.Web.HttpContext.Current.Session["CurrentUser"] as CurrentUser; bll_Product.SyncInventory(item, user?.Id); } catch (Exception ex) { ViewBag.ErrorMsg = ex.Message; } return(RedirectToAction(nameof(NCInventory), new { errorMsg = ViewBag.ErrorMsg, isloadCondition = true })); }
/// <summary> /// 同步NC线材库存数据 /// </summary> /// <param name="item"></param> /// <param name="userId"></param> public void SyncInventory(WWInventoryItem item, string userId) { // 首先查询NC数据,同步PCI // 步骤:验证PCI是否有数据,计算差量->同步(将总量分摊到每支上,保留4位小数) // C_SFOB=1 可在PCI系统同步性能成分 var inventory = GetNCInventory(item.InventoryCode, item.Gz, item.Zxbz, item.Spec, item.BatchNo) .Where(w => w.StdCode == item.Zxbz) .Where(w => w.ZLDJ == item.ZLDJ) .Where(w => w.MtrlCode == item.MtrlCode) .Where(w => w.BZYQ == item.BZYQ).FirstOrDefault(); if (inventory == null || inventory.Count == 0) { throw new Exception("NC数据不存在,请刷新页面重试"); } // 暂不支持PCI有的数据同步 if (inventory.PciCount > 0) { throw new Exception("PCI已存在数据,暂不支持同步"); } var list = new List <Mod_TRC_ROLL_PRODCUT>(); decimal avgAmt = Math.Round(inventory.Wgt / inventory.Count, 4); for (int i = 1; i <= inventory.Count; i++) { decimal wgt = avgAmt; if (i == inventory.Count) { // 最后一只,计算余量 wgt = inventory.Wgt - avgAmt * (i - 1); } var mod = new Mod_TRC_ROLL_PRODCUT { C_ID = $"{item.BatchNo}{(i).ToString("0000")}", C_BATCH_NO = item.BatchNo, N_WGT = wgt, C_BZYQ = inventory.BZYQ, //C_STA_ID = string.Empty, //C_CON_NO = string.Empty, //C_CUST_AREA =string.Empty, //C_CUST_NAME = string.Empty, //C_CUST_NO = string.Empty, //C_DP_EMP_ID = string.Empty, //C_DP_GROUP = string.Empty, //C_DP_SHIFT = string.Empty, //C_EMP_ID = string.Empty, //C_FLOOR = string.Empty, //C_GROUP = string.Empty, C_ISFREE = "N", C_IS_DEPOT = "Y", C_JUDGE_LEV_ZH = inventory.ZLDJ, C_LINEWH_CODE = inventory.InventoryCode, C_MAT_CODE = inventory.MtrlCode, C_MAT_DESC = inventory.MtrlName, C_MOVE_TYPE = item.MoveType, C_SPEC = inventory.Spec, C_STD_CODE = inventory.StdCode, C_STL_GRD = inventory.StlGrd, C_STOVE = inventory.LuHao, C_ZYX1 = inventory.zyx1, C_ZYX2 = inventory.zyx2, D_MOD_DT = DateTime.Now, D_DP_DT = DateTime.Now, }; list.Add(mod); } dalOrder.SyncInventory(list); }