/// <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;
		}
Пример #2
0
        /// <summary>
        /// Saves the cast into the database
        /// </summary>
        public RecProductionCast GetCast()
        {
            // If there is a cast object with the same date (Year, Month, Day), shift then use it
            // otherwise create a new one
            var cast = this.FindCast( -1 );
            var svc = new ProjectManager();
            var pcd = svc.LoadProductionCast( this.bedFilter, cast );
            RecProductionCast newCast = null;
            if( pcd != null && pcd.Count > 0 )
            {
                newCast = pcd[0]; // Use the first one
            }
            if( newCast == null )
            {
                newCast = svc.InsertProductionCast( cast );
            }
            if( newCast == null )
            {
                throw new Exception( "Cannot create new cast object!" );
            }
            cast.CastId = newCast.CastId;

            return cast;
        }