Exemple #1
0
        public List <T> Load <T>(T parm)
        {
            var          sqlTxt = SqlConstructor.GetSelectSqlByObj(parm);
            var          tLst   = new List <T>();
            DbConnection dbConn = null;

            try
            {
                var dr = DbHelper.ExecuteReader(sqlTxt, ref dbConn);
                while (dr.Read())
                {
                    var t = MakeMapToObject <T>(dr);
                    if (t != null)
                    {
                        tLst.Add(t);
                    }
                }
            }
            catch (Exception e)
            {
            }
            finally
            {
                if (dbConn != null)
                {
                    dbConn.Close();
                    dbConn.Dispose();
                }
            }

            return(tLst);
        }
Exemple #2
0
        public DataTable LoadDataTableByConditions(CommonSqlKey sqlKey, IList <Condition> parmObj)
        {
            var logStep = 0;

            try
            {
                if (sqlKey == CommonSqlKey.Null)
                {
                    return(null);
                }
                var sqlTxt = CommSqlText.Instance[sqlKey];
                logStep++;
                var parmDic = SqlConstructor.MakeParms(parmObj);
                List <DbParameter> parameter;
                var whereSql = ConditionHandler.GetWhereSql(parmObj.ToList(), out parameter, sqlKey);
                sqlTxt = SqlConstructor.FilterSQLWithInsteadValue(sqlTxt + whereSql, parmDic);
                logStep++;
                parmDic = SqlConstructor.FilterParmsWithList(parmDic, CommSqlText.SqlParms[sqlKey]);
                logStep++;

                return(DbHelper.ExecuteDataTable(sqlTxt, parmDic));
            }
            catch (MySqlException ee)
            {
                Logger.LogInfo(String.Format("GetSingleFromDicDictionary ERROR STEP:{0}, EXCEPTION:{1}", logStep, ee.Message), 0, LogType.ERROR);
                throw ee;
            }
        }
Exemple #3
0
        public int Delete <T>(T t)
        {
            var delSql = SqlConstructor.GetDeleteSqlByParmDic(t);
            var result = DbHelper.ExecuteNonQuery(delSql);

            return(result);
        }
Exemple #4
0
        public List <T> Load <T>(CommonSqlKey sqlKey, IDictionary <string, object> parmObj)
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            //parmDic = SqlConstructor.FilterParmsWithList(parmDic, CommSqlText.SqlParms[sqlKey]);
            return(GetFromDictionary <T>(sqlKey, parmDic));
        }
Exemple #5
0
        private int GetCountFromDictionary <T>(CommonSqlKey sqlKey, IDictionary <string, object> parmDic)
        {
            DbDataReader dr      = null;
            int          tLst    = 0;
            var          logStep = 0;

            try
            {
                //如果为空sql可以,则根据类型和传入参数自动构造select语句,同时where条件为传入参数
                var sqlTxt = sqlKey == CommonSqlKey.Null ? SqlConstructor.GetSelectSqlByParmDic <T>(parmDic) : CommSqlText.Instance[sqlKey];
                logStep++;
                var sqlParameters = sqlKey == CommonSqlKey.Null ? null : parmDic; // SqlConstructor.MakeParms(parmDic, CommSqlText.SqlParms[sqlKey]);
                sqlTxt = SqlConstructor.FilterSQLWithInsteadValue(sqlTxt, sqlParameters);
                logStep++;
                sqlParameters = sqlKey == CommonSqlKey.Null ? null : SqlConstructor.FilterParmsWithList(sqlParameters, CommSqlText.SqlParms[sqlKey]);
                logStep++;
                tLst = DbHelper.ExecuteScalar(sqlTxt, sqlParameters) == null
              ? 0 : int.Parse(DbHelper.ExecuteScalar(sqlTxt, sqlParameters).ToString());
            }
            catch (MySqlException ee)
            {
                Logger.LogInfo(String.Format("GetFromDictionary ERROR STEP:{0}, EXCEPTION:{1}", logStep, ee.Message), 0, LogType.ERROR);
                throw ee;
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                    dr.Dispose();
                }
            }
            return(tLst);
        }
Exemple #6
0
        public DataTable LoadDataTable(CommonSqlKey sqlKey, IDictionary <string, object> parmDic)
        {
            var logStep = 0;

            try
            {
                if (sqlKey == CommonSqlKey.Null)
                {
                    return(null);
                }
                var sqlTxt = CommSqlText.Instance[sqlKey];
                logStep++;
                sqlTxt = SqlConstructor.FilterSQLWithInsteadValue(sqlTxt, parmDic);
                logStep++;
                parmDic = SqlConstructor.FilterParmsWithList(parmDic, CommSqlText.SqlParms[sqlKey]);
                logStep++;

                return(DbHelper.ExecuteDataTable(sqlTxt, parmDic));
            }
            catch (MySqlException ee)
            {
                Logger.LogInfo(String.Format("GetSingleFromDicDictionary ERROR STEP:{0}, EXCEPTION:{1}", logStep, ee.Message), 0, LogType.ERROR);
                throw ee;
            }
        }
Exemple #7
0
        public List <T> Load <T>(CommonSqlKey sqlKey, T parmObj)
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            var resultLst = GetFromDictionary <T>(sqlKey, parmDic);

            return(resultLst);
        }
