public bool selectUnitTypeForItem(Guid itemUnitTypeConfigId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { ItemUnitTypeConfig iutc = uow.GetObjectByKey <ItemUnitTypeConfig>(itemUnitTypeConfigId); iutc.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE; iutc.IsSelected = true; iutc.Save(); UnitBO bo = new UnitBO(); bo.populateDefaultUnitToItemUnit(iutc.ItemId.ItemId, iutc.UnitTypeId.UnitTypeId); uow.CommitChanges(); return(true); } catch { throw; } finally { uow.Dispose(); } } }
public bool unselectUnitTypeForItem(Guid itemUnitTypeConfigId) { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { ItemUnitTypeConfig iutc = uow.GetObjectByKey <ItemUnitTypeConfig>(itemUnitTypeConfigId); iutc.RowStatus = Utility.Constant.ROWSTATUS_DEFAULT; iutc.IsMaster = false; iutc.IsSelected = false; iutc.Save(); XPCollection <ItemUnit> itemUnits = new XPCollection <ItemUnit>(uow, CriteriaOperator.And( new BinaryOperator("ItemId", iutc.ItemId, BinaryOperatorType.Equal), new NotOperator(new NullOperator("UnitId")), new NotOperator(new NullOperator("UnitId.UnitTypeId")), new BinaryOperator("UnitId.UnitTypeId.Code", iutc.UnitTypeId.Code, BinaryOperatorType.Equal) )); foreach (ItemUnit iu in itemUnits) { iu.RowStatus = Utility.Constant.ROWSTATUS_DELETED; iu.Save(); } uow.FlushChanges(); uow.CommitChanges(); return(true); } catch { throw; } finally { uow.Dispose(); } } }
public void PopulateDefaultUnitTypeConfigForAllItems() { using (UnitOfWork uow = XpoHelper.GetNewUnitOfWork()) { try { XPCollection <ItemUnitTypeConfig> configs = new XPCollection <ItemUnitTypeConfig>(uow); uow.Delete(configs); XPCollection <Item> items = new XPCollection <Item>(uow, new BinaryOperator("RowStatus", 0, BinaryOperatorType.GreaterOrEqual)); XPCollection <NAS.DAL.Nomenclature.UnitItem.UnitType> unitTypes = new XPCollection <NAS.DAL.Nomenclature.UnitItem.UnitType>(uow, CriteriaOperator.And( new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_DEFAULT, BinaryOperatorType.Equal), new BinaryOperator("Code", Utility.Constant.NAAN_DEFAULT_CODE, BinaryOperatorType.NotEqual))); if (items == null || items.Count == 0) { return; } foreach (Item item in items) { foreach (NAS.DAL.Nomenclature.UnitItem.UnitType unitType in unitTypes) { ItemUnitTypeConfig iutc = new ItemUnitTypeConfig(uow); iutc.ItemId = item; iutc.RowStatus = Utility.Constant.ROWSTATUS_DEFAULT; if (item.ItemUnits != null && item.ItemUnits.Count > 0) { foreach (ItemUnit iu in item.ItemUnits) { if (iu.UnitId != null && iu.UnitId.UnitTypeId != null && (iu.RowStatus == Utility.Constant.ROWSTATUS_DEFAULT || iu.RowStatus == Utility.Constant.ROWSTATUS_ACTIVE) && iu.UnitId.UnitTypeId == unitType) { iutc.RowStatus = Utility.Constant.ROWSTATUS_ACTIVE; } } } iutc.IsMaster = false; if (unitType.Code.Equals("SPECIFICATION")) { iutc.IsMaster = true; } iutc.UnitTypeId = unitType; iutc.Save(); } } uow.CommitChanges(); } catch { //uow.ExplicitRollbackTransaction(); throw; } } }
public Item addDefaultItem(Session session, NAS.DAL.Nomenclature.Item.Item.TYPEOFITEM info) { try { session.BeginTransaction(); //insert default data into Item table string name = ""; switch (info) { case NAS.DAL.Nomenclature.Item.Item.TYPEOFITEM.PRODUCT: name = "PRODUCT"; break; case NAS.DAL.Nomenclature.Item.Item.TYPEOFITEM.MATERIAL: name = "MATERIAL"; break; case NAS.DAL.Nomenclature.Item.Item.TYPEOFITEM.TOOL: name = "TOOL"; break; case NAS.DAL.Nomenclature.Item.Item.TYPEOFITEM.SERVICE: name = "SERVICE"; break; default: break; } ObjectType objectType = NAS.DAL.Util.getXpoObjectByName <ObjectType>(session, name); Item item = new Item(session) { Code = Guid.NewGuid().ToString(), Description = Utility.Constant.NAAN_DEFAULT_NAME, RowStatus = 0, RowCreationTimeStamp = DateTime.Now }; item.Save(); XPCollection <NAS.DAL.Nomenclature.UnitItem.UnitType> unitTypes = new XPCollection <NAS.DAL.Nomenclature.UnitItem.UnitType>(session, CriteriaOperator.And( new BinaryOperator("RowStatus", Utility.Constant.ROWSTATUS_DEFAULT, BinaryOperatorType.Equal), new BinaryOperator("Code", Utility.Constant.NAAN_DEFAULT_CODE, BinaryOperatorType.NotEqual))); foreach (NAS.DAL.Nomenclature.UnitItem.UnitType unitType in unitTypes) { ItemUnitTypeConfig iutc = new ItemUnitTypeConfig(session); iutc.ItemId = item; iutc.UnitTypeId = unitType; iutc.IsMaster = false; iutc.RowStatus = Utility.Constant.ROWSTATUS_DEFAULT; iutc.Save(); } session.CommitTransaction(); return(item); } catch (Exception) { session.RollbackTransaction(); throw; } }