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){
|
||||
ArrayList l = new ArrayList();
|
||||
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;}
|
||||
// Used in CSLA Stored Procedures
|
||||
private ArrayList AutoKey(ITable tbl){
|
||||
@ -180,7 +180,7 @@
|
||||
string sPrefixType="";
|
||||
string sPrefix="";
|
||||
string sPrefixSet="";
|
||||
string sCheckSep = "if( ";
|
||||
string sCheckSep = "if (";
|
||||
sMakeListParamTypes = "";
|
||||
sMakeListParams = "";
|
||||
sSetTmp = "";
|
||||
@ -195,7 +195,7 @@
|
||||
sepSet="\r\n";
|
||||
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 = "|| ";
|
||||
}
|
||||
}
|
||||
@ -511,6 +511,17 @@
|
||||
}
|
||||
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){
|
||||
// ArrayList l = new ArrayList();
|
||||
// foreach(IColumn column in columns)
|
||||
|
@ -359,7 +359,7 @@
|
||||
break;
|
||||
default:
|
||||
if(column.IsNullable && IsRelObj(column) && s.Contains("{ifLogicL"))
|
||||
ifLogic="if({name} != null)";
|
||||
ifLogic="if ({name} != null) ";
|
||||
break;
|
||||
}
|
||||
s=s.Replace("{ifLogicL}",ifLogic.Replace("{name}",FormatColumnNew("{!local}{?dbtype}",column,sAlias)));
|
||||
|
@ -367,8 +367,14 @@
|
||||
s="Environment.UserName";
|
||||
break;
|
||||
default:
|
||||
if(IsNumeric(s))s="" + s;
|
||||
else s="";
|
||||
if(IsNumeric(s))
|
||||
s = "" + s;
|
||||
else
|
||||
{
|
||||
if(s.StartsWith("N'"))
|
||||
s = "\"" + s.Substring(2,s.Length-3) + "\"";
|
||||
}
|
||||
//else s="";
|
||||
break;
|
||||
}
|
||||
return s;
|
||||
|
@ -255,7 +255,9 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
{
|
||||
StartProc("purgeData");
|
||||
%>
|
||||
AS<%
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION<%
|
||||
ArrayList toProcess = new ArrayList();
|
||||
ArrayList processed = new ArrayList();
|
||||
foreach(string sTable in _selectedTables)
|
||||
@ -307,7 +309,7 @@ AS<%
|
||||
}
|
||||
if(processed.Count ==pCount)return;
|
||||
}
|
||||
EndProc("purgeData");
|
||||
EndProcTran("purgeData");
|
||||
}
|
||||
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")%>
|
||||
)
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
UPDATE [<%=tbl.Name%>]
|
||||
SET
|
||||
<%=FormatColumns("[{name}]={@}",Updatable(tbl),",\r\n","\t\t\t")%>
|
||||
@ -405,7 +409,7 @@ AS
|
||||
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@}",tbl.PrimaryKeys," AND ","")%>
|
||||
<%
|
||||
}
|
||||
EndProc(sproc);
|
||||
EndProcTran(sproc);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Insert
|
||||
@ -419,6 +423,8 @@ AS
|
||||
<%=FormatColumns("{@} {dtype}{?null}",Insertable(tbl),",\r\n","\t")%><%=FormatColumns("{@new} {dtype} output",NotInsertable(tbl),"",",\r\n\t")%>
|
||||
)
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION
|
||||
INSERT INTO [<%=tbl.Name%>]
|
||||
(
|
||||
<%=FormatColumns("[{name}]",Insertable(tbl),",\r\n","\t\t")%>
|
||||
@ -435,7 +441,7 @@ AS
|
||||
SELECT <%=FormatColumns("{@new}=[{name}]",cmp,"\r\n","\t\t")%>
|
||||
FROM [<%=tbl.Name%>] WHERE <%=FormatColumns("[{name}]={@key}",tbl.PrimaryKeys," AND ","")%><%
|
||||
}
|
||||
EndProc(sproc);
|
||||
EndProcTran(sproc);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// Delete
|
||||
@ -448,7 +454,9 @@ AS
|
||||
(
|
||||
<%=FormatColumns("{@} {dtype}",tbl.PrimaryKeys,",\r\n","\t")%>
|
||||
)
|
||||
AS<%
|
||||
AS
|
||||
BEGIN TRY -- Try Block
|
||||
BEGIN TRANSACTION<%
|
||||
foreach(IForeignKey fk in tbl.ForeignKeys)
|
||||
{
|
||||
if(tbl != fk.ForeignTable)
|
||||
@ -467,7 +475,7 @@ AS<%
|
||||
%>
|
||||
DELETE [<%=tbl.Name%>]
|
||||
WHERE <%=FormatColumns("[{name}] = {@}",tbl.PrimaryKeys," AND ","")%><%
|
||||
EndProc(sproc);
|
||||
EndProcTran(sproc);
|
||||
}
|
||||
//----------------------------------------------------------------------
|
||||
// SelectPK
|
||||
@ -638,6 +646,24 @@ GO
|
||||
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sproc%> Succeeded'
|
||||
ELSE PRINT 'Procedure Creation: <%=sproc%> Error on Creation'
|
||||
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);
|
||||
}
|
||||
|
@ -64,27 +64,29 @@ public class GeneratedGui : DotNetScriptGui
|
||||
|
||||
GuiCheckBox chkDetail = MakeGuiCheckBox( "chkDetail", "MakeList & FK", true, "Show MakeList and FK",100 );
|
||||
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;
|
||||
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;
|
||||
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);
|
||||
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;
|
||||
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;
|
||||
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,200, -2);
|
||||
GuiCheckBox chkOne2One = MakeGuiCheckBox("chkOne2One","One to One",true,"One to Many and One to One",150,chkDetail,150, -2);
|
||||
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;
|
||||
GuiCheckBox chkInternal = MakeGuiCheckBox("chkInternal","Internal",true,"Internal Relationships",150,chkDetail, 0, -3);
|
||||
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;
|
||||
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;
|
||||
// Setup Tables selection multi-select listbox.
|
||||
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" );
|
||||
chkAlias.AttachEvent( "onclick", "checkbox_onclick" );
|
||||
chkNames.AttachEvent( "onclick", "checkbox_onclick" );
|
||||
chkProc.AttachEvent( "onclick", "checkbox_onclick" );
|
||||
chooseTables.AttachEvent( "onchange", "chooseTable_onclick" );
|
||||
ui.ShowGui = true;
|
||||
GuiButton btnOK = ui.AddButton( "OK", "OK", "Generate Code" );
|
||||
@ -226,6 +229,7 @@ public class GeneratedGui : DotNetScriptGui
|
||||
GuiCheckBox chkInternal= ui["chkInternal"] as GuiCheckBox;
|
||||
GuiCheckBox chkAlias= ui["chkAlias"] as GuiCheckBox;
|
||||
GuiCheckBox chkNames= ui["chkNames"] as GuiCheckBox;
|
||||
GuiCheckBox chkProc = ui["chkProc"] as GuiCheckBox;
|
||||
GuiLabel labelTest = ui["labelTest"] as GuiLabel;
|
||||
string status = "";
|
||||
if(chkDetail.Checked)status+=", " + chkDetail.Text;
|
||||
@ -240,6 +244,7 @@ public class GeneratedGui : DotNetScriptGui
|
||||
if(chkInternal.Checked)status+=", " + chkInternal.Text;
|
||||
if(chkAlias.Checked)status+=", " + chkAlias.Text;
|
||||
if(chkNames.Checked)status+=", " + chkNames.Text;
|
||||
if(chkProc.Checked)status+=", " + chkProc.Text;
|
||||
if(status == "")
|
||||
{
|
||||
btnOK.Enabled = false;
|
||||
@ -326,6 +331,12 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
_selectedTables = input["chooseTables"] as ArrayList;
|
||||
dicIndexes = new Hashtable();
|
||||
dicDrop = new Hashtable();
|
||||
if((bool)input["chkProc"])
|
||||
{
|
||||
ShowProcs(db);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach( string _newTable in _selectedTables )
|
||||
{
|
||||
_workingTable = MyMeta.Databases[_dbName].Tables[_newTable];
|
||||
@ -342,6 +353,7 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
if((bool)input["chkAlias"])ShowAlias( _workingTable );
|
||||
if((bool)input["chkNames"])ShowNames( _workingTable );
|
||||
}
|
||||
}
|
||||
//foreach(ITable tbl in db.Tables)
|
||||
//{
|
||||
// ShowTable3(tbl);
|
||||
@ -355,6 +367,22 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
//}
|
||||
//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)
|
||||
{
|
||||
if(col.IsInForeignKey)
|
||||
|
@ -70,6 +70,7 @@ public class GeneratedGui : DotNetScriptGui
|
||||
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 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 chkSelectFKs = MakeGuiCheckBox("chkSelectFKs","Select Group",true,"Select by Foreign Key",150,chkPurge,150,0);
|
||||
|
||||
@ -223,22 +224,44 @@ public class GeneratedTemplate : DotNetScriptTemplate
|
||||
SaveProcs(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)
|
||||
{
|
||||
foreach(IProcedure ip in db.Procedures)
|
||||
{
|
||||
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.Contains("sp_")==false && sName.Contains("fn_")==false)
|
||||
output.writeln("Drop procedure [" + sName + "]");
|
||||
if(sName.StartsWith("sp_")==false && sName.StartsWith("fn_")==false && IncludeVolian(sName))
|
||||
output.writeln("DROP " + sType + " [" + sName + "]");
|
||||
} else {
|
||||
if(sName.Contains("sp_")==false && sName.Contains("fn_")==false)
|
||||
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'IsProcedure') = 1)
|
||||
DROP PROCEDURE [<%=sName%>];
|
||||
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[<%=sName%>]') AND OBJECTPROPERTY(id,N'Is<%=sIsType%>') = 1)
|
||||
DROP <%=sType%> [<%=sName%>];
|
||||
GO
|
||||
|
||||
<%
|
||||
@ -246,8 +269,8 @@ GO
|
||||
%>
|
||||
GO
|
||||
-- Display the status of Proc creation
|
||||
IF (@@Error = 0) PRINT 'Procedure Creation: <%=sName%> Succeeded'
|
||||
ELSE PRINT 'Procedure Creation: <%=sName%> Error on Creation'
|
||||
IF (@@Error = 0) PRINT '<%=sIsType%> Creation: <%=sName%> Succeeded'
|
||||
ELSE PRINT '<%=sIsType%> Creation: <%=sName%> Error on Creation'
|
||||
GO
|
||||
<%
|
||||
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)
|
||||
{
|
||||
output.writeln(string.Format("{0}{1}","".PadRight(indent),title));
|
||||
|
@ -1311,147 +1311,6 @@ namespace VEPROMS.CSLA.Library
|
||||
{
|
||||
_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
|
||||
#region ItemInfoList
|
||||
|
Loading…
x
Reference in New Issue
Block a user