Example #1
0
//		#endregion
		#region private static void relate(...);
		private static void relate(
			long[] idTags_in,
			long[] idAuthors_in,
			long[] idSources_in,
			long[] idHighlights_in, 
			long[] idProfiles_in, 

			long idContent_in,

			DBConnection con_in
		) {
			#region Tags . . .
			foreach (int _idtag in idTags_in) {
				DO_NWS_ContentTag.setObject(
					new SO_NWS_ContentTag(
						idContent_in,
						_idtag
					),
					true,

					con_in
				);
			}
			#endregion
			#region Authors . . .
			foreach (int _idauthor in idAuthors_in) {
				DO_NWS_ContentAuthor.setObject(
					new SO_NWS_ContentAuthor(
						idContent_in,
						_idauthor
					),
					true,

					con_in
				);
			}
			#endregion
			#region Sources . . .
			foreach (int _idsource in idSources_in) {
				DO_NWS_ContentSource.setObject(
					new SO_NWS_ContentSource(
						idContent_in,
						_idsource
					),
					true,

					con_in
				);
			}
			#endregion
			#region Highlights . . .
			foreach (int _idhighlight in idHighlights_in) {
				SO_NWS_ContentHighlight _highlight 
					= new SO_NWS_ContentHighlight(
						idContent_in,
						_idhighlight, 
						datetime_minvalue_, 
						datetime_minvalue_
					);
				_highlight.Begin_date_isNull = true;
				_highlight.End_date_isNull = true;

				DO_NWS_ContentHighlight.setObject(
					_highlight,
					true,

					con_in
				);
			}
			#endregion
			#region Profiles . . .
			foreach (int _idprofile in idProfiles_in) {
				DO_NWS_ContentProfile.setObject(
					new SO_NWS_ContentProfile(
						idContent_in,
						_idprofile
					),
					true,

					con_in
				);
			}
			#endregion
		} 
		public static DataTable getDataTable(
			SO_NWS_ContentHighlight[] serializableObjects_in
		) {
			DataTable _output = new DataTable();
			_output.Locale = System.Globalization.CultureInfo.CurrentCulture;
			DataRow _dr;

			DataColumn _dc_ifcontent = new DataColumn("IFContent", typeof(long));
			_output.Columns.Add(_dc_ifcontent);
			DataColumn _dc_ifhighlight = new DataColumn("IFHighlight", typeof(long));
			_output.Columns.Add(_dc_ifhighlight);
			DataColumn _dc_begin_date = new DataColumn("Begin_date", typeof(DateTime));
			_output.Columns.Add(_dc_begin_date);
			DataColumn _dc_end_date = new DataColumn("End_date", typeof(DateTime));
			_output.Columns.Add(_dc_end_date);

			foreach (SO_NWS_ContentHighlight _serializableObject in serializableObjects_in) {
				_dr = _output.NewRow();

				_dr[_dc_ifcontent] = _serializableObject.IFContent;
				_dr[_dc_ifhighlight] = _serializableObject.IFHighlight;
				_dr[_dc_begin_date] = _serializableObject.Begin_date;
				_dr[_dc_end_date] = _serializableObject.End_date;

				_output.Rows.Add(_dr);
			}

			return _output;
		}
		/// <summary>
		/// Selects NWS_ContentHighlight values from Database and assigns them to the appropriate DO_NWS_ContentHighlight property.
		/// </summary>
		/// <param name="IFContent_in">IFContent</param>
		/// <param name="IFHighlight_in">IFHighlight</param>
		/// <param name="dbConnection_in">Database connection, making the use of Database Transactions possible on a sequence of operations across the same or multiple DataObjects</param>
		/// <returns>null if NWS_ContentHighlight doesn't exists at Database</returns>
		public static SO_NWS_ContentHighlight getObject(
			long IFContent_in, 
			long IFHighlight_in, 
			DBConnection dbConnection_in
		) {
			SO_NWS_ContentHighlight _output = null;

			DBConnection _connection = (dbConnection_in == null)
				? DO__Utilities.DBConnection_createInstance(
					DO__Utilities.DBServerType,
					DO__Utilities.DBConnectionstring,
					DO__Utilities.DBLogfile
				) 
				: dbConnection_in;
			IDbDataParameter[] _dataparameters = new IDbDataParameter[] {
				_connection.newDBDataParameter("IFContent_", DbType.Int64, ParameterDirection.InputOutput, IFContent_in, 0), 
				_connection.newDBDataParameter("IFHighlight_", DbType.Int64, ParameterDirection.InputOutput, IFHighlight_in, 0), 
				_connection.newDBDataParameter("Begin_date_", DbType.DateTime, ParameterDirection.Output, null, 0), 
				_connection.newDBDataParameter("End_date_", DbType.DateTime, ParameterDirection.Output, null, 0)
			};
			_connection.Execute_SQLFunction("sp0_NWS_ContentHighlight_getObject", _dataparameters);
			if (dbConnection_in == null) { _connection.Dispose(); }

			if (_dataparameters[0].Value != DBNull.Value) {
				_output = new SO_NWS_ContentHighlight();

				if (_dataparameters[0].Value == System.DBNull.Value) {
					_output.IFContent = 0L;
				} else {
					_output.IFContent = (long)_dataparameters[0].Value;
				}
				if (_dataparameters[1].Value == System.DBNull.Value) {
					_output.IFHighlight = 0L;
				} else {
					_output.IFHighlight = (long)_dataparameters[1].Value;
				}
				if (_dataparameters[2].Value == System.DBNull.Value) {
					_output.Begin_date_isNull = true;
				} else {
					_output.Begin_date = (DateTime)_dataparameters[2].Value;
				}
				if (_dataparameters[3].Value == System.DBNull.Value) {
					_output.End_date_isNull = true;
				} else {
					_output.End_date = (DateTime)_dataparameters[3].Value;
				}

				_output.HasChanges = false;
				return _output;
			}

			return null;
		}
		private static SO_NWS_ContentHighlight[] getRecord(
			DataTable dataTable_in
		) {
			DataColumn _dc_ifcontent = null;
			DataColumn _dc_ifhighlight = null;
			DataColumn _dc_begin_date = null;
			DataColumn _dc_end_date = null;

			SO_NWS_ContentHighlight[] _output 
				= new SO_NWS_ContentHighlight[dataTable_in.Rows.Count];
			for (int r = 0; r < dataTable_in.Rows.Count; r++) {
				if (r == 0) {
					_dc_ifcontent = dataTable_in.Columns["IFContent"];
					_dc_ifhighlight = dataTable_in.Columns["IFHighlight"];
					_dc_begin_date = dataTable_in.Columns["Begin_date"];
					_dc_end_date = dataTable_in.Columns["End_date"];
				}

				_output[r] = new SO_NWS_ContentHighlight();
				if (dataTable_in.Rows[r][_dc_ifcontent] == System.DBNull.Value) {
					_output[r].IFContent = 0L;
				} else {
					_output[r].IFContent = (long)dataTable_in.Rows[r][_dc_ifcontent];
				}
				if (dataTable_in.Rows[r][_dc_ifhighlight] == System.DBNull.Value) {
					_output[r].IFHighlight = 0L;
				} else {
					_output[r].IFHighlight = (long)dataTable_in.Rows[r][_dc_ifhighlight];
				}
				if (dataTable_in.Rows[r][_dc_begin_date] == System.DBNull.Value) {
					_output[r].Begin_date_isNull = true;
				} else {
					_output[r].Begin_date = (DateTime)dataTable_in.Rows[r][_dc_begin_date];
				}
				if (dataTable_in.Rows[r][_dc_end_date] == System.DBNull.Value) {
					_output[r].End_date_isNull = true;
				} else {
					_output[r].End_date = (DateTime)dataTable_in.Rows[r][_dc_end_date];
				}

				_output[r].HasChanges = false;
			}

			return _output;
		}
		/// <summary>
		/// Inserts/Updates NWS_ContentHighlight values into/on Database. Inserts if NWS_ContentHighlight doesn't exist or Updates if NWS_ContentHighlight already exists.
		/// </summary>
		/// <param name="forceUpdate_in">assign with True if you wish to force an Update (even if no changes have been made since last time getObject method was run) and False if not</param>
		/// <param name="dbConnection_in">Database connection, making the use of Database Transactions possible on a sequence of operations across the same or multiple DataObjects</param>
		/// <returns>True if it didn't exist (INSERT), and False if it did exist (UPDATE)</returns>
		public static bool setObject(
			SO_NWS_ContentHighlight NWS_ContentHighlight_in, 
			bool forceUpdate_in, 
			DBConnection dbConnection_in
		) {
			bool ConstraintExist_out;
			if (forceUpdate_in || NWS_ContentHighlight_in.HasChanges) {
				DBConnection _connection = (dbConnection_in == null)
					? DO__Utilities.DBConnection_createInstance(
						DO__Utilities.DBServerType,
						DO__Utilities.DBConnectionstring,
						DO__Utilities.DBLogfile
					) 
					: dbConnection_in;
				IDbDataParameter[] _dataparameters = new IDbDataParameter[] {
					_connection.newDBDataParameter("IFContent_", DbType.Int64, ParameterDirection.Input, NWS_ContentHighlight_in.IFContent, 0), 
					_connection.newDBDataParameter("IFHighlight_", DbType.Int64, ParameterDirection.Input, NWS_ContentHighlight_in.IFHighlight, 0), 
					_connection.newDBDataParameter("Begin_date_", DbType.DateTime, ParameterDirection.Input, NWS_ContentHighlight_in.Begin_date_isNull ? null : (object)NWS_ContentHighlight_in.Begin_date, 0), 
					_connection.newDBDataParameter("End_date_", DbType.DateTime, ParameterDirection.Input, NWS_ContentHighlight_in.End_date_isNull ? null : (object)NWS_ContentHighlight_in.End_date, 0), 

					//_connection.newDBDataParameter("Exists", DbType.Boolean, ParameterDirection.Output, 0, 1)
					_connection.newDBDataParameter("Output_", DbType.Int32, ParameterDirection.Output, null, 0)
				};
				_connection.Execute_SQLFunction(
					"sp0_NWS_ContentHighlight_setObject", 
					_dataparameters
				);
				if (dbConnection_in == null) { _connection.Dispose(); }

				ConstraintExist_out = (((int)_dataparameters[4].Value & 2) == 1);
				if (!ConstraintExist_out) {
					NWS_ContentHighlight_in.HasChanges = false;
				}

				return (((int)_dataparameters[4].Value & 1) != 1);
			} else {
				ConstraintExist_out = false;

				return  false;
			}
		}
		/// <summary>
		/// Inserts/Updates NWS_ContentHighlight values into/on Database. Inserts if NWS_ContentHighlight doesn't exist or Updates if NWS_ContentHighlight already exists.
		/// </summary>
		/// <param name="forceUpdate_in">assign with True if you wish to force an Update (even if no changes have been made since last time getObject method was run) and False if not</param>
		/// <returns>True if it didn't exist (INSERT), and False if it did exist (UPDATE)</returns>
		public static bool setObject(
			SO_NWS_ContentHighlight NWS_ContentHighlight_in, 
			bool forceUpdate_in
		) {
			return setObject(
				NWS_ContentHighlight_in, 
				forceUpdate_in, 
				null
			);
		}