Esempio n. 1
0
        /// <summary>
        /// 添加 采购/出库  需求
        /// </summary>
        /// <param name="entity"></param>
        protected void SetMaterialRequire(Part entity)
        {
            var materialCode = entity.MaterialCode;
            var material     = MaterialManager.GetAll().Where(o => o.Code == materialCode).Include(o => o.MeasureMent.MeasureMentUnits).FirstOrDefault();

            if (material == null)
            {
                return;
            }
            var measureMentUnit = material.MeasureMent.MeasureMentUnits.Where(o => o.Name == entity.MeasureMentUnit).FirstOrDefault();

            var materialRequire = new MaterialRequire();

            materialRequire.RequireSource       = "BOM";
            materialRequire.RequireSourceId     = entity.Id;
            materialRequire.MaterialId          = material.Id;
            materialRequire.CustomSpecification = string.IsNullOrEmpty(material.Specification)? entity.PartSpecification: material.Specification;
            materialRequire.CustomBrand         = material.Brand;

            materialRequire.Number            = entity.PartNum;
            materialRequire.MeasureMentUnitId = measureMentUnit.Id;
            materialRequire.RequireDate       = entity.RequireDate;
            materialRequire.ProjectId         = entity.ProjectId;

            var codematerial = MaterialManager.GetAll().Where(o => o.Code == entity.MaterialCode).FirstOrDefault();

            materialRequire.CustomName = codematerial.Name;


            if (entity.EnableBuy)
            {
                materialRequire.RequireType = RequireType.Buy;
                MaterialRequireManager.InsertAsync(materialRequire).GetAwaiter().GetResult();
            }
            else if (entity.EnableStorage)
            {
                materialRequire.RequireType = RequireType.Storage;
                materialRequire.ToOutNumber = entity.PartNum;
                MaterialRequireManager.InsertAsync(materialRequire).GetAwaiter().GetResult();
            }
        }
Esempio n. 2
0
        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);
                }
            }
        }