/// <summary> 
		/// Load all records of the same factory and project as the supplied record. 
		/// </summary>
		/// <param name="record">A record with factory and project set.</param>
		/// <returns>A list of all mathcing records.</returns>
		public List<RecProductionCastStrand> LoadProductionCastStrand( RecProductionCastStrand record )
		{
			ImpactQuery query = new ImpactQuery()
			{
				Select =
				{
					ImpProductionCastStrand.Factory,
					ImpProductionCastStrand.Project,
					ImpProductionCastStrand.CastId,
					ImpProductionCastStrand.StrandPos,
					ImpProductionCastStrand.StrandX,
					ImpProductionCastStrand.StrandY,
					ImpProductionCastStrand.StrandQuality,
					ImpProductionCastStrand.StrandDimension,
					ImpProductionCastStrand.StrandPrestressing,

				},
				From  = { ImpProductionCastStrand.As( "T1" ) },
				Where = { ImpProductionCastStrand.Factory.Equal( record.Factory ), 
                          ImpProductionCastStrand.Project.Equal( record.Factory ),// Factory, Factory for productionCast & ProductionCastStrand
                          ImpProductionCastStrand.CastId.Equal( record.CastId )}
			};

			string statement = query.ToString();

			List<RecProductionCastStrand> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseProductionCastStrand );
			}

			return result;
		}
		/// <summary>
		/// Load of Transport Vehicle Standard items 
		/// </summary>
		/// <param name="vehicle"></param>
		/// <returns></returns>
		public List<RecTransportVehicleStd> LoadTransportVehicleStd( RecTransportVehicleStd record )
		{
			if( record  == null )
			{
				throw new ArgumentNullException( "TransportVehicleStd" );
			}
			ImpactQuery query = new ImpactQuery()
			{
				Select =
				{
					ImpTransportVehicleStd.Factory,
					ImpTransportVehicleStd.Project, 
					ImpTransportVehicleStd.Name, 

					ImpTransportVehicleStd.Division, 
					ImpTransportVehicleStd.Description, 
					ImpTransportVehicleStd.VehicleType, 
					ImpTransportVehicleStd.TransportType, 

					ImpTransportVehicleStd.Length, 
					ImpTransportVehicleStd.Width, 
					ImpTransportVehicleStd.Height, 
					ImpTransportVehicleStd.Mass,

					ImpTransportVehicleStd.MaxLength, 
					ImpTransportVehicleStd.MaxWidth, 
					ImpTransportVehicleStd.MaxHeight, 
					ImpTransportVehicleStd.MaxMass, 

					ImpTransportVehicleStd.CreatedBy, 
					ImpTransportVehicleStd.CreatedDate, 
					ImpTransportVehicleStd.ChangedBy, 
					ImpTransportVehicleStd.ChangedDate, 
				},
				From = { ImpTransportVehicleStd.As( "T1" ) },
				Where = { ImpTransportVehicleStd.Factory.Equal( record.Factory ), 
						  ImpTransportVehicleStd.Project.Equal( record.Factory ),//for Std use Factory, Factory
						  },
				OrderBy = {ImpTransportVehicleStd.Name}
			};

			string statement = query.ToString();

			List<RecTransportVehicleStd> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseTransportVehicleStd );
			}

			return result;
		}
		/// <summary>
		/// Load all records of the same factory and project as the supplied record.
		/// </summary>
		/// <param name="record">A record with factory and project set.</param>
		/// <returns>A list of all mathcing records.</returns>
		public List<RecTransportStack> LoadTransportStack( RecTransportStack record )
		{
			ImpactQuery query = new ImpactQuery()
			{
				Select =
				{
					ImpTransportStack.Factory,
					ImpTransportStack.Project,
					ImpTransportStack.TransportId,
					ImpTransportStack.VehicleId,
					ImpTransportStack.StackId,
					ImpTransportStack.Rack,
					ImpTransportStack.StackX,
					ImpTransportStack.StackY,
					ImpTransportStack.StackZ,
					ImpTransportStack.StackRotation,
					ImpTransportStack.Description,
					ImpTransportStack.StackType,
					ImpTransportStack.StackPosition,
					ImpTransportStack.MaxLength,
					ImpTransportStack.MaxWidth,
					ImpTransportStack.MaxHeight,
					ImpTransportStack.MaxMass,

				},
				From = { ImpTransportStack.As( "T1" ) },
				Where = { ImpTransportStack.Factory.Equal( record.Factory ), 
						  ImpTransportStack.Project.Equal( record.Project ), 
						  ImpTransportStack.TransportId.Equal( record.TransportId ), 
						  ImpTransportStack.VehicleId.Equal( record.VehicleId ) 
						}
			};
			
			if( record.StackId > 0 )
			{
				query.Where.Add( ImpTransportStack.StackId.Equal( record.StackId ) );
			}

			string statement = query.ToString();

			List<RecTransportStack> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseTransportStack );
			}

			return result;
		}
        /// <summary> 
		/// Load all records of the same factory and project as the supplied record.
		/// </summary>
		/// <param name="record">A record with factory and project set.</param>
		/// <returns>A list of all mathcing records.</returns>
		public List<RecProductionFormStrandStd> LoadProductionFormStrandStd( RecProductionFormStrandStd record )
		{
			ImpactQuery query = new ImpactQuery()
			{
				Select = 
				{
					ImpProductionFormStrandStd.Factory,
					ImpProductionFormStrandStd.Project,
					ImpProductionFormStrandStd.Name,
					ImpProductionFormStrandStd.StrandPos,
					ImpProductionFormStrandStd.StrandX,
					ImpProductionFormStrandStd.StrandY,
					ImpProductionFormStrandStd.StrandQuality,
					ImpProductionFormStrandStd.StrandDimension,
					ImpProductionFormStrandStd.StrandPrestressing,
                    ImpProductionFormStrand.Form,

				},
				From = { ImpProductionFormStrandStd.As( "T1" ) },
                Join =
				{
					Join.Left( ImpProductionFormStrand.As( "T2" ),	
						ImpProductionFormStrand.Factory.Equal( ImpProductionFormStrandStd.Factory ),
						ImpProductionFormStrand.Project.Equal( ImpProductionFormStrandStd.Project ),//Factory, Factory
						ImpProductionFormStrand.Form.Equal( ImpProductionFormStrandStd.Name ),
                        ImpProductionFormStrand.Strand.Equal( ImpProductionFormStrandStd.StrandPos )),
                },

				Where = { ImpProductionFormStrandStd.Factory.Equal( record.Factory ), 
						  ImpProductionFormStrandStd.Project.Equal( record.Factory ), 
						  ImpProductionFormStrandStd.Name.Equal( record.Name )} //Form name
			};

			string statement = query.ToString();

			List<RecProductionFormStrandStd> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseProductionFormStrandStd );
			}

			return result;
		}
