Beispiel #1
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;
		}
        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;
        }
		/// <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>
		/// Delete of Transport Vehicle Standard items
		/// </summary>
		/// <param name="vehicle"></param>
		/// <returns></returns>
		public int DeleteTransportVehicleStd( RecTransportVehicleStd record )
		{
			if( record == null )
			{
				throw new ArgumentNullException( "TransportVehicleStd" );
			}
			// Delete underlying std stacks
			ProjectManager svc = new ProjectManager();
			RecTransportVehicleStackStd stack = new RecTransportVehicleStackStd()
			{ 
				Factory = record.Factory,
				Project = record.Project,
				Name = record.Name, 
			};
			svc.DeleteTransportVehicleStackStd( stack );
 
			// Now delete the std veh
			var delete = new ImpactDelete( ImpTransportVehicleStd.Instance )
			{
				Where = 
				{
					{ ImpTransportVehicleStd.Factory.Equal( record.Factory )},
					{ ImpTransportVehicleStd.Project.Equal( record.Factory )},//for Std use Factory, Factory
					{ ImpTransportVehicleStd.Name.Equal( record.Name )},
				}
			};

			string statement = delete.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;
		}
		/// <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;
		}
Beispiel #7
0
        /// <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 DeleteCalendar(RecCalendar record)
        {
            var delete = new ImpactDelete(ImpCalendar.Instance)
            {
                Where = 
				{
					{ ImpCalendar.Factory.Equal( record.Factory )},
					{ ImpCalendar.Project.Equal( record.Project )},
                    { ImpCalendar.Name.Equal( record.Name )},
				}
            };

            string statement = delete.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 DeleteTransportStack( RecTransportStack record )
		{
			var delete = new ImpactDelete( ImpTransportStack.Instance )
			{
				Where = 
				{
					{ ImpTransportStack.Factory.Equal( record.Factory )},
					{ ImpTransportStack.Project.Equal( record.Project )},
					{ ImpTransportStack.TransportId.Equal( record.TransportId )},
					{ ImpTransportStack.VehicleId.Equal( record.VehicleId )},
					{ ImpTransportStack.StackId.Equal( record.StackId )},
				}
			};

			string statement = delete.ToString();

			int result;

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

			return result;
		}
		/// <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);
		}
		/// <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;
		}