Exemplo n.º 1
0
        /// <summary>
        /// Returns CastData which contains the following info
        /// (1) List<RecProductionFormStd>: a set of beds, each with one production cast ONLY.
        /// The production cast object can contain elements.
        /// (2) ProductionFormStdData: Production Forms Standard Data
        /// </summary>
        /// <param name="filter">BedFilter</param>
        /// <param name="form">RecProductionFormStd</param>
        /// <returns></returns>
        public CastData LoadBedPlanning( BedFilter filter, RecProductionFormStd form )
        {
            if( null == filter || 
                string.IsNullOrEmpty( filter.Factory ) || 
                string.IsNullOrEmpty( filter.Project ) )
            {
                return null;
            }

            ImpactQuery query = new ImpactQuery()
            {
                Select =
				{
					ImpProductionCast.CastId,
					ImpProductionCast.Description,
					ImpProductionCast.StartDate,
					ImpProductionCast.EndDate,
					ImpProductionCast.Tolerance,
					ImpProductionCast.ElementType,
                    ImpProductionCast.Style,
					ImpProductionCast.Strandptn,
                    ImpProductionCast.CastType,
					ImpProductionCast.CastStatus,
                    ImpProductionCast.Form,
					ImpProductionCast.Shift,
					Aggregate.Count( ImpProductionCastStrand.StrandPos ),

					ImpProductionFormStd.Name,
					ImpProductionFormStd.MaxLength,
					ImpProductionFormStd.MaxWidth,
					ImpProductionFormStd.MaxHeight,
                    ImpProductionFormStd.ElementType,
                    ImpProductionFormStd.Style,
					ImpProductionFormStd.Strandptn,
                    ImpProductionFormStd.StrandType,
                    ImpProductionFormStd.FormType,

					ImpModelPlanning.ElementId,
					ImpModelGeometry.ElementMark,
					ImpModelPlanning.ErectionSequenceNo,
					ImpModelPlanning.TransportId,

					ImpModelPlanning.BedSequenceNo,
					ImpModelPlanning.BedX,
					ImpModelPlanning.BedY,
					ImpModelPlanning.BedZ,
					ImpModelPlanning.BedRotation,
                    ImpModelPlanning.ElementIdStatus,
                    ImpModelPlanning.ProductionDate,
                    ImpModelPlanning.PlannedProductionDate,

					ImpElement.ElementLength,
					ImpElement.ElementWidth,
					ImpElement.ElementHeight,
					ImpElement.ElementType,
					ImpElement.GrossArea,
					ImpElement.Product,
					ImpElement.Project,
					ImpElement.AngleLeftSide,
					ImpElement.AngleRightSide,

					ImpElement.Style,
					ImpElement.Strandptn,
					ImpElement.NbrOfStrands,
                    ImpElement.Volume,
                },

                From = { ImpProductionFormStd.As( "FRM" ) },

                Join =
				{
					Join.Left( ImpProductionCast.As( "CST" ),	
						ImpProductionCast.Factory.Equal( ImpProductionFormStd.Factory ),
						ImpProductionCast.Project.Equal( ImpProductionFormStd.Project ),//Factory, Factory
						ImpProductionCast.Form.Equal( ImpProductionFormStd.Name ) ),

					Join.Left( ImpProductionCastStrand.As( "STA" ),	
						ImpProductionCast.Factory.Equal( ImpProductionCastStrand.Factory ),
						ImpProductionCast.Project.Equal( ImpProductionCastStrand.Project ),// Factory, Factory for productionCast & ProductionCastStrand
						ImpProductionCast.CastId.Equal( ImpProductionCastStrand.CastId ) ),


					Join.Left( ImpModelPlanning.As( "MPL" ),	
						ImpProductionCast.Factory.Equal( ImpModelPlanning.Factory ),
						ImpProductionCast.Project.Equal( ImpModelPlanning.Factory ),// Factory, Factory for productionCast & ProductionCastStrand
						ImpProductionCast.CastId.Equal( ImpModelPlanning.CastId ) ),


					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 = {
							ImpProductionCast.Factory.Equal( filter.Factory ), 
							ImpProductionCast.Project.Equal( filter.Factory ), // Factory, Factory for productionCast & ProductionCastStrand
							ImpProductionCast.StartDate.Equal( filter.StartDateFrom ), 
                            ImpProductionCast.Shift.Equal( filter.Shift ), 
						   // ImpModelPlanning.CastId.GreaterThan( 0 ),      // Get even the casts without elements!
						},

                GroupBy = 
                {
					ImpProductionCast.CastId,
					ImpProductionCast.Description,
					ImpProductionCast.StartDate,
					ImpProductionCast.EndDate,
					ImpProductionCast.Tolerance,
					ImpProductionCast.ElementType,
                    ImpProductionCast.Style,
					ImpProductionCast.Strandptn,
                    ImpProductionCast.CastType,
					ImpProductionCast.CastStatus,
					ImpProductionCast.Form,
					ImpProductionCast.Shift,

					ImpProductionFormStd.Name,
					ImpProductionFormStd.MaxLength,
					ImpProductionFormStd.MaxWidth,
					ImpProductionFormStd.MaxHeight,
                    ImpProductionFormStd.ElementType,
                    ImpProductionFormStd.Style,
					ImpProductionFormStd.Strandptn,
                    ImpProductionFormStd.StrandType,
                    ImpProductionFormStd.FormType,

					ImpModelPlanning.ElementId,
					ImpModelGeometry.ElementMark,
					ImpModelPlanning.ErectionSequenceNo,
					ImpModelPlanning.TransportId,

					ImpModelPlanning.BedSequenceNo,
					ImpModelPlanning.BedX,
					ImpModelPlanning.BedY,
					ImpModelPlanning.BedZ,
					ImpModelPlanning.BedRotation,
                    ImpModelPlanning.ElementIdStatus,
                    ImpModelPlanning.ProductionDate,
                    ImpModelPlanning.PlannedProductionDate,

					ImpElement.ElementLength,
					ImpElement.ElementWidth,
					ImpElement.ElementHeight,
					ImpElement.ElementType,
					ImpElement.GrossArea,
					ImpElement.Product,
					ImpElement.Project,
					ImpElement.AngleLeftSide,
					ImpElement.AngleRightSide,

					ImpElement.Style,
					ImpElement.Strandptn,
					ImpElement.NbrOfStrands,
                    ImpElement.Volume,
                },

                OrderBy = 
				{ 
					{ ImpElement.Project },
					{ ImpProductionFormStd.Name },
					{ ImpProductionCast.CastId },
					{ ImpModelPlanning.BedSequenceNo, OrderBy.Ascending }
				},
            };

            if( filter.FormType != FormType.All )
            {
                query.Where.Add( ImpProductionCast.CastType.Equal( filter.FormType ) );
            }

            if( !string.IsNullOrWhiteSpace( filter.Location ) && !filter.Location.Equals( Filter.All ) )
            {
                query.Where.Add( ImpProductionFormStd.Location.Equal( filter.Location ) );
            }
            if( !filter.Bed.Equals( Filter.All ) )
            {
                query.Where.Add( ImpProductionCast.Form.Equal( filter.Bed ) );
            }

            // used when sorting elements on bed
            if( form != null && !string.IsNullOrWhiteSpace( form.Name ) )
            {
                query.Where.Add( ImpProductionFormStd.Name.Equal( form.Name ) );
            }

            var statement = query.ToString();

            var tmList = new List<RecProductionFormStd>();
            var parser = new FormParser( tmList );

            using( var database = new ImpactDatabase() )
            {
                var list = database.GetAll( statement, ParseCast );

                foreach( var item in list )
                {
                    item.Form.Factory = filter.Factory;
                    item.Cast.Factory = filter.Factory;

                    item.Form.Project = filter.Project; // What does that really mean!
                    item.Cast.Project = filter.Project; // What does that really mean!

                    if( null != item.Element )
                    {
                        item.Element.Factory = filter.Factory;
                        // Never set element.project to curFilter.project
                        // since we retrieve elmenets from different projects!
                    }

                    parser.Parse( item.Form, item.Cast, item.Element );
                }
            }

            var formSvc = new ProjectManager();
            var filter2 = new BedFilter( filter ) { Location = "" };
            var productionFormStdData = formSvc.LoadProductionFormStd( filter2 );

            // Load strands
            LoadCastStrands( tmList, filter );
            LoadFormStrands( productionFormStdData.Forms, filter );

            return new CastData( tmList, productionFormStdData );
        }
Exemplo n.º 2
0
        /// <summary>
        /// Returns a set of casts with element information 
        /// </summary>
        /// <param name="filter">curFilter</param>
        /// <param name="reportFilter"> </param>
        /// <returns></returns>
        public CastScheduleData LoadCastSchedule( BedFilter filter, ReportFilter reportFilter )
        {
            if( filter == null || string.IsNullOrEmpty( filter.Factory ) || string.IsNullOrEmpty( filter.Project ) )
            {
                return null;
            }

            var query = new ImpactQuery()
            {
                Select =
				{
					ImpProductionCast.CastId,
					ImpProductionCast.Description,
					ImpProductionCast.StartDate,
					ImpProductionCast.EndDate,
					ImpProductionCast.Tolerance,
					ImpProductionCast.ElementType,
					ImpProductionCast.Style,
					ImpProductionCast.Strandptn,
					ImpProductionCast.CastStatus,
                    ImpProductionCast.CastType,
					ImpProductionCast.Form,
					ImpProductionCast.Shift,

                    Aggregate.Count( ImpProductionCastStrand.StrandPos ),

					ImpProductionFormStd.Location,
                    ImpProductionFormStd.FormType,
					ImpProductionFormStd.MaxLength,
					ImpProductionFormStd.MaxWidth,
					ImpProductionFormStd.MaxHeight,
                    ImpProductionFormStd.ElementType,

					ImpModelPlanning.ElementId,
					ImpModelGeometry.ElementMark,

                    ImpModelGeometry.Building,
                    ImpModelGeometry.FloorId,
                    ImpModelGeometry.Phase,

					ImpModelPlanning.ErectionSequenceNo,
					ImpModelPlanning.TransportId,

					ImpModelPlanning.BedSequenceNo,
					ImpModelPlanning.BedX,
					ImpModelPlanning.BedY,
					ImpModelPlanning.BedZ,
					ImpModelPlanning.BedRotation,
                    ImpModelPlanning.ElementIdStatus,

                    ImpModelPlanning.ProductionDate,
                    ImpModelPlanning.PlannedProductionDate,

                    ImpElement.ElementLength,
					ImpElement.ElementWidth,
					ImpElement.ElementHeight,
					ImpElement.ElementType,
					ImpElement.GrossArea,
					ImpElement.NetArea,
					ImpElement.Volume,
					ImpElement.Product,
					ImpElement.Project,
					ImpElement.AngleLeftSide,
					ImpElement.AngleRightSide,
                    ImpElement.Mass,

					ImpElement.Style,
					ImpElement.Strandptn,
					ImpElement.NbrOfStrands,
				},

                From = { ImpProductionCast.As( "CST" ) },

                Join =
				{
					Join.Left( ImpProductionCastStrand.As( "STA" ),	
						ImpProductionCast.Factory.Equal( ImpProductionCastStrand.Factory ),
						ImpProductionCast.Project.Equal( ImpProductionCastStrand.Project ),//Factory, Factory
						ImpProductionCast.CastId.Equal( ImpProductionCastStrand.CastId ) ),

					Join.Left( ImpProductionFormStd.As( "FRM" ),	
						ImpProductionCast.Factory.Equal( ImpProductionFormStd.Factory ),
						ImpProductionCast.Project.Equal( ImpProductionFormStd.Project ),// Factory, Factory for productionCast & ProductionCastStrand
						ImpProductionCast.Form.Equal( ImpProductionFormStd.Name ) ),

					Join.Left( ImpModelPlanning.As( "MPL" ),	
						ImpProductionCast.Factory.Equal( ImpModelPlanning.Factory ),
						ImpProductionCast.Project.Equal( ImpModelPlanning.Factory ),// Factory, Factory for productionCast & ProductionCastStrand
						ImpProductionCast.CastId.Equal( ImpModelPlanning.CastId ) ),


					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 = {
							ImpProductionCast.Factory.Equal( filter.Factory ), 
							ImpProductionCast.Project.Equal( filter.Factory ), // Factory, Factory for productionCast & ProductionCastStrand
                            //ImpModelPlanning.CastId.GreaterThan( 0 ), 
						},
                GroupBy = 
                {
					ImpProductionCast.CastId,
					ImpProductionCast.Description,
					ImpProductionCast.StartDate,
					ImpProductionCast.EndDate,
					ImpProductionCast.Tolerance,
					ImpProductionCast.ElementType,
					ImpProductionCast.Style,
					ImpProductionCast.Strandptn,
					ImpProductionCast.CastStatus,
                    ImpProductionCast.CastType,
					ImpProductionCast.Form,
					ImpProductionCast.Shift,

					ImpProductionFormStd.Location,
                    ImpProductionFormStd.FormType,
					ImpProductionFormStd.MaxLength,
					ImpProductionFormStd.MaxWidth,
					ImpProductionFormStd.MaxHeight,
                    ImpProductionFormStd.ElementType,

					ImpModelPlanning.ElementId,
					ImpModelGeometry.ElementMark,

                    ImpModelGeometry.Building,
                    ImpModelGeometry.FloorId,
                    ImpModelGeometry.Phase,

					ImpModelPlanning.ErectionSequenceNo,
					ImpModelPlanning.TransportId,

					ImpModelPlanning.BedSequenceNo,
					ImpModelPlanning.BedX,
					ImpModelPlanning.BedY,
					ImpModelPlanning.BedZ,
					ImpModelPlanning.BedRotation,
                    ImpModelPlanning.ElementIdStatus,

                    ImpModelPlanning.ProductionDate,
                    ImpModelPlanning.PlannedProductionDate,

					ImpElement.ElementLength,
					ImpElement.ElementWidth,
					ImpElement.ElementHeight,
					ImpElement.ElementType,
					ImpElement.GrossArea,
					ImpElement.NetArea,
					ImpElement.Volume,
					ImpElement.Product,
					ImpElement.Project,
					ImpElement.AngleLeftSide,
					ImpElement.AngleRightSide,
                    ImpElement.Mass,

					ImpElement.Style,
					ImpElement.Strandptn,
					ImpElement.NbrOfStrands,
                },

                OrderBy = 
				{ 
					{ ImpElement.Project },
					{ ImpProductionCast.StartDate, OrderBy.Descending },
					{ ImpProductionCast.CastId },
				},
            };

            var whereStatus = WhereGroup.Or( new Where[] { } );

            if( filter.NoStatus )
            {
                whereStatus.Add( ImpProductionCast.CastStatus.Equal( CastStatus.NoStatus ) );
            }
            if( filter.Planned )
            {
                whereStatus.Add( ImpProductionCast.CastStatus.Equal( CastStatus.Planned ) );
            }
            if( filter.Produced )
            {
                whereStatus.Add( ImpProductionCast.CastStatus.Equal( CastStatus.Produced ) );
            }

            if( whereStatus.Count > 0 )
            {
               query.Where.Add( whereStatus );
            }

            if( filter.UseStartDateFrom )
            {
                query.Where.Add( ImpProductionCast.StartDate.GreaterThanOrEqual( filter.StartDateFrom ) );
            }
            if( filter.UseStartDateTo )
            {
                query.Where.Add( ImpProductionCast.StartDate.LessThanOrEqual( filter.StartDateTo ) );
            }
            if( filter.UseEndDateFrom )
            {
                query.Where.Add( ImpProductionCast.EndDate.GreaterThanOrEqual( filter.EndDateFrom ) );
            }
            if( filter.UseEndDateTo )
            {
                query.Where.Add( ImpProductionCast.EndDate.LessThanOrEqual( filter.EndDateTo ) );
            }

            if( filter.Shift != 0 )
            {
                query.Where.Add( ImpProductionCast.Shift.Equal( filter.Shift ) );
            }
            if( !string.IsNullOrEmpty(filter.Location) && !filter.Location.Equals( Filter.All ) )
            {
                query.Where.Add( ImpProductionFormStd.Location.Equal( filter.Location ) );
            }
            if( !filter.Bed.Equals( Filter.All ) )
            {
                query.Where.Add( ImpProductionCast.Form.Equal( filter.Bed ) );
            }
            if( !string.IsNullOrEmpty( filter.CastId ) )
            {
                query.Where.Add( ImpProductionCast.CastId.Like( filter.CastId ) );
            }

            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( ImpProductionCast.CastId.Between( range.From, range.To ) );
                    }
                }

                if( list.Count > 0 )
                {
                    query.Where.Add( WhereGroup.Or( list.ToArray() ) );
                }
            }

            var statement = query.ToString();

            var tmList = new List<RecProductionCast>();
            var parser = new CastParser( tmList );

            using( var database = new ImpactDatabase() )
            {
                var list = database.GetAll( statement, ParseSchedule );

                foreach( var item in list )
                {
                    item.Form.Factory = filter.Factory;
                    item.Cast.Factory = filter.Factory;

                    item.Form.Project = filter.Project;
                    item.Cast.Project = filter.Project;

                    if( null != item.Element )
                    {
                        item.Element.Factory = filter.Factory;
                        // Never set element.project to curFilter.project
                        // since we retrieve elmenets from different projects!                    
                    }

                    parser.Parse( item.Form, item.Cast, item.Element );
                }
            }

            // Now load all the existing forms
            var formSvc = new ProjectManager();
            var productionFormStdData = formSvc.LoadProductionFormStd( new BedFilter( filter ) { Location = Filter.All } );
            return new CastScheduleData( tmList, productionFormStdData );
        }