Beispiel #1
0
        public IDataReader GetDataReader(string sql)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text);
                return(scm.ExecuteReader(CommandBehavior.CloseConnection));
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, sql, this.ToString());
                return(null);
            }
        }
Beispiel #2
0
        public IDataReader GetDataReader(string sql, IMyDbParameter[] prams)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text, prams);
                return(scm.ExecuteReader(CommandBehavior.CloseConnection));
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, sql, GetParametersInfo(prams), this.ToString());
                return(null);
            }
        }
 private static void CreateTableTypeHandle(Type pType, DataTypeAttribute dataTypeAttribute, ref StringBuilder sql)
 {
     if (pType == INTTYPE)
     {
         sql.Append(" int ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else if (pType == BOOLTYPE)
     {
         sql.Append(" bit ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else if (pType == STRINGTYPE)
     {
         CreateTableWithAttributeOfString(dataTypeAttribute, ref sql);
     }
     else if (pType == DATETIMETYPE)
     {
         sql.Append(" datetime ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else if (pType == DECIMALTYPE)
     {
         sql.Append(" decimal ");
         CreateTableWithAttributeOfDecimal(dataTypeAttribute, ref sql);
     }
     else if (pType.IsEnum)
     {
         sql.Append(" int ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else if (pType == LONGTYPE)
     {
         sql.Append(" bigint ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else if (pType == BYTESTYPE)
     {
         sql.Append(" image ");
         CreateTableCommSetting(dataTypeAttribute, ref sql);
     }
     else
     {
         LogProxy.ErrorFormat(true, DATATYPEERROR, pType.ToString());
     }
 }
Beispiel #4
0
        public void RunProcedure(string procName, out IDataReader dataReader)
        {
            dataReader = null;

            try
            {
                Open();

                SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure);

                dataReader = scm.ExecuteReader(CommandBehavior.CloseConnection);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, procName, this.ToString());
            }
        }
Beispiel #5
0
        public int ExecuteNonQuery(string sql)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text);
                return(scm.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, sql, this.ToString());
                return(0);
            }
            finally
            {
                Close();
            }
        }
Beispiel #6
0
        public int RunProcedure(string procName)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure);

                return(scm.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, procName, this.ToString());
                return(0);
            }
            finally
            {
                Close();
            }
        }
Beispiel #7
0
        //public void RunProcedure(string procName, IMyDbParameter[] prams, out IDataReader dataReader, out Dictionary<string, object> returnValue)
        //{
        //    dataReader = null;
        //    returnValue = null;

        //    try
        //    {
        //        Open();

        //        SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure, prams);

        //        dataReader = scm.ExecuteReader(CommandBehavior.CloseConnection);
        //        dataReader.Close();
        //        FillValueContainer(prams, scm, out returnValue);
        //    }
        //    catch (Exception ex)
        //    {
        //        LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, procName, GetParametersInfo(prams), this.ToString());
        //    }
        //}

        public int RunProcedure(string procName, IMyDbParameter[] prams)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure, prams);

                return(scm.ExecuteNonQuery());
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, procName, GetParametersInfo(prams), this.ToString());
                return(0);
            }
            finally
            {
                Close();
            }
        }
Beispiel #8
0
        public void RunProcedure(string procName, out DataSet dataSet)
        {
            dataSet = null;

            try
            {
                Open();

                SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure);

                FillDataSet(out dataSet, scm);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, procName, this.ToString());
            }
            finally
            {
                Close();
            }
        }
Beispiel #9
0
        internal static StorageContext GetStorageContext(string name)
        {
            if (StorageContexts == null || StorageContexts.Count == 0)
            {
                LogProxy.Error(STORAGECONTEXTSISNULL, true);
                return(null);
            }

            if (string.IsNullOrEmpty(name))
            {
                return(DefaultStorageContext);
            }

            if (StorageContexts.ContainsKey(name) == false)
            {
                LogProxy.ErrorFormat(true, STORAGECONTEXTISNULL, name);
                return(null);
            }

            return(StorageContexts[name]);
        }
Beispiel #10
0
        public object ExecuteScalar(string sql)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text);
                object     obj = scm.ExecuteScalar();

                return(obj);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, sql, this.ToString());
                return(null);
            }
            finally
            {
                Close();
            }
        }
Beispiel #11
0
        public object ExecuteScalar(string sql, IMyDbParameter[] prams)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text, prams);
                object     obj = scm.ExecuteScalar();

                return(obj);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, sql, GetParametersInfo(prams), this.ToString());
                return(null);
            }
            finally
            {
                Close();
            }
        }
