Пример #1
0
		public bool Load( RecTMElement elem, RecTransport recTransport, RecTransportVehicleStd recVeh )
		{
			// *** Force erection sequence since it is paramount ***
			// Once a vehicle is set till full, never try to put other lighter elements even though
			// the total weight still allowed
			if( IsFull )
			{
				return false;
			}
			// It is not allowed to use a vehicle not capable to carry a single element!
			if( elem.Mass > TransportVehicleStackStdObject.MaxMass )
			{
				string elemMass = elem.Mass.ToString( "#0.000" );
				string stackMaxMass = TransportVehicleStackStdObject.MaxMass.ToString( "#0.000" );
				string msg = string.Format( "The stack \"{0}\" max load capacity {1} < element mass {2} for element \"{3}\", Standard vehicle \"{4}\" !",
					TransportVehicleStackStdObject.Description,
					stackMaxMass,
					elemMass,
					elem.ElementId,
					TransportVehicleStackStdObject.Name );
				throw new FaultException<BusinessFaultContract>( new BusinessFaultContract() { Argument = msg }, "Stack load capacity < Element mass!" );
			}
			double tot = GetTotElementMass() + elem.Mass;
			if( tot > TransportVehicleStackStdObject.MaxMass )
			{
				IsFull = true;
				return false;
			}
			else
			{
				TMElements.Add( new TMElement( elem ) );
			}
			return true;
		}
Пример #2
0
		/// <summary>
		/// Saves the transport into the database
		/// </summary>
		private void SaveTransportVehicle( RecTransport transport, int seq )
		{
			ProjectManager svc = new ProjectManager();
			RecTransportVehicleStd newRec = svc.InsertTransportVehicle( transport, TransportVehicleStdObject, seq );
			// Use the new veh id
			TransportVehicleStdObject.VehicleId = newRec.VehicleId;
		}
Пример #3
0
		/// <summary>
		/// Saves the transport into the database
		/// </summary>
		private void SaveTransportVehicleStack( RecTransport transport, RecTransportVehicleStd recVeh, int seq )
		{
			// Prepare data
			TransportVehicleStackStdObject.Factory = transport.Factory;
			TransportVehicleStackStdObject.Project = transport.Project;
			TransportVehicleStackStdObject.TransportId = transport.TransportId;
			TransportVehicleStackStdObject.VehicleId = recVeh.VehicleId;

			// Save Stack object
			ProjectManager svc = new ProjectManager();
			// Use the new stack id
			TransportVehicleStackStdObject.StackId = svc.InsertTransportVehicleStack( TransportVehicleStackStdObject );
		}
Пример #4
0
		public bool Load( RecTMElement elem, RecTransport recTransport )
		{
			foreach( TMStack tmStack in Stacks )
			{
				// Try to load this element on the current vehicle
				if( tmStack.Load( elem, recTransport, TransportVehicleStdObject ) )
				{
					return true;
				}
			}
			// OK, All the vehicles are already fully loaded
			IsFull = true;
			// return false, to indicate that.
			return false;
		}
Пример #5
0
		public void CreateFromTemplate( RecTransport transportTpl, int templateUsageCount, PlanningFilter filter )
		{
			TransportObject = new RecTransport( transportTpl );
			// Calculate the load date and delivery date based on
			// the template and the template reuse loop(count)
			// The interval is minutes
			TransportObject.LoadDate = GetNextDate( filter.LoadDateFrom, (int)filter.TimeInterval, templateUsageCount );
			TransportObject.DeliveryDate = GetNextDate( filter.DeliveryDateFrom, (int)filter.TimeInterval, templateUsageCount );
			TransportObject.IsTemplate = 0;
			foreach( RecTransportVehicleStd rec in transportTpl.Vehicles )
			{
				TMVehicle tmVehicle = new TMVehicle( rec );
				//Create Stacks from template
				tmVehicle.CreateFromTemplate( rec );

				Vehicles.Add( tmVehicle );
			}
		}