Example #5
0
        /// <summary>
        /// Load all records of the same factory and project as the supplied record.
        /// </summary>
        /// <param name="record">A record with factory and project set.</param>
        /// <returns>A list of all mathcing records.</returns>
        public List<RecCalendar> LoadCalendar(RecCalendar record)
        {
            ImpactQuery query = new ImpactQuery()
            {
                Select =
				{
					ImpCalendar.Factory,
					ImpCalendar.Project,
					ImpCalendar.Name,
					ImpCalendar.Description,
					ImpCalendar.CreatedBy,
					ImpCalendar.CreatedDate,
					ImpCalendar.ChangedBy,
					ImpCalendar.ChangedDate,

				},
                From = { ImpCalendar.As("T1") },
                Where = { ImpCalendar.Factory.Equal(record.Factory), ImpCalendar.Project.Equal(record.Factory) }
            };

            string statement = query.ToString();

            List<RecCalendar> result;

            using (ImpactDatabase database = new ImpactDatabase())
            {
                result = database.GetAll( statement, ParseCalendar );
            }

            if (null != result)
            {
                foreach (RecCalendar recCalendar in result)
                {
                    recCalendar.WorkDays = LoadWorkDays(recCalendar );
                    recCalendar.InvalidDays = LoadInvalidDays(recCalendar);

                }
            }
            return result;
        }
		/// <summary> 
		/// Load all records of the same factory and project as the supplied record.
		/// </summary>
		/// <param name="record">A record with factory and project set.</param>
		/// <returns>A list of all mathcing records.</returns>
		public List<RecTransportVehicleStackStd> LoadTransportVehicleStackStd( RecTransportVehicleStackStd record )
		{
			ImpactQuery query = new ImpactQuery()
			{
				Select =
				{
					ImpTransportVehicleStackStd.Name,
					ImpTransportVehicleStackStd.StackId,
					ImpTransportVehicleStackStd.Rack,
					ImpTransportVehicleStackStd.StackPosition,
					ImpTransportVehicleStackStd.StackX,
					ImpTransportVehicleStackStd.StackY,
					ImpTransportVehicleStackStd.StackZ,
					ImpTransportVehicleStackStd.StackRotation,
					ImpTransportVehicleStackStd.Description,
					ImpTransportVehicleStackStd.StackType,
					ImpTransportVehicleStackStd.MaxLength,
					ImpTransportVehicleStackStd.MaxWidth,
					ImpTransportVehicleStackStd.MaxHeight,
					ImpTransportVehicleStackStd.MaxMass
				},
				From = { ImpTransportVehicleStackStd.As( "T1" ) },
				Where = { ImpTransportVehicleStackStd.Factory.Equal( record.Factory ), 
						  ImpTransportVehicleStackStd.Project.Equal( record.Factory ),//for Std use Factory, Factory
						  ImpTransportVehicleStackStd.Name.Equal( record.Name )}
			};

			string statement = query.ToString();

			List<RecTransportVehicleStackStd> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseTransportVehicleStackStd );
			}

			return result;
		}
		}//end generate
		/// <summary>
		/// Returns the next sequence from the number generator object
		/// </summary>
		/// <param name="rec"></param>
		/// <param name="next"></param>
		private void SetNextNumber( RecNumberGenerator rec, int next )
		{
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				ImpactUpdate update = new ImpactUpdate( ImpNumGen.Instance )
				{
					Columns =
					{
						{ ImpNumGen.NextNumber, next },
						{ ImpNumGen.ChangedDate, DateTime.Now }
					},
					Where =
					{
						ImpNumGen.Factory.Equal( rec.Factory ),
						ImpNumGen.Project.Equal( rec.Project ),
						ImpNumGen.Variable.Equal( rec.Variable ),
					}
				};

				string statement = update.ToString();

				database.ExecuteNonQuery( statement );
			}
		}
		/// <summary>
		/// Update the specified record in the database.
		/// </summary>
		/// <param name="record">The record to update.</param>
		/// <returns></returns>
		public int UpdateSectionStyleStd( RecSectionStyleStd record )
		{

			var update = new ImpactUpdate( ImpSectionStyleStd.Instance )
			{
				Columns = 
				{
					{ ImpSectionStyleStd.SectionType, record.SectionType },
					{ ImpSectionStyleStd.Description, record.Description },
					{ ImpSectionStyleStd.Width, record.Width },
					{ ImpSectionStyleStd.WidthTolerance, record.WidthTolerance },
					{ ImpSectionStyleStd.DiffBottomTop, record.DiffBottomTop },
					{ ImpSectionStyleStd.Height, record.Height },
					{ ImpSectionStyleStd.Endcap, record.Endcap },
					{ ImpSectionStyleStd.Strandptn, record.Strandptn },
					{ ImpSectionStyleStd.RcTemplate, record.RcTemplate },
					{ ImpSectionStyleStd.Material, record.Material },
					{ ImpSectionStyleStd.ProductionLine, record.ProductionLine },
					{ ImpSectionStyleStd.CutType, record.CutType },
					{ ImpSectionStyleStd.UseCutZone, record.UseCutZone },
					{ ImpSectionStyleStd.LiftMethod, record.LiftMethod },
					{ ImpSectionStyleStd.LiftRotation1, record.LiftRotation1 },
					{ ImpSectionStyleStd.LiftRotation2, record.LiftRotation2 },
					{ ImpSectionStyleStd.LiftPlacingLs, record.LiftPlacingLs },
					{ ImpSectionStyleStd.LiftParameterLs, record.LiftParameterLs },
					{ ImpSectionStyleStd.LiftPlacingSs, record.LiftPlacingSs },
					{ ImpSectionStyleStd.LiftParameterSs, record.LiftParameterSs },
					{ ImpSectionStyleStd.LiftCores, record.LiftCores },
					{ ImpSectionStyleStd.LiftCoreLength, record.LiftCoreLength },
					{ ImpSectionStyleStd.LiftCoreDisplayMode, record.LiftCoreDisplayMode },
					{ ImpSectionStyleStd.LiftDistanceMax, record.LiftDistanceMax },
					{ ImpSectionStyleStd.LiftDistanceMin, record.LiftDistanceMin },
					{ ImpSectionStyleStd.LiftSpacing, record.LiftSpacing },
					{ ImpSectionStyleStd.LiftType, record.LiftType },
					{ ImpSectionStyleStd.SectionViewDimStrandGrp, record.SectionViewDimStrandGrp },
					{ ImpSectionStyleStd.SectionViewTxtStrandGrp, record.SectionViewTxtStrandGrp },
					{ ImpSectionStyleStd.SectionViewNbrCores, record.SectionViewNbrCores },
					{ ImpSectionStyleStd.SectionViewScale, record.SectionViewScale },
					{ ImpSectionStyleStd.UseSectionViewSymbol, record.UseSectionViewSymbol },
					{ ImpSectionStyleStd.SectionViewFilename, record.SectionViewFilename },
					{ ImpSectionStyleStd.ChamferDistance, record.ChamferDistance },
					{ ImpSectionStyleStd.ChamferText, record.ChamferText },
					{ ImpSectionStyleStd.ChamferVisibility, record.ChamferVisibility },
					{ ImpSectionStyleStd.RcCoverCut1, record.RcCoverCut1 },
					{ ImpSectionStyleStd.RcCoverCut2, record.RcCoverCut2 },
					{ ImpSectionStyleStd.ElementGrp, record.ElementGrp },
					{ ImpSectionStyleStd.ProductPrefix, record.ProductPrefix },
					{ ImpSectionStyleStd.Product, record.Product },
					{ ImpSectionStyleStd.ElementMarkPrefix, record.ElementMarkPrefix },
					{ ImpSectionStyleStd.DrawingNamePrefix, record.DrawingNamePrefix },
					{ ImpSectionStyleStd.DrawingType, record.DrawingType },
					{ ImpSectionStyleStd.DrawingTemplate, record.DrawingTemplate },
					{ ImpSectionStyleStd.CreatedBy, record.CreatedBy },
					{ ImpSectionStyleStd.CreatedDate, record.CreatedDate },
					{ ImpSectionStyleStd.ChangedBy, record.ChangedBy },
					{ ImpSectionStyleStd.ChangedDate, record.ChangedDate },
					{ ImpSectionStyleStd.LiftHolePosition, record.LiftHolePosition },
				},
				Where = 
				{
					{ ImpSectionStyleStd.Factory.Equal( record.Factory ) },
					{ ImpSectionStyleStd.Project.Equal( record.Project ) },
					{ ImpSectionStyleStd.ElementType.Equal( record.ElementType ) },
					{ ImpSectionStyleStd.Name.Equal( record.Name ) },
				},
			};

			string statement = update.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return result;
		}
		/// <summary>
		/// Delete the specified record from the database.
		/// </summary>
		/// <param name="record">The record to delete from the database.</param>
		/// <returns>The number of affected records.</returns>
		public int DeleteSectionStyleStd( RecSectionStyleStd record )
		{
			var delete = new ImpactDelete( ImpSectionStyleStd.Instance )
			{
				Where = 
				{
					{ ImpSectionStyleStd.Factory.Equal( record.Factory )},
					{ ImpSectionStyleStd.Project.Equal( record.Project )},
					{ ImpSectionStyleStd.ElementType.Equal( record.ElementType )},
					{ ImpSectionStyleStd.Name.Equal( record.Name )},
				}
			};

			string statement = delete.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return result;
		}
	    /// <summary> 
	    /// Load the strands of the given pattern.
	    /// </summary>
	    /// <param name="factory"> </param>
	    /// <param name="project"> </param>
	    /// <param name="elementType"> </param>
	    /// <param name="style"> </param>
	    /// <param name="strandpattern"> </param>
	    /// <returns>A list of all mathcing records.</returns>
	    public List<RecProductionCastStrand> LoadStrands(  string factory, string project, string elementType, string style, string strandpattern )
		{
			// Add, Factory, Factory and Company, Company
			var company = factory.Substring( 0, 2 ) + "00"; //Is this really OK ??!!
            
            var where1 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( factory ), ImpSectionStyleStd.Project.Equal( project ) );
            var where2 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( factory ), ImpSectionStyleStd.Project.Equal( factory ) );
            var where3 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( company ), ImpSectionStyleStd.Project.Equal( company ) );

            var orProjectFactoryCompany = WhereGroup.Or( where1, where2, where3 );

			var query = new ImpactQuery()
			{
				Select =
				{
					ImpSectionStyleStd.Factory,
					ImpSectionStyleStd.Project,
                    ImpSectionStyleStd.Name,
                    ImpSectionStrandptnStd.Name,
					ImpSectionStrandPosStd.StrandPos,
					ImpSectionStrandPosStd.StrandX,
					ImpSectionStrandPosStd.StrandY,
					ImpSectionStrandptnGrpStd.StrandDimension,
                    ImpSectionStrandptnGrpStd.StrandPrestressing,
                    ImpSectionStrandptnGrpStd.StrandQuality,
				},
				From = { ImpSectionStyleStd.As( "T1" ) },
                Join =
				{
					Join.Left( ImpSectionStrandptnStd.As( "T2" ),	
						ImpSectionStrandptnStd.Factory.Equal( ImpSectionStyleStd.Factory ),
						ImpSectionStrandptnStd.Project.Equal( ImpSectionStyleStd.Project ),
						ImpSectionStrandptnStd.ElementType.Equal( ImpSectionStyleStd.ElementType ), 
						ImpSectionStrandptnStd.Section.Equal( ImpSectionStyleStd.Name )),

					Join.Left( ImpSectionStrandptnPosStd.As( "T3" ),	
						ImpSectionStrandptnPosStd.Factory.Equal( ImpSectionStrandptnStd.Factory ),
						ImpSectionStrandptnPosStd.Project.Equal( ImpSectionStrandptnStd.Project ),
						ImpSectionStrandptnPosStd.ElementType.Equal( ImpSectionStrandptnStd.ElementType ), 
						ImpSectionStrandptnPosStd.Section.Equal( ImpSectionStrandptnStd.Section ),
                        ImpSectionStrandptnPosStd.Strandptn.Equal( ImpSectionStrandptnStd.Name )),

					Join.Left( ImpSectionStrandPosStd.As( "T4" ),	
						ImpSectionStrandPosStd.Factory.Equal( ImpSectionStrandptnPosStd.Factory ),
						ImpSectionStrandPosStd.Project.Equal( ImpSectionStrandptnPosStd.Project ),
						ImpSectionStrandPosStd.ElementType.Equal( ImpSectionStrandptnPosStd.ElementType ), 
						ImpSectionStrandPosStd.Section.Equal( ImpSectionStrandptnPosStd.Section ),
                        ImpSectionStrandPosStd.StrandPos.Equal( ImpSectionStrandptnPosStd.StrandPos )),

					Join.Left( ImpSectionStrandptnGrpStd.As( "T5" ),	
						ImpSectionStrandptnGrpStd.Factory.Equal( ImpSectionStrandPosStd.Factory ),
						ImpSectionStrandptnGrpStd.Project.Equal( ImpSectionStrandPosStd.Project ),
						ImpSectionStrandptnGrpStd.ElementType.Equal( ImpSectionStrandPosStd.ElementType ), 
                        ImpSectionStrandptnGrpStd.Section.Equal( ImpSectionStrandPosStd.Section ),
						ImpSectionStrandptnGrpStd.Strandptn.Equal( ImpSectionStrandptnPosStd.Strandptn ),
                        ImpSectionStrandptnGrpStd.StrandGrp.Equal( ImpSectionStrandPosStd.StrandGrp )),
				},

				Where =
				    {
				        ImpSectionStyleStd.ElementType.Equal( elementType ), 
                        ImpSectionStyleStd.Name.Equal( style ), 
                        ImpSectionStrandptnPosStd.Strandptn.Equal( strandpattern ),
                        orProjectFactoryCompany
				    },
			};

			var statement = query.ToString();
           
			List<RecProductionCastStrand> result;

			using( var database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, column => new RecProductionCastStrand()
				                {
				                    Factory = column[0].Cast<string>(),
				                    Project = column[1].Cast<string>(),
				                    Style = column[2].Cast<string>(),
				                    Strandpattern = column[3].Cast<string>(),
                                    StrandPos = column[4].Cast<int>(),
                                    StrandX = column[5].Cast<double>(),
                                    StrandY = column[6].Cast<double>(),
                                    StrandDimension = column[7].Cast<double>(),
                                    StrandPrestressing = column[8].Cast<double>(),
                                    StrandQuality = column[9].Cast<string>(),

				                } );
			}

			if( result == null || result.Count == 0 )
			{
				return result;
			}

	        var strands = ( from o in result where ( o.Factory == factory && o.Project == project ) select o ).ToList();
            if( strands.Count > 0 )
            {
                return strands;
            }

            strands = ( from o in result where ( o.Factory == factory && o.Project == factory ) select o ).ToList();
            if( strands.Count > 0 )
            {
                return strands;
            }

            return ( from o in result where ( o.Factory == company && o.Project == company ) select o ).ToList();
		}
		/// <summary> 
		/// Load all records of the same factory and project as the supplied record.
		/// </summary>
		/// <param name="record">A record with factory and project set.</param>
		/// <returns>A list of all mathcing records.</returns>
		public List<RecSectionStyleStd> LoadSqlServer( RecSectionStyleStd record )
		{
			if( record == null || record.Factory == null )
			{
				return null;
			}
			string company = record.Factory.Substring( 0, 2 ) + "00"; //Is this really OK ??!!

			WhereGroup wgElementType = WhereGroup.Or( ImpSectionStyleStd.ElementType.Equal( "HD/F" ),
													  ImpSectionStyleStd.ElementType.Equal( "D/F" ));

			// Prepare Factory, Project statement
			ImpactQuery projectQuery = new ImpactQuery()
			{
				Select = {
					        ImpSectionStyleStd.Factory,
					        ImpSectionStyleStd.Project,
					        ImpSectionStyleStd.ElementType,
					        ImpSectionStyleStd.Name,
					        ImpSectionStyleStd.SectionType,
					        ImpSectionStyleStd.Description,
				        },
				From = { ImpSectionStyleStd.As( "T1" ) },
				Where = {
                            ImpSectionStyleStd.Factory.Equal( record.Factory ),
					        ImpSectionStyleStd.Project.Equal( record.Project ),
							wgElementType },
			};
			string projectStatement = projectQuery.ToString();

			// Prepare Factory, Factory statement
			ImpactQuery factoryQuery = new ImpactQuery()
			{
				Select = {
					        ImpSectionStyleStd.Factory,
					        ImpSectionStyleStd.Project,
					        ImpSectionStyleStd.ElementType,
					        ImpSectionStyleStd.Name,
					        ImpSectionStyleStd.SectionType,
					        ImpSectionStyleStd.Description,
				        },
				From = { ImpSectionStyleStd.As( "T1" ) },
				Where = {
                            ImpSectionStyleStd.Factory.Equal( record.Factory ),
					        ImpSectionStyleStd.Project.Equal( record.Factory ),
							wgElementType 
                        },
			};
			string factoryStatement = factoryQuery.ToString();
			ImpactQuery projectSubquery = new ImpactQuery {
				Select = { ImpSectionStyleStd.Name },
				From = { ImpSectionStyleStd.As( "T1" ) },
				Where = {
                            ImpSectionStyleStd.Factory.Equal( record.Factory ),
					        ImpSectionStyleStd.Project.Equal( record.Project ),
							wgElementType 
                        },
			};
			factoryStatement += " AND T1.Name Not In (" + projectSubquery.ToString() + ")";

			// Prepare Company, Company statement
			ImpactQuery companyQuery = new ImpactQuery()
			{
				Select = {
					        ImpSectionStyleStd.Factory,
					        ImpSectionStyleStd.Project,
					        ImpSectionStyleStd.ElementType,
					        ImpSectionStyleStd.Name,
					        ImpSectionStyleStd.SectionType,
					        ImpSectionStyleStd.Description,
				        },
				From = { ImpSectionStyleStd.As( "T1" ) },
				Where = {
                            ImpSectionStyleStd.Factory.Equal( company ),
					        ImpSectionStyleStd.Project.Equal( company ),
							wgElementType },
			};
			string companyStatement = companyQuery.ToString();
			ImpactQuery factorySubquery = new ImpactQuery()
			{
				Select = { ImpSectionStyleStd.Name },
				From = { ImpSectionStyleStd.As( "T1" ) },
				Where = {
                            ImpSectionStyleStd.Factory.Equal( record.Factory ),
					        ImpSectionStyleStd.Project.Equal( record.Factory ),
							wgElementType },
			};
			companyStatement += " AND T1.Name Not In (" + projectSubquery.ToString() + ")"
							 + " AND T1.Name Not In (" + factorySubquery.ToString() + ")";
			string statement = projectStatement + " Union " + factoryStatement + " Union " + companyStatement + " Order By T1.ELEMENT_TYPE, T1.Name";

			List<RecSectionStyleStd> result;
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseSectionStyleStd );
			}
			return result;
		}
