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;
        }
Ejemplo n.º 2
0
        public ProductionBed( RecProductionFormStd form, BedFilter filter )
            : base( form )
        {
            this.bedFilter = filter;
            IsFull = false;
            if( null != form.ProductionCast && form.ProductionCast.CastId > 0 )
            {
                // Well this is never used so far
                this.ProductionCast = form.ProductionCast;
            }
            else
            {
                // Create a cast object
                var cast = new RecProductionCast( form )
                               {
                                   Factory = filter.Factory,
                                   Project = filter.Project,
                                   StartDate = filter.StartDateFrom,
                                   EndDate = filter.EndDateFrom,
                                   Shift = filter.Shift
                               };

                if( form.FormType == V120.Planning.Common.FormType.Bed && form.StrandType == V120.Planning.Common.StrandType.Bed )
                {
                    var strand = new RecProductionFormStrandStd()
                                     { Factory = filter.Factory, Project = filter.Project, Name = form.Name };
                    cast.Strands = LoadStandardStrands( strand );
                }

                this.ProductionCast = cast;
            }
        }
		/// <summary>
		/// Parses one row in <see cref="System.Data.Common.DbDataReader"/> into
		/// a new instance of <see cref="Paths.Common.Records.RecProductionFormStrandStd"/>.
		/// </summary>
		/// <param name="dataReader">The data reader.</param>
		/// <returns>A new instance of <see cref="Paths.Common.Records.RecProductionFormStrandStd"/>.</returns>
		public static RecProductionFormStrandStd ParseProductionFormStrandStd( DbDataReader dataReader )
		{
			var record = new RecProductionFormStrandStd();
			record.Factory = dataReader[0].Cast<string>();
			record.Project = dataReader[1].Cast<string>();
			record.Name = dataReader[2].Cast<string>();
			record.StrandPos = dataReader[3].Cast<int>();
			record.StrandX = dataReader[4].Cast<double>();
			record.StrandY = dataReader[5].Cast<double>();
			record.StrandQuality = dataReader[6].Cast<string>();
			record.StrandDimension = dataReader[7].Cast<double>();
			record.StrandPrestressing = dataReader[8].Cast<double>();
            string form = dataReader[9].Cast<string>();
		    record.IsUsed = null != form;
			return record;
		}
        /// <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;
		}
Ejemplo n.º 5
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;
 }
		/// <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;
		}
	    private int UpdateProductionFormStrand( RecProductionFormStrandStd record )
        {
            if( null == record || string.IsNullOrEmpty( record.Factory ) || string.IsNullOrEmpty( record.Name ) || record.StrandPos < 0 )
            {
                return 0;
            }

	        var found = FindProductionFormStrand( record );
            if( record.IsUsed )
            {
                if( !found )
                {
                    InsertProductionFormStrand( record );
                }
            }
            else
            {
                if( found )
                {
                    DeleteProductionFormStrand( record );
                }
            }
            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;
        }
        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;
        }
		//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>
		/// 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;
		}
Ejemplo n.º 13
0
 /// <summary>
 /// Returns no of strands
 /// </summary>
 /// <param name="castunit"></param>
 /// <returns></returns>
 private int GetNumberOfStrands( RecProductionFormStd castunit )
 {
     var nbrOfStrands = 0;
     if( castunit == null || string.IsNullOrEmpty( castunit.Factory ) || string.IsNullOrEmpty( castunit.Project ) )
     {
         return nbrOfStrands;
     }
     var svc = new ProjectManager();
     var recStrand = new RecProductionFormStrandStd { Factory = castunit.Factory, Project = castunit.Project, Name = castunit.Name };
     var strands = svc.LoadProductionFormStrandStd( recStrand );
     if( null != strands )
     {
         nbrOfStrands = (from o in strands where o.IsUsed select o).Count();
     }
     return nbrOfStrands;
 }