Пример #6
0
		void SimpleSave( RecTransport transport )
		{
			if( TMElements == null || TMElements.Count == 0 )
			{
				return;
			}
			// Update the elements with transport info;
			int loadSeq = TMElements.Count;
			foreach( TMElement tmElement in TMElements )
			{
				tmElement.StackSequenceNo = loadSeq;
				tmElement.VehicleId = TransportVehicleStdObject.VehicleId;

				tmElement.Factory = transport.Factory;
				tmElement.Project = transport.Project;
				tmElement.TransportId = transport.TransportId;

				tmElement.Save();
				loadSeq--;
			}
		}
Пример #7
0
 RecTransportVehicleStd GetStandardVehicle( RecTMElement rec )
 {
     ProjectManager svc = new ProjectManager();
     RecTransport recTrans = new RecTransport();
     recTrans.Factory = rec.Factory;
     recTrans.Project = rec.Project;
     recTrans.TransportId = rec.TransportId;
     List<RecTransportVehicleStd> vehList = svc.LoadTransportVehiclesEx( recTrans, rec.VehicleId );
     if( vehList != null && vehList.Count > 0 )
     {
         return vehList[0];
     }
     return null;
 }
		/// <summary>
		///  Remove Transport Vehicles Standard items from transport
		/// </summary>
		/// <param name="rec"></param>
		/// <param name="list"></param>
		/// <returns></returns>
		public int RemoveTransportVehicles( RecTransport rec, List<RecTransportVehicleStd> list )
		{
			if( rec == null || list == null || list.Count == 0 )
			{
				return 0;
			}
			string project = "";
			if( rec.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = rec.Factory;
			}
			else
			{
				project = rec.Project;
			}
			string ids = "";
			foreach( RecTransportVehicleStd vehicle in list )
			{
				ids += Conv.Sql( vehicle.VehicleId ) + ",";
			}
			// remove last comma(,)
			if( ids.Length > 0 )
			{
				ids = ids.Substring( 0, ids.Length - 1 );
			}

			string sql = "Delete from IMP_TRANSPORT_VEHICLE Where "
									+ "FACTORY = " + Conv.Sql( rec.Factory ) + " AND "
									+ "PROJECT = " + Conv.Sql( project ) + " AND "// Templates are saved on factory level (factory, factory), 2012-04-23
									+ "TRANSPORT_ID = " + Conv.Sql( rec.TransportId ) + " AND "
									+ "VEHICLE_ID IN (" + ids + ")";

			int result = 0;
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				result = database.ExecuteNonQuery( sql );
			}
			return result;
		}
		private void LoadVehicleStdDetails_( RecTransport veh )
		{
			// Try to find the vehicle in factory, factory otherwise
			// try to find it in company, compnay
		}
Пример #10
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;
		}
Пример #11
0
        /// <summary>
        /// Update the transport and elements with new status
        /// </summary>
        /// <param name="transports"></param>
        /// <param name="recTransportStatus"></param>
        /// <returns></returns>
        public int UpdateStatusTransport( List<RecTransport> transports, RecTransport recTransportStatus )
        {
            if( null == transports || transports.Count == 0 )
            {
                return 0;
            }

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

            foreach( RecTransport recTransport in transports )
            {
                UpdateStatus( recTransport, recTransportStatus, settings );
            }

            return 0;
        }
Пример #12
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;
		}
Пример #13
0
		public int DeleteCascadeVehicleTransport( RecTransport transport, RecTransportVehicleStd veh )
		{
			RecTransportStack rec = new RecTransportStack();
			rec.Factory = transport.Factory;
			rec.Project = transport.Project;
			rec.TransportId = transport.TransportId;
			rec.VehicleId = veh.VehicleId;

			// Delete cascade stacks
			ProjectManager svc = new ProjectManager();
			List<RecTransportStack> stacks = svc.LoadTransportStack( rec );
			foreach( RecTransportStack stack in stacks )
			{
				this.DeleteCascadeStackTransport( transport, veh, stack );
			}

			// Now delete the vehicle
			ProjectManager vehSvc = new ProjectManager();
			List<RecTransportVehicleStd> vehicles = new List<RecTransportVehicleStd>();
			vehicles.Add( veh );
			return vehSvc.RemoveTransportVehicles( transport, vehicles );
		}
