Пример #1
0
 private void AppendRegionGetFriendlyName()
 {
     sb.AppendLine("		/// <summary>");
     sb.AppendLine("		/// Gets the friendly name (if one is defined) of the field.");
     sb.AppendLine("		/// </summary>");
     sb.AppendLine("		public static string GetFriendlyName(FieldNameConstants field)");
     sb.AppendLine("		{");
     sb.AppendLine("			switch (field)");
     sb.AppendLine("			{");
     foreach (Reference reference in _currentView.Columns)
     {
         CustomViewColumn column = (CustomViewColumn)reference.Object;
         if (column.Generated)
         {
             sb.AppendLine("				case FieldNameConstants."+ column.PascalName + ":");
             sb.AppendLine("					return \""+ column.FriendlyName + "\";");
         }
     }
     sb.AppendLine("			}");
     sb.AppendLine("			return \"\";");
     sb.AppendLine("		}");
     sb.AppendLine();
     sb.AppendLine("		string IBusinessObject.GetFriendlyName(Enum field)");
     sb.AppendLine("		{");
     sb.AppendLine("			return GetFriendlyName((FieldNameConstants)field);");
     sb.AppendLine("		}");
     sb.AppendLine();
 }
Пример #2
0
 private void AppendRegionGetMaxLength()
 {
     sb.AppendLine("		/// <summary>");
     sb.AppendLine("		/// Gets the maximum size of the field value.");
     sb.AppendLine("		/// </summary>");
     sb.AppendLine("		public static int GetMaxLength(FieldNameConstants field)");
     sb.AppendLine("		{");
     sb.AppendLine("			switch (field)");
     sb.AppendLine("			{");
     foreach (Reference reference in _currentView.Columns)
     {
         CustomViewColumn column = (CustomViewColumn)reference.Object;
         if (column.Generated)
         {
             sb.AppendLine("				case FieldNameConstants."+ column.PascalName + ":");
             if (ModelHelper.IsTextType(column.DataType))
             {
                 sb.AppendLine("					return "+ column.Length + ";");
             }
             else
             {
                 sb.AppendLine("					return 0;");
             }
         }
     }
     sb.AppendLine("			}");
     sb.AppendLine("			return 0;");
     sb.AppendLine("		}");
     sb.AppendLine();
     sb.AppendLine("		int IBusinessObject.GetMaxLength(Enum field)");
     sb.AppendLine("		{");
     sb.AppendLine("			return GetMaxLength((FieldNameConstants)field);");
     sb.AppendLine("		}");
     sb.AppendLine();
 }
Пример #3
0
 public ArrayList GetValidSearchColumns()
 {
     try
     {
         ArrayList validColumns = new ArrayList();
         foreach (Reference reference in _currentView.GeneratedColumns)
         {
             CustomViewColumn dc = (CustomViewColumn)reference.Object;
             if (!(dc.DataType == System.Data.SqlDbType.Binary ||
                   dc.DataType == System.Data.SqlDbType.Image ||
                   dc.DataType == System.Data.SqlDbType.NText ||
                   dc.DataType == System.Data.SqlDbType.Text ||
                   dc.DataType == System.Data.SqlDbType.Timestamp ||
                   dc.DataType == System.Data.SqlDbType.Udt ||
                   dc.DataType == System.Data.SqlDbType.VarBinary ||
                   dc.DataType == System.Data.SqlDbType.Variant ||
                   dc.DataType == System.Data.SqlDbType.Money))
             {
                 validColumns.Add(dc);
             }
         }
         return(validColumns);
     }
     catch (Exception ex)
     {
         throw new Exception(_currentView.PascalName + ": Failed on generation of select or template", ex);
     }
 }
Пример #4
0
        private void AppendRegionConstructors()
        {
            sb.AppendLine("		#region Contructors /Initialization");
            sb.AppendLine();
            sb.AppendLine("		internal Domain"+ _currentView.PascalName + "Collection():base(\"" + _currentView.PascalName + "\")");
            sb.AppendLine("		{");
            sb.AppendLine("			try");
            sb.AppendLine("			{");
            sb.AppendLine("				base.TableName = \""+ _currentView.PascalName + "Collection\";");
            sb.AppendLine("				this.InitClass();");
            sb.AppendLine("			}");
            Globals.AppendBusinessEntryCatch(sb);
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		private void InitClass() ");
            sb.AppendLine("		{");
            sb.AppendLine("			BeginInit();");

            //Create columns
            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn column = (CustomViewColumn)reference.Object;
                sb.AppendLine("			this.column"+ column.PascalName + " = new DataColumn(\"" + column.DatabaseName + "\", typeof(" + column.GetCodeType() + "), null, System.Data.MappingType.Element);");
                sb.AppendLine("			base.Columns.Add(this.column"+ column.PascalName + ");");
                sb.AppendLine("			this.column"+ column.PascalName + ".AllowDBNull = true;");
                sb.AppendLine("			this.column"+ column.PascalName + ".Caption = \"" + column.PascalName + "\";");
                sb.AppendLine("			this.column"+ column.PascalName + ".ReadOnly = true;");
            }

            sb.AppendLine("			EndInit();");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
        }
