public int CopyStrandsFromTemplate( RecProductionCast record )
        {
            var rec = new RecProductionFormStrandStd
                          { Factory = record.Factory, Project = record.Project, Name = record.Form };
            var svc = new ProjectManager();
            var list = svc.LoadProductionFormStrandStd( rec );
            if (list == null || list.Count == 0)
            {
                return 0;
            }
            list = (from o in list where o.IsUsed select o).ToList();

            foreach (var std in list)
            {
                var strand = new RecProductionCastStrand
                                 {
                                     Factory = record.Factory,
                                     Project = record.Project,
                                     CastId = record.CastId,
                                     StrandPos = std.StrandPos,
                                     StrandX = std.StrandX,
                                     StrandY = std.StrandY,
                                     StrandQuality = std.StrandQuality,
                                     StrandDimension = std.StrandDimension,
                                     StrandPrestressing = std.StrandPrestressing
                                 };

                this.InsertProductionCastStrand( strand, null, null );
            }

            return list.Count;
        }
        /// <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;
		}
Example #3
0
 /// <summary>
 /// Load standard strands into strand list
 /// </summary>
 /// <param name="record"></param>
 /// <returns></returns>
 public List<RecProductionCastStrand> LoadStandardStrands( RecProductionFormStrandStd record )
 {
     var strands = new List<RecProductionCastStrand>();
     var svc = new ProjectManager();
     var list = svc.LoadProductionFormStrandStd( record );
     list = ( from o in list where o.IsUsed select o ).ToList();
     foreach( var std in list )
     {
         var strand = new RecProductionCastStrand()
             {
                 Factory = record.Factory,
                 Project = record.Project,
                 StrandPos = std.StrandPos,
                 CastId = 0, // Since it is not created yet
             };
         strands.Add( strand );
     }
     return strands;
 }
