using Models;
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
namespace DAL
{
public class GoogleMapApiResultService
{
//增
public Boolean Add(GoogleMapApiResult g)
{
//select @@identity可获取插入记录时生成的标识ID
string sql = "insert into GoogleMapApiResult Values(@Diid,@Date,@Moment,@StartAddress,@EndAddress,@Time,@Distance);SELECT @@IDENTITY ";
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@Diid",g.Diid),
new SqlParameter("@Date",g.Date),
new SqlParameter("@Moment",g.Moment),
new SqlParameter("@StartAddress",g.StartAddress),
new SqlParameter("@EndAddress",g.EndAddress),
new SqlParameter("@Time",g.Time),
new SqlParameter("@Distance",g.Distance)
};
//执行,得到受影响行数
int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
if (affectRows > 0)
{
return true;
}
else
{
return false;
}
}
//删
public bool Del(int id)
{
string sql = "Delete from GoogleMapApiResult where Id=" + id;
//执行,得到受影响行数
int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text);
if (affectRows > 0)
{
return true;
}
else
{
return false;
}
}
//改
public bool Edit(GoogleMapApiResult g)
{
string sql = "Update GoogleMapApiResult set Diid=@Diid,Date=@Date,Time=@Time,Distance=@Distance where Id=@Id";
SqlParameter[] param = new SqlParameter[]
{
new SqlParameter("@Diid",g.Diid),
new SqlParameter("@Date",g.Date),
new SqlParameter("@Moment",g.Moment),
new SqlParameter("@StartAddress",g.StartAddress),
new SqlParameter("@EndAddress",g.EndAddress),
new SqlParameter("@Time",g.Time),
new SqlParameter("@Distance",g.Distance),
new SqlParameter("@Id",g.Id)
};
//执行,得到受影响行数
int affectRows = SqlHelper.ExecuteNonQuery(sql, CommandType.Text, param);
if (affectRows > 0)
{
return true;
}
else
{
return false;
}
}
///
/// 多个查询
///
///
public List GetMultiple()
{
return excuteMultiple("Select * from GoogleMapApiResult");
}
///
/// 单查询
///
///
///
public GoogleMapApiResult GetSingle(int id)
{
return excuteSingle("Select * from GoogleMapApiResult where Id=" + id);
}
///
/// 条件查询
///
///
///
///
///
public GoogleMapApiResult GetByDiidAddress(int diid, string startaddress, string endadress)
{
return excuteSingle("select * from GoogleMapApiResult where Diid=" + diid + " and StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
}
//分页查询;多个
///
/// 条件查询
///
/// 起始地址
/// 目的地址
///
public GoogleMapApiResult GetByAddress(string startaddress, string endadress)
{
return excuteSingle("select * from GoogleMapApiResult where StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
}
//条件查询2;多个
//...
///
///查询读取执行入口
///
///
///
/// 返回集合
List excuteMultiple(string sql, params SqlParameter[] param)
{
List list = ServiceBase.excuteSql(new GoogleMapApiResult(), "GoogleMapApiResult", sql, CommandType.Text, param);
return list;
}
///
///查询读取执行入口
///
///
///
/// 返回单个对象
GoogleMapApiResult excuteSingle(string sql, params SqlParameter[] param)
{
List list = excuteMultiple(sql, param);
if (list == null || list.Count == 0)
{
return null;
}
else
{
return list[0];
}
}
}
}