1. 程式人生 > >用事件跟委托執行調用數據庫的方法

用事件跟委托執行調用數據庫的方法

l數據庫 sqlserve lec return linq 調用 new res +=

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

}
}

用事件跟委托執行調用數據庫的方法