- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
N-LEV EL UNDO in C#
CHAPTER 13 N-LEV EL UNDO Painting PDF417 In Visual C# Using Barcode generator for Visual Studio .NET Control to generate, create PDF417 image in .NET framework applications. www.OnBarcode.comDecode PDF 417 In Visual C# Using Barcode recognizer for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.comFigure 13-2. Edit process in which objects are removed and CancelEdit is called Another common scenario follows the same process but with a call to ApplyEdit() at the end, as shown in Figure 13-3. Generate Matrix In C#.NET Using Barcode encoder for .NET Control to generate, create Matrix 2D Barcode image in VS .NET applications. www.OnBarcode.comCode 128 Creator In C#.NET Using Barcode printer for VS .NET Control to generate, create Code 128 Code Set B image in .NET framework applications. www.OnBarcode.comFigure 13-3. Edit process in which objects are removed and ApplyEdit is called
Printing PDF417 In Visual C# Using Barcode generator for .NET Control to generate, create PDF-417 2d barcode image in Visual Studio .NET applications. www.OnBarcode.comGenerating GTIN - 13 In Visual C# Using Barcode creation for .NET Control to generate, create EAN 13 image in Visual Studio .NET applications. www.OnBarcode.comCHAPTER 13 N-LEV EL UNDO
Creating Barcode In C# Using Barcode drawer for Visual Studio .NET Control to generate, create Barcode image in .NET framework applications. www.OnBarcode.comUSD - 8 Drawer In C# Using Barcode maker for .NET framework Control to generate, create Code11 image in .NET framework applications. www.OnBarcode.comThe first two steps are identical, of course, but after the call to ApplyEdit(), things are quite different. Since changes to the collection are accepted rather than rejected, the changes become permanent. Child A remains marked for deletion, and if the collection is saved back to the database, the data for child A is deleted from the database. Child B is totally gone at this point. It is a new object added and deleted at edit level 1, and all changes made at edit level 1 are accepted. Since the collection knows that B was never in the database (because it was added at edit level 1), it can simply discard the object entirely from memory. Let s look at one last scenario. Just to illustrate how rough this gets, this will be more complex. It involves nested BeginEdit(), CancelEdit(), and ApplyEdit() calls on the collection. This can easily happen if the collection contains child or grandchild objects and they are displayed in a Windows Forms UI that uses modal dialog windows to edit each level (parent, child, grandchild, etc.). Again, child A is loaded from the database and child B is added at edit level 1. Finally, C is added at edit level 2. Then all three child objects are removed, as shown in Figure 13-4. PDF-417 2d Barcode Generator In VB.NET Using Barcode maker for .NET framework Control to generate, create PDF 417 image in .NET framework applications. www.OnBarcode.comPDF 417 Drawer In None Using Barcode generator for Office Word Control to generate, create PDF-417 2d barcode image in Office Word applications. www.OnBarcode.comFigure 13-4. The result after loading, adding, and removing objects Suppose ApplyEdit() is now called on the collection. This applies all edits made at edit level 2, putting the collection back to edit level 1. Since child C was added at edit level 2, it simply goes away, but child B sticks around because it was added at edit level 1, which is illustrated in Figure 13-5. Both objects remain marked for deletion because the changes made at edit level 2 were applied. Were CancelEdit() called now, the collection would return to the same state as when the first BeginEdit() was called, meaning that only child A (not marked for deletion) would be left. Code 128 Maker In Java Using Barcode creator for Eclipse BIRT Control to generate, create Code 128 image in BIRT reports applications. www.OnBarcode.comReading QR Code 2d Barcode In .NET Framework Using Barcode scanner for VS .NET Control to read, scan read, scan image in .NET framework applications. www.OnBarcode.comCHAPTER 13 N-LEV EL UNDO
EAN13 Encoder In None Using Barcode maker for Excel Control to generate, create EAN13 image in Excel applications. www.OnBarcode.comEAN 13 Encoder In Objective-C Using Barcode encoder for iPad Control to generate, create GTIN - 13 image in iPad applications. www.OnBarcode.comFigure 13-5. Result after calling ApplyEdit Alternatively, a call to ApplyEdit() would commit all changes made at edit level 1: child A would continue to be marked for deletion, and child B would be totally discarded because it was added and deleted at edit level 1. Both of these possible outcomes are illustrated in Figure 13-6. QR Generation In Java Using Barcode creation for Java Control to generate, create QR-Code image in Java applications. www.OnBarcode.comEAN-13 Supplement 5 Generator In None Using Barcode creator for Microsoft Word Control to generate, create EAN 13 image in Office Word applications. www.OnBarcode.comFigure 13-6. Result after calling either CancelEdit or ApplyEdit Having gone through all that, let s take a look at the code that implements these behaviors. The DeleteChild() and UnDeleteChild() methods deal with marking the child objects as deleted and moving them between the active items in the collection and the DeletedList object: Creating Barcode In Java Using Barcode generation for BIRT reports Control to generate, create Barcode image in BIRT applications. www.OnBarcode.comCode 128 Code Set B Printer In None Using Barcode creator for Online Control to generate, create Code128 image in Online applications. www.OnBarcode.comCHAPTER 13 N-LEV EL UNDO
Drawing Barcode In Java Using Barcode maker for Java Control to generate, create Barcode image in Java applications. www.OnBarcode.comGS1 - 12 Creator In Java Using Barcode printer for Android Control to generate, create UPC Code image in Android applications. www.OnBarcode.comprivate void DeleteChild(C child) { // set child edit level Core.UndoableBase.ResetChildEditLevel(child, this.EditLevel, false); // remove from the index RemoveIndexItem(child); // remove from the position map RemoveFromMap(child); // mark the object as deleted child.DeleteChild(); // and add it to the deleted collection for storage DeletedList.Add(child); } private void UnDeleteChild(C child) { // since the object is no longer deleted, remove it from // the deleted collection DeletedList.Remove(child); // we are inserting an _existing_ object so // we need to preserve the object's editleveladded value // because it will be changed by the normal add process int saveLevel = child.EditLevelAdded; InsertIndexItem(child); Add(child); child.EditLevelAdded = saveLevel; } On the surface, this doesn t seem too complicated but look at the code that deals with the child s EditLevelAdded property in the UnDeleteChild() method. In the InsertItem() method I discussed earlier, the assumption is that any child being added to the collection is a new object and therefore InsertItem() sets its edit level value to the collection s current value. However, the InsertItem() method is run when this preexisting object is reinserted into the collection, altering its edit level. That would leave the child object with an incorrect edit level value. The problem is that in this case, the child object isn t a new object; it is a preexisting object that is just being restored to the collection. To solve this, the object s edit level value is stored in a temporary field, the child object is re-added to the collection, and then the child object s edit level value is reset to the original value, effectively leaving it unchanged.
|
|