Пример #5
0
        private string GetPropertyNode(CustomViewColumn column)
        {
            var propertyString = new StringBuilder();

            //Attributes Name and Type
            propertyString.AppendFormat("		<Property Name=\"{0}\" Type=\"{1}\" ", column.PascalName, column.EFSqlCodeType());

            //Attribute Nullable
            propertyString.Append("Nullable=\"" + (column.AllowNull ? "true" : "false") + "\" ");

            //Attribute MaxLength
            if (!string.IsNullOrEmpty(column.EFGetCodeMaxLengthString()))
            {
                propertyString.AppendFormat("MaxLength=\"{0}\" ", column.EFGetCodeMaxLengthString());
            }

            //Attribute Precision Scale
            if (column.EFSupportsPrecision())
            {
                propertyString.AppendFormat("Precision=\"{0}\" Scale=\"{1}\" ", column.Length.ToString(), column.Scale);
            }

            //Attribute Unicode
            if (column.EFUnicode().HasValue)
            {
                var unicodeString = column.EFUnicode().Value ? "true" : "false";
                propertyString.AppendFormat("Unicode=\"{0}\" ", unicodeString);
            }

            //Attribute FixedLength
            if (column.EFIsFixedLength().HasValue)
            {
                var isFixedLengthString = column.EFIsFixedLength().Value ? "true" : "false";
                propertyString.AppendFormat("FixedLength=\"{0}\" ", isFixedLengthString);
            }

            //Primary Key

            /*
             * if (column.PrimaryKey)
             * {
             *      //propertyString.Append("xmlns:a=\"http://schemas.microsoft.com/ado/2006/04/codegeneration\" ");
             *      if (column.IsIntegerType && column.Identity == IdentityTypeConstants.Database)
             *      {
             *              //propertyString.Append("a:SetterAccess=\"Private\" DefaultValue=\"-1\" annotation:StoreGeneratedPattern=\"Identity\" ");
             *              propertyString.Append("DefaultValue=\"-1\" annotation:StoreGeneratedPattern=\"Identity\" ");
             *      }
             *      else
             *      {
             *              //propertyString.Append("a:SetterAccess=\"Public\" ");
             *      }
             * }
             */

            propertyString.Append("/>").AppendLine();
            return(propertyString.ToString());
        }
Пример #6
0
 private void AppendRegionDataColumnsSetup()
 {
     sb.AppendLine("		#region Data Columns Setup");
     foreach (Reference reference in _currentView.GeneratedColumns)
     {
         CustomViewColumn column = (CustomViewColumn)reference.Object;
         sb.AppendLine("		private DataColumn column"+ column.PascalName + ";");
         sb.AppendLine();
         sb.AppendLine("		[Widgetsphere.Core.Attributes.DataSetting(\"\", false, 0)]");
         sb.AppendLine("		public DataColumn "+ column.PascalName + "Column");
         sb.AppendLine("		{");
         sb.AppendLine("			get { return this.column"+ column.PascalName + "; }");
         sb.AppendLine("		}");
         sb.AppendLine();
     }
     sb.AppendLine("		#endregion");
     sb.AppendLine();
 }
Пример #7
0
        public static string BuildSelectList(CustomView view, ModelRoot model)
        {
            int           index  = 0;
            StringBuilder output = new StringBuilder();

            foreach (Reference columnRef in view.GeneratedColumns)
            {
                CustomViewColumn dc = (CustomViewColumn)columnRef.Object;
                output.Append("CONVERT(" + dc.DatabaseType + ", [view_" + view.DatabaseName + "].[" + dc.DatabaseName + "]) AS [" + dc.DatabaseName + "]");
                if (index < view.GeneratedColumns.Count - 1)
                {
                    output.Append(",");
                }
                output.AppendLine();
                index++;
            }
            return(output.ToString());
        }
        private ArrayList GetValidSearchColumns()
        {
            ArrayList validColumns = new ArrayList();

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dc = (CustomViewColumn)reference.Object;
                if (!(dc.DataType == System.Data.SqlDbType.Binary ||
                      dc.DataType == System.Data.SqlDbType.Image ||
                      dc.DataType == System.Data.SqlDbType.NText ||
                      dc.DataType == System.Data.SqlDbType.Text ||
                      dc.DataType == System.Data.SqlDbType.Timestamp ||
                      dc.DataType == System.Data.SqlDbType.Udt ||
                      dc.DataType == System.Data.SqlDbType.VarBinary ||
                      dc.DataType == System.Data.SqlDbType.Variant ||
                      dc.DataType == System.Data.SqlDbType.Money))
                {
                    validColumns.Add(dc);
                }
            }
            return(validColumns);
        }
Пример #9
0
 private void AppendRegionGetFieldLength()
 {
     sb.AppendLine("		#region GetFieldLength");
     sb.AppendLine();
     sb.AppendLine("		/// <summary>");
     sb.AppendLine("		/// Determines the length of the specified field if it can be set.");
     sb.AppendLine("		/// </summary>");
     sb.AppendLine("		public int GetFieldLength("+ _currentView.PascalName + ".FieldNameConstants field)");
     sb.AppendLine("		{");
     foreach (Reference colRef in _currentView.Columns)
     {
         CustomViewColumn column = (CustomViewColumn)colRef.Object;
         if (ModelHelper.IsTextType(column.DataType))
         {
             sb.AppendLine("			if(field == FieldNameConstants."+ column.PascalName + ")");
             sb.AppendLine("				return "+ column.Length + ";");
         }
     }
     sb.AppendLine("			//Catch all for all other data types");
     sb.AppendLine("			return -1;");
     sb.AppendLine("		}");
     sb.AppendLine("		#endregion");
     sb.AppendLine();
 }