Пример #14
0
        /// <summary>
        /// Parsing method
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="vehicle"></param>
        /// <param name="rack"></param>
        /// <param name="elem"></param>
        public void Parse( RecTransport transport, RecTransportVehicleStd vehicle, RecTransportVehicleStackStd stack, RecTMElement elem )
        {
            string transpKey = transport.Factory + transport.Project + transport.TransportId;
            RecTMVehicle vehObj = null;
            RecTMStack stackObj = null;
            RecTMTransport transpObj = null;
            if( dic.ContainsKey( transpKey ) )
            {
                transpObj = dic[transpKey];
            }
            else
            {
                transpObj = new RecTMTransport();
                dic.Add( transpKey, transpObj );
                tmList.Add( transpObj );
            }
            transpObj.TransportObject = transport;

            bool isVehicleMode = vehicle.VehicleId != 0;
            if( isVehicleMode || transpObj.Vehicles.Count > 0 )
            {
                vehObj = transpObj.FindVehicle( vehicle );
                if( vehObj == null )
                {
                    vehObj = new RecTMVehicle();
                    transpObj.AddVehicle( vehObj );
                }
                vehObj.TransportVehicleStdObject = vehicle;
                if( stack.StackId != 0 )
                {
                    stackObj = vehObj.FindStack( stack );
                    if( stackObj == null )
                    {
                        stackObj = new RecTMStack();
                        vehObj.AddStack( stackObj );
                    }
                    stackObj.TransportVehicleStackStdObject = stack;
                    // To be revised!!!!!!!!!!! rackObj.TransportVehicleStackStdObject = stack;
                }
            }
            // Save the element if we do have an element
            if( elem.ElementId > 0 )
            {
                if( stackObj != null )
                {
                    stackObj.TMElements.Add( elem );
                }
                else if( vehObj != null )
                {
                    vehObj.TMElements.Add( elem );
                }
                else
                {
                    transpObj.TMElements.Add( elem );
                }
            }
        }
Пример #15
0
		public void Save( RecTransport transport, int seq )
		{
			// Save the transport object;
			SaveTransportVehicle( transport, seq );

			// Vehicle transport Mode, saves vehicle objects and elements on them
			foreach( TMStack stack in Stacks )
			{
				stack.Save( transport, TransportVehicleStdObject, seq );
				seq++;
			}
		}
Пример #16
0
        /// <summary>
        /// Sets element no status
        /// </summary>
        /// <param name="rec"></param>
        /// <returns></returns>
        private int SaveElementTransportNoStatus( RecTransport rec, List<RecElementIdStatusStd> settings )
        {
            int produced = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, 4 ).StatusId;
            int notProduced = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, 3 ).StatusId;
            int readyForProduction = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, 2 ).StatusId;
            int notReadyForProduction = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, 1 ).StatusId;

            switch( ImpactDatabase.DataSource )
            {
                case DataSource.SqlServer:
                case DataSource.SqlServerExpress:
                {
                    string statement = string.Format( @"
                        UPDATE PLN
                        SET
                        PLN.ELEMENT_ID_STATUS =
                        ( CASE 
                          WHEN (PLN.CAST_ID > 0 AND PLN.PRODUCTION_DATE is  not null ) THEN {0}
                          WHEN (PLN.CAST_ID > 0) THEN {1}
                          WHEN (GEO.READY_FOR_PRODUCTION > 0) THEN {2}
                          ELSE {3}
                          END
                        )
                        FROM IMP_MODEL_PLANNING PLN
                        INNER JOIN IMP_MODEL_GEOMETRY GEO ON
                           PLN.FACTORY = GEO.FACTORY AND
                           PLN.PROJECT = GEO.PROJECT AND
                           PLN.ELEMENT_ID = GEO.ELEMENT_ID
                        WHERE 
                        PLN.TRANSPORT_ID =  {4} AND
                        PLN.FACTORY = '{5}' AND
                        PLN.PROJECT = '{6}' 
                        ", produced, notProduced, readyForProduction, notReadyForProduction, rec.TransportId, rec.Factory, rec.Project );

                    int result;

                    using( ImpactDatabase database = new ImpactDatabase() )
                    {
                        result = database.ExecuteNonQuery( statement );
                    }
                    return result;
                }
                case DataSource.Ingres92:
                case DataSource.Ingres100:
                {
                    int result = 0;
                    List<StatusDataHolder> list = LoadElementStatusData( rec.Factory, rec.Project, 0, rec.TransportId, true );
                    if( null == list || list.Count == 0 )
                    {
                        return 0;
                    }
                    foreach( StatusDataHolder data in list )
                    {
                        int idStatus = 0;
                        if( data.CastId > 0 && data.ProductionDate != null )
                        {
                            idStatus = produced;
                        }
                        else if( data.CastId > 0 )
                        {
                            idStatus = notProduced;
                        }
                        else if( 1 == data.ReadyForProduction )
                        {
                            idStatus = readyForProduction;
                        }
                        else
                        {
                            idStatus = notReadyForProduction;
                        }

                        result = UpdateElementStatus( data.Factory, data.Project, data.ElementId, idStatus );
                    }
                    return result;
                }
            }
            return 0;
        }
