public FlowDetail GetFlowDetailByItem(string flowCode, string itemCode, string locationFromCode, string locationToCode) { Flow flow = flowDao.LoadFlow(flowCode); FlowDetail flowDetail = null; DetachedCriteria criteria = DetachedCriteria.For(typeof(FlowDetail)); criteria.CreateAlias("Flow", "fl"); criteria.CreateAlias("fl.LocationFrom", "lf"); criteria.CreateAlias("fl.LocationTo", "lt"); criteria.Add(Expression.Eq("fl.Code", flowCode)); criteria.Add(Expression.Eq("Item.Code", itemCode)); if (locationFromCode != null && locationFromCode != string.Empty) { criteria.Add( Expression.Or( Expression.Eq("LocationFrom.Code", locationFromCode), Expression.And( Expression.IsNull("LocationFrom"), Expression.Eq("lf.Code", locationFromCode)))); } else { criteria.Add(Expression.And( Expression.IsNull("LocationFrom"), Expression.IsNull("lf.Code"))); } if (locationToCode != null && locationToCode != string.Empty) { criteria.Add( Expression.Or( Expression.Eq("LocationTo.Code", locationToCode), Expression.And( Expression.IsNull("LocationTo"), Expression.Eq("lt.Code", locationToCode)))); } else { criteria.Add(Expression.And( Expression.IsNull("LocationTo"), Expression.IsNull("lt.Code"))); } //todo ур╣╫ж╠╫с╥╣╩ь IList <FlowDetail> flowDetailList = criteriaMgr.FindAll <FlowDetail>(criteria); if (flowDetailList.Count > 0) { flowDetail = (FlowDetail)flowDetailList[0]; } else if (flowDetailList.Count == 0 && flow.ReferenceFlow != null && flow.ReferenceFlow.Trim() != string.Empty) { criteria = DetachedCriteria.For(typeof(FlowDetail)); criteria.CreateAlias("Flow", "fl"); criteria.CreateAlias("fl.LocationFrom", "lf"); criteria.CreateAlias("fl.LocationTo", "lt"); criteria.Add(Expression.Eq("fl.Code", flowCode)); criteria.Add(Subqueries.In(itemCode, DetachedCriteria.For(typeof(FlowDetail)) .CreateAlias("Item", "i") .CreateAlias("Flow", "f") .Add(Expression.Eq("f.Code", flow.ReferenceFlow)) .SetProjection(Projections.ProjectionList().Add(Projections.Property("i.Code"))) )); if (locationFromCode != null && locationFromCode != string.Empty) { criteria.Add( Expression.Or( Expression.Eq("LocationFrom.Code", locationFromCode), Expression.And( Expression.IsNull("LocationFrom"), Expression.Eq("lf.Code", locationFromCode)))); } else { criteria.Add(Expression.And( Expression.IsNull("LocationFrom"), Expression.IsNull("lf.Code"))); } if (locationToCode != null && locationToCode != string.Empty) { criteria.Add( Expression.Or( Expression.Eq("LocationTo.Code", locationToCode), Expression.And( Expression.IsNull("LocationTo"), Expression.Eq("lt.Code", locationToCode)))); } else { criteria.Add(Expression.And( Expression.IsNull("LocationTo"), Expression.IsNull("lt.Code"))); } flowDetailList = criteriaMgr.FindAll <FlowDetail>(criteria); if (flowDetailList.Count != 0) { flowDetail = (FlowDetail)flowDetailList[0]; } } return(flowDetail); }
public virtual Flow LoadFlow(String code) { return(entityDao.LoadFlow(code)); }