Пример #10
0
        private void AppendRegionGetDefault()
        {
            sb.AppendLine("		#region GetDefault");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the default value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public object GetDefault(FieldNameConstants field)");
            sb.AppendLine("		{");

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                sb.AppendLine("			if(field == FieldNameConstants."+ dbColumn.PascalName + ")");
                switch (dbColumn.DataType)
                {
                case System.Data.SqlDbType.Char:
                case System.Data.SqlDbType.NChar:
                case System.Data.SqlDbType.NText:
                case System.Data.SqlDbType.NVarChar:
                case System.Data.SqlDbType.Text:
                case System.Data.SqlDbType.VarChar:
                case System.Data.SqlDbType.UniqueIdentifier:
                    sb.AppendLine("				return \""+ dbColumn.Default + "\";");
                    break;

                case System.Data.SqlDbType.BigInt:
                case System.Data.SqlDbType.Int:
                case System.Data.SqlDbType.SmallInt:
                case System.Data.SqlDbType.TinyInt:
                    if (dbColumn.AllowNull)
                    {
                        sb.AppendLine("				return null;");
                    }
                    else
                    {
                        long lvalue;
                        if (long.TryParse("0" + dbColumn.Default, out lvalue))
                        {
                            sb.AppendLine("				return 0"+ dbColumn.Default + ";");
                        }
                        else                                 //THIS IS AN ERROR CONDITION
                        {
                            sb.AppendLine("				return 0;");
                        }
                    }
                    break;

                case System.Data.SqlDbType.DateTime:
                case System.Data.SqlDbType.SmallDateTime:
                    if (dbColumn.AllowNull)
                    {
                        sb.AppendLine("				return null;");
                    }
                    else
                    {
                        DateTime dtvalue;
                        if (dbColumn.Default == "")
                        {
                            sb.AppendLine("				return DateTime.Now;");
                        }
                        else if (DateTime.TryParse(dbColumn.Default, out dtvalue))
                        {
                            sb.AppendLine("				return DateTime.Parse(\""+ dbColumn.Default + "\");");
                        }
                        else                                 //THIS IS AN ERROR CONDITION
                        {
                            sb.AppendLine("				return DateTime.Now;");
                        }
                    }
                    break;

                case System.Data.SqlDbType.Bit:
                    bool bvalue;
                    if (bool.TryParse(dbColumn.Default, out bvalue))
                    {
                        sb.AppendLine("				return "+ (bvalue ? "true" : "false") + ";");
                    }
                    else                             //THIS IS AN ERROR CONDITION
                    {
                        sb.AppendLine("				return false;");
                    }
                    break;

                case System.Data.SqlDbType.Decimal:
                case System.Data.SqlDbType.Float:
                case System.Data.SqlDbType.Money:
                case System.Data.SqlDbType.Real:
                case System.Data.SqlDbType.SmallMoney:
                    if (dbColumn.AllowNull)
                    {
                        sb.AppendLine("				return null;");
                    }
                    else
                    {
                        decimal dvalue;
                        if (decimal.TryParse("0" + dbColumn.Default, out dvalue))
                        {
                            sb.AppendLine("				return 0"+ dbColumn.Default + ";");
                        }
                        else                                 //THIS IS AN ERROR CONDITION
                        {
                            sb.AppendLine("				return 0;");
                        }
                    }
                    break;
                }
            }
            sb.AppendLine();
            sb.AppendLine("			return null;");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		object IBusinessObject.GetDefault(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDefault((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
        }
Пример #11
0
        private void AppendFullTemplate(StringBuilder sb)
        {
            int index = 0;

            try
            {
                sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + this.StoredProcedureName + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
                sb.AppendLine("	drop procedure [dbo].[" + this.StoredProcedureName + "]");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("CREATE PROCEDURE [dbo].[" + this.StoredProcedureName + "]");
                sb.AppendLine("(");
                sb.AppendLine("	@page int, -- page number selected by the user");
                sb.AppendLine("	@pageSize int, -- number of items on the page");
                sb.AppendLine("	@orderByColumn varchar(100), -- name of column to order things by");
                sb.AppendLine("	@ascending bit, -- order column ascending or descending");
                sb.AppendLine("	@filter varchar(100) = null, -- filter statement passed in to determine like criteria on order by column");
                sb.AppendLine("	@count int out -- number of items in the collection");
                sb.AppendLine(")");
                sb.AppendLine("AS");
                sb.AppendLine();
                sb.AppendLine("SET NOCOUNT ON;");
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("CREATE TABLE #tmpTable ");
                sb.AppendLine("(");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("[" + column.DatabaseName + "]" + " " + column.DataType);
                    if (StringHelper.Match(column.DataType.ToString(), "binary", true) ||
                        StringHelper.Match(column.DataType.ToString(), "char", true) ||
                        StringHelper.Match(column.DataType.ToString(), "decimal", true) ||
                        StringHelper.Match(column.DataType.ToString(), "nchar", true) ||
                        StringHelper.Match(column.DataType.ToString(), "numeric", true) ||
                        StringHelper.Match(column.DataType.ToString(), "nvarchar", true) ||
                        StringHelper.Match(column.DataType.ToString(), "varbinary", true) ||
                        StringHelper.Match(column.DataType.ToString(), "varchar", true))
                    {
                        sb.Append("(" + column.Length + ")");
                    }
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine(")");
                sb.AppendLine();
                sb.AppendLine("DECLARE @total__ivqatedr int");
                sb.AppendLine("DECLARE @orderByColumnIndex int");
                sb.AppendLine("INSERT INTO #tmpTable");
                sb.AppendLine("(");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("[" + column.DatabaseName + "]");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine(")");
                sb.AppendLine("SELECT");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("CONVERT(" + column.DatabaseType + ", [view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "]) AS [" + column.DatabaseName + "]");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine("FROM");
                sb.AppendLine("	[view_" + _currentView.DatabaseName + "]");
                sb.AppendLine("WHERE");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("	(@orderByColumn = '" + column.DatabaseName + "' and (((@filter is null) and ([view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "] is null)) or (@filter is not null and [view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "] LIKE @filter)))");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(" OR ");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine("ORDER BY");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.AppendLine("	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN '" + column.DatabaseName + "' THEN [view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "] END END DESC, ");
                    sb.Append("	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN '" + column.DatabaseName + "' THEN [view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "] END END");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine();
                sb.AppendLine("-- set @count based on the rows moved in the previous statement");
                sb.AppendLine("SET @count = ( SELECT count(*) FROM [#tmpTable] )");
                sb.AppendLine();
                sb.AppendLine("-- remove top x values from the temp table based upon the specific page requested");
                sb.AppendLine("SET @total__ivqatedr = (@pageSize * @page) - @pageSize");
                sb.AppendLine("IF (@total__ivqatedr <> 0)");
                sb.AppendLine("BEGIN");
                sb.AppendLine("	SET ROWCOUNT @total__ivqatedr");
                sb.AppendLine("	DELETE FROM #tmpTable");
                sb.AppendLine("END");
                sb.AppendLine();
                sb.AppendLine("-- return the number of rows requested as the page size");
                sb.AppendLine("SET ROWCOUNT @pageSize");
                sb.AppendLine("SELECT");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("[" + column.DatabaseName + "]");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }

                sb.AppendLine("FROM");
                sb.AppendLine("#tmpTable");
                sb.AppendLine("ORDER BY");

                index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.AppendLine("	CASE @ascending WHEN 0 THEN CASE @orderByColumn WHEN '" + column.DatabaseName + "' THEN [" + column.DatabaseName + "] END END DESC, ");
                    sb.Append("	CASE @ascending WHEN 1 THEN CASE @orderByColumn WHEN '" + column.DatabaseName + "' THEN [" + column.DatabaseName + "] END END");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.Append(Environment.NewLine + "\t");
                    index++;
                }
                sb.AppendLine();
                sb.AppendLine("DROP TABLE #tmpTable");
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("GO");
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        private void AppendSearchClass()
        {
            ArrayList validColumns = new ArrayList();

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dc = (CustomViewColumn)reference.Object;
                if (!(dc.DataType == System.Data.SqlDbType.Binary ||
                      dc.DataType == System.Data.SqlDbType.Image ||
                      dc.DataType == System.Data.SqlDbType.NText ||
                      dc.DataType == System.Data.SqlDbType.Text ||
                      dc.DataType == System.Data.SqlDbType.Timestamp ||
                      dc.DataType == System.Data.SqlDbType.Udt ||
                      dc.DataType == System.Data.SqlDbType.VarBinary ||
                      dc.DataType == System.Data.SqlDbType.Variant ||
                      dc.DataType == System.Data.SqlDbType.Money))
                {
                    validColumns.Add(dc);
                }
            }

            if (validColumns.Count != 0)
            {
                sb.AppendLine("	#region " + _currentView.PascalName + "SelectBySearch");
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// The select command used to select all rows from the '"+ _currentView.PascalName + "' table");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("	[Serializable]");
                sb.AppendLine("	public partial class " + _currentView.PascalName + "SelectBySearch : SelectCommand, ISerializable");
                sb.AppendLine("	{");
                sb.AppendLine("		private "+ _currentView.PascalName + "Search " + _currentView.PascalName + ";");
                sb.AppendLine();
                sb.AppendLine("		#region Serialization");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Serialization constructor");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		protected "+ _currentView.PascalName + "SelectBySearch(SerializationInfo info, StreamingContext context)");
                sb.AppendLine("			: base(info, context)");
                sb.AppendLine("		{");
                sb.AppendLine("			"+ _currentView.PascalName + " = (" + _currentView.PascalName + "Search)info.GetValue(\"" + _currentView.PascalName + "\", typeof(" + _currentView.PascalName + "Search));");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Method used internally for serialization");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override void GetObjectData(SerializationInfo info, StreamingContext context)");
                sb.AppendLine("		{");
                sb.AppendLine("			base.GetObjectData(info, context);");
                sb.AppendLine("			info.AddValue(\""+ _currentView.PascalName + "\", " + _currentView.PascalName + ");");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion ");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Select objects by "+ _currentView.PascalName + " search object");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public "+ _currentView.PascalName + "SelectBySearch(" + _currentView.PascalName + "Search searchObject)");
                sb.AppendLine("		{");
                sb.AppendLine("			"+ _currentView.PascalName + " = searchObject;");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine();
                sb.AppendLine("	");
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Creates a persistable domainCollection");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override IDomainCollection CreateDomainCollection()");
                sb.AppendLine("		{");
                sb.AppendLine("			Domain"+ _currentView.PascalName + "Collection colDomain = new Domain" + _currentView.PascalName + "Collection();");
                sb.AppendLine("			return colDomain;");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// The stored procedure name to select values by primary key to populate a '"+ _currentView.PascalName + "' collection");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override string StoredProcedureName");
                sb.AppendLine("		{");
                sb.AppendLine("			get");
                sb.AppendLine("			{");
                sb.AppendLine("				if ("+ _currentView.PascalName + ".SearchType == SearchType.OR)");
                sb.AppendLine("					return \"gen_"+ Globals.GetPascalName(_model, _currentView) + "SelectBySearchOr\";");
                sb.AppendLine("				else");
                sb.AppendLine("					return \"gen_"+ Globals.GetPascalName(_model, _currentView) + "SelectBySearchAnd\";");
                sb.AppendLine("			}");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Initializes the parameters for this select command");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		protected override void SetupParameterValues(SubDomainBase subDomain)");
                sb.AppendLine("		{");
                sb.AppendLine("			if ("+ _currentView.PascalName + " != null)");
                sb.AppendLine("			{");
                foreach (CustomViewColumn dc in validColumns)
                {
                    sb.AppendLine("				if ("+ _currentView.PascalName + "." + dc.PascalName + " != null)");
                    sb.AppendLine("				{");
                    sb.AppendLine("					ParameterValues.Add(\"@"+ dc.DatabaseName + "\", " + _currentView.PascalName + "." + dc.PascalName + ");");
                    sb.AppendLine("				}");
                }
                sb.AppendLine("				ParameterValues.Add(\"@max_row_count\", "+ _currentView.PascalName + ".MaxRowCount);");
                sb.AppendLine();
                sb.AppendLine("			}");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#region SelectCommand Abstact Override");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// The connection string used to connect to the database");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override string ConnectionString");
                sb.AppendLine("		{");
                sb.AppendLine("			get { return ConfigurationValues.GetInstance().ConnectionString; }");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Determines the default time out");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override int DefaultTimeOut");
                sb.AppendLine("		{");
                sb.AppendLine("			get {	return ConfigurationValues.GetInstance().DefaultTimeOut; }");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("	}");
                sb.AppendLine();
                sb.AppendLine("	#endregion");
                sb.AppendLine();
            }
        }
