123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- using Bowin.Common.Log;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Text;
- using YLShipBuildLandMap.Entity;
- namespace YLShipBuildLandMap.Services.SystemSetting
- {
- public interface IExecSqlService
- {
- DataTable select(string sql);
- int insert(string sql);
- int update(string sql);
- int delete(string sql);
- }
- public class ExecSqlService: IExecSqlService
- {
- private YLShipBuildLandMapContext DbContext { get; set; }
- public ExecSqlService(YLShipBuildLandMapContext dbContext)
- {
- this.DbContext = dbContext;
- }
- public DataTable select(string sql)
- {
- if (!sql.ToLower().Contains("where"))
- throw new Exception("请添加where条件");
- LogHelper.WriteLog(LogType.CommmLog, $"exec sql:{sql}");
- return this.DbContext.Database.SqlQuery(sql);
- }
- public int insert(string sql)
- {
- if (!sql.ToLower().Contains("insert"))
- throw new Exception("缺少关键字insert");
- LogHelper.WriteLog(LogType.CommmLog, $"exec sql:{sql}");
- this.DbContext.Database.SqlQuery(sql);
- return 1;
- }
- public int update(string sql)
- {
- if (!sql.ToLower().Contains("update"))
- throw new Exception("缺少关键字update");
- if (!sql.ToLower().Contains("where"))
- throw new Exception("请添加where条件");
- LogHelper.WriteLog(LogType.CommmLog, $"exec sql:{sql}");
- this.DbContext.Database.SqlQuery(sql);
- return 1;
- }
- public int delete(string sql)
- {
- if (!sql.ToLower().Contains("delete"))
- throw new Exception("缺少关键字delete");
- if (!sql.ToLower().Contains("where"))
- throw new Exception("请添加where条件");
- LogHelper.WriteLog(LogType.CommmLog, $"exec sql:{sql}");
- this.DbContext.Database.SqlQuery(sql);
- return 1;
- }
- }
- }
|