T_CityManager am = new T_CityManager();
string tou = "var LAreaData=[";
string value = "";
List<T_City> plist = am.GetAllBySQL(" AND FParentID=0").ToList();
int count = 0;
foreach (T_City prov in plist)
{
if (count == 0)
{
value += "{\"id\":\"" + prov.PID + "\",\"name\":\"" + prov.FName + "\""; }
else
{
value += ",{\"id\":\"" + prov.PID + "\",\"name\":\"" + prov.FName + "\"";
} List<T_City> slist = am.GetAllBySQL(" AND FParentID=" + prov.PID).ToList();
if (slist.Count > 0)
{
value += ",\"child\":[";
}
else if (slist.Count == 1)
{
value += "},";
} foreach (T_City city in slist)
{ value += "{\"id\":\"" + city.PID + "\",\"name\":\"" + city.FName + "\"";
List<T_City> qlist = am.GetAllBySQL(" AND FParentID=" + city.PID).ToList();
if (qlist.Count==0)
{
value += "},";
}
if (qlist.Count > 0)
{
value += ",\"child\":[";
} foreach (var qu in qlist)
{
value += "{\"id\":\"" + qu.PID + "\",\"name\":\"" + qu.FName + "\"},";
}
if (qlist.Count > 0)
{
value = value.Substring(0, value.Length - 1);
value += "]},";
}
}
if (slist.Count > 0)
{
value = value.Substring(0, value.Length - 1);
value += "]}";
} count++;
}
tou = tou + value + "]";
}