Example #12
0
		/// <summary>
		/// Load data, returns transport templates only
		/// </summary>
		/// <param name="transport"></param>
		/// <returns></returns>
		public List<RecTransport> LoadTransport( RecTransport record )
		{
			if( record == null )
			{
				throw new ArgumentNullException( "Transport" );
			}
			string project = "";
			if( record.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = record.Factory;
			}
			else
			{
				project = record.Project;
			}
			ImpactQuery query = new ImpactQuery()
			{
				Select =
				{
					ImpTransport.TransportId,
					ImpTransport.Description,
					ImpTransport.LoadLocation,
					ImpTransport.LoadDate,
					ImpTransport.DeliveryDate,
					ImpTransport.TimeInterval,
					ImpTransport.LoadDivision,
					ImpTransport.DeliveryDivision,
					ImpTransport.IsTemplate,
					ImpTransport.TemplateId,
					ImpTransport.IsVisible,
					ImpTransport.TransportStatus
				},
				From = { ImpTransport.As( "T1" ) },
				Where = { ImpTransport.Factory.Equal( record.Factory ), 
						  ImpTransport.Project.Equal( project ), // Templates are saved on factory level (factory, factory), 2012-04-23
						  ImpTransport.IsTemplate.Equal( record.IsTemplate )},
				//OrderBy = { 
				//            {ImpTransport.TransportId, OrderBy.Descending} // gives Asc !! to be corrected
				//          }
			};

			string statement = query.ToString();
			statement += " ORDER BY T1.TRANSPORT_ID DESC";

			List<RecTransport> result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, column =>
				{
					return new RecTransport()
					{
						Factory = record.Factory,
						Project = record.Project,

						TransportId = DataConverter.Cast<int>( column[0] ),
						Description = DataConverter.Cast<string>( column[1] ),
						LoadLocation = DataConverter.Cast<string>( column[2] ),
						LoadDate = DataConverter.Cast<DateTime>( column[3] ),
						DeliveryDate = DataConverter.Cast<DateTime>( column[4] ),
						TimeInterval = DataConverter.Cast<int>( column[5] ),
						LoadDivision = DataConverter.Cast<string>( column[6] ),
						DeliveryDivision = DataConverter.Cast<string>( column[7] ),
						IsTemplate = DataConverter.Cast<int>( column[8] ),
						TemplateId = DataConverter.Cast<int>( column[9] ),
						IsVisible = DataConverter.Cast<int>( column[10] ),
						TransportStatus = DataConverter.Cast<int>( column[11] ),
					};
				} );
			}

			return result;
		}