Exemple #8
0
        private List <T> GetFromDictionary <T>(CommonSqlKey sqlKey, IDictionary <string, object> parmDic)
        {
            DbConnection dbConn  = null;
            DbDataReader dr      = null;
            var          tLst    = new List <T>();
            var          logStep = 0;

            try
            {
                //如果为空sql可以,则根据类型和传入参数自动构造select语句,同时where条件为传入参数
                var sqlTxt = sqlKey == CommonSqlKey.Null ? SqlConstructor.GetSelectSqlByParmDic <T>(parmDic) : CommSqlText.Instance[sqlKey];
                logStep++;
                var sqlParameters = sqlKey == CommonSqlKey.Null ? null : parmDic; // SqlConstructor.MakeParms(parmDic, CommSqlText.SqlParms[sqlKey]);
                sqlTxt = SqlConstructor.FilterSQLWithInsteadValue(sqlTxt, sqlParameters);
                logStep++;
                sqlParameters = sqlKey == CommonSqlKey.Null ? null : SqlConstructor.FilterParmsWithList(sqlParameters, CommSqlText.SqlParms[sqlKey]);
                logStep++;

                dr      = DbHelper.ExecuteReader(sqlTxt, sqlParameters, ref dbConn);
                logStep = 100;
                if (dr == null)
                {
                    return(tLst);
                }
                var hasCount = dr.Read();
                while (hasCount)
                {
                    logStep += 10;
                    var t = MakeMapToObject <T>(dr);
                    if (t != null)
                    {
                        tLst.Add(t);
                    }
                    logStep += 1;
                    hasCount = dr.Read();
                }
            }
            catch (MySqlException ee)
            {
                //Logger.LogInfo(String.Format("GetFromDictionary ERROR STEP:{0}, EXCEPTION:{1}", logStep, ee.Message), 0, LogType.ERROR);
                throw ee;
            }
            finally
            {
                if (dr != null)
                {
                    dr.Close();
                    dr.Dispose();
                }
                if (dbConn != null)
                {
                    dbConn.Close();
                    dbConn.Dispose();
                }
            }
            return(tLst);
        }
Exemple #9
0
        public object Execute <T>(CommonSqlKey sqlKey, T t)
        {
            var sqlContent    = CommSqlText.Instance[sqlKey];
            var sqlParameters = SqlConstructor.MakeParms(t);

            sqlParameters = SqlConstructor.FilterParmsWithList(sqlParameters, CommSqlText.SqlParms[sqlKey]);
            var result = DbHelper.ExecuteScalar(sqlContent, sqlParameters);

            return(result);
        }
Exemple #10
0
        public int Delete <T>(object kv)
        {
            if (!ReflectionHandler.IsValueType(kv))
            {
                return(Delete((T)kv));
            }
            var delSql = SqlConstructor.GetDeleteSqlByParmDic <T>(kv);
            var result = DbHelper.ExecuteNonQuery(delSql);

            return(result);
        }
Exemple #11
0
        public int Delete <T>(CommonSqlKey sqlKey, T t)
        {
            var sqlContent    = CommSqlText.Instance[sqlKey];
            var sqlParameters = SqlConstructor.MakeParms(t);

            sqlContent    = SqlConstructor.FilterSQLWithInsteadValue(sqlContent, sqlParameters);
            sqlParameters = SqlConstructor.FilterParmsWithList(sqlParameters, CommSqlText.SqlParms[sqlKey]);
            var result = DbHelper.ExecuteNonQuery(sqlContent, sqlParameters);

            return(result);
        }
Exemple #12
0
        private int GetSequenceId <T>()
        {
            var autoIdSql = SqlConstructor.GetSequeceIdSql <T>();

            if (String.IsNullOrEmpty(autoIdSql))
            {
                return(0);
            }
            var seqId = int.Parse(DbHelper.ExecuteScalar(autoIdSql).ToString());

            return(seqId);
        }
Exemple #13
0
        public int CountByConditions(CommonSqlKey sqlKey, IList <Condition> parmObj)
        {
            var result  = 0;
            var parmDic = SqlConstructor.MakeParms(parmObj);

            var sqlTxt = CommSqlText.Instance[sqlKey];

            var sqlParameters = parmDic;

            //解析where 后查询条件
            List <DbParameter> parameter;
            var whereSql = ConditionHandler.GetWhereSql(parmObj.ToList(), out parameter, sqlKey);

            sqlTxt = sqlTxt + whereSql;

            result = DbHelper.ExecuteScalar(sqlTxt, sqlParameters) == null
                ? 0
                : int.Parse(DbHelper.ExecuteScalar(sqlTxt, sqlParameters).ToString());

            return(result);
        }
Exemple #14
0
        public List <T> LoadByConditions <T>(CommonSqlKey sqlKey, IList <Condition> parmObj)
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            return(GetFromDictionaryByConditions <T>(sqlKey, parmDic, parmObj));
        }
Exemple #15
0
        public List <T> LoadByConditionsWithOrder <T>(CommonSqlKey sqlKey, IList <Condition> parmObj, string orderField = "", string orderType = "")
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            return(GetFromDictionaryByConditionsWithOrder <T>(sqlKey, parmDic, parmObj, orderField, orderType));
        }
Exemple #16
0
        private int CreateBatch <T>(List <T> ts)
        {
            var sql = SqlConstructor.GetCreateSQL(ts);

            return(DbHelper.ExecuteNonQuery(sql));
        }
Exemple #17
0
        public int CountByDictionary <T>(CommonSqlKey sqlKey, IDictionary <string, object> parmObj)
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            return(GetCountFromDictionary <T>(sqlKey, parmDic));
        }
Exemple #18
0
        public object Single <T>(CommonSqlKey sqlKey, T parmObj)
        {
            var parmDic = SqlConstructor.MakeParms(parmObj);

            return(GetSingleFromDicDictionary(sqlKey, parmDic));
        }