123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121 |
- using Cksoft.Data;
- using Cksoft.Data.Repository;
- using Cksoft.Unity;
- using System;
- using System.Collections.Generic;
- using System.Data;
- namespace DllUnityBll
- {
- public class UnityBll
- {
- /// <summary>
- /// 根据条件查询返回实体集合
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="dbcode"></param>
- /// <param name="condition"></param>
- /// <param name="entity">实体变量</param>
- /// <param name="erroinfo"></param>
- /// <returns></returns>
- public IEnumerable<T> SelectForEntity<T>(string dbcode, string condition, object entity, ref string erroinfo) where T : class,new()
- {
- IDatabase db = null;
- try
- {
- db = DbFactory.Base(dbcode);
- string sqlstr = EntityHelper.GetSelectSql(entity,condition, ref erroinfo);
- IEnumerable<T> redt = db.FindList<T>(sqlstr);
- return redt;
- }
- catch (Exception ex)
- {
- erroinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- /// <summary>
- /// 老的查询实体方法
- /// </summary>
- /// <typeparam name="T"></typeparam>
- /// <param name="dbcode"></param>
- /// <param name="sqlstr"></param>
- /// <param name="tablename"></param>
- /// <param name="erroinfo"></param>
- /// <returns></returns>
- public IEnumerable<T> SelectForEntity<T>(string dbcode, string sqlstr, string tablename, ref string erroinfo) where T : class
- {
- IDatabase db = null;
- try
- {
- db = DbFactory.Base(dbcode);
- IEnumerable<T> redt = db.FindList<T>(sqlstr);
- return redt;
- }
- catch (Exception ex)
- {
- erroinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- public DataSet Select(string sqlstr, string tablename, ref string erroinfo)
- {
- IDatabase db = null;
- try
- {
- string dbcode = "sqlconn";
- db = DbFactory.Base(dbcode);
- DataTable redt = db.FindTableFor(sqlstr, tablename);
- DataSet tempds = new DataSet();
- tempds.Merge(redt);
- return tempds;
- }
- catch (Exception ex)
- {
- erroinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- public DataSet Select(string dbcode, string sqlstr, string tablename, ref string erroinfo)
- {
- IDatabase db = null;
- try
- {
- db = DbFactory.Base(dbcode);
- DataTable redt = db.FindTableFor(sqlstr, tablename);
- DataSet tempds = new DataSet();
- tempds.Merge(redt);
- return tempds;
- }
- catch (Exception ex)
- {
- erroinfo = ex.Message.ToString();
- return null;
- }
- finally
- {
- if (db != null)
- db.Close();
- }
- }
- }
- }
|