Пример #17
0
        /// <summary> 
        /// Creates a new record if the desired record is not yet created 
        /// and updates the desired record.
        /// </summary>
        /// <param name="rec">RecTransportPlanner</param>
        public int SaveElementTransportStatus( RecTransport rec, List<RecElementIdStatusStd> settings )
        {
            if( rec == null || rec.Factory == null || rec.Project == null || rec.TransportId == 0 )
            {
                return 0;
            }
            bool isValidElementIdStatus = rec.ElementIdStatus != -1;
            bool noStatus = rec.TransportStatus == (int)TransportStatus.NoStatus;
            int result = 0;
            if( noStatus )
            {
                result = SaveElementTransportNoStatus( rec, settings );
            }

            // Now update the element with transport information
            ImpactUpdate update = new ImpactUpdate( ImpModelPlanning.Instance )
            {
                Columns =
                {
                    //{ ImpTransport.TransportStatus, record.TransportStatus },
                },
                Where =
				{
					ImpModelPlanning.Factory.Equal( rec.Factory ),
					ImpModelPlanning.Project.Equal( rec.Project ),
					ImpModelPlanning.TransportId.Equal( rec.TransportId ),
				}
            };

            if( noStatus )
            {
                if( rec.ClearDeliveryDate )
                {
                    update.Columns.Add( ImpModelPlanning.DeliveryDate, null );
                }
                if( rec.ClearPlannedDeliveryDate )
                {
                    update.Columns.Add( ImpModelPlanning.PlannedDeliveryDate, null );
                }
            }
            else if( rec.TransportStatus == (int)TransportStatus.Planned )
            {
                if( rec.UpdateElementStatus && isValidElementIdStatus )
                {
                    update.Columns.Add( ImpModelPlanning.ElementIdStatus, rec.ElementIdStatus );
                }
                if( rec.UpdateDeliveryDate && rec.DeliveryDate != null )
                {
                    //update.Columns.Add( ImpModelPlanning.DeliveryDate, rec.DeliveryDate );
                    update.Columns.Add( ImpModelPlanning.PlannedDeliveryDate, rec.DeliveryDate );
                }
            }
            else if( rec.TransportStatus == (int)TransportStatus.CallOff )
            {
                if( rec.UpdateElementStatus && isValidElementIdStatus )
                {
                    update.Columns.Add( ImpModelPlanning.ElementIdStatus, rec.ElementIdStatus );
                }
            }
            else if( rec.TransportStatus == (int)TransportStatus.Delivered )
            {
                if( rec.UpdateElementStatus && isValidElementIdStatus )
                {
                    update.Columns.Add( ImpModelPlanning.ElementIdStatus, rec.ElementIdStatus );
                }
                if( rec.UpdateDeliveryDate && rec.DeliveryDate != null )
                {
                    update.Columns.Add( ImpModelPlanning.DeliveryDate, rec.DeliveryDate );
                }
            }

            if( update.Columns.Count == 0 )
            {
                return 0; // Nothing to update
            }

            string sql = update.ToString();

            using( ImpactDatabase database = new ImpactDatabase() )
            {
                result += database.ExecuteNonQuery( sql );
            }
            return result;
        }