Example #4
0
        /// <summary>
        /// LoadStrands
        /// </summary>
        /// <param name="forms"></param>
        /// <param name="filter"></param>
        private void LoadCastStrands( IEnumerable<RecProductionFormStd> forms, Filter filter )
        {
            foreach( var recProductionFormStd in forms )
            {
                var rec = new RecProductionCastStrand()
                              {
                                  Factory = filter.Factory,
                                  Project = filter.Project,
                                  CastId = recProductionFormStd.ProductionCast.CastId
                              };
                if( null != recProductionFormStd.ProductionCast )
                {
                    if( recProductionFormStd.FormType == FormType.Bed && recProductionFormStd.StrandType == StrandType.Bed )
                    {
                        // Load cast strands
                        var svc = new ProjectManager();
                        recProductionFormStd.ProductionCast.Strands = svc.LoadProductionCastStrand( rec );
                    }
                    var et = recProductionFormStd.ProductionCast.ElementType;
                    var hasStrands = et.Equals( "HD" ) || et.Equals( "HD/F" );

                    if( hasStrands )
                    {
                        var strandSvc = new ProjectManager();
                        recProductionFormStd.ProductionCast.Strands = strandSvc.LoadStrands(
                            filter.Factory,
                            filter.Project,
                            recProductionFormStd.ProductionCast.ElementType,
                            recProductionFormStd.ProductionCast.Style,
                            recProductionFormStd.ProductionCast.Strandptn );
                    }
                }
            }
        }
		/// <summary>
		/// Update the specified record in the database.
		/// </summary>
		/// <param name="record">The record to update.</param>
		/// <returns></returns>
		public int UpdateProductionCastStrand( RecProductionCastStrand record )
		{

			var update = new ImpactUpdate( ImpProductionCastStrand.Instance )
			{
				Columns = 
				{
					{ ImpProductionCastStrand.StrandX, record.StrandX },
					{ ImpProductionCastStrand.StrandY, record.StrandY },
					{ ImpProductionCastStrand.StrandQuality, record.StrandQuality },
					{ ImpProductionCastStrand.StrandDimension, record.StrandDimension },
					{ ImpProductionCastStrand.StrandPrestressing, record.StrandPrestressing },
				},
				Where = 
				{
					{ ImpProductionCastStrand.Factory.Equal( record.Factory ) },
					{ ImpProductionCastStrand.Project.Equal( record.Factory ) },// Factory, Factory for productionCast & ProductionCastStrand
					{ ImpProductionCastStrand.CastId.Equal( record.CastId ) },
					{ ImpProductionCastStrand.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 DeleteProductionCastStrand( RecProductionCastStrand record )
		{
			var delete = new ImpactDelete( ImpProductionCastStrand.Instance )
			{
				Where = 
				{
					ImpProductionCastStrand.Factory.Equal( record.Factory ),
					ImpProductionCastStrand.Project.Equal( record.Factory ),// Factory, Factory for productionCast & ProductionCastStrand
					ImpProductionCastStrand.CastId.Equal( record.CastId ),
				}
			};

            if (record.StrandPos > 0)
            {
                delete.Where.Add( ImpProductionCastStrand.StrandPos.Equal(record.StrandPos) );
            }

			var statement = delete.ToString();

			int result;

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

			return result;
		}
	    /// <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 InsertProductionCastStrand(RecProductionCastStrand record, RecProductionFormStd form, BedFilter filter)
		{
            if (null == record)
            {
                return -1;
            }
            int castId = record.CastId;
            if (castId <= 0)
            {
                if (null == form || null == filter)
                {
                    return -1;
                }
                var cast = new RecProductionCast
                    {
                        Factory = record.Factory,
                        Project = record.Project,
                        CastType = form.FormType,
                        Description = "",
                        Shift = filter.Shift,
                        StartDate = filter.StartDateFrom,
                        EndDate = filter.StartDateFrom,
                        Form = form.Name,
                        Tolerance = form.Tolerance,
                        ElementType = form.ElementType,
                        Style = form.Style,
                        Strandptn = form.Strandptn,
                        CastStatus = 0,
                        CastDivision = ""
                    };

                var svc = new ProjectManager();
                var newCast = svc.InsertProductionCast(cast);
                castId = newCast.CastId;
            }

			var insert = new ImpactInsert( ImpProductionCastStrand.Instance )
			{
				Columns = 
				{
					{ ImpProductionCastStrand.Factory, record.Factory },
					{ ImpProductionCastStrand.Project, record.Factory },// Factory, Factory for productionCast & ProductionCastStrand
					{ ImpProductionCastStrand.CastId, castId },
					{ ImpProductionCastStrand.StrandPos, record.StrandPos },
					{ ImpProductionCastStrand.StrandX, record.StrandX },
					{ ImpProductionCastStrand.StrandY, record.StrandY },
					{ ImpProductionCastStrand.StrandQuality, record.StrandQuality },
					{ ImpProductionCastStrand.StrandDimension, record.StrandDimension },
					{ ImpProductionCastStrand.StrandPrestressing, record.StrandPrestressing },
				}
			};

			string statement = insert.ToString();

			int result;

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

			return result;
		}
	    /// <summary>
	    /// Parses one row in <see cref="System.Data.Common.DbDataReader"/> into
	    /// a new instance of <see>
	    ///                     <cref>Paths.Common.Records.RecProductionCastStrand</cref>
	    ///                   </see> .
	    /// </summary>
	    /// <param name="dataReader">The data reader.</param>
	    /// <returns>A new instance of <see>
	    ///                              <cref>Paths.Common.Records.RecProductionCastStrand</cref>
	    ///                            </see> .</returns>
	    public static RecProductionCastStrand ParseProductionCastStrand( DbDataReader dataReader )
		{
			var record = new RecProductionCastStrand();
			record.Factory = DataConverter.Cast<string>( dataReader[0] );
			record.Project = DataConverter.Cast<string>( dataReader[1] );
			record.CastId = DataConverter.Cast<int>( dataReader[2] );
			record.StrandPos = DataConverter.Cast<int>( dataReader[3] );
			record.StrandX = DataConverter.Cast<double>( dataReader[4] );
			record.StrandY = DataConverter.Cast<double>( dataReader[5] );
			record.StrandQuality = DataConverter.Cast<string>( dataReader[6] );
			record.StrandDimension = DataConverter.Cast<double>( dataReader[7] );
			record.StrandPrestressing = DataConverter.Cast<double>( dataReader[8] );
			return record;
		}
Example #9
0
        public void AssignProductionCast( List<RecProductionFormStd> casts )
        {
            foreach( RecProductionFormStd formCast in casts )
            {
                if( null != formCast.ProductionCast && !string.IsNullOrWhiteSpace( formCast.Name ) && formCast.Name.Equals( this.Name ) )
                {
                    // Assign the ProductionCast
                    this.ProductionCast = formCast.ProductionCast;

                    // Now handle special case
                    if( this.FormType == (int)V120.Planning.Common.FormType.Bed && this.StrandType == V120.Planning.Common.StrandType.Bed )
                    {
                        var strand = new RecProductionCastStrand()
                                         { Factory = this.bedFilter.Factory, Project = this.bedFilter.Project, CastId = formCast.ProductionCast.CastId };
                        this.ProductionCast.Strands = LoadCastStrands( strand );
                    }
                }
            }
        }
Example #10
0
 public List<RecProductionCastStrand> LoadCastStrands( RecProductionCastStrand record )
 {
     var svc = new ProjectManager();
     return svc.LoadProductionCastStrand( record );
 }
		/// <summary>
		/// Returns a list of the reset element ids.
		/// </summary>
		/// <param name="record">The record to delete from the database.</param>
		/// <returns>The number of affected records.</returns>
		public CastScheduleResult DeleteProductionCast( RecProductionCast record )
		{
            ProjectManager projectManagerService = new ProjectManager();   
            BedFilter filter = new BedFilter();
            filter.Factory = record.Factory;
            List<string> projectsInvolved = projectManagerService.LoadCastProjects( filter, record.CastId );
            if( null == projectsInvolved )
            {
                return null;
            }

            ProjectManager mgr = new ProjectManager();
            RecElementIdStatusStd std = new RecElementIdStatusStd { Factory = record.Factory, Project = record.Project };
            List<RecElementIdStatusStd> settings = mgr.LoadStandardSettings( std );

			ModelPlanner svc = new ModelPlanner( );
            List<int> deletedIds = svc.LoadElementIds( record.Factory, record.Project, record.CastId );

            // (1) Reset elements
            // Update Status, Note this can be optimized!
            RecProductionCast recProductionCastStatus = new RecProductionCast( record );
            recProductionCastStatus.CastStatus = (int)CastStatus.NoStatus;
            recProductionCastStatus.ElementIdStatus = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, recProductionCastStatus.CastStatus).StatusId;
            UpdateStatus( record, recProductionCastStatus, settings );
            // Now reset
			svc.ResetElementProduction( record.Factory, record.Project, record.CastId, 0, false );

            // (2) Delete strands
            RecProductionCastStrand recStrand = new RecProductionCastStrand();
            recStrand.Factory = record.Factory;
            recStrand.Project = record.Factory; // Factory, Factory for productionCast & ProductionCastStrand
            recStrand.CastId = record.CastId;
            recStrand.StrandPos = 0;
            ProjectManager strand = new ProjectManager();
            strand.DeleteProductionCastStrand(recStrand);
            // (3) Now delete the cast Object
            int result = 0;
            // The cast object can be deleted if no elements belong to other projects other that the current one
            if( projectsInvolved.Count == 0 || (projectsInvolved.Count == 1 && projectsInvolved[0].Equals( record.Project ) )  )
            {
                var delete = new ImpactDelete( ImpProductionCast.Instance )
                {
                    Where = 
				{
					{ ImpProductionCast.Factory.Equal( record.Factory )},
					{ ImpProductionCast.Project.Equal( record.Factory )},// Factory, Factory for productionCast & ProductionCastStrand
					{ ImpProductionCast.CastId.Equal( record.CastId )},
				}
                };

                string statement = delete.ToString();

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

			return new CastScheduleResult(deletedIds, projectsInvolved);
		}