逆水行船

别人的天堂,是我的异乡;无端的繁华,倍添我的惆怅

 

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);
  }
 }
}

posted on   荣-  阅读(311)  评论(0编辑  收藏  举报

编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· 阿里巴巴 QwQ-32B真的超越了 DeepSeek R-1吗?
· 【译】Visual Studio 中新的强大生产力特性
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构

导航

统计

点击右上角即可分享
微信分享提示