public void DrillUpUpdateAllCoefficientsOfItem(UnitOfWork uow, Guid itemId, Guid currentItemUnitId) { NAS.DAL.Nomenclature.Item.ItemUnit currentItemUnit = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.ItemUnit>(currentItemUnitId); NAS.DAL.Nomenclature.Item.Item item = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (currentItemUnit == null) { throw new Exception("The ItemUnit is not exist in system"); } if (item == null) { throw new Exception("The Item is not exist in system"); } NAS.DAL.Nomenclature.Item.ItemUnit parent = currentItemUnit.ParentItemUnitId; if (parent == null) { return; } parent.Coefficient = currentItemUnit.Coefficient / currentItemUnit.NumRequired; parent.Save(); uow.FlushChanges(); DrillUpUpdateAllCoefficientsOfItem(uow, itemId, parent.ItemUnitId); }
public void DrillDownDeleteLogicUnitOfItem(UnitOfWork uow, Guid itemId, Guid deletingItemUnitId) { NAS.DAL.Nomenclature.Item.ItemUnit currentItemUnit = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.ItemUnit>(deletingItemUnitId); NAS.DAL.Nomenclature.Item.Item item = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (currentItemUnit == null) { throw new Exception("The ItemUnit is not exist in system"); } if (item == null) { throw new Exception("The Item is not exist in system"); } XPCollection <NAS.DAL.Nomenclature.Item.ItemUnit> childrentItemUnit = new XPCollection <ItemUnit>(uow, new BinaryOperator("ParentItemUnitId!Key", currentItemUnit.ItemUnitId, BinaryOperatorType.Equal)); currentItemUnit.RowStatus = Utility.Constant.ROWSTATUS_DELETED; currentItemUnit.Save(); uow.FlushChanges(); foreach (NAS.DAL.Nomenclature.Item.ItemUnit currIU in childrentItemUnit) { DrillDownDeleteLogicUnitOfItem(uow, itemId, currIU.ItemUnitId); } }
public void DrillDownUpdateAllCoefficientsOfItem(UnitOfWork uow, Guid itemId, Guid currentItemUnitId) { NAS.DAL.Nomenclature.Item.ItemUnit currentItemUnit = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.ItemUnit>(currentItemUnitId); NAS.DAL.Nomenclature.Item.Item item = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (currentItemUnit == null) { throw new Exception("The ItemUnit is not exist in system"); } if (item == null) { throw new Exception("The Item is not exist in system"); } XPCollection <NAS.DAL.Nomenclature.Item.ItemUnit> childrentItemUnit = new XPCollection <ItemUnit>(uow, new BinaryOperator("ParentItemUnitId!Key", currentItemUnit.ItemUnitId, BinaryOperatorType.Equal)); foreach (NAS.DAL.Nomenclature.Item.ItemUnit currIU in childrentItemUnit) { currIU.Coefficient = currentItemUnit.Coefficient * currIU.NumRequired; currIU.Save(); uow.FlushChanges(); DrillDownUpdateAllCoefficientsOfItem(uow, itemId, currIU.ItemUnitId); } }
public bool updateMasterUnitTypeOfItem(Guid itemId, Guid masterUnitTypeId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Nomenclature.UnitItem.UnitType ut = uow.GetObjectByKey <NAS.DAL.Nomenclature.UnitItem.UnitType>(masterUnitTypeId); NAS.DAL.Nomenclature.Item.Item i = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (ut == null) { throw new Exception("The UnitType is not exist in system"); } if (i == null) { throw new Exception("The Item is not exist in system"); } if (i.itemUnitTypeConfigs == null || i.itemUnitTypeConfigs.Count == 0) { throw new Exception("The UnitTypes are blank with this item"); } IEnumerable <UnitType> tmpLst = i.itemUnitTypeConfigs.Select(o => o.UnitTypeId).Where(rs => rs.UnitTypeId == masterUnitTypeId); if (tmpLst == null || tmpLst.Count() == 0) { throw new Exception("The MasterUnitTypeId is not in ItemUnitTypeConfig"); } foreach (NAS.DAL.Nomenclature.Item.ItemUnitTypeConfig config in i.itemUnitTypeConfigs) { if (config.UnitTypeId.UnitTypeId.Equals(masterUnitTypeId)) { config.IsMaster = true; } else { config.IsMaster = false; } config.Save(); } uow.CommitChanges(); return(true); } catch { throw; } finally { uow.Dispose(); } } }
public NAS.DAL.Nomenclature.Item.ItemUnitTypeConfig getItemUnitTypeConfig(Session session, Guid itemId, Guid unitTypeId) { try { NAS.DAL.Nomenclature.UnitItem.UnitType ut = session.GetObjectByKey <NAS.DAL.Nomenclature.UnitItem.UnitType>(unitTypeId); NAS.DAL.Nomenclature.Item.Item i = session.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); ItemUnitTypeConfig iutc = session.FindObject <ItemUnitTypeConfig>( CriteriaOperator.And( new BinaryOperator("UnitTypeId", ut, BinaryOperatorType.Equal), new BinaryOperator("ItemId", i, BinaryOperatorType.Equal) ) ); return(iutc); } catch { throw; } }
public void InsertItems(List <ItemEntity> itemEntityList, string itemTradingTypeName, string objectTypeName) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { foreach (var itemEntity in itemEntityList) { try { if (itemEntity.Code.Equals("EVE006")) { string debug = "Y"; } //Check required if (itemEntity.Code == null || itemEntity.Code.Trim().Length == 0) { continue; } //Check dupplicate code bool isExist = NAS.DAL.Util.isExistXpoObject <NAS.DAL.Nomenclature.Item.Item> ("Code", itemEntity.Code, Constant.ROWSTATUS_ACTIVE, Constant.ROWSTATUS_DEFAULT, Constant.ROWSTATUS_INACTIVE); if (isExist) { continue; } //Get item trading type ItemTradingType itemTradingType = Util.getXPCollection <ItemTradingType>(uow, "Name", itemTradingTypeName).FirstOrDefault(); //Get Manufacturer ManufacturerOrg manufacturerOrg = Util.getXPCollection <ManufacturerOrg>(uow, "Code", itemEntity.ManufacturerCode, Constant.ROWSTATUS_ACTIVE).FirstOrDefault(); if (manufacturerOrg == null) { manufacturerOrg = Util.getDefaultXpoObject <ManufacturerOrg>(uow); } //Insert into Item table NAS.DAL.Nomenclature.Item.Item item = new NAS.DAL.Nomenclature.Item.Item(uow) { Code = itemEntity.Code, Description = itemEntity.Description, ManufacturerOrgId = manufacturerOrg, ItemTradingTypeId = itemTradingType, Name = itemEntity.Name, RowStatus = Constant.ROWSTATUS_ACTIVE, RowCreationTimeStamp = DateTime.Now }; item.Save(); //Get Supplier SupplierOrg supplierOrg = Util.getXPCollection <SupplierOrg>(uow, "Code", itemEntity.SupplierCode, Constant.ROWSTATUS_ACTIVE).FirstOrDefault(); if (supplierOrg != null) { //Insert into ItemSupplier table ItemSupplier itemSupplier = new ItemSupplier(uow) { ItemId = item, SupplierOrgId = supplierOrg }; itemSupplier.Save(); } ObjectType objectType = Util.getXPCollection <ObjectType>(uow, "Name", objectTypeName, Constant.ROWSTATUS_ACTIVE).FirstOrDefault(); if (objectType != null) { //Insert into ItemSupplier table ItemCustomType itemCustomType = new ItemCustomType(uow) { ItemId = item, ObjectTypeId = objectType }; itemCustomType.Save(); } uow.CommitChanges(); //using (Session itemUnitSession = XpoHelper.GetNewSession()) //{ // //Get UNIT relation type // ItemUnitRelationType unitRelationType = // NAS.DAL.Util.getXPCollection<ItemUnitRelationType>(itemUnitSession, "Name", "UNIT").FirstOrDefault(); // itemEntity.ItemUnits = itemEntity.ItemUnits.OrderBy(r => r.Level).ToList(); // ////Insert into ItemUnit // foreach (ItemUnitEntity itemUnitEntity in itemEntity.ItemUnits) // { // NAS.DAL.Nomenclature.Item.Item itemTemp = // NAS.DAL.Util.getXPCollection<NAS.DAL.Nomenclature.Item.Item> // (itemUnitSession, "Code", itemUnitEntity.ItemCode).FirstOrDefault(); // Unit unit = // NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.UnitCode).FirstOrDefault(); // if (unit == null) // break; // Unit parentUnit = // NAS.DAL.Util.getXPCollection<Unit>(itemUnitSession, "Code", itemUnitEntity.ParentUnitCode).FirstOrDefault(); // ItemUnit parentItemUnit = itemTemp.ItemUnits.Where(r => r.UnitId == parentUnit).FirstOrDefault(); // ItemUnit itemUnit = new ItemUnit(itemUnitSession) // { // ItemId = itemTemp, // ItemUnitRelationTypeId = unitRelationType, // NumRequired = itemUnitEntity.NumRequired, // RowStatus = Constant.ROWSTATUS_ACTIVE, // UnitId = unit, // ParentItemUnitId = parentItemUnit, // RowCreationTimeStamp = DateTime.Now // }; // itemUnit.Save(); // } //} } catch (Exception ex) { string msg = ex.Message; } } } }
public bool UpdateDefaultItemUnitOfItem(Guid itemId, Guid defaultItemUnitId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { NAS.DAL.Nomenclature.Item.ItemUnit iu = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.ItemUnit>(defaultItemUnitId); NAS.DAL.Nomenclature.Item.Item i = uow.GetObjectByKey <NAS.DAL.Nomenclature.Item.Item>(itemId); if (iu == null) { throw new Exception("The ItemUnit is not exist in system"); } if (i == null) { throw new Exception("The Item is not exist in system"); } IEnumerable <NAS.DAL.Nomenclature.Item.ItemUnit> tmpLst = i.ItemUnits.Where( row => row.UnitId != null && row.ItemId != null && row.UnitId.UnitTypeId != null && row.UnitId.UnitTypeId.Code == iu.UnitId.UnitTypeId.Code); foreach (NAS.DAL.Nomenclature.Item.ItemUnit o in tmpLst) { if (o.ItemUnitId.Equals(defaultItemUnitId)) { o.Coefficient = 1; o.IsDefault = true; } else { o.IsDefault = false; } o.Save(); } DrillDownUpdateAllCoefficientsOfItem(uow, itemId, defaultItemUnitId); DrillUpUpdateAllCoefficientsOfItem(uow, itemId, defaultItemUnitId); uow.CommitChanges(); return(true); } catch { throw; } finally { uow.Dispose(); } } }