zoukankan      html  css  js  c++  java
  • C#-IEditableObject Interface

    IEditableObject Interface

    Definition

    Namespace:

    System.ComponentModel

    Assemblies:

    System.ComponentModel.dll, System.dll, netstandard.dll

    Provides functionality to commit or rollback changes to an object that is used as a data source.

    C#Copy

    public interface IEditableObject

    Derived

    System.Data.DataRowView

    Examples

    The following sample provides a simple implementation of the IEditableObject interface. The Customer class stores customer information and can be used as a collection for a customer database. This sample assumes that you have used the CustomerList class that can be found in sample in the IBindingList class.

    C#Copy

    public class Customer : IEditableObject 
    {
       
        struct CustomerData 
        {
            internal string id ;
            internal string firstName ;
            internal string lastName ;
        }
        
        private CustomersList parent;
        private CustomerData custData; 
        private CustomerData backupData; 
        private bool inTxn = false;
    
        // Implements IEditableObject
        void IEditableObject.BeginEdit() 
        {
            Console.WriteLine("Start BeginEdit");
            if (!inTxn) 
            {
                this.backupData = custData;
                inTxn = true;
                Console.WriteLine("BeginEdit - " + this.backupData.lastName);
            }
            Console.WriteLine("End BeginEdit");
        }
    
        void IEditableObject.CancelEdit() 
        {
            Console.WriteLine("Start CancelEdit");
            if (inTxn) 
            {
                this.custData = backupData;
                inTxn = false;
                Console.WriteLine("CancelEdit - " + this.custData.lastName);
            }
            Console.WriteLine("End CancelEdit");
        }
    
        void IEditableObject.EndEdit() 
        {
            Console.WriteLine("Start EndEdit" + this.custData.id + this.custData.lastName);
            if (inTxn) 
            {
                backupData = new CustomerData();
                inTxn = false;
                Console.WriteLine("Done EndEdit - " + this.custData.id + this.custData.lastName);
            }
            Console.WriteLine("End EndEdit");
        }
    
        public Customer(string ID) : base() 
        {
            this.custData = new CustomerData();
            this.custData.id = ID;
            this.custData.firstName = "";
            this.custData.lastName = "";
        }
    
        public string ID 
        {
            get 
            {
                return this.custData.id;
            }
        }
        
        public string FirstName 
        {
            get 
            {
                return this.custData.firstName;
            }
            set 
            {
                this.custData.firstName = value;
                this.OnCustomerChanged();
            }
        }
             
        public string LastName 
        {
            get 
            {
                return this.custData.lastName;
            }
            set 
            {
                this.custData.lastName = value;
                this.OnCustomerChanged();
            }
        }
       
        internal CustomersList Parent 
        {
            get 
            {
                return parent;
            }
            set 
            {
                parent = value ;
            }
        }
    
        private void OnCustomerChanged() 
        {
            if (!inTxn && Parent != null) 
            {
                Parent.CustomerChanged(this);
            }
        }
        
        public override string ToString() 
        {
            StringWriter sb = new StringWriter();
            sb.Write(this.FirstName);
            sb.Write(" ");
            sb.Write(this.LastName);
            return sb.ToString();
        }   
    }
    

    Remarks

    This interface is typically used to capture the BeginEditEndEdit, and CancelEdit semantics of a DataRowView.

  • 相关阅读:
    cocos2d-x 获得系统语言繁体
    状态机
    cocos2d-x 混合模式
    cocos2d-x 3.x 橡皮擦功能
    MySQL 库大小、表大小、索引大小查询命令
    MySQL批量杀进程
    多实例MySQL批量添加用户和密码并授权
    删除或清空具有外键约束的表数据报-ERROR 1701 (42000)
    ERROR 1062 (23000): Duplicate entry '0' for key 'PRIMARY'
    MySQL 多实例给root用户创建密码
  • 原文地址:https://www.cnblogs.com/grj001/p/12222975.html
Copyright © 2011-2022 走看看