Пример #13
0
        private void AppendRegionGetValue()
        {
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		#region GetValue");
            sb.AppendLine();
            sb.AppendLine("		public object GetValue(FieldNameConstants field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return GetValue(field, null);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public object GetValue(FieldNameConstants field, object defaultValue)");
            sb.AppendLine("		{");
            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                sb.AppendLine("		if(field == FieldNameConstants."+ dbColumn.PascalName + ")");
                sb.AppendLine("		{");
                if (dbColumn.AllowNull)
                {
                    sb.AppendLine("			return (this.Is"+ dbColumn.PascalName + "Null() ? defaultValue : this." + EnsureValidPropertyName(dbColumn.PascalName) + ");");
                }
                else
                {
                    sb.AppendLine("			return this."+ EnsureValidPropertyName(dbColumn.PascalName) + ";");
                }

                sb.AppendLine("		}");
            }
            sb.AppendLine("		throw new Exception(\"Field '\" + field.ToString() + \"' not found!\");");
            sb.AppendLine("		}");
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public int GetInteger(FieldNameConstants field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetInteger(field, int.MinValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public int GetInteger(FieldNameConstants field, int defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			object o = this.GetValue(field, defaultValue);");
            sb.AppendLine("			if (o is string)");
            sb.AppendLine("			{");
            sb.AppendLine("				int a;");
            sb.AppendLine("				if (int.TryParse((string)o, out a))");
            sb.AppendLine("					return a;");
            sb.AppendLine("				else");
            sb.AppendLine("					throw new InvalidCastException();");
            sb.AppendLine("			}");
            sb.AppendLine("			else");
            sb.AppendLine("			{");
            sb.AppendLine("				return (int)o;");
            sb.AppendLine("			}");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public double GetDouble(FieldNameConstants field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDouble(field, double.MinValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public double GetDouble(FieldNameConstants field, double defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			object o = this.GetValue(field, defaultValue);");
            sb.AppendLine("			if (o is string)");
            sb.AppendLine("			{");
            sb.AppendLine("				double a;");
            sb.AppendLine("				if (double.TryParse((string)o, out a))");
            sb.AppendLine("					return a;");
            sb.AppendLine("				else");
            sb.AppendLine("					throw new InvalidCastException();");
            sb.AppendLine("			}");
            sb.AppendLine("			else");
            sb.AppendLine("			{");
            sb.AppendLine("				return (double)o;");
            sb.AppendLine("			}");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public DateTime GetDateTime(FieldNameConstants field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDateTime(field, DateTime.MinValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public DateTime GetDateTime(FieldNameConstants field, DateTime defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			object o = this.GetValue(field, defaultValue);");
            sb.AppendLine("			if (o is string)");
            sb.AppendLine("			{");
            sb.AppendLine("				DateTime a;");
            sb.AppendLine("				if (DateTime.TryParse((string)o, out a))");
            sb.AppendLine("					return a;");
            sb.AppendLine("				else");
            sb.AppendLine("					throw new InvalidCastException();");
            sb.AppendLine("			}");
            sb.AppendLine("			else");
            sb.AppendLine("			{");
            sb.AppendLine("				return (DateTime)o;");
            sb.AppendLine("			}");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public string GetString(FieldNameConstants field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetString(field, \"\");");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Gets the value of one of this object's properties.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		public string GetString(FieldNameConstants field, string defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			object o = this.GetValue(field, defaultValue);");
            sb.AppendLine("			if (o is string)");
            sb.AppendLine("			{");
            sb.AppendLine("				return (string)o;");
            sb.AppendLine("			}");
            sb.AppendLine("			else");
            sb.AppendLine("			{");
            sb.AppendLine("				return o.ToString();");
            sb.AppendLine("			}");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
        }
Пример #14
0
        public void AppendFullTemplate()
        {
            try
            {
                sb.AppendLine("		#region Class Members");
                sb.AppendLine();
                sb.AppendLine("		#region FieldNameConstants Enumeration");
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Enumeration to define each property that maps to a database field for the '"+ _currentView.PascalName + "' view.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public enum FieldNameConstants");
                sb.AppendLine("		{");
                foreach (Reference reference in _currentView.GeneratedColumns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.AppendLine("			 /// <summary>");
                    sb.AppendLine("			 /// Field mapping for the '"+ column.PascalName + "' property");
                    sb.AppendLine("			 /// </summary>");
                    sb.AppendLine("			[System.ComponentModel.Description(\"Field mapping for the '"+ column.PascalName + "' property\")]");
                    sb.AppendLine("			"+ column.PascalName + ",");
                }
                sb.AppendLine("		}");
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("		internal Domain"+ _currentView.PascalName + " wrappedClass;");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                //Constructors
                sb.AppendLine("		#region Constructors");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Creates a '"+ _currentView.PascalName + "' object from a domain object");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		internal "+ _currentView.PascalName + "(Domain" + _currentView.PascalName + " classToWrap)");
                sb.AppendLine("		{");
                sb.AppendLine("			wrappedClass = classToWrap;");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Creates a '"+ _currentView.PascalName + "' object from a DataRowView");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public "+ _currentView.PascalName + "(DataRowView drvToWrap)");
                sb.AppendLine("		{");
                sb.AppendLine("			wrappedClass = (Domain"+ _currentView.PascalName + ")drvToWrap.Row;");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                //Events
                sb.AppendLine("		#region Events");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// This event is raised when any field is changed.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public event PropertyChangedEventHandler PropertyChanged;");

                foreach (Reference reference in _currentView.GeneratedColumns)
                {
                    CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// This event is raised when the '"+ dbColumn.PascalName + "' field is changed.");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		public event EventHandler "+ dbColumn.PascalName + "Changed;");
                }
                sb.AppendLine();

                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// This event is raised when any field is changed.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		protected virtual void OnPropertyChanged(PropertyChangedEventArgs e)");
                sb.AppendLine("		{");
                sb.AppendLine("			if (this.PropertyChanged != null)");
                sb.AppendLine("				this.PropertyChanged(this, e);");
                sb.AppendLine("		}");
                sb.AppendLine();

                foreach (Reference reference in _currentView.GeneratedColumns)
                {
                    CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                    sb.AppendLine("		/// <summary>");
                    sb.AppendLine("		/// Raises the "+ dbColumn.PascalName + "Changed event.");
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		protected virtual void On"+ dbColumn.PascalName + "Changed(System.EventArgs e)");
                    sb.AppendLine("		{");
                    sb.AppendLine("			if (this."+ dbColumn.PascalName + "Changed != null)");
                    sb.AppendLine("				this."+ dbColumn.PascalName + "Changed(this, e);");
                    sb.AppendLine("		}");
                    sb.AppendLine();
                }
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                //Properties
                sb.AppendLine("		#region Properties");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Determines if this object is part of a collection or is detached");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		[System.ComponentModel.Browsable(false)]");
                sb.AppendLine("		public bool IsParented");
                sb.AppendLine("		{");
                sb.AppendLine("		  get { return (((DataRow)this.WrappedClass).RowState != DataRowState.Detached); }");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Returns the internal object that this object wraps");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		[System.ComponentModel.Browsable(false)]");
                sb.AppendLine("		public object WrappedClass");
                sb.AppendLine("		{");
                sb.AppendLine("			get{return wrappedClass;}");
                sb.AppendLine("			set{wrappedClass = (Domain"+ _currentView.PascalName + ")value;}");
                sb.AppendLine("		}");
                sb.AppendLine();

                foreach (Reference reference in _currentView.GeneratedColumns)
                {
                    CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;

                    sb.AppendLine("			 	");
                    sb.AppendLine();
                    sb.AppendLine();
                    sb.AppendLine();
                    sb.AppendLine("		/// <summary>");
                    if (dbColumn.Description != "")
                    {
                        sb.AppendLine("		/// "+ dbColumn.Description);
                    }
                    else
                    {
                        sb.AppendLine("		/// Property for View field: "+ dbColumn.PascalName);
                    }
                    sb.AppendLine("		/// </summary>");
                    sb.AppendLine("		[Widgetsphere.Core.Attributes.DataSetting(\""+ dbColumn.FriendlyName + "\", " + dbColumn.GridVisible.ToString().ToLower() + ", " + dbColumn.SortOrder.ToString() + ")]");
                    sb.AppendLine("		public "+ dbColumn.GetCodeType() + " " + EnsureValidPropertyName(dbColumn.PascalName) + "");
                    sb.AppendLine("		{");
                    sb.AppendLine("			get");
                    sb.AppendLine("			{");
                    sb.AppendLine("				try");
                    sb.AppendLine("				{");
                    sb.AppendLine("					return wrappedClass."+ dbColumn.PascalName + ";");
                    sb.AppendLine("				}");
                    Globals.AppendBusinessEntryCatch(sb);
                    sb.AppendLine("			}");
                    sb.AppendLine();
                    sb.AppendLine("		}");
                }
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("		#region Null Methods");

                foreach (Reference reference in _currentView.GeneratedColumns)
                {
                    CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                    if (dbColumn.AllowNull)
                    {
                        sb.AppendLine();
                        sb.AppendLine("		/// <summary>");
                        sb.AppendLine("		/// Determines if the field '"+ dbColumn.PascalName + "' is null");
                        sb.AppendLine("		/// </summary>");
                        sb.AppendLine("		/// <returns>Boolean value indicating if the specified value is null</returns>");
                        sb.AppendLine("		public bool Is"+ dbColumn.PascalName + "Null() ");
                        sb.AppendLine("		{");
                        sb.AppendLine("			try");
                        sb.AppendLine("			{");
                        sb.AppendLine("				return wrappedClass.Is"+ dbColumn.PascalName + "Null();");
                        sb.AppendLine("			}");
                        Globals.AppendBusinessEntryCatch(sb);
                        sb.AppendLine("		}");
                        sb.AppendLine();
                    }
                }

                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("		#region Collection Operation Methods");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Removes this object from its parent collection. It will not be deleted from the database.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public void Remove()");
                sb.AppendLine("		{");
                sb.AppendLine("			try");
                sb.AppendLine("			{");
                sb.AppendLine("				wrappedClass.Remove();");
                sb.AppendLine("			}");
                Globals.AppendBusinessEntryCatch(sb);
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();
                sb.AppendLine("		#region Overrides");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Serves as a hash function for this particular type.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override int GetHashCode()");
                sb.AppendLine("		{");
                sb.AppendLine("		  return base.GetHashCode();");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// Returns a value indicating whether the current object is equal to a specified object.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		public override bool Equals(object obj)");
                sb.AppendLine("		{");
                sb.AppendLine("			if (obj == null)");
                sb.AppendLine("			{");
                sb.AppendLine("				return false;");
                sb.AppendLine("			}");
                sb.AppendLine("			else if (obj.GetType() == this.GetType())");
                sb.AppendLine("			{");
                sb.AppendLine("				if (this.wrappedClass == (("+ _currentView.PascalName + ")obj).wrappedClass)");
                sb.AppendLine("					return true;");
                sb.AppendLine("			}");
                sb.AppendLine("			return false;");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                //IBusinessObject.ParentCollection
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// This is a reference back to the generic collection that holds this object.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		#region IBusinessObject ParentCollection");
                sb.AppendLine();
                sb.AppendLine("		[System.ComponentModel.Browsable(false)]");
                sb.AppendLine("		IBusinessCollection IBusinessObject.ParentCollection");
                sb.AppendLine("		{");
                sb.AppendLine("			get");
                sb.AppendLine("			{");
                sb.AppendLine("				return ParentCollection;");
                sb.AppendLine("			}");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                //ParentCollection
                sb.AppendLine("		/// <summary>");
                sb.AppendLine("		/// This is a reference back to the collection that holds this object.");
                sb.AppendLine("		/// </summary>");
                sb.AppendLine("		#region ParentCollection");
                sb.AppendLine();
                sb.AppendLine("		[System.ComponentModel.Browsable(false)]");
                sb.AppendLine("		public "+ _currentView.PascalName + "Collection ParentCollection");
                sb.AppendLine("		{");
                sb.AppendLine("			get");
                sb.AppendLine("			{");
                sb.AppendLine("				return new "+ _currentView.PascalName + "Collection(wrappedClass.ParentCol);");
                sb.AppendLine("			}");
                sb.AppendLine("		}");
                sb.AppendLine();
                sb.AppendLine("		#endregion");
                sb.AppendLine();

                this.AppendRegionGetFriendlyName();
                this.AppendRegionGetMaxLength();
                this.AppendRegionGetMask();
                this.AppendRegionGetDefault();
                this.AppendRegionGetValue();
                this.AppendRegionGetFieldLength();
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #15
0
        private void AppendFullTemplate(StringBuilder sb)
        {
            try
            {
                sb.AppendLine("if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[" + this.StoredProcedureName + "]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)");
                sb.AppendLine("	drop procedure [dbo].[" + this.StoredProcedureName + "]");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER ON ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("CREATE PROCEDURE [dbo].[" + this.StoredProcedureName + "]");

                if (_currentView.Parameters.Count > 0)
                {
                    sb.AppendLine("(");
                    sb.Append(this.BuildParameterList());
                    sb.AppendLine(")");
                }

                sb.AppendLine("AS");
                sb.AppendLine("SET NOCOUNT ON;");
                sb.AppendLine();

                sb.AppendLine("SELECT ");

                int index = 0;
                foreach (Reference reference in _currentView.Columns)
                {
                    CustomViewColumn column = (CustomViewColumn)reference.Object;
                    sb.Append("CONVERT(" + column.DatabaseType + ", [view_" + _currentView.DatabaseName + "].[" + column.DatabaseName + "]) AS [" + column.DatabaseName + "]");
                    if (index < _currentView.Columns.Count - 1)
                    {
                        sb.Append(",");
                    }
                    sb.AppendLine();
                    index++;
                }
                sb.AppendLine("FROM");
                sb.AppendLine("[view_" + _currentView.DatabaseName + "]");

                sb.AppendLine();
                sb.AppendLine();

                sb.AppendLine("GO");
                sb.AppendLine();
                sb.AppendLine("SET QUOTED_IDENTIFIER OFF ");
                sb.AppendLine("GO");
                sb.AppendLine("SET ANSI_NULLS ON ");
                sb.AppendLine("GO");
                sb.AppendLine();
                if (_model.Database.GrantExecUser != string.Empty)
                {
                    sb.AppendFormat("GRANT EXECUTE ON [dbo].[{0}] TO [{1}]", this.StoredProcedureName, _model.Database.GrantExecUser).AppendLine();
                    sb.AppendLine("GO");
                    sb.AppendLine();
                }
            }
            catch (Exception ex)
            {
                throw;
            }
        }
Пример #16
0
        private void AppendTemplate()
        {
            sb.AppendLine("		#region Member Variables");
            sb.AppendLine();
            sb.AppendLine("		internal Domain"+ _currentView.PascalName + "Collection ParentCol;");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
            sb.AppendLine("		#region Constructor");
            sb.AppendLine();
            sb.AppendLine("		internal Domain"+ _currentView.PascalName + "(DataRowBuilder rb) : base(rb) ");
            sb.AppendLine("		{");
            sb.AppendLine("			this.ParentCol = ((Domain"+ _currentView.PascalName + "Collection)(base.Table));");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
            sb.AppendLine("		#region Properties");
            sb.AppendLine();

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                sb.AppendLine();
                sb.AppendLine("		internal "+ dbColumn.GetCodeType() + " " + dbColumn.PascalName);
                sb.AppendLine("		{");
                sb.AppendLine("			get ");
                sb.AppendLine("			{");
                sb.AppendLine("				try ");
                sb.AppendLine("				{");
                sb.AppendLine("					return (("+ dbColumn.GetCodeType() + ")(base[this.ParentCol." + dbColumn.PascalName + "Column]));");
                sb.AppendLine("				}");
                sb.Append("				catch ");
                if (StringHelper.Match(dbColumn.GetCodeType(), "string", true))
                {
                    sb.AppendLine(" (InvalidCastException) ");
                    sb.AppendLine("				{");
                    sb.AppendLine("					return string.Empty;");
                }
                else
                {
                    sb.AppendLine("				(InvalidCastException e) ");
                    sb.AppendLine("				{");
                    sb.AppendLine("					throw new StrongTypingException(\"Cannot get value because it is DBNull.\", e);");
                }
                sb.AppendLine("				}");
                sb.AppendLine("			}");
                sb.AppendLine();
                sb.AppendLine("		}");
            }

            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();


            sb.AppendLine("		#region Null Methods");
            sb.AppendLine();

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn dbColumn = (CustomViewColumn)reference.Object;
                if (dbColumn.AllowNull)
                {
                    sb.AppendLine();
                    sb.AppendLine("		internal bool Is"+ dbColumn.PascalName + "Null() ");
                    sb.AppendLine("		{");
                    sb.AppendLine("			return base.IsNull(this.ParentCol."+ dbColumn.PascalName + "Column);");
                    sb.AppendLine("		}");
                    sb.AppendLine("						");
                }
            }

            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
            AppendRegionRelationshipMethods();
            sb.Append("		internal void Remove()").AppendLine();
            sb.Append("		{").AppendLine();
            sb.Append("			this.ParentCol.Remove"+ _currentView.PascalName + "(this);").AppendLine();
            sb.Append("		}").AppendLine();
        }
Пример #17
0
        private void AppendRegionIBusinessObject()
        {
            sb.AppendLine("		#region IBusinessObject Members");
            sb.AppendLine();
            sb.AppendLine("		IPrimaryKey IBusinessObject.PrimaryKey");
            sb.AppendLine("		{");
            sb.AppendLine("			get { return null; }");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		object IBusinessObject.GetValue(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetValue((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		object IBusinessObject.GetValue(Enum field, object defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetValue((FieldNameConstants)field, defaultValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		double IBusinessObject.GetDouble(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDouble((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		double IBusinessObject.GetDouble(Enum field, double defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDouble((FieldNameConstants)field, defaultValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		DateTime IBusinessObject.GetDateTime(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDateTime((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		DateTime IBusinessObject.GetDateTime(Enum field, DateTime defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetDateTime((FieldNameConstants)field, defaultValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		int IBusinessObject.GetInteger(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetInteger((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		int IBusinessObject.GetInteger(Enum field, int defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetInteger((FieldNameConstants)field, defaultValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		string IBusinessObject.GetString(Enum field)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetString((FieldNameConstants)field);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		string IBusinessObject.GetString(Enum field, string defaultValue)");
            sb.AppendLine("		{");
            sb.AppendLine("			return this.GetString((FieldNameConstants)field, defaultValue);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		Enum IBusinessObject.Container");
            sb.AppendLine("		{");
            sb.AppendLine("			get { return this.Container; }");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// Determines if all of the fields for the specified object exactly matches the current object.");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		/// <param name=\"item\">The object to compare</param>");
            sb.AppendLine("		/// <returns></returns>");
            sb.AppendLine("		public override bool IsEquivalent(IBusinessObject item)");
            sb.AppendLine("		{");
            sb.AppendLine("			if (item == null) return false;");
            sb.AppendLine("			if (!(item is "+ _currentView.PascalName + ")) return false;");
            sb.AppendLine("			"+ _currentView.PascalName + " o = item as " + _currentView.PascalName + ";");
            sb.AppendLine("			return (");

            int index = 0;

            foreach (Reference reference in _currentView.GeneratedColumns)
            {
                CustomViewColumn column = (CustomViewColumn)reference.Object;
                sb.Append("				o."+ column.PascalName + " == this." + column.PascalName);
                if (index < _currentView.GeneratedColumns.Count - 1)
                {
                    sb.Append(" &&");
                }
                sb.AppendLine();
                index++;
            }

            sb.AppendLine("				);");
            sb.AppendLine("		}");
            sb.AppendLine();
            sb.AppendLine("		#endregion");
            sb.AppendLine();
        }