Example #13
0
		/// <summary>
		/// Returns max value of transport_id
		/// </summary>
		/// <param name="transport"></param>
		/// <returns></returns>
		public int GetMaxTransportId( RecTransport record )
		{
			if( record == null )
			{
				throw new ArgumentNullException( "Transport" );
			}
			int ret = 0;
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				ImpactQuery query = new ImpactQuery()
				{
					Select =
					{
						 Aggregate.Max(ImpTransport.TransportId)
					},
					From = { ImpTransport.As( "T1" ) },
					Where = { ImpTransport.Factory.Equal( record.Factory ), 
							  ImpTransport.Project.Equal( record.Project ),
							  ImpTransport.TransportId.GreaterThan( 0 )},
				};
				string statement = query.ToString();
				List<int> result = null;
				try
				{
					result = database.GetAll( statement, column =>
					{
						return DataConverter.Cast<int?>( column[0] ) ?? 0;
					} );
					ret = result[0];
				}
				catch( Exception ) { }//Just eat it please!
			}
			return ret;
		}
        /// <summary>
        /// The load user data.
        /// </summary>
        /// <param name="user">
        /// The user.
        /// </param>
        /// <returns>
        /// The StruSoft.Impact.V120.ProjectManager.Core.ProjectBrowserData.UserData.
        /// </returns>
        public UserData LoadUserData( string user )
        {
            user = user.ToLower();

            ImpactQuery query = new ImpactQuery( true )
            {
                From = {
                          ImpUser.As( "U" ) 
                       }, 
                Select = {
                            ImpUserGroup.Company, ImpUserGroupStd.RoleId 
                         }, 
                Join =
                {
                    Join.Inner( ImpUserGroup.As( "UG" ), ImpUser.Userid.Equal( ImpUserGroup.Userid ) ), 
                    Join.Inner( ImpUserGroupStd.As( "UGS" ), ImpUserGroup.UserGroup.Equal( ImpUserGroupStd.Name ) ), 
                }, 
                Where = {
                           ImpUser.Userid.Equal( user ) 
                        }, 
            };

            string statement = query.ToString();

            UserData userData = new UserData
                                {
                UserId = user
            };

            using( var database = new ImpactDatabase() )
            {
                var groupedCompanyRoleList = database.GetAll( 
                    statement, 
                    column => new
                    {
                        Company = column[0].Cast<string>(), 
                        Role = column[1].Cast<UserRole>(), 
                    }

                ).GroupBy( x => x.Company ).ToList();

                foreach( var companyGroup in groupedCompanyRoleList )
                {
                    UserRoleData urd = new UserRoleData( companyGroup.Key, from item in companyGroup select item.Role );

                    userData.UserRoles.Add( urd );
                }
            }

            return userData;
        }
