Esempio n. 1
0
        private DataTable GetQueryView(string queryName, Hashtable hash, int pageSize, int currentPageIndex,
                                       out int totalCount)
        {
            DataBaseAccess db = ExportManager.GetDao();

            ExportItemConfig item       = ExportManager.GetConfigByQueryName(queryName);
            string           query      = item.Query;
            string           queryTotal = item.Total;

            //添加分页参数
            if (hash != null)
            {
                foreach (DictionaryEntry o in hash)
                {
                    if (UnsafeSqlReg.IsMatch(o.Value.ToString()))
                    {
                        throw new ArgumentException("含有不安全的查询!");
                    }
                }
                hash.Add("page_start", currentPageIndex <= 0 ? 0 : (currentPageIndex - 1) * pageSize);
                hash.Add("page_end", (currentPageIndex) * pageSize);
                hash.Add("page_size", pageSize);


                //格式化
                query = query.Template(hash);
                // throw new Exception(query + "/" + currentPageIndex+"/"+pageSize);
                if (!String.IsNullOrEmpty(queryTotal))
                {
                    queryTotal = queryTotal.Template(hash);
                }
            }


            //获取分页结果
            DataTable dataTable = db.GetDataSet(query, hash).Tables[0];

            //获取统计数据
            if (!String.IsNullOrEmpty(queryTotal))
            {
                object data = db.ExecuteScalar(queryTotal, hash);
                int.TryParse(data.ToString(), out totalCount);
            }
            else
            {
                totalCount = dataTable.Rows.Count;
            }

            return(dataTable);
        }
Esempio n. 2
0
        private ExportItemConfig GetConfigByQueryName(string queryName)
        {
            if (!this.configDict.ContainsKey(queryName))
            {
                string filePath = _baseDirectory + "query/" + queryName + ".config";

                if (!File.Exists(filePath))
                {
                    throw new Exception("不包含查询:" + queryName);
                }
                ExportItemConfig cfg = ExportUtil.GetExportItemFormXml(
                    File.ReadAllText(filePath)
                    , null);

                this.configDict.Add(queryName, cfg);
            }
            return(this.configDict[queryName]);
        }