Updates to MyGeneration Templates
This commit is contained in:
parent
fd69da45b9
commit
f3782ea2a2
@ -454,7 +454,7 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
_subclassName = ClassName( fk.PrimaryTable);
|
||||
else
|
||||
_subclassName = ClassName( fk.PrimaryTable) + ClassName( fk.ForeignTable )+sAlias;
|
||||
_tableName = "//TODO: No Table Name";
|
||||
_tableName = "//CSLATODO: No Table Name";
|
||||
vlnHeader("\r\nusing System.Collections.Generic;\r\nusing Csla.Validation;");
|
||||
string sInterface = "";
|
||||
if (_chkPartCM)
|
||||
@ -855,7 +855,8 @@ namespace <%=_nameSpace%>
|
||||
//sExtDirty += " || " + MemberName(sLists+sAlias) + ".IsDirty";
|
||||
//sExtValid += " && " + MemberName(sLists+sAlias) + ".IsValid";
|
||||
sExtDirty += string.Format(" || ({0} == null ? false : {0}.IsDirtyList(list))",MemberName(sLists+sAlias));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValid)",MemberName(sLists+sAlias));
|
||||
// Added List 20100924
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValidList(list))",MemberName(sLists+sAlias));
|
||||
} else {
|
||||
string sItem = ClassName(fk.ForeignTable);
|
||||
//vlnProperty(sItem+sAlias, MemberName("My" + sItem)+sAlias,"My" + sItem + sAlias,
|
||||
@ -866,7 +867,7 @@ namespace <%=_nameSpace%>
|
||||
" = null;","Related Field" + Debug("20070501.1"),true,false,true,fk,sCheck,null,null);
|
||||
bool bReq = !fk.ForeignColumns[0].IsNullable;
|
||||
sExtDirty += string.Format(" || ({0} == null ? false : {0}.IsDirtyList(list))",MemberName("My" + sItem+sAlias));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValid)",MemberName("My" + sItem+sAlias));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValidList(list))",MemberName("My" + sItem+sAlias));
|
||||
}
|
||||
}
|
||||
else //
|
||||
@ -877,7 +878,7 @@ namespace <%=_nameSpace%>
|
||||
//sExtDirty += string.Format(" || ({0} == null? " + bReq.ToString().ToLower() + " : {0}.IsDirty)",MemberName("My" + sClass));
|
||||
//sExtValid += string.Format(" && ({0} == null? " + (!bReq).ToString().ToLower() + " : {0}.IsValid)",MemberName("My" + sClass));
|
||||
sExtDirty += string.Format(" || ({0} == null ? false : {0}.IsDirtyList(list))",MemberName("My" + sClass));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValid)",MemberName("My" + sClass));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValidList(list))",MemberName("My" + sClass));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1045,7 +1046,7 @@ namespace <%=_nameSpace%>
|
||||
if (<%=sMemberName%><%=suffix%> != tmp.ToString())
|
||||
{
|
||||
<%=sMemberName%><%=suffix%> = tmp.ToString();
|
||||
// TODO: Any Cross Property Validation
|
||||
// CSLATODO: Any Cross Property Validation
|
||||
}
|
||||
}
|
||||
catch
|
||||
@ -1091,7 +1092,7 @@ namespace <%=_nameSpace%>
|
||||
private void vlnToString(IColumns Columns)
|
||||
{
|
||||
%>
|
||||
// TODO: Replace base <%=_className%>.ToString function as necessary
|
||||
// CSLATODO: Replace base <%=_className%>.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
@ -1118,14 +1119,14 @@ namespace <%=_nameSpace%>
|
||||
keyID+=").GetHashCode()";
|
||||
}
|
||||
%>
|
||||
// TODO: Check <%=_className%>.GetIdValue to assure that the ID returned is unique
|
||||
// CSLATODO: Check <%=_className%>.GetIdValue to assure that the ID returned is unique
|
||||
/// <summary>
|
||||
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
|
||||
/// </summary>
|
||||
/// <returns>A Unique ID for the current <%=_className%></returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return <%=keyID%>;
|
||||
return My<%=_className%>Unique; // Absolutely Unique ID
|
||||
}<%
|
||||
}
|
||||
private string extName
|
||||
@ -1198,12 +1199,12 @@ namespace <%=_nameSpace%>
|
||||
%>
|
||||
//ValidationRules.AddDependantProperty("x", "y");
|
||||
<%=extMName%>.AddValidationRules(ValidationRules);
|
||||
// TODO: Add other validation rules
|
||||
// CSLATODO: Add other validation rules
|
||||
}
|
||||
protected override void AddInstanceBusinessRules()
|
||||
{
|
||||
<%=extMName%>.AddInstanceValidationRules(ValidationRules);
|
||||
// TODO: Add other validation rules
|
||||
// CSLATODO: Add other validation rules
|
||||
}<%
|
||||
foreach(IColumn field in Columns)
|
||||
{
|
||||
@ -1282,7 +1283,7 @@ namespace <%=_nameSpace%>
|
||||
#region Authorization Rules
|
||||
protected override void AddAuthorizationRules()
|
||||
{
|
||||
//TODO: Who can read/write which fields<%
|
||||
//CSLATODO: Who can read/write which fields<%
|
||||
foreach(IColumn field in Columns)
|
||||
{
|
||||
if (field.DataTypeName != "timestamp"){
|
||||
@ -1303,23 +1304,23 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
protected override void AddInstanceAuthorizationRules()
|
||||
{
|
||||
//TODO: Who can read/write which fields
|
||||
//CSLATODO: Who can read/write which fields
|
||||
<%=extMName%>.AddInstanceAuthorizationRules(AuthorizationRules);
|
||||
}
|
||||
public static bool CanAddObject()
|
||||
{
|
||||
// TODO: Can Add Authorization
|
||||
// CSLATODO: Can Add Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
public static bool CanGetObject()
|
||||
{
|
||||
// TODO: CanGet Authorization
|
||||
// CSLATODO: CanGet Authorization
|
||||
return true;
|
||||
}
|
||||
public static bool CanDeleteObject()
|
||||
{
|
||||
// TODO: CanDelete Authorization
|
||||
// CSLATODO: CanDelete Authorization
|
||||
//bool result = false;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
|
||||
@ -1373,7 +1374,7 @@ namespace <%=_nameSpace%>
|
||||
%>
|
||||
public static bool CanEditObject()
|
||||
{
|
||||
// TODO: CanEdit Authorization
|
||||
// CSLATODO: CanEdit Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
@ -1414,7 +1415,7 @@ namespace <%=_nameSpace%>
|
||||
protected static int <%=_className%>Unique
|
||||
{ get { return ++_<%=_className%>Unique; } }
|
||||
private int _My<%=_className%>Unique = <%=_className%>Unique;
|
||||
public int My<%=_className%>Unique
|
||||
public int My<%=_className%>Unique // Absolutely Unique ID - Editable
|
||||
{ get { return _My<%=_className%>Unique; } }
|
||||
protected <%=_className%>()
|
||||
{/* require use of factory methods */
|
||||
@ -1899,14 +1900,14 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
// DataPortal_Create
|
||||
%>
|
||||
// TODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
// CSLATODO: If Create needs to access DB - It should not be marked RunLocal
|
||||
[RunLocal()]
|
||||
private new void DataPortal_Create()
|
||||
{
|
||||
<%=FormatColumns("{member} = new Guid();",Guid(Columns),"\r\n","\t\t\t")%><%=FormatColumns("{member} = Next{prop};",AutoKey(Columns),"\r\n","\t\t\t")%>
|
||||
// Database Defaults
|
||||
<%=FormatColumns("{member} = " + extMName + ".Default{prop};",HasDefaults(Columns),"\r\n","\t\t\t")%>
|
||||
// TODO: Add any defaults that are necessary
|
||||
// CSLATODO: Add any defaults that are necessary
|
||||
ValidationRules.CheckRules();
|
||||
}<%
|
||||
vlnReadData(Columns,true);
|
||||
@ -1988,7 +1989,7 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
}
|
||||
%>
|
||||
// TODO: Define any additional output parameters
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure<%
|
||||
foreach(IColumn column in Columns)
|
||||
@ -2087,7 +2088,7 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
}
|
||||
%>
|
||||
// TODO: Define any additional output parameters
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure<%
|
||||
IColumn tsCol=null;
|
||||
@ -2168,7 +2169,7 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
}
|
||||
%>
|
||||
// TODO: Define any additional output parameters
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure<%
|
||||
foreach(IColumn column in Columns)
|
||||
@ -2384,7 +2385,7 @@ namespace <%=_nameSpace%>
|
||||
}
|
||||
}
|
||||
%>
|
||||
// TODO: Define any additional output parameters
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
// Save all values being returned from the Procedure<%
|
||||
tsCol=null;
|
||||
@ -2466,7 +2467,7 @@ namespace <%=_nameSpace%>
|
||||
cm.CommandType = CommandType.StoredProcedure;
|
||||
cm.CommandText = "delete<%=_className%>";
|
||||
// Input PK Fields<%=sValuesD%>
|
||||
// TODO: Define any additional output parameters
|
||||
// CSLATODO: Define any additional output parameters
|
||||
cm.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
@ -2640,11 +2641,11 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
// Read members
|
||||
//output.write(FormatColumns(dicRead,Columns,"","\r\n\t\t\t\t\t\t\t"));
|
||||
//dicRead1 = new Hashtable();
|
||||
//dicRead1["timestamp"]="\r\n\t\t\t\t\t\tdr.GetBytes(\"{name}\", 0, {member}, 0, 8);";// TODO: Need to handle TimeStamp
|
||||
//dicRead1["timestamp"]="\r\n\t\t\t\t\t\tdr.GetBytes(\"{name}\", 0, {member}, 0, 8);";// CSLATODO: Need to handle TimeStamp
|
||||
//output.write(FormatColumns(dicRead1,Columns,""));
|
||||
// if (_workingTable != fk.ForeignTable)
|
||||
// FKSelect(fk,tbl);
|
||||
// TODO: Fix This See Below
|
||||
// CSLATODO: Fix This See Below
|
||||
// foreach(IColumn field in Columns)
|
||||
// {
|
||||
// if (field.IsInForeignKey && field.IsInPrimaryKey)
|
||||
@ -2846,7 +2847,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
// {
|
||||
// partial class <%=_className%>Extension : extensionBase
|
||||
// {
|
||||
// // TODO: Override automatic defaults<%
|
||||
// // CSLATODO: Override automatic defaults<%
|
||||
foreach(IColumn column in HasDefaults(columns))
|
||||
{
|
||||
%>
|
||||
@ -3641,16 +3642,16 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}
|
||||
// if (sKey == "")sKey="base.GetIdValue()";
|
||||
%>
|
||||
// TODO: Check <%=sFkClassName%>.GetIdValue to assure that the ID returned is unique
|
||||
// CSLATODO: Check <%=sFkClassName%>.GetIdValue to assure that the ID returned is unique
|
||||
/// <summary>
|
||||
/// Overrides Base GetIdValue - Used internally by CSLA to determine equality
|
||||
/// </summary>
|
||||
/// <returns>A Unique ID for the current <%=sFkClassName%></returns>
|
||||
protected override object GetIdValue()
|
||||
{
|
||||
return <%=sKey%>;
|
||||
return My<%=_className%>Unique; // Absolutely Unique ID
|
||||
}
|
||||
// TODO: Replace base <%=sFkClassName%>.ToString function as necessary
|
||||
// CSLATODO: Replace base <%=sFkClassName%>.ToString function as necessary
|
||||
/// <summary>
|
||||
/// Overrides Base ToString
|
||||
/// </summary>
|
||||
@ -3667,7 +3668,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
string sColumn = RequiredRelatedColumn(col);
|
||||
if (sColumn != null){ // Let the Validation Rules handle IsDirty and IsValid - LazyLoad should be ignored.
|
||||
sExtDirty += string.Format(" || ({0} == null ? false : {0}.IsDirtyList(list))",MemberName(sColumn));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValid)",MemberName(sColumn));
|
||||
sExtValid += string.Format(" && ({0} == null ? true : {0}.IsValidList(list))",MemberName(sColumn));
|
||||
}
|
||||
}
|
||||
//if (sExtDirty!="")
|
||||
@ -3776,7 +3777,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}
|
||||
}
|
||||
%>
|
||||
// TODO: Add other validation rules
|
||||
// CSLATODO: Add other validation rules
|
||||
}<%
|
||||
foreach(IColumn column in fk.ForeignTable.Columns)
|
||||
{
|
||||
@ -3847,7 +3848,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
#region Authorization Rules
|
||||
protected override void AddAuthorizationRules()
|
||||
{
|
||||
//TODO: Who can read/write which fields<%
|
||||
//CSLATODO: Who can read/write which fields<%
|
||||
foreach(IColumn column in fk.ForeignTable.Columns)
|
||||
{
|
||||
if (!(IsIn(column,fk.ForeignColumns)) && column.DataTypeName != "timestamp")
|
||||
@ -3865,18 +3866,18 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}
|
||||
public static bool CanAddObject()
|
||||
{
|
||||
// TODO: Can Add Authorization
|
||||
// CSLATODO: Can Add Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
public static bool CanGetObject()
|
||||
{
|
||||
// TODO: CanGet Authorization
|
||||
// CSLATODO: CanGet Authorization
|
||||
return true;
|
||||
}
|
||||
public static bool CanDeleteObject()
|
||||
{
|
||||
// TODO: CanDelete Authorization
|
||||
// CSLATODO: CanDelete Authorization
|
||||
//bool result = false;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("ProjectManager"))result = true;
|
||||
//if (Csla.ApplicationContext.User.IsInRole("Administrator"))result = true;
|
||||
@ -3885,7 +3886,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}
|
||||
public static bool CanEditObject()
|
||||
{
|
||||
// TODO: CanEdit Authorization
|
||||
// CSLATODO: CanEdit Authorization
|
||||
//return Csla.ApplicationContext.User.IsInRole("ProjectManager");
|
||||
return true;
|
||||
}
|
||||
@ -4001,6 +4002,12 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
#region Factory Methods
|
||||
public int CurrentEditLevel
|
||||
{ get { return EditLevel; } }
|
||||
private static int _<%=_className%>Unique = 0;
|
||||
private static int <%=_className%>Unique
|
||||
{ get { return ++_<%=_className%>Unique; } }
|
||||
private int _My<%=_className%>Unique = <%=_className%>Unique;
|
||||
public int My<%=_className%>Unique // Absolutely Unique ID - Editable FK
|
||||
{ get { return _My<%=_className%>Unique; } }
|
||||
internal static <%=sFkClassName%> New(<%=sKeysTypes%>)
|
||||
{
|
||||
return new <%=sFkClassName%>(<%=sValues%>);
|
||||
@ -4023,7 +4030,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
private <%=sFkClassName%>(<%=sValues2%>)
|
||||
{
|
||||
MarkAsChild();
|
||||
// TODO: Add any initialization & defaults
|
||||
// CSLATODO: Add any initialization & defaults
|
||||
<%=FormatColumns("\t\t\t{member} = {class}.Next{prop};\r\n",AutoKey(fk),"","")%><%=FormatColumns("{member} = " + extMName + ".Default{prop};",HasDefaults(fk),"\r\n","\t\t\t")%>
|
||||
<%=sInit%>
|
||||
ValidationRules.CheckRules();
|
||||
@ -4238,7 +4245,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}<%
|
||||
// ForeignKeys - List Foreign Keys - May want to create stored procedures
|
||||
%>
|
||||
// TODO: Add alternative gets -
|
||||
// CSLATODO: Add alternative gets -
|
||||
//public static <%=_className%> Get(<criteria>)
|
||||
//{
|
||||
// try
|
||||
@ -4428,11 +4435,14 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
}
|
||||
private void AddRefreshMine(string sMember)
|
||||
{
|
||||
_refreshMine += string.Format("\t\t\tif({0} != null)\r\n",sMember);
|
||||
_refreshMine += string.Format("\t\t\t{{\r\n",sMember);
|
||||
_refreshMine += string.Format("\t\t\t\t{0}.Dispose();// Dispose related value\r\n",sMember);
|
||||
_refreshMine += string.Format("\t\t\t\t{0} = null;// Reset related value\r\n",sMember);
|
||||
_refreshMine += string.Format("\t\t\t}}\r\n",sMember);
|
||||
_refreshMine += string.Format("//RHM Removed 20090724 - Duplicates function of code above.\r\n",sMember);
|
||||
_refreshMine += string.Format("// - Dispose caused error when a new step was added.\r\n",sMember);
|
||||
_refreshMine += string.Format("// - Resequence of transitions did not work properly.\r\n",sMember);
|
||||
_refreshMine += string.Format("//\t\t\tif({0} != null)\r\n",sMember);
|
||||
_refreshMine += string.Format("//\t\t\t{{\r\n");
|
||||
_refreshMine += string.Format("//\t\t\t\t{0}.Dispose();// Dispose related value\r\n",sMember);
|
||||
_refreshMine += string.Format("//\t\t\t\t{0} = null;// Reset related value\r\n",sMember);
|
||||
_refreshMine += string.Format("//\t\t\t}}\r\n");
|
||||
}
|
||||
private void vlnBusinessMethodsInfo(IColumns columns)
|
||||
{
|
||||
@ -4587,7 +4597,7 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
private static int <%=_className%>Unique
|
||||
{ get { return ++_<%=_className%>Unique; } }
|
||||
private int _My<%=_className%>Unique = <%=_className%>Unique;
|
||||
public int My<%=_className%>Unique
|
||||
public int My<%=_className%>Unique // Absolutely Unique ID - Info
|
||||
{ get { return _My<%=_className%>Unique; } }
|
||||
protected <%=_className%>()
|
||||
{/* require use of factory methods */
|
||||
@ -4859,15 +4869,21 @@ private void vlnDataPortalFetch(string sPrefix,IColumns cols,string sql,bool get
|
||||
if (_LoggingInfo)
|
||||
Console.WriteLine("{0} MB {1}", _CurrentProcess.WorkingSet64 / 1000000, string.Format(s, hashCode));
|
||||
}
|
||||
private static string _ConnectionName = "<%=_dbConnection%>";
|
||||
public static string ConnectionName
|
||||
{
|
||||
get { return Database._ConnectionName; }
|
||||
set { Database._ConnectionName = value; }
|
||||
}
|
||||
public static string <%=_dbConnection%>_Connection
|
||||
{
|
||||
get
|
||||
{
|
||||
DateTime.Today.ToLongDateString();
|
||||
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings["<%=_dbConnection%>"];
|
||||
ConnectionStringSettings cs = ConfigurationManager.ConnectionStrings[ConnectionName];
|
||||
if (cs == null)
|
||||
{
|
||||
throw new ApplicationException("Database.cs Could not find connection <%=_dbConnection%>");
|
||||
throw new ApplicationException("Database.cs Could not find connection " + ConnectionName);
|
||||
}
|
||||
return cs.ConnectionString;
|
||||
}
|
||||
|
@ -255,6 +255,7 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
{
|
||||
StartProc("purgeData");
|
||||
%>
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION<%
|
||||
@ -329,6 +330,7 @@ BEGIN TRY -- Try Block
|
||||
string sproc = "get" + ClassesName(tbl);
|
||||
StartProc(sproc);
|
||||
%>
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT
|
||||
<%=FormatColumns("[{name}]",tbl.Columns,",\r\n","\t\t")%><%=FKCounts(tbl)%>
|
||||
@ -388,6 +390,7 @@ AS
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}{?null}",tbl.Columns,",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",Computed(tbl),"",",\r\n\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
@ -422,6 +425,7 @@ BEGIN TRY -- Try Block
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}{?null}",Insertable(tbl),",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",NotInsertable(tbl),"",",\r\n\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
@ -454,6 +458,7 @@ BEGIN TRY -- Try Block
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION<%
|
||||
@ -488,6 +493,7 @@ BEGIN TRY -- Try Block
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT
|
||||
<%=FormatColumns("[{name}]",tbl.Columns,",\r\n","\t\t")%><%=FKCounts(tbl)%>
|
||||
@ -523,6 +529,7 @@ AS
|
||||
%>(
|
||||
<%=FormatColumns("{@} {dtype}",ind.Columns,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT
|
||||
<%=FormatColumns("[{name}]",tbl.Columns,",\r\n","\t\t")%><%=FKCounts(tbl)%>
|
||||
@ -545,6 +552,7 @@ AS
|
||||
%>(
|
||||
<%=FormatColumns("{@} {dtype}",fk.ForeignColumns,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT
|
||||
<%=FormatColumns("[{name}]",tbl.Columns,",\r\n","\t\t")%><%=FKCounts(tbl)%>
|
||||
@ -570,6 +578,7 @@ AS
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT COUNT(*)
|
||||
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@}",tbl.PrimaryKeys," AND ","")%><%
|
||||
@ -599,6 +608,7 @@ AS
|
||||
(
|
||||
<%=FormatColumns2("{@} {dtype}",FK,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS
|
||||
SELECT
|
||||
<%=FormatColumns("[{name}]",tbl.Columns,",\r\n","\t\t")%><%=FKCounts(tbl)%>
|
||||
@ -619,6 +629,7 @@ AS
|
||||
(
|
||||
<%=FormatColumns2("{@} {dtype}",FK,",\r\n","\t")%>
|
||||
)
|
||||
WITH EXECUTE AS OWNER
|
||||
AS<%
|
||||
string sWhere = "\r\n\tWHERE\r\n\t\t" + FormatColumns2("[{fktable}].[{fkname}]={@}",FK," AND ","");
|
||||
FKSelect(FK,(FK.PrimaryTable==tbl?FK.ForeignTable:FK.PrimaryTable),FKCounts(tbl),sWhere);
|
||||
|
@ -76,6 +76,8 @@ public class GeneratedGui : DotNetScriptGui
|
||||
chkFKCalc2.Checked = false;
|
||||
GuiCheckBox chkColumns2 = MakeGuiCheckBox("chkColumns2","PrimFK",true,"Primary Foreign Key",150,chkDetail,300, -1);
|
||||
chkColumns2.Checked = false;
|
||||
GuiCheckBox chkNewFK = MakeGuiCheckBox( "chkNewFK", "NewFK", true, "NewFK" ,150,chkDetail,450,-1);
|
||||
chkNewFK.Checked = false;
|
||||
GuiCheckBox chkRelated = MakeGuiCheckBox("chkRelated","Related",true,"Related",150,chkDetail,0,-2);
|
||||
chkRelated.Checked = false;
|
||||
GuiCheckBox chkOne2One = MakeGuiCheckBox("chkOne2One","One to One",true,"One to Many and One to One",150,chkDetail,150, -2);
|
||||
@ -230,6 +232,7 @@ public class GeneratedGui : DotNetScriptGui
|
||||
GuiCheckBox chkAlias= ui["chkAlias"] as GuiCheckBox;
|
||||
GuiCheckBox chkNames= ui["chkNames"] as GuiCheckBox;
|
||||
GuiCheckBox chkProc = ui["chkProc"] as GuiCheckBox;
|
||||
GuiCheckBox chkNewFK = ui["chkNewFK"] as GuiCheckBox;
|
||||
GuiLabel labelTest = ui["labelTest"] as GuiLabel;
|
||||
string status = "";
|
||||
if(chkDetail.Checked)status+=", " + chkDetail.Text;
|
||||
@ -245,6 +248,7 @@ public class GeneratedGui : DotNetScriptGui
|
||||
if(chkAlias.Checked)status+=", " + chkAlias.Text;
|
||||
if(chkNames.Checked)status+=", " + chkNames.Text;
|
||||
if(chkProc.Checked)status+=", " + chkProc.Text;
|
||||
if(chkNewFK.Checked)status+=", " + chkNewFK.Text;
|
||||
if(status == "")
|
||||
{
|
||||
btnOK.Enabled = false;
|
||||
@ -352,6 +356,7 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
if((bool)input["chkInternal"])ShowInternalRelated( _workingTable );
|
||||
if((bool)input["chkAlias"])ShowAlias( _workingTable );
|
||||
if((bool)input["chkNames"])ShowNames( _workingTable );
|
||||
if((bool)input["chkNewFK"])ShowNewFK( _workingTable );
|
||||
}
|
||||
}
|
||||
//foreach(ITable tbl in db.Tables)
|
||||
@ -382,6 +387,19 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
}
|
||||
}
|
||||
}
|
||||
private void ShowNewFK(ITable tbl)
|
||||
{
|
||||
%>NewFK Output:<%=tbl.Name%>
|
||||
<%
|
||||
foreach(IForeignKey fk in tbl.ForeignKeys)
|
||||
{
|
||||
if(tbl.Name == fk.PrimaryTable.Name)
|
||||
{
|
||||
%>Foreign Table <%=fk.ForeignTable.Name%> Column <%=fk.ForeignColumns[0].Name%>
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private string ForeignKeyCheck(IColumn col)
|
||||
{
|
||||
|
@ -221,7 +221,7 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
_exportPath = input["outputPath"].ToString();
|
||||
_dbName = input["chooseDatabase"].ToString();
|
||||
IDatabase db = MyMeta.Databases[_dbName];
|
||||
SaveProcs(db);
|
||||
SaveProcsSorted(db);
|
||||
//SaveTables(db);
|
||||
}
|
||||
private bool IncludeVolian(string sName)
|
||||
@ -264,6 +264,47 @@ IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[<%=sName%>]') AN
|
||||
DROP <%=sType%> [<%=sName%>];
|
||||
GO
|
||||
|
||||
<%
|
||||
output.write(ip.ProcedureText.TrimEnd("\r\n".ToCharArray()).Replace(" \r\n","\r\n"));
|
||||
%>
|
||||
GO
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT '<%=sIsType%> Creation: <%=sName%> Succeeded'
|
||||
ELSE PRINT '<%=sIsType%> Creation: <%=sName%> Error on Creation'
|
||||
GO
|
||||
<%
|
||||
SaveFile(ip.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void SaveProcsSorted(IDatabase db)
|
||||
{
|
||||
SortedList sortedList = new SortedList();
|
||||
foreach(IProcedure ip in db.Procedures)
|
||||
{
|
||||
sortedList.Add(ip.Name,ip);
|
||||
}
|
||||
foreach(IProcedure ip in sortedList.Values)
|
||||
{
|
||||
if(ip.Schema != "sys"){
|
||||
bool isProc = IsProcedure(ip);
|
||||
string sType = isProc ? "PROCEDURE" : "FUNCTION";
|
||||
string sIsType = isProc ? "Procedure" : (IsTableFunction(ip) ? "TableFunction" : "ScalarFunction");
|
||||
string sName = ip.Name;
|
||||
if((bool)input["chkDrop"]){
|
||||
if(sName.StartsWith("sp_")==false && sName.StartsWith("fn_")==false && IncludeVolian(sName))
|
||||
output.writeln("DROP " + sType + " [" + sName + "]");
|
||||
} else {
|
||||
if(sName.StartsWith("sp_")==false && sName.StartsWith("fn_")==false && IncludeVolian(sName))
|
||||
{
|
||||
%>
|
||||
/****** Object: StoredProcedure [<%=sName%>] ******/
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[<%=sName%>]') AND OBJECTPROPERTY(id,N'Is<%=sIsType%>') = 1)
|
||||
DROP <%=sType%> [<%=sName%>];
|
||||
GO
|
||||
|
||||
<%
|
||||
output.write(ip.ProcedureText.TrimEnd("\r\n".ToCharArray()).Replace(" \r\n","\r\n"));
|
||||
%>
|
||||
@ -281,7 +322,7 @@ GO
|
||||
}
|
||||
private bool IsProcedure(IProcedure ip)
|
||||
{
|
||||
return ip.ProcedureText.Contains("CREATE PROCEDURE");
|
||||
return ip.ProcedureText.ToUpper().Contains("CREATE PROCEDURE");
|
||||
}
|
||||
private bool IsTableFunction(IProcedure ip)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user