示例#1
0
文件: SQLServer.cs 项目: winal/Scree
        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);
            }
        }
示例#2
0
文件: SQLServer.cs 项目: winal/Scree
        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);
            }
        }
示例#3
0
 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());
     }
 }
示例#4
0
文件: SQLServer.cs 项目: winal/Scree
        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());
            }
        }
示例#5
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#6
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#7
0
文件: SQLServer.cs 项目: winal/Scree
        //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();
            }
        }
示例#8
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#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]);
        }
示例#10
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#11
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#12
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#13
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#14
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#15
0
文件: SQLServer.cs 项目: winal/Scree
        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();
            }
        }
示例#16
0
文件: DbProxy.cs 项目: winal/Scree
        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);
        }
示例#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 结束
            }