123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- 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;
- }
- }
- /// <summary>
- /// 多个查询
- /// </summary>
- /// <returns></returns>
- public List<GoogleMapApiResult> GetMultiple()
- {
- return excuteMultiple("Select * from GoogleMapApiResult");
- }
- /// <summary>
- /// 单查询
- /// </summary>
- /// <param name="id"></param>
- /// <returns></returns>
- public GoogleMapApiResult GetSingle(int id)
- {
- return excuteSingle("Select * from GoogleMapApiResult where Id=" + id);
- }
- /// <summary>
- /// 条件查询
- /// </summary>
- /// <param name="diid"></param>
- /// <param name="startaddress"></param>
- /// <param name="endadress"></param>
- /// <returns></returns>
- public GoogleMapApiResult GetByDiidAddress(int diid, string startaddress, string endadress)
- {
- return excuteSingle("select * from GoogleMapApiResult where Diid=" + diid + " and StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
- }
- //分页查询;多个
- /// <summary>
- /// 条件查询
- /// </summary>
- /// <param name="startaddress">起始地址</param>
- /// <param name="endadress">目的地址</param>
- /// <returns></returns>
- public GoogleMapApiResult GetByAddress(string startaddress, string endadress)
- {
- return excuteSingle("select * from GoogleMapApiResult where StartAddress='" + startaddress + "' and EndAddress='" + endadress + "'");
- }
- //条件查询2;多个
- //...
- /// <summary>
- ///查询读取执行入口
- /// </summary>
- /// <param name="sql"></param>
- /// <param name="param"></param>
- /// <returns>返回集合</returns>
- List<GoogleMapApiResult> excuteMultiple(string sql, params SqlParameter[] param)
- {
- List<GoogleMapApiResult> list = ServiceBase<GoogleMapApiResult>.excuteSql(new GoogleMapApiResult(), "GoogleMapApiResult", sql, CommandType.Text, param);
- return list;
- }
- /// <summary>
- ///查询读取执行入口
- /// </summary>
- /// <param name="sql"></param>
- /// <param name="param"></param>
- /// <returns>返回单个对象</returns>
- GoogleMapApiResult excuteSingle(string sql, params SqlParameter[] param)
- {
- List<GoogleMapApiResult> list = excuteMultiple(sql, param);
- if (list == null || list.Count == 0)
- {
- return null;
- }
- else
- {
- return list[0];
- }
- }
- }
- }
|