Пример #1
0
        private SqlCommand GetSqlTextCmd()
        {
            string    sql   = base.GetSqlWithoutOrderBy(this._u8DataEngineHelper.SqlFromDataEngine);
            Hashtable paras = new Hashtable();

            if (sql.Contains("@") && this._filterSrv != null)
            {
                foreach (string key in this._filterSrv.Keys)
                {
                    if (key.Contains("."))
                    {
                        continue;
                    }
                    FilterItem fi      = this._filterSrv[key];
                    string     parakey = "@" + fi.Key.ToLower();
                    if (parakey != _cmdParaFilterString.ToLower() &&
                        fi.Value1 != null && !paras.Contains(parakey))
                    {
                        paras.Add(parakey, fi.Value1);
                    }
                    if (fi.HasSecondValue)
                    {
                        parakey = "@" + fi.Key.ToLower() + "__2";
                        if (fi.Value2 != null && !paras.Contains(parakey))
                        {
                            paras.Add(parakey, fi.Value2);
                        }
                    }
                }
            }
            SqlCommand cmd = SqlCommandHelper.GetSqlCommand(sql, paras);

            cmd.CommandType = CommandType.Text;
            return(cmd);
        }
Пример #2
0
 /// <summary>
 /// 从存储过程将数据填写到临时表
 /// </summary>
 /// <param name="storeprocedureName">存储过程名称</param>
 /// <param name="tempTableName">目标临时表名称</param>
 /// <param name="paras">存储过程的参数键值集合</param>
 public void Storeprocedure2TempTable(
     string storeprocedureName,
     string tempTableName,
     Hashtable paras)
 {
     Storeprocedure2TempTable(
         SqlCommandHelper.GetSqlCommand(storeprocedureName, paras),
         tempTableName);
 }
Пример #3
0
 /// <summary>
 /// 如果存储过程的参数中包含@TableName参数,
 /// 则使用UfDataCnnString执行给定的存储过程
 /// </summary>
 /// <param name="storeprocedureName">存储过程对应的SqlCommand对象</param>
 private bool ExecuteStoreProOnlyIfNecessary(SqlCommand cmd)
 {
     if (cmd != null &&
         cmd.Parameters.Contains(_cmdParaTableName))
     {
         cmd.Parameters[_cmdParaTableName].Value = GetTempTableName();
         SqlCommandHelper.ExecuteStoreProcedure(cmd, this._loginInfor.UfDataCnnString);
         this.CheckWhetherHadCreatedTempTable(cmd);
         return(true);
     }
     return(false);
 }
Пример #4
0
        private SqlCommand GetStoreProcedureCmd()
        {
            Hashtable paras = new Hashtable();

            if (this._u8DataEngineHelper.CmdParameters != null &&
                this._filterSrv != null)
            {
                foreach (object obj in this._u8DataEngineHelper.CmdParameters)
                {
                    if (obj.ToString().ToLower() == "@tablename")
                    {
                        paras.Add("@tablename", null);
                    }
                    else if (obj.ToString().ToLower() == "@filterstring")
                    {
                        paras.Add("@filterstring", this._u8DataEngineHelper.RawFilterString);
                    }
                    else
                    {
                        string key = obj.ToString();
                        if (key.Contains("."))
                        {
                            continue;
                        }
                        if (key.EndsWith("__2"))
                        {
                            FilterItem fi = this._filterSrv[key.Substring(1, key.Length - 4)];
                            if (fi != null && fi.HasSecondValue && fi.Value2 != null)
                            {
                                paras.Add(key, fi.Value2);
                            }
                        }
                        else
                        {
                            FilterItem fi = this._filterSrv[key.Substring(1)];
                            if (fi != null && fi.Value1 != null)
                            {
                                paras.Add(key, fi.Value1);
                            }
                        }
                    }
                    //FilterItem fi = this._filterSrv[obj.ToString()];
                    //if (fi != null)
                    //    paras.Add(fi.Key, fi.Value1);
                }
            }

            return(SqlCommandHelper.GetSqlCommand(
                       this._u8DataEngineHelper.SqlFromDataEngine,
                       paras));
        }
Пример #5
0
        /// <summary>
        /// 判断含有@TableName的存储过程在被执行之后
        /// 是否成功创建了临时表,如果没有创建则抛出异常
        /// </summary>
        /// <param name="cmd">执行存储过程的SqlCommand对象</param>
        private void CheckWhetherHadCreatedTempTable(SqlCommand cmd)
        {
            string tableName = this._tempTableName.ToLower().Replace("tempdb..", string.Empty);

            if ((!string.IsNullOrEmpty(tableName)) && tableName.StartsWith("[") && tableName.EndsWith("]"))
            {
                tableName = tableName.Substring(1, tableName.Length - 2);
            }
            if (!SqlHelper.IsTableExsited(tableName, this._loginInfor.TempDBCnnString))
            {
                string exMsg = SqlCommandHelper.GetMsgWhenStoreProcedureError(cmd, null);
                throw new TempDBServiceException(
                          "执行了含有@TableName参数的存储过程,但是存储过程内部没有成功创建临时表",
                          exMsg);
            }
        }
Пример #6
0
        private void Storeprocedure2TempTable(
            SqlCommand cmd,
            string tempTableName)
        {
            SqlDataReader reader = null;

            try
            {
                reader = SqlHelper.ExecuteReader(
                    this._loginInfor.UfDataCnnString,
                    cmd);
            }
            catch (Exception e)
            {
                string exMsg = SqlCommandHelper.GetMsgWhenStoreProcedureError(cmd, e);
                throw new TempDBServiceException(e, exMsg);
            }
            this.Reader2TempTable(reader, tempTableName);
        }
 protected override SqlCommand GetHandlingCommand()
 {
     return(SqlCommandHelper.GetSqlCommand(
                base._customDataSource.StoreProcName,
                GetCmdParas()));
 }