Beispiel #1
0
 public virtual void replaceMacros(IDictionary macros)
 {
     if ((macros != null) && (macros.Count != 0))
     {
         ShortMap propGetMap = ExpMap.PropGetMap;
         if (propGetMap != null)
         {
             object obj2 = propGetMap[302];
             if (obj2 is string)
             {
                 string text = (string)obj2;
                 propGetMap.put(302, MacroCalc.replaceMacros(text, macros));
             }
         }
         string expStr = ExpMap.ExpStr;
         if (expStr != null)
         {
             ExpMap.ExpStr = MacroCalc.replaceMacros(expStr, macros);
         }
         ShortMap propEngMap = ExpMap.PropEngMap;
         if (propEngMap != null)
         {
             for (int i = 0; i < propEngMap.size(); i++)
             {
                 ExpParseInfo expInfo = (ExpParseInfo)propEngMap.getValue(i);
                 expInfo.ExpStr = MacroCalc.replaceMacros(expInfo.ExpStr, macros);
             }
         }
     }
 }
Beispiel #2
0
        public virtual DataSet getDataSet(Env env)
        {
            DataSet       set3;
            DataSetConfig config     = (DataSetConfig)this.hashtable_0["dsc"];
            CellExt1      cs         = (CellExt1)this.hashtable_0["ecs"];
            string        name       = config.Name;
            IDbCommand    pst        = null;
            IDataReader   rs         = null;
            IDbConnection connection = null;

            try
            {
                bool   flag;
                bool   flag2;
                string dataSourceName = config.DataSourceName;
                if (dataSourceName != null)
                {
                    connection = env.getConnection(dataSourceName);
                    if (connection == null)
                    {
                        connection = env.getConnection();
                    }
                }
                else
                {
                    connection     = env.getConnection();
                    dataSourceName = "";
                }
                if ((connection == null) || (connection.State == null))
                {
                    return(null);
                }
                if ((dataSourceName != null) && (dataSourceName.Trim().Length != 0))
                {
                    flag = env.getIsEncoding(dataSourceName);
                }
                else
                {
                    flag = env.getIsEncoding();
                }
                string dbCharset = env.getDBCharset(dataSourceName);
                if ((dbCharset == null) || (dbCharset.Trim().Length == 0))
                {
                    dbCharset = env.getDBCharset();
                }
                string str = MacroCalc.replaceMacros(config.SQL, env.MacrosMap);
                if ((dataSourceName != null) && (dataSourceName.Trim().Length != 0))
                {
                    flag2 = env.getNeedTransSQLcode(dataSourceName);
                }
                else
                {
                    flag2 = env.getNeedTransSQLcode();
                }
                if (flag2)
                {
                    str = Encoding.GetEncoding(dbCharset).GetString(Encoding.Default.GetBytes(str));
                }
                string[] sqlArguments     = config.SqlArguments;
                string[] sqlArgumentsName = config.SqlArgumentsName;
                int[]    argumentTypes    = config.ArgumentTypes;
                object[] objArray         = null;
                if (sqlArguments != null)
                {
                    objArray = new object[sqlArguments.Length];
                    int num7 = 0;
                    for (int i = 0; i < sqlArguments.Length; i++)
                    {
                        num7 = ExpString.indexOf(str, "?", num7 + 1, 18);
                        if ((sqlArguments[i] != null) && sqlArguments[i].ToLower().Equals("@@result"))
                        {
                            objArray[i] = "@@result";
                        }
                        else
                        {
                            objArray[i] = ConvertTool.getValue(new ExpParse(cs, sqlArguments[i]).calculate());
                            if ((objArray[i] != null) && (objArray[i] is ArrayList))
                            {
                                objArray[i] = ((ArrayList)objArray[i]).ToArray();
                                if (((((object[])objArray[i]).Length > 0) && (((object[])objArray[i])[0] is string)) && flag2)
                                {
                                    for (int j = 0; j < ((object[])objArray[i]).Length; j++)
                                    {
                                        ((object[])objArray[i])[j] = Convert.ToString(Encoding.GetEncoding(dbCharset).GetBytes((string)((object[])objArray[i])[0]));
                                    }
                                }
                            }
                            else if ((objArray[i] is string) && flag2)
                            {
                                objArray[i] = Convert.ToString(Encoding.GetEncoding(dbCharset).GetBytes((string)objArray[i]));
                            }
                            if ((objArray[i] != null) && objArray[i].GetType().IsArray)
                            {
                                int           length  = ((object[])objArray[i]).Length;
                                StringBuilder builder = new StringBuilder(2 * length);
                                for (int k = 0; k < length; k++)
                                {
                                    builder.Append("?,");
                                }
                                if ((builder.Length > 0) && (builder[builder.Length - 1] == ','))
                                {
                                    builder.Remove(builder.Length - 1, 1);
                                }
                                if (builder.Length > 1)
                                {
                                    str = new StringBuilder(str.Substring(0, num7).ToString().ToString()).Append(builder.ToString()).Append(str.Substring(num7 + 1)).ToString().ToString();
                                }
                                num7 += builder.Length;
                            }
                        }
                    }
                }
                Logger.debug("下面开始打出sql");
                int num6 = 0;
                if ((3 != config.SQLType) || (connection is OleDbConnection))
                {
                    try
                    {
                        Logger.debug(new StringBuilder(name.ToString().ToString()).Append("=").Append(str).ToString().ToString());
                        pst = SupportClass.TransactionManager.manager.PrepareStatement(connection, str);
                        goto Label_0472;
                    }
                    catch (Exception exception3)
                    {
                        throw new ReportError(new StringBuilder("数据集").Append(name).Append(" sql异常:").Append(exception3.Message).ToString().ToString(), exception3);
                    }
                }
                try
                {
                    pst = SupportClass.TransactionManager.manager.PrepareCall(connection, str);
                }
                catch (Exception exception4)
                {
                    throw new ReportError(new StringBuilder("数据集").Append(name).Append(" sql异常:").Append(exception4.Message).ToString().ToString(), exception4);
                }
Label_0472:
                if ((objArray == null) || (objArray.Length <= 0))
                {
                    goto Label_06A2;
                }
                int index = 0;
                int num3  = 0;
Label_048F:
                if (num3 >= objArray.Length)
                {
                    goto Label_06A2;
                }
                index++;
                if ((sqlArguments[num3] == null) || !sqlArguments[num3].ToLower().Equals("@@result"))
                {
                    goto Label_050E;
                }
                if (!(pst is OracleCommand))
                {
                    goto Label_0698;
                }
                try
                {
                    OracleParameter parameter = new OracleParameter();
                    parameter.ParameterName = (sqlArgumentsName[num3]);
                    parameter.OracleType    = (OracleType)(5);
                    parameter.Direction     = (ParameterDirection)(2);
                    pst.Parameters.Add(parameter);
                    goto Label_0698;
                }
                catch (Exception)
                {
                    goto Label_0698;
                }
Label_0504:
                num6 = index;
                goto Label_068D;
Label_050E:
                try
                {
                    if ((objArray[num3] != null) && objArray[num3].GetType().IsArray)
                    {
                        string msg = new StringBuilder("第").Append(num3).Append("个参数组: ").ToString().ToString();
                        for (int m = 0; m < ((object[])objArray[num3]).Length; m++)
                        {
                            msg = (msg.ToString() + ((object[])objArray[num3])[m].ToString()).ToString().ToString() + ",";
                            SQLTool.setObject(pst, index, ((object[])objArray[num3])[m], argumentTypes[num3], sqlArgumentsName[num3]);
                            index++;
                        }
                        Logger.debug(msg);
                        index--;
                    }
                    else
                    {
                        Logger.debug(new StringBuilder("第").Append(num3).Append("个参数: ").Append(objArray[num3]).ToString().ToString());
                        if ((6 == argumentTypes[num3]) && (objArray[num3] == null))
                        {
                            objArray[num3] = "";
                        }
                        SQLTool.setObject(pst, index, objArray[num3], argumentTypes[num3], sqlArgumentsName[num3]);
                    }
                }
                catch (Exception exception2)
                {
                    throw new ReportError(new StringBuilder("数据集").Append(name).Append("的sql第").Append(num3 + 1).Append("个参数异常:").Append(exception2.Message).ToString().ToString(), exception2);
                }
Label_068D:
                num3++;
                goto Label_048F;
Label_0698:
                if (num6 == 0)
                {
                    goto Label_0504;
                }
                goto Label_068D;
Label_06A2:
                try
                {
                    rs = pst.ExecuteReader();
                }
                catch (Exception exception)
                {
                    throw new ReportError(new StringBuilder("数据集").Append(name).Append("的 sql异常:").Append(exception.Message).ToString().ToString(), exception);
                }
                string beginRow = config.BeginRow;
                string endRow   = config.EndRow;
                if (((beginRow == null) || (beginRow.Trim().Length == 0)) || beginRow.Trim().ToUpper().Equals("null".ToUpper()))
                {
                    beginRow = "0";
                }
                if (((endRow == null) || (endRow.Trim().Length == 0)) || endRow.Trim().ToUpper().Equals("null".ToUpper()))
                {
                    endRow = "0";
                }
                beginRow = MacroCalc.replaceMacros(beginRow, env.MacrosMap);
                endRow   = MacroCalc.replaceMacros(endRow, env.MacrosMap);
                int num  = 0;
                int num2 = 0;
                try
                {
                    object obj2 = ConvertTool.getValue(new ExpParse(env, beginRow).calculate());
                    object obj3 = ConvertTool.getValue(new ExpParse(env, endRow).calculate());
                    if ((obj2 is int) && (obj3 is int))
                    {
                        num  = (int)obj2;
                        num2 = (int)obj3;
                    }
                }
                catch (Exception)
                {
                    throw new ReportError("数据集的起始行或者结束行设置有误。");
                }
                ArrayList   fieldText    = config.getFieldTextList();
                RecordCheck oRecordCheck = new RecordCheck(new ConnectionConfig().getDBOperator(), env.Request, env.Session);
                DataSet     set          = DataSetTool.populate(null, rs, num, num2, dbCharset, fieldText, false, flag, oRecordCheck);
                if ((config.IndexCols != null) && (config.IndexCols.Length > 0))
                {
                    set.createIndex(config.IndexCols, config.IndexSorted);
                }
                set3 = set;
            }
            catch (ReportError error)
            {
                throw error;
            }
            catch (Exception exception5)
            {
                throw new ReportError(exception5.Message, exception5);
            }
            finally
            {
                try
                {
                    if (rs != null)
                    {
                        rs.Close();
                    }
                    if (pst != null)
                    {
                        pst.Dispose();
                    }
                }
                catch (Exception exception6)
                {
                    throw new ReportError(exception6.Message, exception6);
                }
            }
            return(set3);
        }