📄 frmconf.cs
字号:
//
this.button6.Location = new System.Drawing.Point(280, 152);
this.button6.Name = "button6";
this.button6.TabIndex = 54;
this.button6.Text = "关闭";
this.button6.Click += new System.EventHandler(this.button6_Click);
//
// textBox8
//
this.textBox8.Location = new System.Drawing.Point(40, 120);
this.textBox8.Multiline = true;
this.textBox8.Name = "textBox8";
this.textBox8.Size = new System.Drawing.Size(200, 96);
this.textBox8.TabIndex = 53;
this.textBox8.Text = "";
//
// button5
//
this.button5.Location = new System.Drawing.Point(280, 92);
this.button5.Name = "button5";
this.button5.TabIndex = 52;
this.button5.Text = "删除";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(280, 32);
this.button3.Name = "button3";
this.button3.TabIndex = 50;
this.button3.Text = "新增";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// treeView1
//
this.treeView1.FullRowSelect = true;
this.treeView1.ImageIndex = -1;
this.treeView1.Location = new System.Drawing.Point(40, 24);
this.treeView1.Name = "treeView1";
this.treeView1.SelectedImageIndex = -1;
this.treeView1.ShowLines = false;
this.treeView1.Size = new System.Drawing.Size(200, 80);
this.treeView1.TabIndex = 49;
this.treeView1.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.treeView1_AfterSelect);
//
// FrmConf
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(448, 317);
this.Controls.AddRange(new System.Windows.Forms.Control[] {
this.tabControl1});
this.Name = "FrmConf";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "帐户配置";
this.Load += new System.EventHandler(this.FrmConf_Load);
this.tabControl1.ResumeLayout(false);
this.tabPage1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.Numtimeout)).EndInit();
this.tabPage2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void tabControl1_SelectedIndexChanged(object sender, System.EventArgs e)
{
}
private void button2_Click(object sender, System.EventArgs e)
{
///<summary>
///配置信息的保存,以单行保存为主
///在其他的POP3的帐号信息以POP+帐号名称+‘/’+用户名+“/”+密码+“/”+是否在服务器保留备份
///<summary>
bool bnull =false;
if(Txtname.Text.Trim().Length<1)
{bnull=true;}
if(Txtemail.Text.Trim().Length<1)
{bnull=true;}
if(Txtsmtpname.Text.Trim().Length<1)
{bnull=true;}
if(Txtsmtpport.Text.Trim().Length<1)
{bnull=true;}
if(Txtpop3name.Text.Trim().Length<1)
{bnull=true;}
if(Txtpop3port.Text.Trim().Length<1)
{bnull=true;}
if(Txtusername.Text.Trim().Length<1)
{bnull=true;}
if(Txtuserpwd.Text.Trim().Length<1)
{bnull=true;}
int s=Txtemail.Text.IndexOf("@");
int s1=Txtemail.Text.IndexOf(".");
if(s==-1||s1==-1)
{
bnull=true;
MessageBox.Show ("邮件格式不是合法邮件地址!");
Txtemail.Focus();
}
string Acon="";
if(!bnull)
{
Acon=Acon+"Dispname:"+ Txtname.Text +"\r\n";
Acon=Acon+"Dispemail:"+ Txtemail.Text +"\r\n";
Acon=Acon+"smtpname:"+ Txtsmtpname.Text +"\r\n";
Acon=Acon+"smtpport:"+ Txtsmtpport.Text +"\r\n";
Acon=Acon+"pop3name:"+ Txtpop3name.Text +"\r\n";
Acon=Acon+"pop3port:"+ Txtpop3port.Text +"\r\n";
Acon=Acon+"username:"+ Txtusername.Text +"\r\n";
Acon=Acon+"userpwd:"+ Txtuserpwd.Text +"\r\n";
Acon=Acon+"emailbak:"+ Chkbak.Checked.ToString() +"\r\n";
Acon=Acon+"smtplogin:"+ Chksmtplogin.Checked.ToString() +"\r\n";
Acon=Acon+"timeout:"+ Numtimeout.Value +"\r\n";
//写入第一部分内容
FileStream fout = new FileStream("skymail.wg", FileMode.OpenOrCreate, FileAccess.Write);
Byte[] bytearrayinput=ConvertStringToByteArray(Acon);
string password="wanwengu";
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
CryptoStream encStream = new CryptoStream(fout,rijn.CreateEncryptor(key,key),CryptoStreamMode.Write);
encStream.Write(bytearrayinput,0,bytearrayinput.Length);
encStream.Close();
fout.Close();
this.Close();
}
}
public static Byte[] ConvertStringToByteArray(String s)
{
return (new UnicodeEncoding()).GetBytes(s);
}
private void FrmConf_Load(object sender, System.EventArgs e)
{
this.disptree();
}
public void disptree()
{
treeView1.Nodes.Clear();
FileInfo ad=new FileInfo("skymail.wg");
if (ad.Exists)
{
string password="wanwengu";
FileStream fin = new FileStream("skymail.wg", FileMode.Open, FileAccess.Read);
UnicodeEncoding UE = new UnicodeEncoding();
byte[] key = UE.GetBytes(password);
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
CryptoStream cryptostreamDecr = new CryptoStream(fin,rijn.CreateDecryptor(key,key),CryptoStreamMode.Read);
string con="";
StreamReader t = new StreamReader(cryptostreamDecr, new UnicodeEncoding());
con=t.ReadToEnd();
cryptostreamDecr.Close();
fin.Close();
string[] conn=con.Split(new char[]{'\n'});
for(int j=0;j<conn.Length;j++ )
{
string szTemp=conn[j];
int hint=szTemp.IndexOf(":"); ///将单行字符串以冒号为分隔分成两个字符串
if(hint!=-1)
{
string headcaption;
string headvalue;
headcaption=szTemp.Substring(0,hint);
headvalue=szTemp.Substring(hint+1,szTemp.Length-hint-1).Trim(); ;
switch (headcaption)
{
case "Dispname":
Txtname.Text =headvalue;
break;
case "Dispemail":
Txtemail.Text =headvalue;
break;
case "smtpname":
Txtsmtpname.Text =headvalue;
break;
case "smtpport":
Txtsmtpport.Text=headvalue;
break;
case "pop3name":
Txtpop3name.Text=headvalue;
break;
case "pop3port":
Txtpop3port.Text=headvalue;
break;
case "username":
Txtusername.Text=headvalue;
break;
case "userpwd":
Txtuserpwd.Text=headvalue;
break;
case "smtplogin":
if(headvalue.IndexOf("True")!=-1)
{
Chksmtplogin.Checked=true;
}
else
{
Chksmtplogin.Checked=false;
};
break;
case "emailbak":
if(headvalue.IndexOf("True")!=-1)
{
Chkbak.Checked=true;
}
else
{
Chkbak.Checked=false;
};
break;
case "timeout":
int tmpchar=1;
switch(headvalue)
{
case "2":
tmpchar=2;
break;
case "3":
tmpchar=3;
break;
case "4":
tmpchar=4;
break;
case "5":
tmpchar=5;
break;
}
Numtimeout.Value=(Decimal)tmpchar;
break;
}
}
}
FileInfo af=new FileInfo("skymail1.wg");
if (af.Exists)
{
fin = new FileStream("skymail1.wg", FileMode.Open, FileAccess.Read);
key = UE.GetBytes(password);
cryptostreamDecr = new CryptoStream(fin,rijn.CreateDecryptor(key,key),CryptoStreamMode.Read);
con=(new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd();
cryptostreamDecr.Close();
fin.Close();
conn=con.Split(new char[]{'\n'});
for(int j=0;j<conn.Length;j++ )
{
string[] conn1=conn[j].Split('/') ;
for(int k=0;k<conn1.Length;k++ )
{
string szTemp=conn1[k];
int hint=szTemp.IndexOf(":"); ///将单行字符串以冒号为分隔分成两个字符串
if(hint!=-1)
{
string headcaption;
string headvalue;
headcaption=szTemp.Substring(0,hint);
headvalue=szTemp.Substring(hint+1,szTemp.Length-hint-1).Trim();
switch (headcaption)
{
case "pop3name":
treeView1.Nodes.Add(headvalue);
break;
}
}
}
}
}
}
}
private void button3_Click(object sender, System.EventArgs e)
{
FrmConfPop3 fcon=new FrmConfPop3();
fcon.ShowDialog();
this.disptree();
}
private void tabPage2_Click(object sender, System.EventArgs e)
{
//MessageBox.Show("ffffffffffffff");
}
private void button6_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
}
private void treeView1_AfterSelect(object sender, System.Windows.Forms.TreeViewEventArgs e)
{
textBox8.Text ="";
FileInfo af=new FileInfo("skymail1.wg");
if (af.Exists)
{
string password="wanwengu";
FileStream fin = new FileStream("skymail1.wg", FileMode.Open, FileAccess.Read);
UnicodeEncoding UE = new UnicodeEncoding();
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
byte[] key = UE.GetBytes(password);
CryptoStream cryptostreamDecr = new CryptoStream(fin,rijn.CreateDecryptor(key,key),CryptoStreamMode.Read);
string con=(new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd();
cryptostreamDecr.Close();
fin.Close();
string[] conn=con.Split(new char[]{'\n'});
string[] conn1=conn[e.Node.Index].Split('/') ;
for(int k=0;k<conn1.Length;k++ )
{
string szTemp=conn1[k];
int hint=szTemp.IndexOf(":"); ///将单行字符串以冒号为分隔分成两个字符串
if(hint!=-1)
{
string headcaption;
string headvalue;
headcaption=szTemp.Substring(0,hint);
headvalue=szTemp.Substring(hint+1,szTemp.Length-hint-1).Trim();
switch (headcaption)
{
case "pop3name":
textBox8.Text=textBox8.Text + "pop3服务器名称:" + headvalue+"\r\n";
break;
case "pop3port":
textBox8.Text=textBox8.Text + "pop3服务器端口:" + headvalue+"\r\n";
break;
case "username":
textBox8.Text=textBox8.Text + "用户名:" + headvalue+"\r\n";
break;
case "userpwd":
string temp="";
for(int i=0;i<headvalue.Length;i++ )
{
temp=temp+"*";
}
textBox8.Text=textBox8.Text + "密码:" + temp + "\r\n";
break;
case "emailbak":
textBox8.Text=textBox8.Text + "是否在服务器上保留备份:" + headvalue;
break;
}
}
}
}
}
private void button5_Click(object sender, System.EventArgs e)
{
FileInfo af=new FileInfo("skymail1.wg");
if (af.Exists)
{
string password="wanwengu";
FileStream fin = new FileStream("skymail1.wg", FileMode.Open, FileAccess.Read);
UnicodeEncoding UE = new UnicodeEncoding();
SymmetricAlgorithm rijn = SymmetricAlgorithm.Create();
byte[] key = UE.GetBytes(password);
CryptoStream cryptostreamDecr = new CryptoStream(fin,rijn.CreateDecryptor(key,key),CryptoStreamMode.Read);
string con=(new StreamReader(cryptostreamDecr, new UnicodeEncoding())).ReadToEnd();
cryptostreamDecr.Close();
fin.Close();
string[] conn=con.Trim().Split(new char[]{'\n'});
string conn1="";
for(int i=0;i<conn.Length;i++ )
{
if(i!=treeView1.SelectedNode.Index)
{
conn1=conn1+conn[i].Trim()+"\r\n";
}
}
af.Delete();
af.Refresh();
FileStream fout = new FileStream("skymail1.wg", FileMode.OpenOrCreate, FileAccess.ReadWrite);
Byte[] bytearrayinput=ConvertStringToByteArray(conn1);
CryptoStream encStream = new CryptoStream(fout,rijn.CreateEncryptor(key,key),CryptoStreamMode.Write);
encStream.Write(bytearrayinput,0,bytearrayinput.Length);
encStream.Close();
fout.Close();
}
textBox8.Text="";
this.disptree();
}
private void button1_Click(object sender, System.EventArgs e)
{
this.Close();
this.Dispose();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -