一、读取配置函数
private void loadAddressInfo()
{
this.localAddressInfo.province = -1;
this.localAddressInfo.city = -1;
this.localAddressInfo.dis = -1;
if (File.Exists(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt"))
{
StreamReader streamReader = new StreamReader(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt", Encoding.GetEncoding("GB2312"));
string text = "";
try
{
while (text != null)
{
text = streamReader.ReadLine();
if (text != null && !text.Equals(""))
{
string[] array = text.Split(new char[]
{
':'
});
if (array.Length == 2)
{
if (array[0] == "realName")
{
this.tb_realName.Text = array[1].Replace("&", "\r\n");
}
if (array[0] == "mobile")
{
this.tb_phone.Text = array[1].Replace("&", "\r\n");
}
if (array[0] == "solidFirst")
{
this.tb_solidFirst.Text = array[1].Replace("&", "\r\n");
}
if (array[0] == "solidSec")
{
this.tb_solidSec.Text = array[1].Replace("&", "\r\n");
}
if (array[0] == "province")
{
if (array[1] != "")
{
this.localAddressInfo.province = int.Parse(array[1]);
}
else
{
this.localAddressInfo.province = -1;
}
}
if (array[0] == "city")
{
if (array[1] != "")
{
this.localAddressInfo.city = int.Parse(array[1]);
}
else
{
this.localAddressInfo.city = -1;
}
}
if (array[0] == "dis")
{
if (array[1] != "")
{
this.localAddressInfo.dis = int.Parse(array[1]);
}
else
{
this.localAddressInfo.dis = -1;
}
}
if (array[0] == "edittextarea")
{
this.tb_edittextarea.Text = array[1];
}
if (array[0] == "postalcode")
{
this.tb_postalcode.Text = array[1];
}
}
}
}
}
catch (Exception var_3_2FF)
{
}
this.first_flag = false;
streamReader.Close();
}
}
2、保存配置函数
private void btn_saveYYInfo_Click(object sender, EventArgs e)
{
if (!File.Exists(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt"))
{
File.Create(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt").Close();
}
StreamWriter streamWriter = null;
FileStream fileStream = null;
try
{
fileStream = new FileStream(Directory.GetCurrentDirectory() + "\\phoneAddInfo.txt", FileMode.Create, FileAccess.Write);
streamWriter = new StreamWriter(fileStream, Encoding.GetEncoding("GB2312"));
streamWriter.Flush();
streamWriter.BaseStream.Seek(0L, SeekOrigin.Begin);
streamWriter.WriteLine("realName:" + this.tb_realName.Text);
streamWriter.WriteLine("mobile:" + this.tb_phone.Text);
streamWriter.WriteLine("province:" + this.cbb_province.SelectedIndex);
streamWriter.WriteLine("city:" + this.cbb_city.SelectedIndex);
streamWriter.WriteLine("dis:" + this.cbb_dis.SelectedIndex);
streamWriter.WriteLine("edittextarea:" + this.tb_edittextarea.Text);
streamWriter.WriteLine("postalcode:" + this.tb_postalcode.Text);
streamWriter.Flush();
streamWriter.Close();
streamWriter.Dispose();
fileStream.Close();
fileStream.Dispose();
MessageBox.Show("暂存预约地址信息成功!");
}
catch (Exception var_2_17C)
{
streamWriter.Close();
streamWriter.Dispose();
fileStream.Close();
fileStream.Dispose();
}
}