///<summary>Drops table in DB. Recreates Table, then fills with Data. ///Pass in the userod.UserNum of the user that is making the change. Typically Security.CurUser.UserNum.</summary> public static void RevertFrom(WikiListHist wikiListHist, long userNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), wikiListHist, userNum); return; } if (!WikiLists.CheckExists(wikiListHist.ListName)) { return; //should never happen. } DataTable tableRevertedContent = new DataTable(); using (XmlReader xmlReader = XmlReader.Create(new StringReader(wikiListHist.ListContent))){ tableRevertedContent.ReadXml(xmlReader); } //Begin the process of deleting old table and creating new one. //Save current wiki list content to the history WikiListHists.Insert(GenerateFromName(wikiListHist.ListName, userNum)); //Delete current wiki list WikiLists.DeleteList(wikiListHist.ListName); //Create a new empty wiki list, except for the PK column WikiLists.CreateNewWikiList(wikiListHist.ListName); //Load header data List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetFromListHist(wikiListHist); //Add one column per header, skipping the Pk column for (int i = 1; i < listHeaders.Count; i++) //skip the first one, because the first one is the primary key { WikiLists.AddColumn(listHeaders[i].ListName); } //Update db with current names and current widths of columns in the WikiListHeaderWidth table to the reverted values WikiListHeaderWidths.UpdateNamesAndWidths(wikiListHist.ListName, listHeaders); //Fill db table with the reverted values. for (int i = 0; i < tableRevertedContent.Rows.Count; i++) { DataRow row = tableRevertedContent.Rows[i]; row[0] = WikiLists.AddItem(wikiListHist.ListName); //setPK and add new row DataTable tableOneItem = tableRevertedContent.Clone(); tableOneItem.Rows.Add(tableOneItem.NewRow()); tableOneItem.Rows[0].ItemArray = row.ItemArray; WikiLists.UpdateItem(wikiListHist.ListName, tableOneItem); } }
///<summary>Drops table in DB. Recreates Table, then fills with Data. ///Pass in the userod.UserNum of the user that is making the change. Typically Security.CurUser.UserNum.</summary> public static void RevertFrom(WikiListHist wikiListHist, long userNum) { if (RemotingClient.RemotingRole == RemotingRole.ClientWeb) { Meth.GetVoid(MethodBase.GetCurrentMethod(), wikiListHist, userNum); return; } if (!WikiLists.CheckExists(wikiListHist.ListName)) { return; //should never happen. } Insert(GenerateFromName(wikiListHist.ListName, userNum)); //Save current wiki list content to the history List <WikiListHeaderWidth> listHeaders = WikiListHeaderWidths.GetFromListHist(wikiListHist); //Load header data WikiLists.CreateNewWikiList(wikiListHist.ListName, listHeaders, true); //dropTableIfExists=true, so the existing table and HeaderWidth rows will be dropped DataTable tableRevertedContent = new DataTable(); using (StringReader sr = new StringReader(wikiListHist.ListContent)) using (XmlReader xmlReader = XmlReader.Create(sr)) { tableRevertedContent.ReadXml(xmlReader); } string commandStart = $@"INSERT INTO wikilist_{POut.String(wikiListHist.ListName)} ({string.Join(",",listHeaders.Select(x => POut.String(x.ColName)))}) VALUES " ; StringBuilder sb = new StringBuilder(commandStart); string commaStr = ""; for (int i = 0; i < tableRevertedContent.Rows.Count; i++) { string rowStr = "(" + string.Join(",", tableRevertedContent.Rows[i].ItemArray.Select(x => "'" + POut.String(x.ToString()) + "'")) + ")"; if (sb.Length + rowStr.Length + 1 > TableBase.MaxAllowedPacketCount) { Db.NonQ(sb.ToString()); sb = new StringBuilder(commandStart); commaStr = ""; } sb.Append(commaStr + rowStr); commaStr = ","; if (i == tableRevertedContent.Rows.Count - 1) { Db.NonQ(sb.ToString()); } } }