版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/sinat_23338865/article/details/82663530
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Converters;
using AutoBuy.Frid;
using AutoBuy.Helper;
using System.Diagnostics;
using System.IO.Ports;
using AutoBuy.language;
namespace AutoBuy.Forms
{
public partial class FrmConfig : FrmBase
{
public JObject AllData;
public JObject Citydata;
public JObject Countydata;
public JObject Istoreshop;
public List<string> Shopaddrurl = new List<string>();
public bool Readerableflage = true;
public FrmConfig(bool enable)
{
Readerableflage = enable;
InitializeComponent();
this.shopaddrtxt.Text = geturl;
string jsonText ={\"北京市\":{\"北京市1\":{\"越秀区\":{\"体验店1\":\"www.11.com\",\"体验店2\":\"www.12.com\"},\"天河区\":{\"体验店1\":\"www.13.com\",\"体验店2\":\"www.14.com\"}},\"北京市2\":{\"南山区\":{\"体验店1\":\"www.15.com\",\"体验店2\":\"www.16.com\"},\"宝安区\":{\"体验店1\":\"www.17.com\",\"体验店2\":\"www.18.com\"}}}}
this.AllData = JObject.Parse(jsonText);
foreach (KeyValuePair<string, JToken> keyValuePair in this.AllData)
{
this.Province.Items.Add(keyValuePair.Key);
this.Province.Text = this.Province.Items[0].ToString();
}
}
public bool CfgRetflag = false;
public static bool FrmSetCfg(bool enable)
{
FrmConfig frmConfig = new FrmConfig(enable);
frmConfig.ShowDialog();
return frmConfig.CfgRetflag;
}
private void Province_SelectedIndexChanged(object sender, EventArgs e)
{
this.City.Items.Clear();
this.City.SelectedItem = null;
Citydata = JObject.Parse(this.AllData[(string)this.Province.SelectedItem].ToString());
foreach (KeyValuePair<string, JToken> keyValuePair in Citydata) { this.City.Items.Add(keyValuePair.Key); }
this.City.Text = this.City.Items[0].ToString();
}
private void City_SelectedIndexChanged(object sender, EventArgs e)
{
this.County.Items.Clear();
this.County.SelectedItem = null;
Countydata = JObject.Parse(this.Citydata[(string)this.City.SelectedItem].ToString());
foreach (KeyValuePair<string, JToken> keyValuePair in Countydata)
{
this.County.Items.Add(keyValuePair.Key);
}
this.County.Text = this.County.Items[0].ToString();
}
private void County_SelectedIndexChanged(object sender, EventArgs e)
{
this.ShopAddr.Items.Clear(); //清空店地址
this.ShopAddr.SelectedItem = null;
Shopaddrurl.Clear();
Istoreshop = JObject.Parse(this.Countydata[(string)this.County.SelectedItem].ToString());
foreach (KeyValuePair<string, JToken> shopname in Istoreshop)
{
this.ShopAddr.Items.Add(shopname.Key);
}
this.ShopAddr.Text = this.ShopAddr.Items[0].ToString();
}
private void btnSetAddrOK_Click(object sender, EventArgs e)
{
JObject Selectedshop = JObject.Parse(Countydata[this.County.SelectedItem].ToString()); //选中的区
foreach (KeyValuePair<string, JToken> shopname in Istoreshop)
{
Shopaddrurl.Add(shopname.Value.ToString());
}
var index = this.ShopAddr.SelectedIndex; //选中的店url
var url = Shopaddrurl[this.ShopAddr.SelectedIndex];
}
}
}