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;
namespace PasswordManage
{
public partial class frmStart : Form
{
public frmStart()
{
InitializeComponent();
this.timer1.Enabled = true;
}
private void timer1_Tick(object sender, EventArgs e)
{
if (this.Opacity > 0.01)
{
this.Opacity = this.Opacity - 0.02;
}
else
{
this.timer1.Enabled = false;
this.Hide();//隐藏当前窗体
//打开一个新窗体
PersonalEditions pe = new PersonalEditions();
pe.Show();
}
}
}
}
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;
namespace PasswordManage
{
public partial class PersonalEditions : Form
{
public PersonalEditions()
{
InitializeComponent();
}
private void PersonalEditions_Load(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "Wave.ssk";
dsUsers.ReadXml("Users.xml");
dgdUserKey.DataSource = dsUsers.Tables["UserKey"];
//设置表头
dgdUserKey.Columns[0].HeaderText = "序号";
dgdUserKey.Columns[1].HeaderText = "标题";
dgdUserKey.Columns[2].HeaderText = "网址";
dgdUserKey.Columns[3].HeaderText = "姓名";
dgdUserKey.Columns[4].HeaderText = "密码";
dgdUserKey.Columns[5].HeaderText = "更新时间";
}
private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void 绿色风格ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "WaveColor1.ssk";
}
private void 蓝色风格ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.skinEngine1.SkinFile = "Wave.ssk";
}
private void PersonalEditions_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
private void 导出ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
if (diaSavaFile.ShowDialog() ==DialogResult.OK)
{
dsUsers.WriteXml(@diaSavaFile.FileName+".xml");
this.Visible = true;
MessageBox.Show("文件导出成功!", "提醒");
}
else
{
this.Visible = true;
}
}
private void 导入ToolStripMenuItem_Click(object sender, EventArgs e)
{
this.Hide();
if (diaFile.ShowDialog() == DialogResult.OK)
{
if (diaFile.OpenFile()!= null)
{
//将文件导入到新的数据集
dsNew.ReadXml(@diaFile.FileName);
//遍历新数据集中的行
foreach (DataRow dr in dsNew.Tables["UserKey"].Rows)
{
//新建一行数据
DataRow newRow = dsUsers.Tables["UserKey"].NewRow();
newRow["Number"] = dr["Number"];
newRow["Title"] = dr["Title"];
newRow["NetAdd"] = dr["NetAdd"];
newRow["Name"] = dr["Name"];
newRow["Key"] = dr["Key"];
newRow["UpdateTiem"] = dr["UpdateTiem"];
//将新建的这行数据添加到旧的数据集中去
dsUsers.Tables[0].Rows.Add(newRow);
}
int n = dsUsers.Tables[0].Rows.Count;
for (int i = 0; i < n; i++)
{
dsUsers.Tables["UserKey"].Rows[i]["Number"] =i + 1;
}
//将数据写入Users.xml
dsUsers.WriteXml(@"Users.xml");
MessageBox.Show("文件导入成功!");
this.Visible = true;
}
}
}
private void 添加ToolStripMenuItem_Click(object sender, EventArgs e)
{
AddKey ak = new AddKey(dsUsers);
ak.ShowDialog();
}
}
}
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;
namespace PasswordManage
{
public partial class AddKey : Form
{
private DataSet dsUsers;
//通过构造函数传值
public AddKey(DataSet ds)
{
InitializeComponent();
dsUsers=ds;
int n=dsUsers.Tables["UserKey"].Rows.Count;
this.lblNumber.Text=Convert.ToString(n+1);
this.txtNet.Text="http://";
}
private void btnReturn_Click(object sender, EventArgs e)
{
this.Close();
}
//添加记录
private void btnAdd_Click(object sender, EventArgs e)
{
if(this.txtTitle.Text.Trim()=="")
{
MessageBox.Show("标题不能为空!","提醒");
return;
}
DataRow newRow=dsUsers.Tables["UserKey"].NewRow();
newRow["Number"] = this.lblNumber.Text;
newRow["Title"] = this.txtTitle.Text;
newRow["NetAdd"] = this.txtNet.Text;
newRow["Name"] = this.txtUserName.Text;
newRow["Key"] = this.txtPassword.Text;
newRow["UpdateTiem"] = DateTime.Now.ToString();
dsUsers.Tables["UserKey"].Rows.Add(newRow);
dsUsers.WriteXml(@"Users.xml");
}
}
}