/// <summary> /// 初始化QQ账号列表 /// </summary> private void initQQList() { if (!File.Exists(qqInfoPath)) //判断XML文件是否存在 { File.Create(qqInfoPath).Close(); //创建一个XML文件,并关闭文件对象 XmlTextWriter xmlWriter = new XmlTextWriter(qqInfoPath, Encoding.UTF8); //实例化一个XML文件写入器 xmlWriter.WriteStartDocument(); //编写XML文件声明 xmlWriter.Close(); //关闭XML文件写入器 qqList = new List <QQInfo>(); //实例化QQ账号列表 } else { qqList = QQFilePath.GetQQList(qqInfoPath);//获取QQ账号列表 } }
private void lvInfo_DoubleClick(object sender, EventArgs e) { if (0 == lvInfo.Items.Count || lvInfo.FocusedItem == null)//判断ListView控件中是否有项 { return; } string strNum = lvInfo.FocusedItem.Text; //获取选择的项 frmAddQQ frmaddqq = new frmAddQQ(); //实例化“添加QQ账号”窗体 frmaddqq.ControlsStatus(strNum); //控制窗体中的控件状态 if (frmaddqq.ShowDialog() == DialogResult.OK) //判断窗体的返回值 { this.qqList.Add(frmaddqq.GetQQInfo()); //将要修改的QQ账号添加到QQ账号列表中 initListView(); //重新初始化ListView控件中的项 QQFilePath.SetQQList(qqInfoPath, qqList); //将QQ账号列表中的数据写入到XML文件 } }
private void btnAdd_Click(object sender, EventArgs e) { frmAddQQ frmaddqq = new frmAddQQ(); //实例化“添加QQ账号”窗体 if (frmaddqq.ShowDialog() == DialogResult.OK) //判断窗体的返回值 { QQInfo qqinfo = frmaddqq.GetQQInfo(); //获取添加的QQ账号信息 for (int i = 0; i < lvInfo.Items.Count; i++) //遍历ListView控件中的所有项 { if (qqinfo.Number == lvInfo.Items[i].Text) //判断遍历到的项与要添加的项是否相同 { MessageBox.Show("号码已存在"); return; } } this.qqList.Add(qqinfo); //将要添加的QQ账号添加到QQ账号列表中 initListView(); //重新初始化ListView控件中的项 QQFilePath.SetQQList(qqInfoPath, qqList); //将QQ账号列表中的数据写入到XML文件 } }
private void frmMain_FormClosing(object sender, FormClosingEventArgs e) { QQFilePath.SetQQList(qqInfoPath, qqList);//将QQ账号列表中的数据写入到XML文件 }