用事件跟委托执行调用数据库的方法
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Model;
using Dal;
namespace Unit_WeekOne.Controllers
{
public class IndexController : Controller
{
SqlServer sl = new SqlServer();
MySql mys = new MySql();
// GET: Index
public ActionResult Index()
{
Events<UserInfoModel> evs = new Events<UserInfoModel>();
evs.deleteEnents += SqlList;
List<UserInfoModel> list= evs.Send();
return View(list);
}
/// <summary>
/// 执行SqlServer的数据库
/// </summary>
/// <returns></returns>
public List<UserInfoModel> SqlList()
{
List<UserInfoModel> list= sl.SqlServers<UserInfoModel>();
return list;
}
/// <summary>
/// 执行MySql数据库
/// </summary>
/// <returns></returns>
//public List<UserInfoModel> MyList()
//{
// List<UserInfoModel> list = mys.MySqls<UserInfoModel>();
// return list;
//}
/// <summary>
/// 定义事件执行的方法
/// </summary>
/// <typeparam name="T"></typeparam>
public class Events<T>
{
public delegate List<T> deleteEnent(); //定义一个委托
public event deleteEnent deleteEnents; //定义一个事件
public List<T> Send()
{
return deleteEnents();
}
}
}
}