C/S中的MVC(4) 荣

using System;
using System.Data;
using System.Windows.Forms;

using Business;

namespace Business.Base
{
 /// <summary>
 /// Description:窗体的基类。
 /// </summary>
 public class FormBase
 {
  /// <summary>
  /// 存储窗体所需数据的DataSet对象。
  /// </summary>
  protected DataSet dataSet;

  /// <summary>
  /// 取得数据的委托。
  /// </summary>
  protected delegate void SetDataHandler();

  /// <summary>
  /// 处理成功信息的委托。
  /// </summary>
  protected delegate void SucessFunctionHandler();

  /// <summary>
  /// 执行操作的委托。
  /// </summary>
  protected delegate void ActionHandler();

  /// <summary>
  /// 执行操作的委托。
  /// </summary>
  private delegate void ActionParHandler(System.Windows.Forms.Form form, object obj);

  /// <summary>
  /// 取得数据的事件。
  /// </summary>
  protected event SetDataHandler SetDataEvent;

  /// <summary>
  /// 处理成功信息的事件。
  /// </summary>
  protected event SucessFunctionHandler SucessFunctionEvent;

  /// <summary>
  /// 执行操作的事件。
  /// </summary>
  protected event ActionHandler ActionEvent;

  /// <summary>
  /// 执行操作的事件。
  /// </summary>
  private event ActionParHandler ActionParEvent;

  /// <summary>
  /// Description:执行操作。
  /// </summary>
  protected void DoAction()
  {
   try
   {
    //取得数据
    if (SetDataEvent != null)
    {
     SetDataEvent();
    }

    //执行操作
    if (ActionEvent != null)
    {
     ActionEvent();
    }

    //成功后的操作
    if (SucessFunctionEvent != null)
    {
     SucessFunctionEvent();
    }
   }
   catch(Exception ex)
   {
    CommonBN.DealError(ex, "");
   }
   finally
   {
    //清除事件
    SucessFunctionEvent = null;
    SetDataEvent = null;
    ActionEvent = null;
   }
  }

  /// <summary>
  /// Description:执行操作。
  /// </summary>
  private void DoAction(System.Windows.Forms.Form form, object obj)
  {
   try
   {
    //取得数据
    if (SetDataEvent != null)
    {
     SetDataEvent();
    }

    //执行操作
    if (ActionParEvent != null)
    {
     ActionParEvent(form, obj);
    }

    //成功后的操作
    if (SucessFunctionEvent != null)
    {
     SucessFunctionEvent();
    }
   }
   catch(Exception ex)
   {
    CommonBN.DealError(ex , "");
   }
   finally
   {
    //清除事件
    SucessFunctionEvent = null;
    SetDataEvent = null;
    ActionEvent = null;
   }
  }

  /// <summary>
  /// Description:取得窗体的初始数据。
  /// </summary>
  protected void GetInitialData(System.Windows.Forms.Form form, object obj)
  {
   FormFactoryBN bn = new FormFactoryBN();

   //取得初始数据
   bn.InitialData(dataSet, form, obj);
  }

  /// <summary>
  /// Description:初始化控件。
  /// </summary>
  protected virtual void InitialData()
  {
  }

  /// <summary>
  /// Description:窗体初始化执行的操作。
  /// </summary>
  protected void LoadData(System.Windows.Forms.Form form, object obj)
  {
   this.ActionParEvent += new ActionParHandler(GetInitialData);
   this.SucessFunctionEvent += new SucessFunctionHandler(InitialData);
   DoAction(form, obj);
  }
 }
}

原文地址:https://www.cnblogs.com/admin11/p/213599.html