Example #15
0
		/// <summary>
		/// Delete of Transport items
		/// </summary>
		/// <param name="transport"></param>
		/// <returns></returns>
		public int DeleteCascadeTransport( RecTransport transport )
		{
			if( transport == null || transport.TransportId == 0 )
			{
				throw new ArgumentNullException( "RecTransport" );
			}
			string project = "";
			if( transport.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = transport.Factory;
			}
			else
			{
				project = transport.Project;
			}
			// Delete cascade vehicles
			ProjectManager vehSvc = new ProjectManager();
			List<RecTransportVehicleStd> vehicles = vehSvc.LoadTransportVehicles( transport );
			foreach( RecTransportVehicleStd veh in vehicles )
			{
				this.DeleteCascadeVehicleTransport( transport, veh );
			}

			int ret = 0;
			// Now let's delete the transport 
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				ImpactDelete delete = new ImpactDelete( ImpTransport.Instance )
				{
					Where = { ImpTransport.Factory.Equal( transport.Factory ), 
							  ImpTransport.Project.Equal( project ),// Templates are saved on factory level (factory, factory), 2012-04-23
							  ImpTransport.TransportId.Equal( transport.TransportId )},
				};
				string statement = delete.ToString();
				ret = database.ExecuteNonQuery( statement );
			}
			return ret;
		}
        /// <summary>
        /// Returns a new erections sequence number for the specified project, of the specified factory.
        /// </summary>
        /// <param name="factory">
        /// The factory to which the project belongs.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <returns>
        /// The next available erection sequence number.
        /// </returns>
        public int GetNewErectionSequenceNumber( string factory, string project )
        {
            project = project.PadLeft( 12 );

            ImpactQuery query = new ImpactQuery
                                {
                Select = {
                            Aggregate.Max( ImpModelPlanning.ErectionSequenceNo ) 
                         }, 
                From = {
                          ImpModelPlanning.As( "T1" ) 
                       }, 
                Where =
                {
                    ImpModelPlanning.Factory.Equal( factory ), 
                    ImpModelPlanning.Project.Equal( project ), 
                }, 
            };

            string statement = query.ToString();

            using( var database = new ImpactDatabase() )
            {
                var erectionSequenceList = database.GetAll( statement, column => column[0].Cast<int>() );

                int maxEs = 0;

                if( erectionSequenceList.Count != 0 )
                {
                    maxEs = erectionSequenceList[0];
                }

                maxEs++;

                return maxEs;
            }
        }
		/// <summary>
		/// Update the specified record in the database.
		/// </summary>
		/// <param name="record">The record to update.</param>
		/// <returns></returns>
		public int UpdateProductionFormStrandStd( RecProductionFormStrandStd record )
		{
            // Update IMP_PRODUCTION_FORM_STRAND check the flag IsUsed
            // Update IMP_PRODUCTION_FORM_STRAND_STD
		    UpdateProductionFormStrand( record );

			var update = new ImpactUpdate( ImpProductionFormStrandStd.Instance )
			{
				Columns = 
				{
					{ ImpProductionFormStrandStd.StrandX, record.StrandX },
					{ ImpProductionFormStrandStd.StrandY, record.StrandY },
					{ ImpProductionFormStrandStd.StrandQuality, record.StrandQuality },
					{ ImpProductionFormStrandStd.StrandDimension, record.StrandDimension },
					{ ImpProductionFormStrandStd.StrandPrestressing, record.StrandPrestressing },
				},
				Where = 
				{
					ImpProductionFormStrandStd.Factory.Equal( record.Factory ),
					ImpProductionFormStrandStd.Project.Equal( record.Factory ), // Factory, Factory Level
					ImpProductionFormStrandStd.Name.Equal( record.Name ),
					ImpProductionFormStrandStd.StrandPos.Equal( record.StrandPos ),
				},
			};

			string statement = update.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return result;
		}
		/// <summary>
		/// Delete the specified record from the database.
		/// </summary>
		/// <param name="record">The record to delete from the database.</param>
		/// <returns>The number of affected records.</returns>
		public int DeleteProductionFormStrandStd( RecProductionFormStrandStd record )
		{
            // Delete relation first
		    DeleteProductionFormStrand( record );

            // Now delete the record
			var delete = new ImpactDelete( ImpProductionFormStrandStd.Instance )
			{
				Where = 
				{
					{ ImpProductionFormStrandStd.Factory.Equal( record.Factory )},
					{ ImpProductionFormStrandStd.Project.Equal( record.Factory )},
					{ ImpProductionFormStrandStd.Name.Equal( record.Name )}, //Form name
				}
			};
			if( record.StrandPos > 0 )
			{
				delete.Where.Add( ImpProductionFormStrandStd.StrandPos.Equal( record.StrandPos ) );
			}
			string statement = delete.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return result;
		}
