/// <summary> /// 带debug的json返回 /// </summary> /// <param name="obj"></param> /// <param name="status"></param> /// <param name="message"></param> /// <param name="debug"></param> /// <returns></returns> public static string GetJson(object obj, int status, string message, object debug) { ReturnData data = new JSONHelper.ReturnData(); data.returntype = status; if (obj != null && obj.GetType().Name.IndexOf("DataTable") >= 0) { data.data = JSONHelper.DataTableToList((DataTable)obj); } else { data.data = obj; } #if DEBUG if (debug != null && debug.GetType().Name.IndexOf("Exception") >= 0) { Exception ex = (Exception)debug; ExceptionData de = new ExceptionData(); de.source = ex.Source; de.message = ex.Message; de.trace = ex.StackTrace; debug = de; LogHelper.Error(ex); } data.debug = debug; #endif data.returntext = message; return(ObjectToJSON(data)); }
private List <Area> DownloadAreas() { System.Net.WebClient wc = new System.Net.WebClient(); JSONHelper.JsonData data = new JSONHelper.JsonData(); data.sinfo = new SecurityInfo(FxtCommon.SignName, "1003104", "108746028", "855190548"); data.sinfo.functionname = "garealist"; data.info.funinfo = new { fxtcompanyid = 25, typecode = 1003302, cityid = FxtAddIn.CityID, }; string str = data.GetJsonString(); List <Area> areas = new List <Area>(); try { string list = FxtCommon.APIPostBack(FxtCommon.API_Datacenter, str); JSONHelper.ReturnData rtn = JSONHelper.JSONToObject <JSONHelper.ReturnData>(list); if (rtn.returntype > 0) { //获取行政区列表 string strdata = rtn.data.ToString(); areas = JSONHelper.JSONStringToList <Area>(strdata); } } catch (Exception ex) { SetStatus(EnumHelper.LabelStatus.Faild, ex.Message); } return(areas); }
private void GetProvinces() { EnableControls(false); btnGetProvine.Visible = false; //初始化省份列表 cbProvince.DropDownStyle = ComboBoxStyle.DropDownList; System.Net.WebClient wc = new System.Net.WebClient(); JSONHelper.JsonData data = new JSONHelper.JsonData(); data.sinfo = new SecurityInfo(FxtCommon.SignName, "1003104", "108746028", "855190548"); data.sinfo.functionname = "provincelist"; data.info.funinfo = new { fxtcompanyid = 25, typecode = 1003302 }; string str = data.GetJsonString(); try { string provincelist = FxtCommon.APIPostBack(FxtCommon.API_Datacenter, str); JSONHelper.ReturnData rtn = JSONHelper.JSONToObject <JSONHelper.ReturnData>(provincelist); if (rtn.returntype > 0) { EnableControls(true); List <Province> provinces = JSONHelper.JSONStringToList <Province>(rtn.data.ToString()); foreach (Province item in provinces) { item.provincename = FxtCommon.GetPinyinFirst(item.provincename.Replace("省", "").Replace("自治区", "").Replace("壮族", "")) + "_" + item.provincename; } provinces.Sort((x, y) => x.provincename.CompareTo(y.provincename)); cbProvince.DropDownStyle = ComboBoxStyle.DropDownList; cbProvince.DataSource = provinces; cbProvince.ValueMember = "provinceid"; cbProvince.DisplayMember = "provincename"; SetStatus(EnumHelper.LabelStatus.Success, "获取省份城市成功"); } else { SetStatus(EnumHelper.LabelStatus.Faild, rtn.returntext.ToString()); btnGetProvine.Visible = true; btnGetProvine.Enabled = true; } } catch (Exception ex) { SetStatus(EnumHelper.LabelStatus.Faild, ex.Message); btnGetProvine.Visible = true; btnGetProvine.Enabled = true; } }
/// <summary> /// 下载城市楼盘 /// </summary> /// <param name="pageindex"></param> /// <param name="pagerecords"></param> /// <param name="projects"></param> /// <param name="done"></param> private void DownLoadProjects(int pageindex, int pagerecords, List <Project> projects, out bool done) { done = false; JSONHelper.JsonData data = new JSONHelper.JsonData(); data.sinfo = new SecurityInfo(FxtCommon.SignName, "1003104", "108746028", "855190548"); data.sinfo.functionname = "plist";// "splist";"allplist" data.info.funinfo = new { fxtcompanyid = 25, typecode = 1003302, cityid = FxtAddIn.CityID, key = "", pageindex = pageindex, pagerecords = pagerecords }; string str = data.GetJsonString(); try { string list = FxtCommon.APIPostBack(FxtCommon.API_Datacenter, str); JSONHelper.ReturnData rtn = JSONHelper.JSONToObject <JSONHelper.ReturnData>(list); if (rtn.returntype > 0) { //获取楼盘列表 string strdata = rtn.data.ToString(); //StreamWriter write = File.CreateText(@"c:\windows\temp\temp_projects.txt"); //write.Write(strdata); //write.Close(); List <Project> cp = JSONHelper.JSONStringToList <Project>(strdata); if (cp.Count > 0) { projects.AddRange(cp);// = projects.Concat(cp).ToList(); } if (cp.Count < pagerecords) { done = true; } else { pageindex++; DownLoadProjects(pageindex, pagerecords, projects, out done); } } } catch (Exception ex) { SetStatus(EnumHelper.LabelStatus.Faild, ex.Message); } }
private void GetCitys() { EnableControls(false); btnGetCity.Visible = false; System.Net.WebClient wc = new System.Net.WebClient(); JSONHelper.JsonData data = new JSONHelper.JsonData(); data.sinfo = new SecurityInfo(FxtCommon.SignName, "1003104", "108746028", "855190548"); data.sinfo.functionname = "citylist"; data.info.funinfo = new { fxtcompanyid = 25, typecode = 1003302, provinceid = cbProvince.SelectedValue }; string str = data.GetJsonString(); try { string citylist = FxtCommon.APIPostBack(FxtCommon.API_Datacenter, str); JSONHelper.ReturnData rtn = JSONHelper.JSONToObject <JSONHelper.ReturnData>(citylist); if (rtn.returntype > 0) { EnableControls(true); List <City> citys = JSONHelper.JSONStringToList <City>(rtn.data.ToString()); foreach (City item in citys) { item.cityname = FxtCommon.GetPinyinFirst(item.cityname.Replace("市", "").Replace("直辖", "")) + "_" + item.cityname; } citys.Sort((x, y) => x.cityname.CompareTo(y.cityname)); cbCity.DropDownStyle = ComboBoxStyle.DropDownList; cbCity.DataSource = citys; cbCity.ValueMember = "cityid"; cbCity.DisplayMember = "cityname"; SetStatus(EnumHelper.LabelStatus.Success, "获取城市成功"); } else { SetStatus(EnumHelper.LabelStatus.Faild, "获取城市失败"); btnGetCity.Visible = true; btnGetCity.Enabled = true; } } catch (Exception ex) { SetStatus(EnumHelper.LabelStatus.Faild, ex.Message); btnGetCity.Visible = true; btnGetCity.Enabled = true; } }