Пример #18
0
		public TMTransport( RecTransport transport )
		{
			IsFull = false;
			TransportObject = transport;
		}
Пример #19
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;
		}
Пример #20
0
		public void Save( RecTransport transport, RecTransportVehicleStd recVeh, int seq )
		{
			//Rack transport Mode, saves vehicle objects and elements on them
			//TransportVehicleStackStdObject.Save(_transport);


			//// Save the stack object;
			SaveTransportVehicleStack( transport, recVeh, seq );

			// Save elements
			SimpleSave( transport, recVeh );

		}
Пример #21
0
        /// <summary>
        /// Delete Cascade Stack
        /// </summary>
        /// <param name="transport"></param>
        /// <param name="veh"></param>
        /// <param name="stack"></param>
        /// <returns></returns>
		public int DeleteCascadeStackTransport( RecTransport transport, RecTransportVehicleStd veh, RecTransportStack stack )
		{
            ProjectManager mgr = new ProjectManager();
            RecElementIdStatusStd std = new RecElementIdStatusStd { Factory = transport.Factory, Project = transport.Project };
            List<RecElementIdStatusStd> settings = mgr.LoadStandardSettings( std );

            // Update Status, Note this can be optimized!
            RecTransport recTransportStatus = new RecTransport( transport );
            recTransportStatus.TransportStatus = (int)TransportStatus.NoStatus;
            recTransportStatus.ElementIdStatus = RecElementIdStatusStd.GetLocalSettingFromGlobalId( settings, recTransportStatus.TransportStatus).StatusId;
            UpdateStatus( transport, recTransportStatus, settings );
            // No reset
			ModelPlanner svc = new ModelPlanner();
			svc.ResetTransport( transport.Factory, transport.Project, 0, transport.TransportId, veh.VehicleId, stack.StackId );

			ProjectManager StackSvc = new ProjectManager();
			return StackSvc.DeleteTransportStack( stack );
		}
		/// <summary>
		///  Insert of Transport Vehicle Standard items
		/// </summary>
		/// <param name="rec"></param>
		/// <param name="list"></param>
		/// <returns></returns>
		public List<RecTransportVehicleStd> InsertTransportVehicles( RecTransport rec, List<RecTransportVehicleStd> list )
		{
			if( rec == null || list == null || list.Count == 0 )
			{
				return null;
			}
			List<RecTransportVehicleStd> res = new List<RecTransportVehicleStd>();
			int seq = 1;
			foreach( RecTransportVehicleStd vehicle in list )
			{
				res.Add( InsertTransportVehicle( rec, vehicle, seq ) );
				seq++;
			}

			return res;
		}
Пример #23
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;
		}
		/// <summary>
		/// Insert of Transport Vehicle Standard items
		/// </summary>
		/// <param name="rec"></param>
		/// <param name="vehicle"></param>
		/// <param name="seq"></param>
		/// <returns></returns>
		public RecTransportVehicleStd InsertTransportVehicle( RecTransport rec, RecTransportVehicleStd vehicle, int seq )
		{
			if( rec == null || rec.Factory == null || rec.Project == null )
			{
				throw new ArgumentNullException( "Transport" );
			}
			string project = "";
			if( rec.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = rec.Factory;
			}
			else
			{
				project = rec.Project;
			}
			RecTransportVehicleStd res = new RecTransportVehicleStd( vehicle );
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				// 1. Instantiate a new command with a query and connection
				ProjectManager ng = new ProjectManager();
				int vehicleId = ng.GetNextNumber( rec.Factory, rec.Project, RecNumberGenerator.NG_VEHICLE_ID );

				string sql = "Insert into IMP_TRANSPORT_VEHICLE(FACTORY,PROJECT,TRANSPORT_ID,VEHICLE_ID,VEHICLE,VEHICLE_SEQUENCE_NO,TRANSPORT_TYPE)values("
										+ Conv.Sql( rec.Factory ) + ","
										+ Conv.Sql( project ) + "," //Templates are saved on factory level (factory, factory), 2012-04-23
										+ Conv.Sql( rec.TransportId ) + ","
										+ Conv.Sql( vehicleId ) + ","
										+ Conv.Sql( vehicle.Name ) + ","
										+ Conv.Sql( seq ) + ","
										+ Conv.Sql( vehicle.TransportType )
										+ ")";

				database.ExecuteNonQuery( sql );

				res.VehicleId = vehicleId;
			}
			return res;
		}
