using Models;
using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace DAL
{
///
/// 培训费用数据访问层
///
public class TrainingExpensesService
{
List excuteSql(string sql, params SqlParameter[] param)
{
return ServiceBase.excuteSql(new TrainingExpenses(), "TrainingExpenses", sql, CommandType.Text, param);
}
TrainingExpenses excuteType(string sql, params SqlParameter[] param)
{
//查询结果放入对象集合
List hdList = excuteSql(sql, param);
//判断集合是否为空
if (hdList == null || hdList.Count == 0)
{
//返回null
return null;
}
//返回单个对象
return hdList[0];
}
public List GetAll()
{
return excuteSql(" select * from TrainingExpenses where isdel = 0 ");
}
public TrainingExpenses GetByCountry(string country)
{
return excuteType(string.Format(" select * from TrainingExpenses where isdel = 0 and country = '{0}' ",country));
}
public List GetLikeByCountry(string country)
{
return excuteSql(string.Format(" select * from TrainingExpenses where isdel = 0 and country like '%{0}%' ", country));
}
public bool Add(TrainingExpenses TE)
{
string sql = "insert into TrainingExpenses values(@continent,@country,@currency,@expense,@operationTime,@operationUser,@Isdel)";
SqlParameter[] parameter = new SqlParameter[]{
new SqlParameter("@continent",TE.continent),
new SqlParameter("@country",TE.country),
new SqlParameter("@currency",TE.currency),
new SqlParameter("@expense",TE.expense),
new SqlParameter("@operationTime",TE.operationTime),
new SqlParameter("@operationUser",TE.operationUser),
new SqlParameter("@Isdel","0")
};
if (SqlHelper.ExecuteNonQuery(sql, CommandType.Text, parameter) > 0)
return true;
return false;
}
}
}