示例#1
0
        /// <summary>
        /// 浏览页获取数据
        /// </summary>
        /// <param name="condition"></param>
        /// <returns></returns>
        public static object Search(string RID, string table, Boolean IsShowAll)
        {
            //string sqlText =
            //            @"
            //            if(object_id('@tbl') is null)
            //            select '' where 1=2
            //            else
            //            select * from [@tbl] where RID = '@RID'
            //            order by ACTION_DATE desc
            //            "
            string sqlText =
                @"
            if(object_id('@tbl') is null)
            select '' where 1=2
            else
            select * from [@tbl] where @Condition
            order by ACTION_DATE desc
            "
                .Replace("@tbl", table.Replace("'", ""))
                .Replace("@Condition", (IsShowAll ? "1=1" : "RID ='" + RID.Replace("'", "") + "'"));
            var rst = new System.Data.DataTable();

            using (DB db = new DB())
            {
                rst = SQlHelper.ExecuteToDataTable(sqlText, System.Data.CommandType.Text);
                if (rst != null)
                {
                    var cols = new System.Data.DataColumn[rst.Columns.Count];
                    rst.Columns.CopyTo(cols, 0);
                    cols = cols.Where(x => !(x.ColumnName.Equals("RID", StringComparison.CurrentCultureIgnoreCase) || x.ColumnName.Equals("LOG_ID", StringComparison.CurrentCultureIgnoreCase)))
                           .ToArray();
                    var o = new
                    {
                        columns = cols.Select(x => new { title = x.ColumnName.Replace("_", " "), field = x.ColumnName, width = "165px", format = x.DataType.Name == "DateTime" ? "{0:yyyy-MM-dd HH:mm:ss}" : "" }),
                        schema  = new
                        {
                            model = new
                            {
                                fields = cols.ToDictionary(k => k.ColumnName, v => new { type = v.DataType.Name == "DateTime" ? "date" : "string" })
                            }
                        },
                        Data = rst
                    };
                    return(o);
                }
            }
            return(rst);
        }
示例#2
0
        /// <summary>
        /// 获取组织架构的
        /// </summary>
        /// <param name="httpContext"></param>
        /// <returns></returns>
        public static string GetSectTreeData(HttpContext httpContext)
        {
            string msg      = "ok";
            string Rstr     = string.Empty;
            string keywords = httpContext.Request["keywords"]; // SelectTree.Tools.RequestHelper.GetRequest("keywords");

            String pid    = httpContext.Request["pid"];        // SelectTree.Tools.RequestHelper.GetRequest("pid");
            String action = httpContext.Request["treeAction"]; // SelectTree.Tools.RequestHelper.GetRequest("action");//为getchild时表示需要获取pid对应的子节点

            SqlParameter[] sqlParas = new SqlParameter[] {
                new SqlParameter("@SourceID", SqlDbType.VarChar, 50)
                , new SqlParameter("@ParentRID", SqlDbType.VarChar, 50)
                , new SqlParameter("@TextInput", SqlDbType.NVarChar, 100)
            };

            if (!String.IsNullOrEmpty(pid))//如果是点击树形控件的加号,异步查询子节点
            {
                sqlParas[0].Value = "AjaxGetTreeDataByParentRID";
                sqlParas[1].Value = pid;
                sqlParas[2].Value = "";
                DataTable dt = SQlHelper.ExecuteToDataTable("p_AjaxGetOrgTreeData", CommandType.StoredProcedure, sqlParas);
                Rstr += JsonConvert.SerializeObject(dt);//SelectTree.Tools.JsonHelper.ToJson(dt);
            }
            else
            {
                if (String.IsNullOrEmpty(keywords))//如果文本框没有输入值,则加载默认数据
                {
                    sqlParas[0].Value = "AjaxGetTreeDataDefault";
                    sqlParas[1].Value = "";
                    sqlParas[2].Value = "";
                    DataTable dt = SQlHelper.ExecuteToDataTable("p_AjaxGetOrgTreeData", CommandType.StoredProcedure, sqlParas);
                    Rstr += JsonConvert.SerializeObject(dt);//SelectTree.Tools.JsonHelper.ToJson(dt);
                }
                else//按输入文本框内容检索
                {
                    sqlParas[0].Value = "AjaxGetTreeDataByText";
                    sqlParas[1].Value = "";
                    sqlParas[2].Value = keywords;
                    DataTable dt = SQlHelper.ExecuteToDataTable("p_AjaxGetOrgTreeData", CommandType.StoredProcedure, sqlParas);
                    Rstr += JsonConvert.SerializeObject(dt);// SelectTree.Tools.JsonHelper.ToJson(dt);
                }
            }
            return("{\"msg\":\"" + msg + "\",\"dataJSON\":" + Rstr + "}");
        }