Пример #25
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>
		/// Loading Transport Vehicle Standard items
		/// </summary>
		/// <param name="rec"></param>
		/// <returns></returns>
		public List<RecTransportVehicleStd> LoadTransportVehicles( RecTransport rec )
		{
			return LoadTransportVehiclesEx( rec, 0 );
		}
Пример #27
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>
		/// Loading Transport Vehicle Standard items
		/// </summary>
		/// <param name="rec"></param>
		/// <returns></returns>
		public List<RecTransportVehicleStd> LoadTransportVehiclesEx( RecTransport rec, int vehicleId )
		{
			if( rec == null || rec.Factory == null || rec.Project == null )
			{
				return null;
			}
			string project = "";
			if( rec.IsTemplate == 1 )
			{
				// Templates are saved on factory level (factory, factory), 2012-04-23
				project = rec.Factory;
			}
			else
			{
				project = rec.Project;
			}
			List<RecTransportVehicleStd> lst = new List<RecTransportVehicleStd>();
			using( ImpactDatabase database = new ImpactDatabase() )
			{
				// 1. Instantiate a new command with a query and connection
				string wcVehicle = "";
				if( vehicleId > 0 )
				{
					wcVehicle = " AND TSP.VEHICLE_ID=" + Conv.Sql( vehicleId );
				}
				string sql = "SELECT TSP.TRANSPORT_TYPE AS TSP_TRANSPORT_TYPE, TSP.VEHICLE_ID AS TSP_VEHICLE_ID, "
							+ "VEH.VEHICLE_TYPE, VEH.NAME, VEH.Description, VEH.Max_Length, VEH.Max_Width, VEH.Max_Height, VEH.Max_Mass"
							+ " FROM "
							+ "IMP_TRANSPORT_VEHICLE_STD VEH "
							+ "join IMP_TRANSPORT_VEHICLE TSP ON "
							+ "VEH.FACTORY = TSP.FACTORY "
							+ "AND VEH.PROJECT = TSP.FACTORY "// Factory, Factory only so far!!!
							+ "AND VEH.NAME = TSP.VEHICLE "
							+ "Where "
							+ "TSP.FACTORY=" + Conv.Sql( rec.Factory ) + " AND "
							+ "TSP.PROJECT=" + Conv.Sql( project ) + " AND " // Templates are saved on factory level (factory, factory), 2012-04-23
							+ "TSP.TRANSPORT_ID=" + Conv.Sql( rec.TransportId )
							+ wcVehicle
							+ " Order By TSP.VEHICLE_SEQUENCE_NO";

				lst = database.GetAll( sql, column => new RecTransportVehicleStd()
				{
					TransportType = DataConverter.Cast<int>( column[0] ),
					VehicleId = DataConverter.Cast<int>( column[1] ),
					VehicleType = DataConverter.Cast<int>( column[2] ),


					Name = DataConverter.Cast<string>( column[3] ),
					Description = DataConverter.Cast<string>( column[4] ),
					MaxLength = DataConverter.Cast<double>( column[5] ),
					MaxWidth = DataConverter.Cast<double>( column[6] ),
					MaxHeight = DataConverter.Cast<double>( column[7] ),
					MaxMass = DataConverter.Cast<double>( column[8] ),

					// Make life easier for the client
					TransportId = rec.TransportId,
					Factory = rec.Factory,
					Project = rec.Project,
				} );
			}
			return lst;
		}