Exemple #1
0
		/// <summary>
		/// Load information
		/// </summary>
		public MethodResult loadFields ()
		{
			MethodResult	result	= new MethodResult ();
			Database		parent	= getParent ();

			// Check Connection
			if (null == parent)
			{
				throw new NullReferenceException ("Parent is null!");
				result.status	= MethodResult.Result.failed;
			}
			else
			{
				// Server ready?
				if (!BaseDAL.DBaseHelper.IsServerConnected (parent.getConnection ()))
					result.status	= MethodResult.Result.failed;
				else
				{
					if (fields == null)
						fields = new List<Field> ();	// Create new instance
					else
						clearFields ();					// Clear current tables list

				#region Load tables information
					// Generate command
					string	cmd	= string.Format (Resources.Table.GetFields, parent.getName (), getName ());

					// Run
					CommandResult	dRes	= BaseDAL.DBaseHelper.executeCommand (BaseDAL.Base.EnumExecuteType.reader, parent.getConnection (), cmd, true);

					if (dRes.status == BaseDAL.Base.EnumCommandStatus.success)
					{
						if (dRes.model is DataTable)
						{
							DataTable	table	= dRes.model as DataTable;

							foreach (DataRow row in table.Rows)
							{
								string	fieldName;
								Field	field;

								fieldName	= row["COLUMN_NAME"].ToString ();
								field		= new Field (this, fieldName, getAutoload ());
								fields.Add (field);
							}
						}

						result.status	= MethodResult.Result.success;
					}
					else
						result.status	= MethodResult.Result.failed;
				#endregion
				}
			}

			return result;
		}
Exemple #2
0
		/// <summary>
		/// Load Field Referntial Information
		/// </summary>
		public MethodResult loadReferentialInformation ()
		{
			MethodResult	result	= new MethodResult ();

			Database	dbase;
			Table		table		= getParent ();
			string		fieldName	= getName ();

			if (null != table)
				dbase	= table.getParent ();
			else
				dbase	= null;

			if ((table == null) || (dbase == null))
			{
				throw new NullReferenceException ("Table or Database is null");
				result.status	= MethodResult.Result.failed;
			}
			else
			{
				dbase	= table.getParent ();

				// Server ready?
				if (!BaseDAL.DBaseHelper.IsServerConnected (dbase.getConnection ()))
					result.status	= MethodResult.Result.failed;
				else
				{
					string	cmd	= Resources.Field.GetReferentialInformation;
					
					// Clear last information
					if (null != referentialColumn)
						referentialColumn.Clear ();
					else
						referentialColumn	= new List<ForeignKeyModel> ();

					// Prepare command
					cmd	= string.Format (cmd, dbase.getName (), table.getName (), fieldName);
				
					// Run
					CommandResult	dRes	= BaseDAL.DBaseHelper.executeCommand (BaseDAL.Base.EnumExecuteType.reader, dbase.getConnection (), cmd, true);

					if (dRes.status == BaseDAL.Base.EnumCommandStatus.success)
					{
						if (dRes.model is DataTable)
						{
							DataTable	resTable	= dRes.model as DataTable;

							if (resTable.Rows.Count > 0)
								foreach (DataRow row in resTable.Rows)
									referentialColumn.Add (
										new ForeignKeyModel (row["primaryTable"].ToString (), row["primaryColumn"].ToString (), row["foreignTable"].ToString (), row["foreignColumn"].ToString ())
										);
						}

						result.status	= MethodResult.Result.success;
					}
					else
						result.status	= MethodResult.Result.failed;
				}
			}

			return result;
		}
Exemple #3
0
		/// <summary>
		/// Load information
		/// </summary>
		public MethodResult loadTables ()
		{
			MethodResult	result		= new MethodResult ();
			SqlConnection	connection	= getConnection ();

			// Check Connection
			if (null == connection)
				result.status	= MethodResult.Result.failed;
			else
			{
				// Server ready?
				if (!BaseDAL.DBaseHelper.IsServerConnected (connection))
					result.status	= MethodResult.Result.failed;
				else
				{
					if (null == tables)
						tables	= new List<Table> ();	// Create new instance of list
					else
						clearTables ();					// Clear current tables list

				#region Load tables information
					// Generate command
					string	cmd	= string.Format (Resources.Database.GetTables, getName ());

					// Run
					CommandResult	dRes	= BaseDAL.DBaseHelper.executeCommand (BaseDAL.Base.EnumExecuteType.reader, connection, cmd, true);

					if (dRes.status == BaseDAL.Base.EnumCommandStatus.success)
					{
						if (dRes.model is DataTable)
						{
							DataTable	table	= dRes.model as DataTable;

							foreach (DataRow row in table.Rows)
							{
								string	tableName;
								Table	newTable;

								tableName	= row["TABLE_NAME"].ToString ();
								newTable	= new Table (this, tableName, getAutoload ());
								tables.Add (newTable);
							}
						}

						result.status	= MethodResult.Result.success;
					}
					else
						result.status	= MethodResult.Result.failed;
				#endregion
				}
			}

			return result;
		}
Exemple #4
0
		/// <summary>
		/// Load Field Information
		/// </summary>
		public MethodResult loadInformation ()
		{
			MethodResult	result	= new MethodResult ();

			Database	dbase;
			Table		table		= getParent ();
			string		fieldName	= getName ();

			if (null != table)
				dbase	= table.getParent ();
			else
				dbase	= null;

			if ((table == null) || (dbase == null))
			{
				throw new NullReferenceException ("Table or Database is null");
				result.status	= MethodResult.Result.failed;
			}
			else
			{
				dbase	= table.getParent ();

				// Server ready?
				if (!BaseDAL.DBaseHelper.IsServerConnected (dbase.getConnection ()))
					result.status	= MethodResult.Result.failed;
				else
				{
					string	cmd	= Resources.Field.GetInformation;

					// Clear old properties
					if (getProperties () == null)
						setProperties (new Dictionary<string, object>());
					else
						getProperties ().Clear ();

					// Prepare command
					cmd	= string.Format (cmd, dbase.getName (), table.getName (), fieldName);
				
					// Run
					CommandResult	dRes	= BaseDAL.DBaseHelper.executeCommand (BaseDAL.Base.EnumExecuteType.reader, dbase.getConnection (), cmd, true);

					if (dRes.status == BaseDAL.Base.EnumCommandStatus.success)
					{
						if (dRes.model is DataTable)
						{
							DataTable	resTable	= dRes.model as DataTable;

							if (resTable.Rows.Count > 0)
								foreach (DataColumn col in resTable.Columns)
									getProperties ().Add (col.ColumnName, resTable.Rows[0][col.ColumnName]);
						}

						result.status	= MethodResult.Result.success;
					}
					else
						result.status	= MethodResult.Result.failed;
				}
			}

			return result;
		}