Пример #1
0
        public HttpResponseMessage GetFilter(string type, string field)
        {
            string returntxt = "";
            string strsql    = "";

            if (type.Contains(",") == true)
            {
                if (type.Split(',')[1] != "")
                {
                    string strLocalpathother = System.Web.Hosting.HostingEnvironment.MapPath(@"~/App_Data/Config/" + type.Split(',')[1] + ".json"); //配置的json文件地址
                    strLocalpath = strLocalpathother;                                                                                               //这个操作是为了区分各个系统 以防更改了河北的配置导致重庆的也一同更改了
                }
            }
            DataTable dt = new DataTable();

            try
            {
                string getjson = rule.GetJson(strLocalpath);//json配置文件转换
                JArray jsonObj = JArray.Parse(getjson);
                for (int i = 0; i < jsonObj.Count; i++)
                {
                    string typemodel = jsonObj[i]["type"].ToString();

                    if (type.Split(',')[0] == typemodel)
                    {
                        JArray jsonObjs = JArray.Parse(jsonObj[i]["condition"].ToString());
                        JArray jsonend  = JArray.Parse(jsonObjs[0]["one"].ToString());

                        for (int j = 0; j < jsonend.Count; j++)
                        {
                            if (jsonend[j]["value"].ToString() == field)
                            {
                                string isTranslate = jsonend[j]["istranslate"].ToString();

                                if (isTranslate == "yes")
                                {
                                    dt = rule.GetFiled(jsonObj[i]["table"].ToString(), field, jsonend[j]["dictionaries"].ToString());
                                }
                                else
                                {
                                    strsql = "select distinct " + field + " as 'label'," + field + " as 'value' from " + jsonObj[i]["table"].ToString() + "";
                                    dt     = rule.getdt(strsql);
                                }
                                returntxt = rule.JsonStr("ok", "", dt);
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
                returntxt = rule.JsonStr("error", e.Message, "");
            }
            return(new HttpResponseMessage {
                Content = new StringContent(returntxt, System.Text.Encoding.UTF8, "application/json")
            });
        }