Example #19
0
        /// <summary>
        /// Load
        /// </summary>
        /// <param name="reportFilter"></param>
        /// <returns></returns>
        public DrawingReportData Load( ReportFilter reportFilter )
        {
            var data = new DrawingReportData();

            var query = new ImpactQuery()
            {
                Select =
                    {
                        ImpDrawing.Factory,
                        ImpDrawing.Project,
                        ImpDrawing.DrawingName,
                        ImpDrawing.DrawingType,
                        ImpDrawing.DesignedBy,
                        ImpDrawing.Status,
                        ImpDrawing.ApprovedDate,
                        ImpDrawing.CreatedDate,
                        ImpDrawing.Text6,
                    },
                From = { ImpDrawing.As( "T1" ) },
                Join =
                    {
                        Join.Left(
                            ImpElement.As( "T2" ),
                            ImpDrawing.Factory.Equal( ImpElement.Factory ),
                            ImpDrawing.Project.Equal( ImpElement.Project ),
                            ImpDrawing.DrawingName.Equal( ImpElement.DrawingName ) ),
                    },
                Where =
                    {
                        ImpDrawing.Factory.Equal( reportFilter.Factory ),
                        ImpDrawing.Project.Equal( reportFilter.Project ),
                    },
            };

            if( 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( ImpDrawing.DrawingName.Between( range.From, range.To ) );
                    }
                }

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

            var statement = query.ToString();

            using( var database = new ImpactDatabase() )
            {
				data.Rows = database.GetAll( statement, column => new DrawingReportRow()
				                {
				                    Factory = column[0].Cast<string>(),
				                    Project = column[1].Cast<string>(),
				                    DrawingName = column[2].Cast<string>(),
				                    DrawingType = column[3].Cast<string>(),
                                    DesignedBy = column[4].Cast<string>(),
                                    Status = column[5].Cast<string>(),
                                    ApprovedDate = column[6].Cast<DateTime?>(),
                                    CreatedDate = column[7].Cast<DateTime?>(),
                                    DrawingText6 = column[8].Cast<string>(),
				                } );
            }

            return data;

        }
        /// <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;
        }
        /// <summary>
        /// The update erection sequence.
        /// </summary>
        /// <param name="factory">
        /// The factory.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <param name="erectionSequenceList">
        /// The erection sequence list.
        /// </param>
        /// <returns>
        /// The System.Boolean.
        /// </returns>
        public bool UpdateErectionSequence( string factory, string project, List<KeyValuePair<int, int>> erectionSequenceList )
        {
            project = project.PadLeft( 12 );

            List<string> statementList = new List<string>( erectionSequenceList.Count );

            using( var database = new ImpactDatabase() )
            {
                var allIdArray = erectionSequenceList.Select( x => (object)x.Key ).ToArray();
                ImpactQuery query = new ImpactQuery
                                    {
                    Select = {
                                ImpModelPlanning.ElementId 
                             }, 
                    From = {
                              ImpModelPlanning.As( "T1" ) 
                           }, 
                    Where =
                    {
                        ImpModelPlanning.Factory.Equal( factory ), 
                        ImpModelPlanning.Project.Equal( project ), 
                        ImpModelPlanning.ElementId.In( allIdArray ), 
                    }, 
                };

                string statement = query.ToString();
                var existingPlanningList = database.GetAll( statement, column => column[0].Cast<int>() );
                var groupedByInsertUpdate = erectionSequenceList.GroupBy( x => existingPlanningList.Remove( x.Key ) ).ToList();

                var updateList = groupedByInsertUpdate.Find( x => x.Key );

                var insertList = groupedByInsertUpdate.Find( x => !x.Key );

                if( null != updateList )
                {
                    foreach( var item in updateList )
                    {
                        var update = new ImpactUpdate( ImpModelPlanning.Instance )
                        {
                            Columns = {
                                         { ImpModelPlanning.ErectionSequenceNo, item.Value } 
                                      }, 
                            Where =
                            {
                                ImpModelPlanning.Factory.Equal( factory ), 
                                ImpModelPlanning.Project.Equal( project ), 
                                ImpModelPlanning.ElementId.Equal( item.Key ), 
                            }
                        };
                        statementList.Add( update.ToString() );
                    }
                }

                if( null != insertList )
                {
                    foreach( var item in insertList )
                    {
                        var insert = new ImpactInsert( ImpModelPlanning.Instance )
                        {
                            Columns =
                            {
                            { ImpModelPlanning.Factory, factory }, 
                            { ImpModelPlanning.Project, project }, 
                            { ImpModelPlanning.ElementId, item.Key }, 
                            { ImpModelPlanning.ErectionSequenceNo, item.Value }, 
                            }, 
                        };

                        statementList.Add( insert.ToString() );
                    }
                }

                int result = database.ExecuteNonQuery( statementList.ToArray() );

                return result > 0;
            }
        }
		//public List<RecProductionFormStrandStd> LoadFormStrandStd( RecProductionFormStd rec )
		//{
		//    ImpactQuery query = new ImpactQuery()
		//    {
		//        Select =
		//        {
		//            //ImpProductionFormStrandStd.Name,
		//            ImpProductionFormStrandStd.StrandPos,
		//            ImpProductionFormStrandStd.StrandX,
		//            ImpProductionFormStrandStd.StrandY,
		//            ImpProductionFormStrandStd.StrandDimension, 
		//            ImpProductionFormStrandStd.StrandQuality, 
		//            ImpProductionFormStrandStd.StrandPrestressing, 
		//        },
		//        From = { ImpProductionFormStrandStd.As( "STD" ) },

		//        Where =
		//        {
		//            ImpProductionFormStrandStd.Factory.Equal( rec.Factory ),
		//            ImpProductionFormStrandStd.Project.Equal( rec.Factory ),
		//            ImpProductionFormStrandStd.Name.Equal( rec.Name ), //Form name
		//        },
		//        OrderBy = 
		//        { 
		//            { ImpProductionFormStrandStd.StrandPos },
		//        },
		//    };
		//    string statement = query.ToString();
		//    List<RecProductionFormStrandStd> result;

		//    using( ImpactDatabase database = new ImpactDatabase() )
		//    {
		//        result = database.GetAll( statement, FormStrandParse );
		//    }

		//    return result;
		//}

		//public static RecProductionFormStrandStd FormStrandParse( DbDataReader column )
		//{
		//    var record = new RecProductionFormStrandStd();
		//    //record.Name = DataConverter.Cast<string>( column[0] );
		//    record.StrandPos = DataConverter.Cast<int>( column[0] );
		//    record.StrandX = DataConverter.Cast<double>( column[1] );
		//    record.StrandY = DataConverter.Cast<double>( column[2] );
		//    record.StrandDimension = DataConverter.Cast<double>( column[3] );
		//    record.StrandQuality = DataConverter.Cast<string>( column[4] );
		//    record.StrandPrestressing = DataConverter.Cast<double>( column[5] );
		//    return record;
		//}

		//public int DeleteFormStrandStd( RecProductionFormStd recProductionFormStd, RecProductionFormStrandStd recProductionFormStrandStd )
		//{
		//    return 0;
		//}

        private bool FindProductionFormStrand( RecProductionFormStrandStd record )
        {
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				var query = new ImpactQuery()
				{
					From = { ImpProductionFormStrand.As( "T1" ) },
					Where =
					{
						ImpProductionFormStrand.Factory.Equal( record.Factory ),
						ImpProductionFormStrand.Project.Equal( record.Factory ),
						ImpProductionFormStrand.Form.Equal( record.Name ),
						ImpProductionFormStrand.Strand.Equal( record.StrandPos.ToString() ),
					},
				};

				var statement = query.ToString();
				record = database.GetFirst( statement, column => new RecProductionFormStrandStd() );
			}

			return record != null;
        }
        /// <summary>
        /// The update planning element data.
        /// </summary>
        /// <param name="factory">
        /// The factory.
        /// </param>
        /// <param name="project">
        /// The project.
        /// </param>
        /// <param name="planningElementList">
        /// The planning element list.
        /// </param>
        /// <exception cref="InvalidOperationException">
        /// Thrown when the database source is unknown.
        /// </exception>
        public void UpdatePlanningElementData( string factory, string project, List<PlanningElementDataUpdate> planningElementList )
        {
            project = Util.CorrectProjectName( project );
                      
            switch( ImpactDatabase.DataSource )
            {
                case DataSource.Ingres92:
                case DataSource.Ingres100:
                {
                    // Create a query that return all the id's of those elements that aldready has planning data.
                    ImpactQuery query = new ImpactQuery()
                        {
                            From = { ImpModelPlanning.As( "T1" ) },
                            Select = { ImpModelPlanning.ElementId },
                            Where =
                                    {
                                        ImpModelPlanning.Factory.Equal(factory),
                                        ImpModelPlanning.Project.Equal(project),
                                        ImpModelPlanning.ElementId.In<int>( planningElementList.Select( element => element.ElementId ) )
                                    }
                        };

                    using( var database = new ImpactDatabase() )
                    {
                        var existingIds = database.GetAll( query.ToString(), reader => reader[0].Cast<int>() );

                        var statementList = new List<string>( planningElementList.Count );

                        foreach( var element in planningElementList )
                        {
                            string producingFactory;

                            if( 0 == string.Compare( Factory.External.Number, element.ProducingFactory, StringComparison.OrdinalIgnoreCase ) )
                            {
                                producingFactory = ProjectBrowserLoader.ProducingFactoryExternalValue;
                            }
                            else
                            {
                                producingFactory = element.ProducingFactory;
                            }

                            if( existingIds.Contains( element.ElementId ) )
                            {
                                // We have an update.
                                var update = new ImpactUpdate( ImpModelPlanning.Instance )
                                {
                                    Where = 
                                        {
                                            ImpModelPlanning.Factory.Equal( factory ), 
                                            ImpModelPlanning.Project.Equal( project ), 
                                            ImpModelPlanning.ElementId.Equal( element.ElementId ), 
                                        },
                                    Columns =
                                        {
                                            { ImpModelPlanning.ProductionFactory, producingFactory ?? string.Empty }, 
                                            { ImpModelPlanning.DivisionProduction, element.Division ?? string.Empty }, 
                                            { ImpModelPlanning.ProductionDate, element.ProductionDate }, 
                                            { ImpModelPlanning.DeliveryDate, element.DeliveryDate }, 
                                            { ImpModelPlanning.ErectionSequenceNo, element.ErectionSequenceNo }, 
                                            { ImpModelPlanning.PlannedDrawingDate, element.PlannedDrawingDate }, 
                                            { ImpModelPlanning.PlannedProductionDate, element.PlannedProductionDate }, 
                                            { ImpModelPlanning.PlannedReadyForDeliveryDate, element.PlannedStorageDate }, 
                                            { ImpModelPlanning.PlannedDeliveryDate, element.PlannedDeliveryDate }, 
                                            { ImpModelPlanning.PlannedErectionDate, element.PlannedErectionDate }, 
                                            { ImpModelPlanning.ElementIdStatus, element.Status }, 
                                        }
                                };

                                statementList.Add( update.ToString() );
                            }
                            else
                            {
                                // We must insert a new row.
                                var insert = new ImpactInsert( ImpModelPlanning.Instance )
                                {
                                    Columns =
                                        {
                                            { ImpModelPlanning.Factory, factory }, 
                                            { ImpModelPlanning.Project, project }, 
                                            { ImpModelPlanning.ElementId, element.ElementId }, 
                                            { ImpModelPlanning.ProductionFactory, producingFactory ?? string.Empty }, 
                                            { ImpModelPlanning.DivisionProduction, element.Division ?? string.Empty }, 
                                            { ImpModelPlanning.ProductionDate, element.ProductionDate }, 
                                            { ImpModelPlanning.DeliveryDate, element.DeliveryDate }, 
                                            { ImpModelPlanning.ErectionSequenceNo, element.ErectionSequenceNo }, 
                                            { ImpModelPlanning.PlannedDrawingDate, element.PlannedDrawingDate }, 
                                            { ImpModelPlanning.PlannedProductionDate, element.PlannedProductionDate }, 
                                            { ImpModelPlanning.PlannedReadyForDeliveryDate, element.PlannedStorageDate }, 
                                            { ImpModelPlanning.PlannedDeliveryDate, element.PlannedDeliveryDate }, 
                                            { ImpModelPlanning.PlannedErectionDate, element.PlannedErectionDate }, 
                                            { ImpModelPlanning.ElementIdStatus, element.Status }, 
                                        }
                                };

                                statementList.Add( insert.ToString() );
                            }
                        }

                        database.ExecuteNonQuery( statementList.ToArray() );
                    }
                    break;
                }
                case DataSource.SqlServer:
                case DataSource.SqlServerExpress:
                {
                    List<string> statementList = new List<string>( planningElementList.Count );

                    foreach( var element in planningElementList )
                    {
                        string producingFactory;

                        if( 0 == string.Compare( Factory.External.Number, element.ProducingFactory, StringComparison.OrdinalIgnoreCase ) )
                        {
                            producingFactory = ProjectBrowserLoader.ProducingFactoryExternalValue;
                        }
                        else
                        {
                            producingFactory = element.ProducingFactory;
                        }

                        ImpactInsertOrUpdate insertOrUpdate = new ImpactInsertOrUpdate( ImpModelPlanning.Instance )
                        {
                            Keys =
                            {
                                { ImpModelPlanning.Factory, factory }, 
                                { ImpModelPlanning.Project, project }, 
                                { ImpModelPlanning.ElementId, element.ElementId }, 
                            }, 
                            Columns =
                            {
                                { ImpModelPlanning.ProductionFactory, producingFactory ?? string.Empty }, 
                                { ImpModelPlanning.DivisionProduction, element.Division ?? string.Empty }, 
                                { ImpModelPlanning.ProductionDate, element.ProductionDate }, 
                                { ImpModelPlanning.DeliveryDate, element.DeliveryDate }, 
                                { ImpModelPlanning.ErectionSequenceNo, element.ErectionSequenceNo }, 
                                { ImpModelPlanning.PlannedDrawingDate, element.PlannedDrawingDate }, 
                                { ImpModelPlanning.PlannedProductionDate, element.PlannedProductionDate }, 
                                { ImpModelPlanning.PlannedReadyForDeliveryDate, element.PlannedStorageDate }, 
                                { ImpModelPlanning.PlannedDeliveryDate, element.PlannedDeliveryDate }, 
                                { ImpModelPlanning.PlannedErectionDate, element.PlannedErectionDate }, 
                                { ImpModelPlanning.ElementIdStatus, element.Status }, 
                            }
                        };

                        statementList.Add( insertOrUpdate.ToString() );
                    }

                    using( var database = new ImpactDatabase() )
                    {
                        database.ExecuteNonQuery( statementList.ToArray() );
                    }

                    break;
                }

                default:
                {
                    throw new InvalidOperationException( "Unknown database source." );
                }
            }
        }
        private int InsertProductionFormStrand ( RecProductionFormStrandStd record )
        {
			var insert = new ImpactInsert( ImpProductionFormStrand.Instance )
			{
				Columns = 
				{
					{ ImpProductionFormStrand.Factory, record.Factory },
					{ ImpProductionFormStrand.Project, record.Factory },// (factory, factory)
					{ ImpProductionFormStrand.Form, record.Name }, 
					{ ImpProductionFormStrand.Strand, record.StrandPos.ToString() },
				}
			};

			string statement = insert.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}
            return result;
        }
