Ejemplo n.º 1
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;
		}
Ejemplo n.º 2
0
		/// <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 RecProductionCast InsertProductionCast( RecProductionCast record )
		{
            // Get new sequence
			ProjectManager ng = new ProjectManager();
			string company = ProjectManager.GetCompany( record.Factory );
			int castId = ng.GetNextNumber( company, company, RecNumberGenerator.CMP_NG_CAST_ID );

			var insert = new ImpactInsert( ImpProductionCast.Instance )
			{
				Columns = 
				{
					{ ImpProductionCast.Factory, record.Factory },
					{ ImpProductionCast.Project, record.Factory }, // Factory, Factory for productionCast
					{ ImpProductionCast.CastId, castId }, //Sequence
					{ ImpProductionCast.CastType, record.CastType },
					{ ImpProductionCast.Description, record.Description },
					{ ImpProductionCast.Shift, record.Shift },
					{ ImpProductionCast.StartDate, record.StartDate },
					{ ImpProductionCast.EndDate, record.EndDate },
					{ ImpProductionCast.Form, record.Form },
					{ ImpProductionCast.Tolerance, record.Tolerance },
					{ ImpProductionCast.ElementType, record.ElementType },
					{ ImpProductionCast.Style, record.Style },
					{ ImpProductionCast.Strandptn, record.Strandptn },
					{ ImpProductionCast.CastStatus, record.CastStatus },
					{ ImpProductionCast.CastDivision, record.CastDivision },
				}
			};

			string statement = insert.ToString();

			int result;

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

            // Copy strands from template (form)
            if (!string.IsNullOrWhiteSpace(record.Form))
            {
                record.CastId = castId;
                ProjectManager svc = new ProjectManager( );
                svc.CopyStrandsFromTemplate( record );
            }

			return record;
		}
		/// <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;
		}
		/// <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 InsertTransportVehicleStackStd( RecTransportVehicleStackStd record )
		{
			ProjectManager ng = new ProjectManager();
			string company = ProjectManager.GetCompany( record.Factory );
			record.StackId = ng.GetNextNumber( company, company, RecNumberGenerator.CMP_NG_STACK_ID );

			var insert = new ImpactInsert( ImpTransportVehicleStackStd.Instance )
			{
				Columns = 
				{
					{ ImpTransportVehicleStackStd.Factory, record.Factory },
					{ ImpTransportVehicleStackStd.Project, record.Factory }, //Std use, Factory, Factory
					{ ImpTransportVehicleStackStd.Name, record.Name },
					{ ImpTransportVehicleStackStd.StackId, record.StackId },
					{ ImpTransportVehicleStackStd.Rack, record.Rack },
					{ ImpTransportVehicleStackStd.StackPosition, record.StackPosition },
					{ ImpTransportVehicleStackStd.StackX, record.StackX },
					{ ImpTransportVehicleStackStd.StackY, record.StackY },
					{ ImpTransportVehicleStackStd.StackZ, record.StackZ },
					{ ImpTransportVehicleStackStd.StackRotation, record.StackRotation },
					{ ImpTransportVehicleStackStd.Description, record.Description },
					{ ImpTransportVehicleStackStd.StackType, record.StackType },
					{ ImpTransportVehicleStackStd.MaxLength, record.MaxLength },
					{ ImpTransportVehicleStackStd.MaxWidth, record.MaxWidth },
					{ ImpTransportVehicleStackStd.MaxHeight, record.MaxHeight },
					{ ImpTransportVehicleStackStd.MaxMass, record.MaxMass },
				}
			};

			string statement = insert.ToString();

			int result;

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

			return result;
		}