Beispiel #12
0
        public void RunProcedure(string procName, IMyDbParameter[] prams, out Dictionary <string, object> returnValue)
        {
            returnValue = null;

            try
            {
                Open();

                SqlCommand scm = CreateCommand(procName, CommandType.StoredProcedure, prams);
                scm.ExecuteNonQuery();
                FillValueContainer(prams, scm, out returnValue);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, procName, GetParametersInfo(prams), this.ToString());
            }
            finally
            {
                Close();
            }
        }
Beispiel #13
0
        public int ExecuteNonQuery(string sql, IMyDbParameter[] prams)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text, prams);
                int        i   = scm.ExecuteNonQuery();

                scm.Parameters.Clear();
                return(i);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, sql, GetParametersInfo(prams), this.ToString());
                return(0);
            }
            finally
            {
                Close();
            }
        }
Beispiel #14
0
        public DataSet GetDataSet(string sql, IMyDbParameter[] prams)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text, prams);

                DataSet dataSet;
                FillDataSet(out dataSet, scm);

                return(dataSet);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLPRAMSDBOPERATE, sql, GetParametersInfo(prams), this.ToString());
                return(null);
            }
            finally
            {
                Close();
            }
        }
Beispiel #15
0
        public DataSet GetDataSet(string sql)
        {
            try
            {
                Open();

                SqlCommand scm = CreateCommand(sql, CommandType.Text);

                DataSet dataSet;
                FillDataSet(out dataSet, scm);

                return(dataSet);
            }
            catch (Exception ex)
            {
                LogProxy.ErrorFormat(ex, true, SQLDBOPERATE, sql, this.ToString());
                return(null);
            }
            finally
            {
                Close();
            }
        }
Beispiel #16
0
        public static IDbOperate Create(string alias, Type type)
        {
            StorageContext storageContext = MappingService.GetStorageContext(alias, type);

            if (storageContext == null)
            {
                LogProxy.ErrorFormat(true, GETSTORAGECONTEXTNULL, type.FullName, alias);
                return(null);
            }

            if (storageContext.Enabled == false)
            {
                LogProxy.ErrorFormat(true, STORAGECONTEXTUNABLED, storageContext.Name);
                return(null);
            }

            DbProxy proxy = new DbProxy(alias, type);

            proxy.Context          = storageContext;
            proxy.DbServer         = new SQLServer(storageContext);
            proxy.DbServer.Alias   = proxy.Alias;
            proxy.DbServer.ObjType = proxy.ObjType;
            return(proxy);
        }
Beispiel #17
0
            private static IMyDbParameter ParameterBuilder(IMyPropertyInfo property, object pValue)
            {
                #region 构造 IMyDbParameter 开始
                Type pType = property.PropertyType;
                if (pType == INTTYPE)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.Int, pValue));
                }
                else if (pType == BOOLTYPE)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.Bit, pValue));
                }
                else if (pType == STRINGTYPE)
                {
                    if (property.StringDataType.Type == StringType.NVarchar)
                    {
                        if (property.StringDataType.IsMaxLength)
                        {
                            return(DbParameterProxy.Create(property.Name, SqlDbType.NVarChar, pValue));
                        }
                        else
                        {
                            string val = pValue as string;
                            if (!string.IsNullOrEmpty(val) && val.Length > property.StringDataType.Length)
                            {
                                LogProxy.Error(string.Format(LENGTHGAUGE, property.Name, val), true);
                            }

                            return(DbParameterProxy.Create(property.Name, SqlDbType.NVarChar, property.StringDataType.Length, pValue));
                        }
                    }
                    else
                    {
                        return(DbParameterProxy.Create(property.Name, SqlDbType.NText, pValue));
                    }
                }
                else if (pType == DATETIMETYPE)
                {
                    if ((DateTime)pValue == DateTime.MinValue)
                    {
                        return(DbParameterProxy.Create(property.Name, SqlDbType.DateTime, DBNull.Value));
                    }
                    else
                    {
                        return(DbParameterProxy.Create(property.Name, SqlDbType.DateTime, pValue));
                    }
                }
                else if (pType == DECIMALTYPE)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.Decimal, pValue));
                }
                else if (pType.IsEnum)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.Int, (int)pValue));
                }
                else if (pType == LONGTYPE)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.BigInt, pValue));
                }
                else if (pType == BYTESTYPE)
                {
                    return(DbParameterProxy.Create(property.Name, SqlDbType.Image, pValue));
                }
                else
                {
                    LogProxy.ErrorFormat(true, DATATYPEERROR, pType.ToString());
                    return(null);
                }
                #endregion 构造 IMyDbParameter 结束
            }