public int Load( List<RecTMElement> elements, List<RecTransport> templates, PlanningFilter filter, bool generateErectionSequence ) { _filter = filter; if( templates == null || templates.Count == 0 ) { string msg = string.Format( "No transport templates defined!" ); throw new FaultException<BusinessFaultContract>( new BusinessFaultContract() { Argument = msg }, "Cannot manage transport!" ); } // Put elements on the transportation devices int erectionSequence = 1; foreach( RecTMElement elem in elements ) { if( generateErectionSequence ) { elem.ErectionSequenceNo = erectionSequence; erectionSequence++; } if( !ProcessLoad( elem, templates ) ) { break;// stop loading elements if ProcessLoad returns false which occurs when filter.MultipleTemplateUsage = false } } // Finally save the data to the database return SaveToDb( _tmTransports, false ); }
/// <summary> /// Create a chunk of transport as a copy of the chunk of transport templates /// only in memory. /// </summary> /// <param name="templates"></param> public void CreateTransportFromTemplate( PlanningFilter filter, List<RecTransport> templates, int templateUsageCount, List<TMTransport> transportList ) { foreach( RecTransport transport in templates ) { TMTransport tmTransport = new TMTransport(); tmTransport.CreateFromTemplate( transport, templateUsageCount, filter ); transportList.Add( tmTransport ); } }
/// <summary> /// Creates transports based on the given set of templates /// </summary> /// <param name="filter"></param> /// <param name="templates"></param> /// <returns></returns> public int CreateTransport( PlanningFilter filter, List<RecTransport> templates ) { if( filter == null ) { throw new ArgumentNullException( "Transport" ); } // Load template details LoadTemplateDetails( templates ); TMLoader loader = new TMLoader(); List<TMTransport> transportList = new List<TMTransport>(); loader.CreateTransportFromTemplate( filter, templates, 0, transportList ); loader.SaveToDb( transportList, true ); return transportList.Count; }
public void CreateFromTemplate( RecTransport transportTpl, int templateUsageCount, PlanningFilter filter ) { TransportObject = new RecTransport( transportTpl ); // Calculate the load date and delivery date based on // the template and the template reuse loop(count) // The interval is minutes TransportObject.LoadDate = GetNextDate( filter.LoadDateFrom, (int)filter.TimeInterval, templateUsageCount ); TransportObject.DeliveryDate = GetNextDate( filter.DeliveryDateFrom, (int)filter.TimeInterval, templateUsageCount ); TransportObject.IsTemplate = 0; foreach( RecTransportVehicleStd rec in transportTpl.Vehicles ) { TMVehicle tmVehicle = new TMVehicle( rec ); //Create Stacks from template tmVehicle.CreateFromTemplate( rec ); Vehicles.Add( tmVehicle ); } }
/// <summary> /// Automatic transportation management /// </summary> /// <returns></returns> public int AutoTransport( PlanningFilter filter, List<RecTransport> templates, List<RecTMElement> elements ) { if( filter == null ) { throw new ArgumentNullException( "Transport" ); } elements = GetUntransportedElement( filter.Factory, filter.Project, elements ); if( elements == null || elements.Count == 0 ) { return 0; } elements.Sort( RecTMElement.CompareErectionSequence ); // Load template details LoadTemplateDetails( templates ); bool generateErectionSequence = false; TMLoader loader = new TMLoader(); return loader.Load( elements, templates, filter, generateErectionSequence ); }
/// <summary> /// Load of Transport items /// </summary> /// <returns></returns> public List<RecTMTransport> LoadTransports( PlanningFilter filter, ReportFilter reportFilter ) { if( filter == null ) { throw new ArgumentNullException( "Transport" ); } var where = WhereGroup.And( ImpTransport.Factory.Equal( filter.Factory ) ); if( !string.IsNullOrWhiteSpace( filter.Project ) ) { where.Add( ImpTransport.Project.Equal( filter.Project ) ); } WhereGroup whereStatus = WhereGroup.Or( new Where[] { } ); if( filter.NoStatus ) { whereStatus.Add( ImpTransport.TransportStatus.Equal( TransportStatus.NoStatus ) ); } if( filter.Planned ) { whereStatus.Add( ImpTransport.TransportStatus.Equal( TransportStatus.Planned ) ); } if( filter.CallOff ) { whereStatus.Add( ImpTransport.TransportStatus.Equal( TransportStatus.CallOff ) ); } if( filter.Delivered ) { whereStatus.Add( ImpTransport.TransportStatus.Equal( TransportStatus.Delivered ) ); } if( whereStatus.Count > 0 ) { where.Add( whereStatus ); } where.Add( ImpTransport.IsTemplate.Equal( false ) ); WhereGroup wgDeleted = WhereGroup.Or( ImpModelGeometry.Deleted.NotEqual( 1 ), ImpModelGeometry.Deleted.IsNull() ); where.Add( wgDeleted ); if( filter.UseLoadDateFrom ) { where.Add( ImpTransport.LoadDate.GreaterThanOrEqual( filter.LoadDateFrom ) ); } if( filter.UseLoadDateTo ) { where.Add( ImpTransport.LoadDate.LessThanOrEqual( filter.LoadDateTo ) ); } if( filter.UseDeliveryDateFrom ) { where.Add( ImpTransport.DeliveryDate.GreaterThanOrEqual( filter.DeliveryDateFrom ) ); } if( filter.UseDeliveryDateTo ) { where.Add( ImpTransport.DeliveryDate.LessThanOrEqual( filter.DeliveryDateTo ) ); } if( reportFilter != null && reportFilter.Ranges.Count > 0 ) { var list = new List<Where>(); foreach( var range in reportFilter.Ranges ) { if( !string.IsNullOrEmpty( range.From ) && !string.IsNullOrEmpty( range.To ) ) { list.Add( ImpTransport.TransportId.Between( range.From, range.To ) ); } } if( list.Count > 0 ) { where.Add( WhereGroup.Or( list.ToArray() ) ); } } where.Add( ImpTransport.TransportId.GreaterThan( 0 ) ); ImpactQuery query = new ImpactQuery() { Select = { ImpTransport.Project, ImpTransport.TransportId, ImpTransport.Description, ImpTransport.LoadDate, ImpTransport.DeliveryDate, ImpTransport.TransportStatus, ImpTransportVehicle.VehicleId, ImpTransportVehicleStd.Name, ImpTransportVehicleStd.MaxMass, ImpTransportVehicle.TransportType, ImpTransportVehicleStd.VehicleType, ImpTransportStack.StackId, //ImpTransportStack.Rack, ImpTransportStack.MaxMass, ImpTransportStack.Description, ImpTransportStack.StackType, ImpModelPlanning.ElementId, ImpModelPlanning.ErectionSequenceNo, ImpModelPlanning.StackSequenceNo, ImpModelPlanning.StackId, ImpModelPlanning.ElementIdStatus, ImpModelPlanning.PlannedDeliveryDate, ImpModelPlanning.DeliveryDate, ImpModelGeometry.ElementMark, ImpModelGeometry.Building, ImpModelGeometry.FloorId, ImpModelGeometry.Phase, ImpElement.ElementType, ImpElement.Product, ImpElement.Style, ImpElement.Mass, ImpElement.ElementLength, ImpElement.ElementWidth, ImpElement.ElementHeight, ImpElement.GrossArea, ImpElement.NetArea, }, //ELEMENT_TYPE, STYLE BOUNDING_BOX_AREA From = { ImpTransport.As( "TRA" ) }, Join = { Join.Left( ImpTransportVehicle.As( "TRV" ), ImpTransport.Factory.Equal( ImpTransportVehicle.Factory ), ImpTransport.Project.Equal( ImpTransportVehicle.Project ), ImpTransport.TransportId.Equal( ImpTransportVehicle.TransportId ) ), Join.Left( ImpTransportVehicleStd.As( "VST" ), ImpTransport.Factory.Equal( ImpTransportVehicleStd.Factory ), ImpTransport.Factory.Equal( ImpTransportVehicleStd.Project ), // Factory, factory only so far (Needs to be complated with company, company) ImpTransportVehicle.Vehicle.Equal( ImpTransportVehicleStd.Name ) ), Join.Left( ImpTransportStack.As( "RCK" ), ImpTransport.Factory.Equal( ImpTransportStack.Factory ), ImpTransport.Project.Equal( ImpTransportStack.Project ), ImpTransport.TransportId.Equal( ImpTransportStack.TransportId ), ImpTransportVehicle.VehicleId.Equal( ImpTransportStack.VehicleId )), Join.Left( ImpModelPlanning.As( "MPL" ), ImpTransport.Factory.Equal( ImpModelPlanning.Factory ), ImpTransport.Project.Equal( ImpModelPlanning.Project ), ImpTransport.TransportId.Equal( ImpModelPlanning.TransportId ), ImpTransportVehicle.VehicleId.Equal( ImpModelPlanning.VehicleId ) , ImpTransportStack.StackId.Equal( ImpModelPlanning.StackId ) ), Join.Left( ImpModelGeometry.As( "MGO" ), ImpModelPlanning.Factory.Equal( ImpModelGeometry.Factory ), ImpModelPlanning.Project.Equal( ImpModelGeometry.Project ), ImpModelPlanning.ElementId.Equal( ImpModelGeometry.ElementId ) ), Join.Left( ImpElement.As( "ELM" ), ImpModelGeometry.Factory.Equal( ImpElement.Factory ), ImpModelGeometry.Project.Equal( ImpElement.Project ), ImpModelGeometry.ElementMark.Equal( ImpElement.ElementMark ) ), }, Where = { where }, OrderBy = { { ImpTransport.TransportId, OrderBy.Descending }, { ImpTransportVehicle.VehicleId }, { ImpTransportStack.StackId }, { ImpModelPlanning.StackSequenceNo, OrderBy.Descending } }, }; string statement = query.ToString(); List<RecTMTransport> tmList = new List<RecTMTransport>(); TranportParser parser = new TranportParser( tmList ); using( ImpactDatabase database = new ImpactDatabase() ) { var list = database.GetAll( statement, column => { string project = DataConverter.Cast<string>( column[0] ); int transportId = DataConverter.Cast<int>( column[1] ); return new { // TODO: THEIB, you must handle null dates in your record class. transport = new RecTransport() { Factory = filter.Factory, Project = project, TransportId = transportId, Description = DataConverter.Cast<string>( column[2] ), LoadDate = DataConverter.Cast<DateTime>( column[3] ), DeliveryDate = DataConverter.Cast<DateTime?>( column[4] ), TransportStatus = DataConverter.Cast<int>( column[5] ), }, veh = new RecTransportVehicleStd() { Factory = filter.Factory, Project = project, VehicleId = DataConverter.Cast<int?>( column[6] ) ?? 0, Name = DataConverter.Cast<string>( column[7] ), MaxMass = DataConverter.Cast<double?>( column[8] ) ?? 0d, TransportId = transportId, TransportType = DataConverter.Cast<int?>( column[9] ) ?? 0, VehicleType = DataConverter.Cast<int?>( column[10] ) ?? 0 }, stack = new RecTransportVehicleStackStd() { StackId = DataConverter.Cast<int?>( column[11] ) ?? 0, MaxMass = DataConverter.Cast<double?>( column[12] ) ?? 0, Description = DataConverter.Cast<string>( column[13] ), StackType = DataConverter.Cast<int?>( column[14] ) ?? 0 }, elem = new RecTMElement() { Factory = filter.Factory, Project = project, ElementId = DataConverter.Cast<int?>( column[15] ) ?? 0, ErectionSequenceNo = DataConverter.Cast<int?>( column[16] ) ?? 0, StackSequenceNo = DataConverter.Cast<int?>( column[17] ) ?? 0, StackId = DataConverter.Cast<int?>( column[18] ) ?? 0, ElementIdStatus = DataConverter.Cast<int?>( column[19] ) ?? 0, PlannedDeliveryDate = DataConverter.Cast<DateTime?>( column[20] ), DeliveryDate = DataConverter.Cast<DateTime?>( column[21] ), ElementMark = DataConverter.Cast<string>( column[22] ), Building = DataConverter.Cast<string>( column[23] ), FloorId = DataConverter.Cast<int?>( column[24] ) ?? 0, Phase = DataConverter.Cast<string>( column[25] ), ElementType = DataConverter.Cast<string>( column[26] ), Product = DataConverter.Cast<string>( column[27] ), Style = DataConverter.Cast<string>( column[28] ), Mass = DataConverter.Cast<double?>( column[29] ) ?? 0d, ElementLength = DataConverter.Cast<double?>( column[30] ) ?? 0d, ElementWidth = DataConverter.Cast<double?>( column[31] ) ?? 0d, ElementHeight = DataConverter.Cast<double?>( column[32] ) ?? 0d, GrossArea = DataConverter.Cast<double?>( column[33] ) ?? 0d, NetArea = DataConverter.Cast<double?>( column[34] ) ?? 0d, } }; } ); foreach( var item in list ) { parser.Parse( item.transport, item.veh, item.stack, item.elem ); } } return tmList; }