예제 #1
0
        public ListItem GetFieldDataSource(int moduleId,string queryName,string fieldName)
        {
            DataQueryCollection lst = service.GetModuleQuery(moduleId);
            var query = lst.FirstOrDefault(c => c.Name == queryName);
            if (query == null)
                return null;
            var field = query.Fields[fieldName];
            if (field == null)
                return null;

            if (field.DispValueType == EnumDisplayValueType.dvtSQL)
            {
                var script =  string.Join(Environment.NewLine,field.DisplayValue);
                script = string.Format(@"SELECT * FROM
                    (
                        SELECT A.*, ROWNUM RN
                        FROM ( {0} ) A
                            WHERE ROWNUM <= 20
                    )
                    WHERE RN >= 0", script);

                using (var con = Unity.GetConnection())
                {
                    var cmd = con.CreateCommand();
                    cmd.CommandText = script;
                    cmd.Connection = con;
                    con.Open();
                    var rd = cmd.ExecuteReader();
                    var dt = new ListItem();
                    dt.Load(rd);
                    return dt;
                }
            }
            return null;
        }