private void BtnImport_Click(object sender, EventArgs e)
{
OpenFileDialog dialog = new OpenFileDialog {
AddExtension = true,
DefaultExt = "txt",
Filter = "txt文件(*.txt)|*.txt",
Title = "请选择要导入的文件:",
FilterIndex = 0
};
if (dialog.ShowDialog() == DialogResult.OK)
{
string[] strArray = StringUtils.FindEmailAddr(File.ReadAllText(dialog.FileName));
if ((strArray != null) || (strArray.Length != 0))
{
ToEmailData data = new ToEmailData();
int num = 0;
int num2 = 0;
List<ToEmailInfo> list = data.List();
Hashtable hashtable = new Hashtable();
foreach (ToEmailInfo info in list)
{
if (((info != null) && !string.IsNullOrEmpty(info.Address)) && !hashtable.Contains(info.Address))
{
hashtable.Add(info.Address, info.Name);
}
}
this.BarImport.Visible = true;
this.ProgressBarImport.Maximum = strArray.Length;
this.ProgressBarImport.Minimum = 0;
this.ProgressBarImport.Value = 0;
foreach (string str in strArray)
{
num2++;
this.ProgressBarImport.Value = num2;
Application.DoEvents();
if ((!string.IsNullOrEmpty(str) && StringUtils.IsEmail(str)) && (hashtable[str] == null))
{
if (data.Total() >= 10)
{
break;
}
num++;
data.Add(str.Trim());
hashtable.Add(str, "");
}
}
this.BarImport.Visible = false;
MessageBox.Show("导入完毕,共加入" + num + "条邮件地址!试用版最多可以加入10条!", "信息提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
if (num > 0)
{
this.LoadToEmail();
}
}
}
}