public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            BLL.Areas          AreaAreasServer = new BLL.Areas();
            List <Model.Areas> ModelListAreas  = AreaAreasServer.GetModelList(string.Format("AreaPID={0}", context.Request["PID"]));

            JavaScriptSerializer myjsSerializer = new JavaScriptSerializer();
            var responseJson = myjsSerializer.Serialize(ModelListAreas);

            context.Response.Write(responseJson);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //string text = "[{\"Name\":\"leichao\",\"Age\":\"20\"},";
            //text += "{\"Name\":\"Ray\",\"Age\":\"19\"}]";
            //context.Response.Write(text);
            BLL.Areas AreasServer = new BLL.Areas();
            //select Id,AreaID,AreaName,AreaPID
            List <Model.Areas>   ModelListAreas = AreasServer.GetModelList("AreaPID=0");
            JavaScriptSerializer myjsSerializer = new JavaScriptSerializer();
            var responseJson = myjsSerializer.Serialize(ModelListAreas);


            context.Response.Write(responseJson);
        }
Exemple #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            Model.Areas NewAreas = new Model.Areas();
            NewAreas.AreasName  = context.Request["value"].ToString();
            NewAreas.ProvinceID = Convert.ToInt32(context.Request["pk"]);
            int ok = new BLL.Areas().AddAreas(NewAreas);

            if (ok == 1)
            {
                context.Response.Write(200);
            }
            else
            {
                context.Response.Write(400);
            }
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat("<option value='{0}'>{1}</option>", -1, "全选");
            //获取到城市的id
            int cId = int.Parse(context.Request["cId"] ?? "1");

            BLL.FarmlandMeg newFarmlandMegBll = new BLL.FarmlandMeg();
            //获取表中该城市下存在的区/县
            DataSet newFarmlandMegAllList = newFarmlandMegBll.GetList("City = " + cId);

            //遍历DataSet
            foreach (DataTable dt in newFarmlandMegAllList.Tables)
            {
                List <Model.FarmlandMeg> FarmlandMegList = newFarmlandMegBll.DataTableToList(dt);
                List <int> existCountry = new List <int>();
                //遍历List中的FarmlandMeg
                foreach (SoilNutrientSoft.Model.FarmlandMeg FM in FarmlandMegList)
                {
                    //判断是否存在该区/县
                    if (!existCountry.Contains(Convert.ToInt32(FM.County)))
                    {
                        //获取到区/县ID
                        int                CountryNum        = Convert.ToInt32(FM.County);
                        BLL.Areas          newAreasBll       = new BLL.Areas();
                        List <Model.Areas> newAreasModelList = newAreasBll.GetModelList("AreaID = " + CountryNum);
                        foreach (SoilNutrientSoft.Model.Areas item in newAreasModelList)
                        {
                            //如果不存在该区/县,就将其添加
                            sb.AppendFormat("<option value='{0}'>{1}</option>", item.AreaID, item.AreaName);
                        }
                        //将其添加至已存List中
                        existCountry.Add(CountryNum);
                    }
                }
            }
            context.Response.Write(sb.ToString());
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";

            StringBuilder newSb = new StringBuilder();

            newSb.Append("[");
            //农田信息对象
            BLL.FarmlandMeg newFarmlandMeg = new BLL.FarmlandMeg();
            //需要的数据集合
            DataSet st = newFarmlandMeg.GetAllList();

            //遍历每张表
            foreach (DataTable item in st.Tables)
            {
                //将表转换成集合
                List <Model.FarmlandMeg> FarmlandMegList = newFarmlandMeg.DataTableToList(item);

                //用于检测是否已经加载过该市的节点  防止多个相同的“市”节点出现
                List <int> existNum = new List <int>();

                //遍历表集合
                int idNum = 1;
                foreach (var data in FarmlandMegList)
                {
                    //地域对象
                    BLL.Areas newAreas = new BLL.Areas();
                    //获取城市对应的ID
                    int cityNum = int.Parse(data.City);
                    //判断该城市是否已经加载,如果已经加载则无需重复加载
                    if (!existNum.Contains(cityNum))
                    {
                        //将表中的城市加到集合中
                        existNum.Add(cityNum);
                        newSb.Append("{");
                        newSb.AppendFormat("\"tags\":[\"-1\"],", idNum);
                        //获取地域数据
                        DataTable          d             = newAreas.GetList(" AreaID = " + cityNum).Tables[0];
                        List <Model.Areas> newAerasModel = newAreas.DataTableToList(d);
                        string             cityName      = newAerasModel[0].AreaName;
                        //节点名称
                        newSb.AppendFormat("\"text\":\"{0}\",", cityName);
                        newSb.Append("\"state\":{\"backColor\": \"#428BCA\"},");
                        //子节点集合
                        newSb.Append("\"nodes\":[");

                        //如果集合中不存在该数就继续加载数据

                        //获取同一个市下的县区
                        DataSet newSameCity = newFarmlandMeg.GetList("City=" + cityNum);
                        foreach (DataTable countryTable in newSameCity.Tables)
                        {
                            //  县/区  同一个城市下的县区集合
                            List <Model.FarmlandMeg> countriesList = newFarmlandMeg.DataTableToList(countryTable);
                            int countryIdNum = 1;
                            //用于检测是否已经加载过该市的节点  防止多个相同的“区/县”节点出现
                            List <int> exitCountry = new List <int>();
                            foreach (var country in countriesList)
                            {
                                //判断是否添加过该  县/区
                                if (!exitCountry.Contains(Convert.ToInt32(country.County)))
                                {
                                    exitCountry.Add(Convert.ToInt32(country.County));
                                    newSb.Append("{");
                                    //通过区县 获取地域数据
                                    DataTable          areasCountry     = newAreas.GetList(" AreaID = " + country.County).Tables[0];
                                    List <Model.Areas> areasCountryList = newAreas.DataTableToList(areasCountry);
                                    //区县名称
                                    string countryName = areasCountryList[0].AreaName;
                                    //newSb.Append("\"id\":" + idNum.ToString() + countryIdNum.ToString() + ",");
                                    newSb.AppendFormat("\"tags\":[\"-1\"],", idNum.ToString() + countryIdNum.ToString());

                                    //newSb.Append("\"state\":{\"expanded\": \"false\"},");
                                    newSb.AppendFormat("\"text\":\"{0}\",", countryName);
                                    newSb.Append("\"nodes\":[");


                                    //获取同一个市区下的集合
                                    DataTable townTable = newFarmlandMeg.GetList(" City= " + cityNum + " and County= " + country.County).Tables[0];
                                    List <Model.FarmlandMeg> townList = newFarmlandMeg.DataTableToList(townTable);
                                    //int townNum = 1;
                                    foreach (var key in townList)
                                    {
                                        newSb.Append("{");
                                        string sampleName = key.Sample_name;
                                        string townId     = key.Id.ToString();
                                        //newSb.Append("\"id\":" + idNum.ToString() + countryIdNum.ToString() + townNum.ToString()+ ",");
                                        //newSb.AppendFormat("\"id\":\"{0}\",", idNum.ToString() + countryIdNum.ToString() + townNum.ToString());
                                        //将数据库中的id给终极子节点
                                        newSb.AppendFormat("\"tags\":[\"{0}\"],", townId);
                                        //添加采样点名称
                                        newSb.AppendFormat("\"text\":\"{0}\"", sampleName);

                                        newSb.Append("},");
                                        //townNum++;
                                    }
                                    //将最后一个“,”移除
                                    newSb.Remove(newSb.Length - 1, 1);
                                    newSb.Append("]");
                                    countryIdNum++;
                                    newSb.Append("},");
                                }
                            }
                            //将最后一个“,”移除
                            newSb.Remove(newSb.Length - 1, 1);
                        }
                        newSb.Append("]");
                        newSb.Append("},");
                        idNum++;
                    }
                }
            }
            if (!(newSb.ToString() == "["))
            {
                //如果StringBuilder中不止“[”,则移除,否则不移除
                //将最后一个“,”移除
                newSb.Remove(newSb.Length - 1, 1);
            }

            newSb.Append("]");
            //context.Response.Write(dataStr);
            context.Response.Write(newSb.ToString());
        }