Example #25
0
		/// <summary>
		/// Update of Transport items
		/// </summary>
		/// <param name="transport"></param>
		/// <returns></returns>
		public int UpdateTransport( RecTransport record )
		{
			if( record == null )
			{
				throw new ArgumentNullException( "Transport" );
			}
			string project = "";
			if( record.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = record.Factory;
			}
			else
			{
				project = record.Project;
			}

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				ImpactUpdate update = new ImpactUpdate( ImpTransport.Instance )
				{
					Columns = 
					{
 						{ ImpTransport.Description, record.Description },
 						{ ImpTransport.LoadDate, record.LoadDate },
 						{ ImpTransport.DeliveryDate, record.DeliveryDate },
 						{ ImpTransport.TimeInterval, record.TimeInterval },
 						{ ImpTransport.IsTemplate, record.IsTemplate },
 						{ ImpTransport.TemplateId, record.TemplateId },
 						{ ImpTransport.IsVisible, record.IsVisible },
					},
					Where =
					{
						ImpTransport.Factory.Equal( record.Factory ),
						ImpTransport.Project.Equal( project ),// Templates are saved on factory level (factory, factory), 2012-04-23
						ImpTransport.TransportId.Equal( record.TransportId ),
					}
				};

				string sql = update.ToString();

				database.ExecuteNonQuery( sql );
			}
			return 0;
		}
        private int DeleteProductionFormStrand  ( RecProductionFormStrandStd record )
        {
			int ret = 0;
			// Now let's delete the transport 
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				ImpactDelete delete = new ImpactDelete( ImpProductionFormStrand.Instance )
				{
					Where = { ImpProductionFormStrand.Factory.Equal( record.Factory ), 
							  ImpProductionFormStrand.Project.Equal( record.Factory ), // (factory, factory)
							  ImpProductionFormStrand.Form.Equal( record.Name ),
                              ImpProductionFormStrand.Strand.Equal( record.StrandPos.ToString() )},
				};
				var statement = delete.ToString();
				ret = database.ExecuteNonQuery( statement );
			}
			return ret;
        }
Example #27
0
        /// <summary>
        /// Update the transport and elements with new status
        /// </summary>
        /// <param name="transports"></param>
        /// <param name="recTransportStatus"></param>
        /// <returns></returns>
        public int UpdateStatus( RecTransport record, RecTransport recTransportStatus, List<RecElementIdStatusStd> settings )
        {
            if( null == record || null == recTransportStatus )
            {
                return 0;
            }

            ModelPlanner plannerService = new ModelPlanner();
            recTransportStatus.Factory = record.Factory;
            recTransportStatus.Project = record.Project;
            recTransportStatus.TransportId = record.TransportId;
            plannerService.SaveElementTransportStatus( recTransportStatus, settings );

            int ret = 0;
            using( ImpactDatabase database = new ImpactDatabase() )
            {
                ImpactUpdate update = new ImpactUpdate( ImpTransport.Instance )
                {
                    Columns = 
					{
 						{ ImpTransport.TransportStatus, recTransportStatus.TransportStatus },
					},
                    Where =
					{
						ImpTransport.Factory.Equal( record.Factory ),
						ImpTransport.Project.Equal( record.Project ),
						ImpTransport.TransportId.Equal( record.TransportId ),
					}
                };
                
                bool b1 = recTransportStatus.TransportStatus == (int)TransportStatus.Planned && recTransportStatus.UpdateDeliveryDate && null != recTransportStatus.DeliveryDate;
                bool b2 = recTransportStatus.TransportStatus == (int)TransportStatus.Delivered && recTransportStatus.UpdateDeliveryDate && null != recTransportStatus.DeliveryDate;

                if( b1 || b2 )
                {
                    update.Columns.Add( ImpTransport.DeliveryDate, recTransportStatus.DeliveryDate );
                }

                string sql = update.ToString();

                ret = database.ExecuteNonQuery( sql );
            }
            return ret;
        }
		/// <summary>
		/// Insert the specified record into the database.
		/// </summary>
		/// <param name="record">The record to insert into the database.</param>
		/// <returns>The number of affected records.</returns>
		public int InsertProductionFormStrandStd( RecProductionFormStrandStd record )
		{
			var insert = new ImpactInsert( ImpProductionFormStrandStd.Instance )
			{
				Columns = 
				{
					{ ImpProductionFormStrandStd.Factory, record.Factory },
					{ ImpProductionFormStrandStd.Project, record.Factory },
					{ ImpProductionFormStrandStd.Name, record.Name }, //Form name ??
					{ ImpProductionFormStrandStd.StrandPos, record.StrandPos },
					{ ImpProductionFormStrandStd.StrandX, record.StrandX },
					{ ImpProductionFormStrandStd.StrandY, record.StrandY },
					{ ImpProductionFormStrandStd.StrandQuality, record.StrandQuality },
					{ ImpProductionFormStrandStd.StrandDimension, record.StrandDimension },
					{ ImpProductionFormStrandStd.StrandPrestressing, record.StrandPrestressing },
				}
			};

			string statement = insert.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return result;
		}
