public void HandleEvent(EntityDeletingEventData <Part> eventData) { var entity = eventData.Entity; var materialRequire = MaterialRequireManager.GetAll().Where(o => o.RequireSource == "BOM" && o.RequireSourceId == entity.Id && o.ProjectId == entity.ProjectId).FirstOrDefault(); if (materialRequire != null) { var isdo = ""; isdo += materialRequire.IsBuyed?"已采购,":""; isdo += materialRequire.IsReceived ? "已入库,":""; isdo += materialRequire.IsUsed ? "已领用,":""; // isdo += materialRequire.IsQuoted ? "已询价,":""; if (string.IsNullOrEmpty(isdo)) { throw new UserFriendlyException("该BOM基础物资已进入流程,无法删除:" + isdo); } } }
public void HandleEvent(EntityChangingEventData <Part> eventData) { var entity = eventData.Entity; var materialRequire = MaterialRequireManager.GetAll().Where(o => o.RequireSource == "BOM" && o.RequireSourceId == entity.Id && o.ProjectId == entity.ProjectId).FirstOrDefault(); if (materialRequire != null) { var oldentity = Query.FirstOrDefault <Part>("select * from Part where id=@0", entity.Id); if (oldentity == null) { return; //throw new UserFriendlyException("不存在记录[Part] Id=" + entity.Id); } var isdo = ""; isdo += materialRequire.IsBuyed ? "已采购," : ""; isdo += materialRequire.IsReceived ? "已入库," : ""; isdo += materialRequire.IsUsed ? "已领用," : ""; // isdo += materialRequire.IsQuoted ? "已询价," : ""; if (!string.IsNullOrEmpty(isdo)) { throw new UserFriendlyException("该BOM基础物资已进入流程,无法修改:" + isdo); } //验证通过的情况下判断物资内容是否改变 if (oldentity.MaterialCode != entity.MaterialCode || oldentity.PartNum != entity.PartNum || oldentity.MeasureMentUnit != entity.MeasureMentUnit || oldentity.RequireDate != entity.RequireDate) { //物资编码 数量 单位改变 改变需求表的内容 var msg = ""; if (oldentity.MaterialCode != entity.MaterialCode) { var codematerial = MaterialManager.GetAll().Where(o => o.Code == entity.MaterialCode).FirstOrDefault(); materialRequire.CustomName = codematerial.Name; materialRequire.CustomSpecification = string.IsNullOrEmpty(codematerial.Specification) ? entity.PartSpecification : codematerial.Specification; materialRequire.CustomBrand = codematerial.Brand; msg += "物料编码改变[" + oldentity.MaterialCode + "-->" + entity.MaterialCode + "] ,"; } if (oldentity.PartNum != entity.PartNum) { materialRequire.Number = entity.PartNum; materialRequire.ToOutNumber = entity.PartNum; msg += "数量改变[" + oldentity.PartNum + "-->" + entity.PartNum + "] ,"; } if (oldentity.MeasureMentUnit != entity.MeasureMentUnit) { msg += "单位改变[" + oldentity.MeasureMentUnit + "-->" + entity.MeasureMentUnit + "] ,"; } if (oldentity.RequireDate != entity.RequireDate) { materialRequire.RequireDate = entity.RequireDate; msg += "物料应到料时间改变[" + oldentity.RequireDate + "-->" + entity.RequireDate + "] ,"; } MaterialRequireManager.AddOperationHistory(materialRequire.Id, "BOM修改:" + msg).GetAwaiter().GetResult(); } } else { if (entity.EnableBuy || entity.EnableStorage) { SetMaterialRequire(entity); } } }