Ejemplo n.º 14
0
        /// <summary>
        /// LoadHollowcoreStrands
        /// </summary>
        /// <param name="form"></param>
        /// <param name="filter"></param>
        /// <returns></returns>
        private List<RecProductionFormStrandStd> LoadHollowcoreStrands( RecProductionFormStd form, Filter filter )
        {

            if( string.IsNullOrEmpty( form.Style ) || string.IsNullOrEmpty( form.Strandptn ) )
            {
                return null;
            }
            var strandSvc = new ProjectManager();
            var strands = strandSvc.LoadStrands(
                            filter.Factory,
                            filter.Project,
                            form.ElementType,
                            form.Style,
                            form.Strandptn );
            if( null != strands && strands.Count > 0 )
            {
                var list = new List<RecProductionFormStrandStd>();
                foreach( var strand in strands)
                {
                    var strandStd = new RecProductionFormStrandStd 
                    { 
                        Factory = strand.Factory, 
                        Project = strand.Project, 
                        StrandPos = strand.StrandPos, 
                        StrandX = strand.StrandX, 
                        StrandY = strand.StrandY, 
                        StrandQuality = strand.StrandQuality,
                        StrandDimension = strand.StrandDimension,
                        StrandPrestressing = strand.StrandPrestressing,
                    };

                    list.Add( strandStd );
                }

                return list;
            }

            return null;
        }
Ejemplo n.º 15
0
        /// <summary>
        /// LoadFormStrands
        /// </summary>
        /// <param name="forms"></param>
        /// <param name="filter"></param>
        private void LoadFormStrands( IEnumerable<RecProductionFormStd> forms, Filter filter )
        {
            if( null == forms )
            {
                return;
            }
            foreach( var recProductionFormStd in forms )
            {
                if( recProductionFormStd.FormType == FormType.Bed && recProductionFormStd.StrandType == StrandType.Bed )
                {
                    // Load for strands
                    var stdSvc = new ProjectManager();
                    var recStrand = new RecProductionFormStrandStd { Factory = filter.Factory, Project = filter.Project, Name = recProductionFormStd.Name };
                    var strands = stdSvc.LoadProductionFormStrandStd( recStrand );
                    if( null != strands )
                    {
                        strands = (from o in strands where o.IsUsed select o).ToList();
                    }
                    recProductionFormStd.Strands = strands;
                }
                else if( recProductionFormStd.FormType == FormType.Bed && ( recProductionFormStd.ElementType.Equals( "HD/F" ) || recProductionFormStd.ElementType.Equals( "D/F" ) ) )
                {
                    recProductionFormStd.Strands = LoadHollowcoreStrands( recProductionFormStd, filter);
                }
            }

        }
Ejemplo n.º 16
0
		/// <summary>
		/// Delete the specified record from the database.
		/// This method should be optimized
		/// </summary>
		/// <param name="record">The record to delete from the database.</param>
		/// <returns>The number of affected records.</returns>
		public int DeleteProductionFormStd( RecProductionFormStd record )
		{
			ProjectManager castSvc = new ProjectManager( );
			int count = castSvc.GetCastCount( record );
			if( count > 0 )
			{
				return 0;
			}

			// Delete form std strands
			RecProductionFormStrandStd strand = new RecProductionFormStrandStd( );
			strand.Factory = record.Factory;
			strand.Project = record.Project;
			strand.Name = record.Name;
			strand.StrandPos = 0;//Means delete all strands related to this form
			ProjectManager svc = new ProjectManager();
			svc.DeleteProductionFormStrandStd( strand );

			// (2) Now delete form
			var delete = new ImpactDelete( ImpProductionFormStd.Instance )
			{
				Where = 
				{
					{ ImpProductionFormStd.Factory.Equal( record.Factory )},
					{ ImpProductionFormStd.Project.Equal( record.Factory )}, //Factory Level, ie(Factory, Factory)
					{ ImpProductionFormStd.Name.Equal( record.Name )},
				}
			};

			string statement = delete.ToString();

			int result;

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

			return result;
		}