Example #29
0
		/// <summary>
		/// Insert of Transport items
		/// </summary>
		/// <param name="transport"></param>
		/// <returns></returns>
		public RecTransport InsertTransport( RecTransport record )
		{
			if( record == null )
			{
				throw new ArgumentNullException( "Transport" );
			}
			RecTransport newTransport = new RecTransport( record );
			string project = "";
			if( record.IsTemplate == 1 )
			{
				//Secure and easy solution for unique sequence id's!!!
				// Use negative value to distinguish templates from transports!
				ProjectManager ng = new ProjectManager();
				newTransport.TransportId = -ng.GetNextNumber( record.Factory, record.Project, RecNumberGenerator.NG_TRANSPORT_ID );

				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = record.Factory;
			}
			else
			{
				//Now let's use the slow, unsecure and bad unique id's using max, what a mess :(
				newTransport.TransportId = GetMaxTransportId( record ) + 1;
				project = record.Project;
			}

			var insert = new ImpactInsert( ImpTransport.Instance )
			{
				Columns = 
				{
					{ ImpTransport.Factory, record.Factory },
					{ ImpTransport.Project, project },// Templates are saved on factory level (factory, factory), 2012-04-23
					{ ImpTransport.TransportId, newTransport.TransportId }, // The new Id!
					{ ImpTransport.Description, record.Description },
					{ ImpTransport.LoadDate, record.LoadDate },
					{ ImpTransport.DeliveryDate, record.DeliveryDate },
					{ ImpTransport.IsTemplate, record.IsTemplate },
					{ ImpTransport.IsVisible, record.IsVisible },
					{ ImpTransport.TemplateId, record.TemplateId },
					{ ImpTransport.TimeInterval, record.TimeInterval },
					{ ImpTransport.TransportStatus, record.TransportStatus },
					{ ImpTransport.LoadLocation, record.LoadLocation },
					{ ImpTransport.LoadDivision, record.LoadDivision },
					{ ImpTransport.DeliveryDivision, record.DeliveryDivision },
				}
			};

			string statement = insert.ToString();

			int result;

			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( statement );
			}

			return newTransport;
		}
	    /// <summary> 
	    /// Load all records of the same factory and project as the supplied record.
	    /// </summary>
	    /// <param name="factory"> </param>
	    /// <param name="project"> </param>
	    /// <returns>A list of all mathcing records.</returns>
	    public List<RecSectionStyleStd> LoadSectionStyleStd(  string factory, string project  )
		{
			// Add, Factory, Factory and Company, Company
			var company = factory.Substring( 0, 2 ) + "00"; //Is this really OK ??!!

			var orElementType = WhereGroup.Or( ImpSectionStyleStd.ElementType.Equal( "HD/F" ),
										       ImpSectionStyleStd.ElementType.Equal( "D/F" ));

            
            var where1 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( factory ), ImpSectionStyleStd.Project.Equal( project ) );
            var where2 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( factory ), ImpSectionStyleStd.Project.Equal( factory ) );
            var where3 = WhereGroup.And( ImpSectionStyleStd.Factory.Equal( company ), ImpSectionStyleStd.Project.Equal( company ) );

            var orProjectFactoryCompany = WhereGroup.Or( where1, where2, where3 );

			var query = new ImpactQuery()
			{
				Select =
				{
					ImpSectionStyleStd.Factory,
					ImpSectionStyleStd.Project,
					ImpSectionStyleStd.ElementType,
					ImpSectionStyleStd.Name,
					ImpSectionStyleStd.SectionType,
					ImpSectionStyleStd.Description,
                    ImpSectionStrandptnStd.Name,
                    Aggregate.Count( ImpSectionStrandptnPosStd.StrandPos ),

                    //ImpSectionStyleStd.Width,
                    //ImpSectionStyleStd.WidthTolerance,
                    //ImpSectionStyleStd.DiffBottomTop,
                    //ImpSectionStyleStd.Height,
                    //ImpSectionStyleStd.Endcap,
                    //ImpSectionStyleStd.Strandptn,
                    //ImpSectionStyleStd.RcTemplate,
                    //ImpSectionStyleStd.Material,
                    //ImpSectionStyleStd.ProductionLine,
                    //ImpSectionStyleStd.CutType,
                    //ImpSectionStyleStd.UseCutZone,
                    //ImpSectionStyleStd.LiftMethod,
                    //ImpSectionStyleStd.LiftRotation1,
                    //ImpSectionStyleStd.LiftRotation2,
                    //ImpSectionStyleStd.LiftPlacingLs,
                    //ImpSectionStyleStd.LiftParameterLs,
                    //ImpSectionStyleStd.LiftPlacingSs,
                    //ImpSectionStyleStd.LiftParameterSs,
                    //ImpSectionStyleStd.LiftCores,
                    //ImpSectionStyleStd.LiftCoreLength,
                    //ImpSectionStyleStd.LiftCoreDisplayMode,
                    //ImpSectionStyleStd.LiftDistanceMax,
                    //ImpSectionStyleStd.LiftDistanceMin,
                    //ImpSectionStyleStd.LiftSpacing,
                    //ImpSectionStyleStd.LiftType,
                    //ImpSectionStyleStd.SectionViewDimStrandGrp,
                    //ImpSectionStyleStd.SectionViewTxtStrandGrp,
                    //ImpSectionStyleStd.SectionViewNbrCores,
                    //ImpSectionStyleStd.SectionViewScale,
                    //ImpSectionStyleStd.UseSectionViewSymbol,
                    //ImpSectionStyleStd.SectionViewFilename,
                    //ImpSectionStyleStd.ChamferDistance,
                    //ImpSectionStyleStd.ChamferText,
                    //ImpSectionStyleStd.ChamferVisibility,
                    //ImpSectionStyleStd.RcCoverCut1,
                    //ImpSectionStyleStd.RcCoverCut2,
                    //ImpSectionStyleStd.ElementGrp,
                    //ImpSectionStyleStd.ProductPrefix,
                    //ImpSectionStyleStd.Product,
                    //ImpSectionStyleStd.ElementMarkPrefix,
                    //ImpSectionStyleStd.DrawingNamePrefix,
                    //ImpSectionStyleStd.DrawingType,
                    //ImpSectionStyleStd.DrawingTemplate,
                    //ImpSectionStyleStd.CreatedBy,
                    //ImpSectionStyleStd.CreatedDate,
                    //ImpSectionStyleStd.ChangedBy,
                    //ImpSectionStyleStd.ChangedDate,
                    //ImpSectionStyleStd.LiftHolePosition,

				},
				From = { ImpSectionStyleStd.As( "T1" ) },
                Join =
				{
					Join.Left( ImpSectionStrandptnStd.As( "T2" ),	
						ImpSectionStrandptnStd.Factory.Equal( ImpSectionStyleStd.Factory ),
						ImpSectionStrandptnStd.Project.Equal( ImpSectionStyleStd.Project ),
						ImpSectionStrandptnStd.ElementType.Equal( ImpSectionStyleStd.ElementType ), 
						ImpSectionStrandptnStd.Section.Equal( ImpSectionStyleStd.Name )),

					Join.Left( ImpSectionStrandptnPosStd.As( "T3" ),	
						ImpSectionStrandptnPosStd.Factory.Equal( ImpSectionStrandptnStd.Factory ),
						ImpSectionStrandptnPosStd.Project.Equal( ImpSectionStrandptnStd.Project ),
						ImpSectionStrandptnPosStd.ElementType.Equal( ImpSectionStrandptnStd.ElementType ), 
						ImpSectionStrandptnPosStd.Section.Equal( ImpSectionStrandptnStd.Section ),
                        ImpSectionStrandptnPosStd.Strandptn.Equal( ImpSectionStrandptnStd.Name )),
				},

				Where = { orElementType, orProjectFactoryCompany },

                GroupBy = 
                {
                    ImpSectionStyleStd.Factory,
                    ImpSectionStyleStd.Project,
                    ImpSectionStyleStd.ElementType,
                    ImpSectionStyleStd.Name,
                    ImpSectionStyleStd.SectionType,
                    ImpSectionStyleStd.Description,
                    ImpSectionStrandptnStd.Name,
                }
			};

			var statement = query.ToString();
           
			List<RecSectionStyleStd> result;

			using( var database = new ImpactDatabase() )
			{
				result = database.GetAll( statement, ParseSectionStyleStd );
			}

			if( result == null || result.Count == 0 )
			{
				return result;
			}

            var companyDic = ( from o in result
				            where ( o.Factory == company && o.Project == company )
				            select new RecSectionStyleStd { Factory = o.Factory, Project = o.Factory, ElementType = o.ElementType, 
                                Name = o.Name, Strandptn = o.Strandptn, NumOfStrands = o.NumOfStrands } ).ToDictionary( x => x.Name + x.Strandptn );

            var factoryDic = ( from o in result
				            where ( o.Factory == factory && o.Project == factory )
				            select new RecSectionStyleStd { Factory = o.Factory, Project = o.Factory, ElementType = o.ElementType, 
                                Name = o.Name, Strandptn = o.Strandptn, NumOfStrands = o.NumOfStrands } ).ToDictionary( x => x.Name + x.Strandptn );

            var projectDic = ( from o in result
				            where ( o.Factory == factory && o.Project == project )
				            select new RecSectionStyleStd { Factory = o.Factory, Project = o.Project, ElementType = o.ElementType, 
                                Name = o.Name, Strandptn = o.Strandptn, NumOfStrands = o.NumOfStrands } ).ToDictionary( x => x.Name + x.Strandptn );

			foreach( var pair in factoryDic )
			{
				if( !projectDic.ContainsKey( pair.Key ) )
				{
					projectDic.Add( pair.Key, pair.Value );
				}
			}
			foreach( var pair in companyDic )
			{
				if( !projectDic.ContainsKey( pair.Key ) )
				{
					projectDic.Add( pair.Key, pair.Value );
				}
			}

			return GetStylesFromDictionary(  projectDic);
		}