Various updates to MyGeneration
Moved ItemInsert code to ItemInsertExt.cs
This commit is contained in:
parent
518c79216a
commit
7f0eb11f47
File diff suppressed because it is too large
Load Diff
@ -12,7 +12,7 @@
|
|||||||
public ArrayList AutoKey(IForeignKey fk){
|
public ArrayList AutoKey(IForeignKey fk){
|
||||||
ArrayList l = new ArrayList();
|
ArrayList l = new ArrayList();
|
||||||
foreach(IColumn column in fk.ForeignTable.Columns){
|
foreach(IColumn column in fk.ForeignTable.Columns){
|
||||||
if(column.IsAutoKey && !IsIn(column,fk.ForeignColumns))l.Add(column);}
|
if (column.IsAutoKey && !IsIn(column,fk.ForeignColumns))l.Add(column);}
|
||||||
return l;}
|
return l;}
|
||||||
// Used in CSLA Stored Procedures
|
// Used in CSLA Stored Procedures
|
||||||
private ArrayList AutoKey(ITable tbl){
|
private ArrayList AutoKey(ITable tbl){
|
||||||
@ -180,7 +180,7 @@
|
|||||||
string sPrefixType="";
|
string sPrefixType="";
|
||||||
string sPrefix="";
|
string sPrefix="";
|
||||||
string sPrefixSet="";
|
string sPrefixSet="";
|
||||||
string sCheckSep = "if( ";
|
string sCheckSep = "if (";
|
||||||
sMakeListParamTypes = "";
|
sMakeListParamTypes = "";
|
||||||
sMakeListParams = "";
|
sMakeListParams = "";
|
||||||
sSetTmp = "";
|
sSetTmp = "";
|
||||||
@ -195,7 +195,7 @@
|
|||||||
sepSet="\r\n";
|
sepSet="\r\n";
|
||||||
if(IsRelObj(col)) // If item is null, don't look it up
|
if(IsRelObj(col)) // If item is null, don't look it up
|
||||||
{
|
{
|
||||||
sParentCheck += sCheckSep + LocalName(RelObjProp(col)) + " != null ";
|
sParentCheck += "/*0*/" + sCheckSep + LocalName(RelObjProp(col)) + " != null ";
|
||||||
sCheckSep = "|| ";
|
sCheckSep = "|| ";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -511,6 +511,17 @@
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
public string ColumnListToString(IList lst)
|
||||||
|
{
|
||||||
|
string retval = "";
|
||||||
|
string sep = "";
|
||||||
|
foreach(IColumn col in lst)
|
||||||
|
{
|
||||||
|
retval += sep + col.Name;
|
||||||
|
sep=", ";
|
||||||
|
}
|
||||||
|
return retval;
|
||||||
|
}
|
||||||
//public ArrayList zzFilteredColumnsAny(IColumns columns,Filter [] fs){
|
//public ArrayList zzFilteredColumnsAny(IColumns columns,Filter [] fs){
|
||||||
// ArrayList l = new ArrayList();
|
// ArrayList l = new ArrayList();
|
||||||
// foreach(IColumn column in columns)
|
// foreach(IColumn column in columns)
|
||||||
|
@ -359,7 +359,7 @@
|
|||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(column.IsNullable && IsRelObj(column) && s.Contains("{ifLogicL"))
|
if(column.IsNullable && IsRelObj(column) && s.Contains("{ifLogicL"))
|
||||||
ifLogic="if({name} != null)";
|
ifLogic="if ({name} != null) ";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
s=s.Replace("{ifLogicL}",ifLogic.Replace("{name}",FormatColumnNew("{!local}{?dbtype}",column,sAlias)));
|
s=s.Replace("{ifLogicL}",ifLogic.Replace("{name}",FormatColumnNew("{!local}{?dbtype}",column,sAlias)));
|
||||||
|
@ -367,8 +367,14 @@
|
|||||||
s="Environment.UserName";
|
s="Environment.UserName";
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if(IsNumeric(s))s="" + s;
|
if(IsNumeric(s))
|
||||||
else s="";
|
s = "" + s;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if(s.StartsWith("N'"))
|
||||||
|
s = "\"" + s.Substring(2,s.Length-3) + "\"";
|
||||||
|
}
|
||||||
|
//else s="";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
|
@ -255,7 +255,9 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
|||||||
{
|
{
|
||||||
StartProc("purgeData");
|
StartProc("purgeData");
|
||||||
%>
|
%>
|
||||||
AS<%
|
AS
|
||||||
|
BEGIN TRY -- Try Block
|
||||||
|
BEGIN TRANSACTION<%
|
||||||
ArrayList toProcess = new ArrayList();
|
ArrayList toProcess = new ArrayList();
|
||||||
ArrayList processed = new ArrayList();
|
ArrayList processed = new ArrayList();
|
||||||
foreach(string sTable in _selectedTables)
|
foreach(string sTable in _selectedTables)
|
||||||
@ -307,7 +309,7 @@ AS<%
|
|||||||
}
|
}
|
||||||
if(processed.Count ==pCount)return;
|
if(processed.Count ==pCount)return;
|
||||||
}
|
}
|
||||||
EndProc("purgeData");
|
EndProcTran("purgeData");
|
||||||
}
|
}
|
||||||
private void InitializeMembers()
|
private void InitializeMembers()
|
||||||
{
|
{
|
||||||
@ -387,6 +389,8 @@ AS
|
|||||||
<%=FormatColumns("{@} {dtype}{?null}",tbl.Columns,",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",Computed(tbl),"",",\r\n\t")%>
|
<%=FormatColumns("{@} {dtype}{?null}",tbl.Columns,",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",Computed(tbl),"",",\r\n\t")%>
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
BEGIN TRY -- Try Block
|
||||||
|
BEGIN TRANSACTION
|
||||||
UPDATE [<%=tbl.Name%>]
|
UPDATE [<%=tbl.Name%>]
|
||||||
SET
|
SET
|
||||||
<%=FormatColumns("[{name}]={@}",Updatable(tbl),",\r\n","\t\t\t")%>
|
<%=FormatColumns("[{name}]={@}",Updatable(tbl),",\r\n","\t\t\t")%>
|
||||||
@ -405,7 +409,7 @@ AS
|
|||||||
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@}",tbl.PrimaryKeys," AND ","")%>
|
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@}",tbl.PrimaryKeys," AND ","")%>
|
||||||
<%
|
<%
|
||||||
}
|
}
|
||||||
EndProc(sproc);
|
EndProcTran(sproc);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Insert
|
// Insert
|
||||||
@ -419,6 +423,8 @@ AS
|
|||||||
<%=FormatColumns("{@} {dtype}{?null}",Insertable(tbl),",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",NotInsertable(tbl),"",",\r\n\t")%>
|
<%=FormatColumns("{@} {dtype}{?null}",Insertable(tbl),",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",NotInsertable(tbl),"",",\r\n\t")%>
|
||||||
)
|
)
|
||||||
AS
|
AS
|
||||||
|
BEGIN TRY -- Try Block
|
||||||
|
BEGIN TRANSACTION
|
||||||
INSERT INTO [<%=tbl.Name%>]
|
INSERT INTO [<%=tbl.Name%>]
|
||||||
(
|
(
|
||||||
<%=FormatColumns("[{name}]",Insertable(tbl),",\r\n","\t\t")%>
|
<%=FormatColumns("[{name}]",Insertable(tbl),",\r\n","\t\t")%>
|
||||||
@ -435,7 +441,7 @@ AS
|
|||||||
SELECT <%=FormatColumns("{@new}=[{name}]",cmp,"\r\n","\t\t")%>
|
SELECT <%=FormatColumns("{@new}=[{name}]",cmp,"\r\n","\t\t")%>
|
||||||
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@key}",tbl.PrimaryKeys," AND ","")%><%
|
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@key}",tbl.PrimaryKeys," AND ","")%><%
|
||||||
}
|
}
|
||||||
EndProc(sproc);
|
EndProcTran(sproc);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// Delete
|
// Delete
|
||||||
@ -448,7 +454,9 @@ AS
|
|||||||
(
|
(
|
||||||
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
||||||
)
|
)
|
||||||
AS<%
|
AS
|
||||||
|
BEGIN TRY -- Try Block
|
||||||
|
BEGIN TRANSACTION<%
|
||||||
foreach(IForeignKey fk in tbl.ForeignKeys)
|
foreach(IForeignKey fk in tbl.ForeignKeys)
|
||||||
{
|
{
|
||||||
if(tbl != fk.ForeignTable)
|
if(tbl != fk.ForeignTable)
|
||||||
@ -467,7 +475,7 @@ AS<%
|
|||||||
%>
|
%>
|
||||||
DELETE [<%=tbl.Name%>]
|
DELETE [<%=tbl.Name%>]
|
||||||
WHERE <%=FormatColumns("[{name}] = {@}",tbl.PrimaryKeys," AND ","")%><%
|
WHERE <%=FormatColumns("[{name}] = {@}",tbl.PrimaryKeys," AND ","")%><%
|
||||||
EndProc(sproc);
|
EndProcTran(sproc);
|
||||||
}
|
}
|
||||||
//----------------------------------------------------------------------
|
//----------------------------------------------------------------------
|
||||||
// SelectPK
|
// SelectPK
|
||||||
@ -638,6 +646,24 @@ GO
|
|||||||
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sproc%> Succeeded'
|
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sproc%> Succeeded'
|
||||||
ELSE PRINT 'Procedure Creation: <%=sproc%> Error on Creation'
|
ELSE PRINT 'Procedure Creation: <%=sproc%> Error on Creation'
|
||||||
GO
|
GO
|
||||||
|
<%
|
||||||
|
SaveFile(sproc);
|
||||||
|
}
|
||||||
|
private void EndProcTran(string sproc)
|
||||||
|
{
|
||||||
|
%>
|
||||||
|
IF( @@TRANCOUNT > 0 ) COMMIT
|
||||||
|
END TRY
|
||||||
|
BEGIN CATCH -- Catch Block
|
||||||
|
IF( @@TRANCOUNT = 1 ) ROLLBACK -- Only rollback if top level
|
||||||
|
ELSE IF( @@TRANCOUNT > 1 ) COMMIT -- Otherwise commit. Top level will rollback
|
||||||
|
EXEC vlnErrorHandler
|
||||||
|
END CATCH
|
||||||
|
GO
|
||||||
|
-- Display the status of Proc creation
|
||||||
|
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sproc%> Succeeded'
|
||||||
|
ELSE PRINT 'Procedure Creation: <%=sproc%> Error on Creation'
|
||||||
|
GO
|
||||||
<%
|
<%
|
||||||
SaveFile(sproc);
|
SaveFile(sproc);
|
||||||
}
|
}
|
||||||
|
@ -64,27 +64,29 @@ public class GeneratedGui : DotNetScriptGui
|
|||||||
|
|
||||||
GuiCheckBox chkDetail = MakeGuiCheckBox( "chkDetail", "MakeList & FK", true, "Show MakeList and FK",100 );
|
GuiCheckBox chkDetail = MakeGuiCheckBox( "chkDetail", "MakeList & FK", true, "Show MakeList and FK",100 );
|
||||||
chkDetail.Checked = false;
|
chkDetail.Checked = false;
|
||||||
GuiCheckBox chkColumns = MakeGuiCheckBox( "chkColumns", "Columns", true, "Show Columns" ,150,chkDetail,200,0);
|
GuiCheckBox chkColumns = MakeGuiCheckBox( "chkColumns", "Columns", true, "Show Columns" ,150,chkDetail,150,0);
|
||||||
chkColumns.Checked = false;
|
chkColumns.Checked = false;
|
||||||
GuiCheckBox chkFKCalc1 = MakeGuiCheckBox( "chkFKCalc1", "FK Calc 1", true, "FK Calc 1" ,150,chkDetail,400,0);
|
GuiCheckBox chkFKCalc1 = MakeGuiCheckBox( "chkFKCalc1", "FK Calc 1", true, "FK Calc 1" ,150,chkDetail,300,0);
|
||||||
chkFKCalc1.Checked = false;
|
chkFKCalc1.Checked = false;
|
||||||
|
GuiCheckBox chkProc = MakeGuiCheckBox( "chkProc", "Procedures", true, "Procedures" ,150,chkDetail,450,0);
|
||||||
|
chkProc.Checked = false;
|
||||||
GuiCheckBox chkUnique = MakeGuiCheckBox( "chkUnique", "Unique", true, "Unique Indexes" ,150,chkDetail,0, -1);
|
GuiCheckBox chkUnique = MakeGuiCheckBox( "chkUnique", "Unique", true, "Unique Indexes" ,150,chkDetail,0, -1);
|
||||||
chkUnique.Checked = false;
|
chkUnique.Checked = false;
|
||||||
GuiCheckBox chkFKCalc2 = MakeGuiCheckBox( "chkFKCalc2", "FK Calc 2", true, "FK Calc 2" ,150,chkDetail,200, -1);
|
GuiCheckBox chkFKCalc2 = MakeGuiCheckBox( "chkFKCalc2", "FK Calc 2", true, "FK Calc 2" ,150,chkDetail,150, -1);
|
||||||
chkFKCalc2.Checked = false;
|
chkFKCalc2.Checked = false;
|
||||||
GuiCheckBox chkColumns2 = MakeGuiCheckBox("chkColumns2","PrimFK",true,"Primary Foreign Key",150,chkDetail,400, -1);
|
GuiCheckBox chkColumns2 = MakeGuiCheckBox("chkColumns2","PrimFK",true,"Primary Foreign Key",150,chkDetail,300, -1);
|
||||||
chkColumns2.Checked = false;
|
chkColumns2.Checked = false;
|
||||||
GuiCheckBox chkRelated = MakeGuiCheckBox("chkRelated","Related",true,"Related",150,chkDetail,0,-2);
|
GuiCheckBox chkRelated = MakeGuiCheckBox("chkRelated","Related",true,"Related",150,chkDetail,0,-2);
|
||||||
chkRelated.Checked = false;
|
chkRelated.Checked = false;
|
||||||
GuiCheckBox chkOne2One = MakeGuiCheckBox("chkOne2One","One to One",true,"One to Many and One to One",150,chkDetail,200, -2);
|
GuiCheckBox chkOne2One = MakeGuiCheckBox("chkOne2One","One to One",true,"One to Many and One to One",150,chkDetail,150, -2);
|
||||||
chkOne2One.Checked = false;
|
chkOne2One.Checked = false;
|
||||||
GuiCheckBox chkIndexes = MakeGuiCheckBox("chkIndexes","Indexes",true,"Compare Foreign Keys to Indexes",150,chkDetail,400, -2);
|
GuiCheckBox chkIndexes = MakeGuiCheckBox("chkIndexes","Indexes",true,"Compare Foreign Keys to Indexes",150,chkDetail,300, -2);
|
||||||
chkIndexes.Checked = false;
|
chkIndexes.Checked = false;
|
||||||
GuiCheckBox chkInternal = MakeGuiCheckBox("chkInternal","Internal",true,"Internal Relationships",150,chkDetail, 0, -3);
|
GuiCheckBox chkInternal = MakeGuiCheckBox("chkInternal","Internal",true,"Internal Relationships",150,chkDetail, 0, -3);
|
||||||
chkInternal.Checked = false;
|
chkInternal.Checked = false;
|
||||||
GuiCheckBox chkAlias = MakeGuiCheckBox("chkAlias","Alias",true,"Aliases",150,chkDetail, 200, -3);
|
GuiCheckBox chkAlias = MakeGuiCheckBox("chkAlias","Alias",true,"Aliases",150,chkDetail, 150, -3);
|
||||||
chkAlias.Checked = false;
|
chkAlias.Checked = false;
|
||||||
GuiCheckBox chkNames = MakeGuiCheckBox("chkNames","Names",true,"Names",150,chkDetail, 400, -3);
|
GuiCheckBox chkNames = MakeGuiCheckBox("chkNames","Names",true,"Names",150,chkDetail, 300, -3);
|
||||||
chkNames.Checked = false;
|
chkNames.Checked = false;
|
||||||
// Setup Tables selection multi-select listbox.
|
// Setup Tables selection multi-select listbox.
|
||||||
GuiLabel label7 = ui.AddLabel( "label7", "Select tables:", "Select tables from the listbox below." );
|
GuiLabel label7 = ui.AddLabel( "label7", "Select tables:", "Select tables from the listbox below." );
|
||||||
@ -113,6 +115,7 @@ public class GeneratedGui : DotNetScriptGui
|
|||||||
chkInternal.AttachEvent( "onclick", "checkbox_onclick" );
|
chkInternal.AttachEvent( "onclick", "checkbox_onclick" );
|
||||||
chkAlias.AttachEvent( "onclick", "checkbox_onclick" );
|
chkAlias.AttachEvent( "onclick", "checkbox_onclick" );
|
||||||
chkNames.AttachEvent( "onclick", "checkbox_onclick" );
|
chkNames.AttachEvent( "onclick", "checkbox_onclick" );
|
||||||
|
chkProc.AttachEvent( "onclick", "checkbox_onclick" );
|
||||||
chooseTables.AttachEvent( "onchange", "chooseTable_onclick" );
|
chooseTables.AttachEvent( "onchange", "chooseTable_onclick" );
|
||||||
ui.ShowGui = true;
|
ui.ShowGui = true;
|
||||||
GuiButton btnOK = ui.AddButton( "OK", "OK", "Generate Code" );
|
GuiButton btnOK = ui.AddButton( "OK", "OK", "Generate Code" );
|
||||||
@ -226,6 +229,7 @@ public class GeneratedGui : DotNetScriptGui
|
|||||||
GuiCheckBox chkInternal= ui["chkInternal"] as GuiCheckBox;
|
GuiCheckBox chkInternal= ui["chkInternal"] as GuiCheckBox;
|
||||||
GuiCheckBox chkAlias= ui["chkAlias"] as GuiCheckBox;
|
GuiCheckBox chkAlias= ui["chkAlias"] as GuiCheckBox;
|
||||||
GuiCheckBox chkNames= ui["chkNames"] as GuiCheckBox;
|
GuiCheckBox chkNames= ui["chkNames"] as GuiCheckBox;
|
||||||
|
GuiCheckBox chkProc = ui["chkProc"] as GuiCheckBox;
|
||||||
GuiLabel labelTest = ui["labelTest"] as GuiLabel;
|
GuiLabel labelTest = ui["labelTest"] as GuiLabel;
|
||||||
string status = "";
|
string status = "";
|
||||||
if(chkDetail.Checked)status+=", " + chkDetail.Text;
|
if(chkDetail.Checked)status+=", " + chkDetail.Text;
|
||||||
@ -240,6 +244,7 @@ public class GeneratedGui : DotNetScriptGui
|
|||||||
if(chkInternal.Checked)status+=", " + chkInternal.Text;
|
if(chkInternal.Checked)status+=", " + chkInternal.Text;
|
||||||
if(chkAlias.Checked)status+=", " + chkAlias.Text;
|
if(chkAlias.Checked)status+=", " + chkAlias.Text;
|
||||||
if(chkNames.Checked)status+=", " + chkNames.Text;
|
if(chkNames.Checked)status+=", " + chkNames.Text;
|
||||||
|
if(chkProc.Checked)status+=", " + chkProc.Text;
|
||||||
if(status == "")
|
if(status == "")
|
||||||
{
|
{
|
||||||
btnOK.Enabled = false;
|
btnOK.Enabled = false;
|
||||||
@ -326,21 +331,28 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
|||||||
_selectedTables = input["chooseTables"] as ArrayList;
|
_selectedTables = input["chooseTables"] as ArrayList;
|
||||||
dicIndexes = new Hashtable();
|
dicIndexes = new Hashtable();
|
||||||
dicDrop = new Hashtable();
|
dicDrop = new Hashtable();
|
||||||
foreach( string _newTable in _selectedTables )
|
if((bool)input["chkProc"])
|
||||||
{
|
{
|
||||||
_workingTable = MyMeta.Databases[_dbName].Tables[_newTable];
|
ShowProcs(db);
|
||||||
if((bool)input["chkDetail"])ShowTable1( _workingTable );
|
}
|
||||||
if((bool)input["chkColumns"])ShowTable2( _workingTable );
|
else
|
||||||
if((bool)input["chkFKCalc1"])ShowTable3( _workingTable );
|
{
|
||||||
if((bool)input["chkUnique"])ShowTable4( _workingTable );
|
foreach( string _newTable in _selectedTables )
|
||||||
if((bool)input["chkFKCalc2"])ShowTable5( _workingTable );
|
{
|
||||||
if((bool)input["chkColumns2"])ShowTable6( _workingTable );
|
_workingTable = MyMeta.Databases[_dbName].Tables[_newTable];
|
||||||
if((bool)input["chkRelated"])ShowTable7( _workingTable );
|
if((bool)input["chkDetail"])ShowTable1( _workingTable );
|
||||||
if((bool)input["chkOne2One"])ShowTable8( _workingTable );
|
if((bool)input["chkColumns"])ShowTable2( _workingTable );
|
||||||
if((bool)input["chkIndexes"])ShowTable9( _workingTable );
|
if((bool)input["chkFKCalc1"])ShowTable3( _workingTable );
|
||||||
if((bool)input["chkInternal"])ShowInternalRelated( _workingTable );
|
if((bool)input["chkUnique"])ShowTable4( _workingTable );
|
||||||
if((bool)input["chkAlias"])ShowAlias( _workingTable );
|
if((bool)input["chkFKCalc2"])ShowTable5( _workingTable );
|
||||||
if((bool)input["chkNames"])ShowNames( _workingTable );
|
if((bool)input["chkColumns2"])ShowTable6( _workingTable );
|
||||||
|
if((bool)input["chkRelated"])ShowTable7( _workingTable );
|
||||||
|
if((bool)input["chkOne2One"])ShowTable8( _workingTable );
|
||||||
|
if((bool)input["chkIndexes"])ShowTable9( _workingTable );
|
||||||
|
if((bool)input["chkInternal"])ShowInternalRelated( _workingTable );
|
||||||
|
if((bool)input["chkAlias"])ShowAlias( _workingTable );
|
||||||
|
if((bool)input["chkNames"])ShowNames( _workingTable );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
//foreach(ITable tbl in db.Tables)
|
//foreach(ITable tbl in db.Tables)
|
||||||
//{
|
//{
|
||||||
@ -355,6 +367,22 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
|||||||
//}
|
//}
|
||||||
//SaveFile();
|
//SaveFile();
|
||||||
}
|
}
|
||||||
|
private void ShowProcs(IDatabase db)
|
||||||
|
{
|
||||||
|
foreach(IProcedure ip in db.Procedures)
|
||||||
|
{
|
||||||
|
//if(ip.Schema != "sys")
|
||||||
|
if(ip.Name=="purgeData" || ip.Name=="ve_GetPath")
|
||||||
|
{
|
||||||
|
%>
|
||||||
|
/****** Object: StoredProcedure [<%=ip.Name%>] Schema <%=ip.Schema%> Type <%=ip.Type.ToString()%> ******/
|
||||||
|
<%
|
||||||
|
bool isFunction=ip.ProcedureText.Contains("CREATE FUNCTION");
|
||||||
|
output.writeln(string.Format("IsFunction = {0}",isFunction));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private string ForeignKeyCheck(IColumn col)
|
private string ForeignKeyCheck(IColumn col)
|
||||||
{
|
{
|
||||||
if(col.IsInForeignKey)
|
if(col.IsInForeignKey)
|
||||||
|
@ -70,6 +70,7 @@ public class GeneratedGui : DotNetScriptGui
|
|||||||
GuiCheckBox chkDrop = MakeGuiCheckBox( "chkDrop", "Drop", true, "Drop Procedures" ,150,chkDelete,200,0);
|
GuiCheckBox chkDrop = MakeGuiCheckBox( "chkDrop", "Drop", true, "Drop Procedures" ,150,chkDelete,200,0);
|
||||||
GuiCheckBox chkSelectPK = MakeGuiCheckBox( "chkSelectPK", "Select One", true, "Select One Record" ,150,chkInsert,0,-1);
|
GuiCheckBox chkSelectPK = MakeGuiCheckBox( "chkSelectPK", "Select One", true, "Select One Record" ,150,chkInsert,0,-1);
|
||||||
GuiCheckBox chkExists = MakeGuiCheckBox("chkExists","Exists",true,"Check Record Exists",150,chkSelectPK,150,0);
|
GuiCheckBox chkExists = MakeGuiCheckBox("chkExists","Exists",true,"Check Record Exists",150,chkSelectPK,150,0);
|
||||||
|
GuiCheckBox chkVolian = MakeGuiCheckBox( "chkVolian", "Volian SPs", true, "Include Volian SPs" ,150,chkExists,200,0);
|
||||||
GuiCheckBox chkPurge = MakeGuiCheckBox("chkPurge","Purge",true,"Purge All Data",150,chkSelectPK,0,-1);
|
GuiCheckBox chkPurge = MakeGuiCheckBox("chkPurge","Purge",true,"Purge All Data",150,chkSelectPK,0,-1);
|
||||||
GuiCheckBox chkSelectFKs = MakeGuiCheckBox("chkSelectFKs","Select Group",true,"Select by Foreign Key",150,chkPurge,150,0);
|
GuiCheckBox chkSelectFKs = MakeGuiCheckBox("chkSelectFKs","Select Group",true,"Select by Foreign Key",150,chkPurge,150,0);
|
||||||
|
|
||||||
@ -223,22 +224,44 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
|||||||
SaveProcs(db);
|
SaveProcs(db);
|
||||||
//SaveTables(db);
|
//SaveTables(db);
|
||||||
}
|
}
|
||||||
|
private bool IncludeVolian(string sName)
|
||||||
|
{
|
||||||
|
return (!sName.StartsWith("ve") || (bool)input["chkVolian"]);
|
||||||
|
}
|
||||||
|
private void SaveProcsTesting(IDatabase db)
|
||||||
|
{
|
||||||
|
foreach(IProcedure ip in db.Procedures)
|
||||||
|
{
|
||||||
|
if(ip.Name == "vefn_SplitROSearch" || ip.Name == "ve_GetPath" || ip.Name == "getItemAndChildren")
|
||||||
|
{
|
||||||
|
output.writeln(string.Format("Name = '{0}' ",ip.Name));
|
||||||
|
output.writeln(string.Format("Schema = '{0}' ",ip.Schema));
|
||||||
|
foreach(IParameter param in ip.Parameters)
|
||||||
|
{
|
||||||
|
output.writeln(string.Format(" Parameter - {0} = {1}",param.Name,param.ParameterType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
private void SaveProcs(IDatabase db)
|
private void SaveProcs(IDatabase db)
|
||||||
{
|
{
|
||||||
foreach(IProcedure ip in db.Procedures)
|
foreach(IProcedure ip in db.Procedures)
|
||||||
{
|
{
|
||||||
if(ip.Schema != "sys"){
|
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;
|
string sName = ip.Name;
|
||||||
if((bool)input["chkDrop"]){
|
if((bool)input["chkDrop"]){
|
||||||
if(sName.Contains("sp_")==false && sName.Contains("fn_")==false)
|
if(sName.StartsWith("sp_")==false && sName.StartsWith("fn_")==false && IncludeVolian(sName))
|
||||||
output.writeln("Drop procedure [" + sName + "]");
|
output.writeln("DROP " + sType + " [" + sName + "]");
|
||||||
} else {
|
} else {
|
||||||
if(sName.Contains("sp_")==false && sName.Contains("fn_")==false)
|
if(sName.StartsWith("sp_")==false && sName.StartsWith("fn_")==false && IncludeVolian(sName))
|
||||||
{
|
{
|
||||||
%>
|
%>
|
||||||
/****** Object: StoredProcedure [<%=sName%>] ******/
|
/****** Object: StoredProcedure [<%=sName%>] ******/
|
||||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[<%=sName%>]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
|
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[<%=sName%>]') AND OBJECTPROPERTY(id,N'Is<%=sIsType%>') = 1)
|
||||||
DROP PROCEDURE [<%=sName%>];
|
DROP <%=sType%> [<%=sName%>];
|
||||||
GO
|
GO
|
||||||
|
|
||||||
<%
|
<%
|
||||||
@ -246,8 +269,8 @@ GO
|
|||||||
%>
|
%>
|
||||||
GO
|
GO
|
||||||
-- Display the status of Proc creation
|
-- Display the status of Proc creation
|
||||||
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sName%> Succeeded'
|
IF (@@Error = 0) PRINT '<%=sIsType%> Creation: <%=sName%> Succeeded'
|
||||||
ELSE PRINT 'Procedure Creation: <%=sName%> Error on Creation'
|
ELSE PRINT '<%=sIsType%> Creation: <%=sName%> Error on Creation'
|
||||||
GO
|
GO
|
||||||
<%
|
<%
|
||||||
SaveFile(ip.Name);
|
SaveFile(ip.Name);
|
||||||
@ -256,6 +279,14 @@ GO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
private bool IsProcedure(IProcedure ip)
|
||||||
|
{
|
||||||
|
return ip.ProcedureText.Contains("CREATE PROCEDURE");
|
||||||
|
}
|
||||||
|
private bool IsTableFunction(IProcedure ip)
|
||||||
|
{
|
||||||
|
return ip.Parameters[0].Name == "@TABLE_RETURN_VALUE";
|
||||||
|
}
|
||||||
private void ShowColumns(IColumns cols,int indent,string title)
|
private void ShowColumns(IColumns cols,int indent,string title)
|
||||||
{
|
{
|
||||||
output.writeln(string.Format("{0}{1}","".PadRight(indent),title));
|
output.writeln(string.Format("{0}{1}","".PadRight(indent),title));
|
||||||
|
@ -1311,147 +1311,6 @@ namespace VEPROMS.CSLA.Library
|
|||||||
{
|
{
|
||||||
_MyContent = new ContentInfo(dr, true);
|
_MyContent = new ContentInfo(dr, true);
|
||||||
}
|
}
|
||||||
#region Insert New Items
|
|
||||||
public ItemInfo InsertSiblingBefore(string text)
|
|
||||||
{
|
|
||||||
return InsertSiblingBefore(text, null);
|
|
||||||
}
|
|
||||||
public ItemInfo InsertSiblingBefore(string text, string number)
|
|
||||||
{
|
|
||||||
ItemInfo prevItemInfo = MyPrevious;
|
|
||||||
ItemInfo newItemInfo = null;
|
|
||||||
PartInfoList partInfoList = null;
|
|
||||||
if(MyParent != null && MyParent.MyContent != null)
|
|
||||||
{
|
|
||||||
MyParent.MyContent.RefreshContentParts();
|
|
||||||
partInfoList = MyParent.MyContent.ContentParts;
|
|
||||||
}
|
|
||||||
using (Item prevItem = prevItemInfo == null ? null : prevItemInfo.Get()) // Get the previous Item
|
|
||||||
{
|
|
||||||
using (Item newItem = Item.MakeItem(prevItem, Content.MakeContent(number, "", MyContent.Type, null, null))) // Create the new Item
|
|
||||||
{
|
|
||||||
using (Item thisItem = Get()) // Get the next item in the list
|
|
||||||
{
|
|
||||||
thisItem.MyPrevious = newItem; // Point to the new item
|
|
||||||
thisItem.Save(); // Save Changes
|
|
||||||
if (prevItem == null)
|
|
||||||
{
|
|
||||||
PartInfo partInfo = partInfoList.Find(this);
|
|
||||||
using (Part part = partInfo.Get())
|
|
||||||
{
|
|
||||||
part.MyItem = newItem;
|
|
||||||
part.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ToDo: Need change PartInfo in PartInfoList
|
|
||||||
newItemInfo = ItemInfo.Get(newItem.ItemID);
|
|
||||||
newItemInfo.ResetOrdinal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newItemInfo;
|
|
||||||
}
|
|
||||||
public ItemInfo InsertSiblingAfter(string text)
|
|
||||||
{
|
|
||||||
return InsertSiblingAfter(text, null);
|
|
||||||
}
|
|
||||||
public ItemInfo InsertSiblingAfter(string text, string number)
|
|
||||||
{
|
|
||||||
return InsertSiblingAfter(text, number, MyContent.Type);
|
|
||||||
}
|
|
||||||
public ItemInfo InsertSiblingAfter(string text, string number, int? type)
|
|
||||||
{
|
|
||||||
ItemInfo nextItemInfo = (NextItemCount > 0) ? NextItems[0] : null;
|
|
||||||
ItemInfo newItemInfo = null;
|
|
||||||
using (Item thisItem = Get()) // Get the Current Item
|
|
||||||
{
|
|
||||||
using (Item newItem = Item.MakeItem(thisItem, Content.MakeContent(number, text, type, null, null))) // Create the new Item
|
|
||||||
{
|
|
||||||
if (nextItemInfo != null) // Simple case, adding to end of list:
|
|
||||||
using (Item nextItem = nextItemInfo.Get()) // Get the next item in the list
|
|
||||||
{
|
|
||||||
nextItem.MyPrevious = newItem; // Point to the new item
|
|
||||||
nextItem.Save(); // Save Changes
|
|
||||||
}
|
|
||||||
// ToDo: Need change PartInfo in PartInfoList
|
|
||||||
newItemInfo = ItemInfo.Get(newItem.ItemID);
|
|
||||||
newItemInfo.ResetOrdinal();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return newItemInfo;
|
|
||||||
}
|
|
||||||
public ItemInfo InsertChild(E_FromType fromType,int type,string text)
|
|
||||||
{
|
|
||||||
return InsertChild(fromType,type,text, null);
|
|
||||||
}
|
|
||||||
public ItemInfo InsertChild(E_FromType fromType,int type, string text, string number)
|
|
||||||
{
|
|
||||||
ItemInfo newItemInfo = null;
|
|
||||||
using (Item thisItem = Get()) // Get the Current Item
|
|
||||||
{
|
|
||||||
using (Item newItem = Item.MakeItem(null, Content.MakeContent(number, text, type, null, null))) // Create the new Item
|
|
||||||
{
|
|
||||||
PartInfo partInfo = MyContent.ContentParts == null ? null : MyContent.ContentParts.Find(fromType);
|
|
||||||
if (partInfo != null)
|
|
||||||
{
|
|
||||||
//this could be equivalent to adding a sibling with a specific type
|
|
||||||
using (Part part = partInfo.Get())
|
|
||||||
{
|
|
||||||
part.MyItem.MyPrevious = newItem;
|
|
||||||
part.MyItem.Save();
|
|
||||||
part.MyItem = newItem;
|
|
||||||
part.Save();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// This means that a part needs to be added to point to the new item
|
|
||||||
//using (Part part = Part.MakePart(thisItem.MyContent, ))
|
|
||||||
//{ ;}
|
|
||||||
thisItem.MyContent.ContentParts.Add((int)fromType, newItem);
|
|
||||||
thisItem.Save();
|
|
||||||
}
|
|
||||||
newItemInfo = ItemInfo.Get(newItem.ItemID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
ResetParts();
|
|
||||||
return newItemInfo;
|
|
||||||
}
|
|
||||||
public ItemInfo NextItem
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (NextItemCount > 0 && NextItems.Count > 0)
|
|
||||||
return NextItems[0];
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private static void ResetOrdinal(int itemID)
|
|
||||||
{
|
|
||||||
bool first = true;
|
|
||||||
ConvertListToDictionary();
|
|
||||||
string key = itemID.ToString();
|
|
||||||
if (_CacheByPrimaryKey.ContainsKey(key))
|
|
||||||
{
|
|
||||||
foreach (ItemInfo itm in _CacheByPrimaryKey[key])
|
|
||||||
{
|
|
||||||
itm._Ordinal = null;
|
|
||||||
//Console.WriteLine("Ordinal {0},{1}",key,itm.MyPrevious == null ? 0 : itm.MyPrevious._Ordinal);
|
|
||||||
if (first && itm.NextItem != null)
|
|
||||||
{
|
|
||||||
ResetOrdinal(itm.NextItem.ItemID);
|
|
||||||
first = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
private void ResetOrdinal()
|
|
||||||
{
|
|
||||||
//_Ordinal = null;
|
|
||||||
//Console.WriteLine("Ordinal {0},{1}",ItemID,MyPrevious == null ? 0 : MyPrevious.Ordinal);
|
|
||||||
ResetOrdinal(ItemID);
|
|
||||||
}
|
|
||||||
#endregion
|
|
||||||
}
|
}
|
||||||
#endregion ItemInfo
|
#endregion ItemInfo
|
||||||
#region ItemInfoList
|
#region ItemInfoList
|
||||||
|
Loading…
x
Reference in New Issue
Block a user