示例#1
0
 /// <summary>
 /// 执行SQL语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="p">参数集合</param>
 public static int ExcuteSQL(string sql, DynamicParameters p)
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Execute(sql, p));
     }
 }
示例#2
0
 /// <summary>
 /// 根据SQL从数据库中读取对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="sql">SQL语句</param>
 /// <param name="p">参数集合</param>
 /// <returns>查询出的对象</returns>
 public static T ReadObject <T>(string sql, DynamicParameters p) where T : class
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <T>(sql, p).SingleOrDefault <T>());
     }
 }
示例#3
0
 /// <summary>
 /// 根据存储过程从数据库中读取对象
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="procName">存储过程名称</param>
 /// <param name="p">参数集合</param>
 /// <returns>查询出的对象</returns>
 public static T ReadObjectBySP <T>(string procName, DynamicParameters p) where T : class
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <T>(procName, p, commandType: CommandType.StoredProcedure).SingleOrDefault <T>());
     }
 }
示例#4
0
 /// <summary>
 /// 将一个集合保存到数据库
 /// </summary>
 /// <typeparam name="T">集合类型</typeparam>
 /// <param name="sql">sql语句,示例 insert AUT_User (Name,Age) values(@Name, @Age)</param>
 /// <param name="collection">集合对象</param>
 public static int SaveCollection <T>(string sql, IList <T> collection)
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Execute(sql, collection, null, 1800));
     }
 }
示例#5
0
 /// <summary>
 /// 根据存储过程从数据库中读取对象集合
 /// </summary>
 /// <typeparam name="T">对象类型</typeparam>
 /// <param name="procName">存储过程名称</param>
 /// <param name="p">参数集合</param>
 /// <returns>对象集合</returns>
 public static List <T> ReadCollectionBySP <T>(string procName, ref DynamicParameters p) where T : class
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <T>(procName, p, commandType: CommandType.StoredProcedure).ToList <T>());
     }
 }
示例#6
0
 /// <summary>
 /// 查询字符串类型的单个返回值
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="p">参数集合</param>
 /// <returns>string型返回值</returns>
 public static string ExecuteScalarString(string sql, DynamicParameters p)
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <string>(sql, p).First());
     }
 }
示例#7
0
 /// <summary>
 /// 查询单个返回值
 /// </summary>
 /// <param name="procName">存储过程名称</param>
 /// <param name="p">参数集合</param>
 /// <returns>int型返回值</returns>
 public static int ExecuteScalarBySP(string procName, DynamicParameters p)
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <int>(procName, p).First());
     }
 }
示例#8
0
 /// <summary>
 /// 根据SQL从数据库中读取对象集合
 /// </summary>
 /// <typeparam name="T"></typeparam>
 /// <param name="sql">SQL语句</param>
 /// <param name="p">参数集合</param>
 /// <returns>对象集合</returns>
 public static List <T> ReadCollection <T>(string sql, DynamicParameters p) where T : class
 {
     using (ConnService connService = new ConnService())
     {
         return(connService.Connection.Query <T>(sql, p).ToList <T>());
     }
 }
示例#9
0
 /// <summary>
 /// 执行存储过程
 /// </summary>
 /// <param name="procName">存储过程名称</param>
 /// <param name="p">参数集合</param>
 public static void ExcuteSP(string procName, DynamicParameters p)
 {
     using (ConnService connService = new ConnService())
     {
         connService.Connection.Execute(procName, p, commandTimeout: 1800, commandType: CommandType.StoredProcedure);
     }
 }
示例#10
0
 public static long ExecuteLong(string sql, DynamicParameters p)
 {
     using (ConnService connService = new ConnService())
     {
         var list = connService.Connection.Query <List <string> >(sql, p);
         return(connService.Connection.Query <long>(sql, p).First());
     }
 }
        public static ConnService GetConnService(this ICoreObject coreObject)
        {
            IDlc        idlc        = (IDlc)coreObject.Context;
            IDlcManager idlcManager = idlc.WorkingContext.DlcManager;
            ConnService ConnService = idlcManager.Load("Siemens.Simatic.HwConfiguration.Connections.Block.Base.ConnectionService")
                                      as ConnService;

            return(ConnService);
        }
示例#12
0
        /// <summary>
        /// 判断数据库中是否存在该数据
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <param name="p">参数集合</param>
        /// <returns>存在返回 True</returns>
        public static bool Exists(string sql, DynamicParameters p)
        {
            int recordCount = 0;

            using (ConnService connService = new ConnService())
            {
                recordCount = connService.Connection.Query <int>(sql, p).First();
            }
            return((recordCount > 0) ? true : false);
        }
示例#13
0
 /// <summary>
 /// 将一个集合保存到数据库
 /// </summary>
 /// <typeparam name="T">集合类型</typeparam>
 /// <param name="sql">sql语句,示例 insert AUT_User (Name,Age) values(@Name, @Age)</param>
 /// <param name="collection">集合对象</param>
 public static void SaveCollection <T>(string sql, IList <T> collection, ConnService connService, IDbTransaction transaction)
 {
     connService.Connection.Execute(sql, collection, transaction);
 }
示例#14
0
 /// <summary>
 /// 执行SQL语句
 /// </summary>
 /// <param name="sql">sql语句</param>
 /// <param name="p">参数集合</param>
 public static void ExcuteSQL(string sql, DynamicParameters p, ConnService connService, IDbTransaction transaction)
 {
     connService.Connection.Execute(sql, p, transaction);
 }