QQ登录器的分层实现之二(业务实现)
2008-04-29 11:23
141 查看
昨晚刚写完第一部份,就得到很多朋友的关注,谢谢大家,现在继续第二部份的内容。先说明一下该工程是用VS2005实现的,其实用什么工具都无所谓,实现是一样的。Config.cs是XML文件操作类,我们这里把它定为配置,所以叫config,Account.cn是QQ帐号实体类,包括了QQ的一些属性,下面我们来一起写吧。
在该软件中,我们主要是为了实现QQ的自动登录,所以实体类中应包括QQ帐号,QQ密码,昵称,是否隐身登录,最后登录时间,启动快捷键等属性,如下代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Login.BLL.Entity
业务实体定下来后,我们开始围绕它来进行增删改查了,就是实现Config.cs类。对于XML的基本知识在这里我就不多加描述了,大家可以到MSDN上查找相关资料。要对XML文件做操作,我们必须引用XML命名空间和文件操作命名空间:
using System.Xml;
using System.IO;
using Login.BLL.Entity;//实体类命名空间
由于该类的方法需要重复调用,故它的方法我们都设为静态的吧。软件初始化时需要读入XML存有的帐号信息以显示给用户看,如果文件不存在怎么办?对了,要创建文件:
public static void CreateXmlFile(string xmlFilePath)
public static void AddAccount(string xmlFilePath,Account item)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFilePath + "data.xml");
XmlElement root = xmlDoc.DocumentElement;
//创建帐号节点Number
XmlNode numberNode = xmlDoc.CreateElement("Number");
XmlAttribute numberAttr = xmlDoc.CreateAttribute("ID");
numberAttr.Value = item.Number;
numberNode.Attributes.Append(numberAttr);
root.InsertAfter(numberNode, root.LastChild);
//在节点Number中创建子节点"昵称"
XmlNode nameNode = xmlDoc.CreateElement("Name");
nameNode.InnerText = item.Name;
numberNode.InsertAfter(nameNode, numberNode.LastChild);
//在节点Number中创建子节点密码
XmlNode pwdNode = xmlDoc.CreateElement("Password");
pwdNode.InnerText = item.Password;
numberNode.InsertAfter(pwdNode, numberNode.LastChild);
//在节点Number中创建子节点"是否隐身"
XmlNode isStealth = xmlDoc.CreateElement("IsStealth");
isStealth.InnerText = item.IsStealth.ToString();
numberNode.InsertAfter(isStealth, numberNode.LastChild);
//在节点Number中创建子节点"快捷键"
XmlNode flashKey = xmlDoc.CreateElement("FlashKey");
flashKey.InnerText = item.FlashKey;
numberNode.InsertAfter(flashKey, numberNode.LastChild);
//在节点Number中创建子节点"最后登录时间"
XmlNode lastTime = xmlDoc.CreateElement("LastLoginTime");
lastTime.InnerText = item.LastLoginTime.ToString(); ;
numberNode.InsertAfter(lastTime, numberNode.LastChild);
//保存文件
xmlDoc.Save(xmlFilePath + "data.xml");
}
添加信息后,文件显示为:
<Account>
<QQpath></QQpath>
<Number ID="32154689">
<Name>小明</Name>
<Password>pDJXA+0NT055Scbs38KCDg==</Password>
<IsStealth>False</IsStealth>
<FlashKey>Ctrl+Q</FlashKey>
<LastLoginTime>2008-4-27 22:54:15</LastLoginTime>
</Number>
</Account>
由于篇幅太长,我还是另开一个标题吧,见谅!
在该软件中,我们主要是为了实现QQ的自动登录,所以实体类中应包括QQ帐号,QQ密码,昵称,是否隐身登录,最后登录时间,启动快捷键等属性,如下代码:
using System;
using System.Collections.Generic;
using System.Text;
namespace Login.BLL.Entity
业务实体定下来后,我们开始围绕它来进行增删改查了,就是实现Config.cs类。对于XML的基本知识在这里我就不多加描述了,大家可以到MSDN上查找相关资料。要对XML文件做操作,我们必须引用XML命名空间和文件操作命名空间:
using System.Xml;
using System.IO;
using Login.BLL.Entity;//实体类命名空间
由于该类的方法需要重复调用,故它的方法我们都设为静态的吧。软件初始化时需要读入XML存有的帐号信息以显示给用户看,如果文件不存在怎么办?对了,要创建文件:
public static void CreateXmlFile(string xmlFilePath)
public static void AddAccount(string xmlFilePath,Account item)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlFilePath + "data.xml");
XmlElement root = xmlDoc.DocumentElement;
//创建帐号节点Number
XmlNode numberNode = xmlDoc.CreateElement("Number");
XmlAttribute numberAttr = xmlDoc.CreateAttribute("ID");
numberAttr.Value = item.Number;
numberNode.Attributes.Append(numberAttr);
root.InsertAfter(numberNode, root.LastChild);
//在节点Number中创建子节点"昵称"
XmlNode nameNode = xmlDoc.CreateElement("Name");
nameNode.InnerText = item.Name;
numberNode.InsertAfter(nameNode, numberNode.LastChild);
//在节点Number中创建子节点密码
XmlNode pwdNode = xmlDoc.CreateElement("Password");
pwdNode.InnerText = item.Password;
numberNode.InsertAfter(pwdNode, numberNode.LastChild);
//在节点Number中创建子节点"是否隐身"
XmlNode isStealth = xmlDoc.CreateElement("IsStealth");
isStealth.InnerText = item.IsStealth.ToString();
numberNode.InsertAfter(isStealth, numberNode.LastChild);
//在节点Number中创建子节点"快捷键"
XmlNode flashKey = xmlDoc.CreateElement("FlashKey");
flashKey.InnerText = item.FlashKey;
numberNode.InsertAfter(flashKey, numberNode.LastChild);
//在节点Number中创建子节点"最后登录时间"
XmlNode lastTime = xmlDoc.CreateElement("LastLoginTime");
lastTime.InnerText = item.LastLoginTime.ToString(); ;
numberNode.InsertAfter(lastTime, numberNode.LastChild);
//保存文件
xmlDoc.Save(xmlFilePath + "data.xml");
}
添加信息后,文件显示为:
<Account>
<QQpath></QQpath>
<Number ID="32154689">
<Name>小明</Name>
<Password>pDJXA+0NT055Scbs38KCDg==</Password>
<IsStealth>False</IsStealth>
<FlashKey>Ctrl+Q</FlashKey>
<LastLoginTime>2008-4-27 22:54:15</LastLoginTime>
</Number>
</Account>
由于篇幅太长,我还是另开一个标题吧,见谅!
相关文章推荐
- QQ登录器的分层实现之三(业务实现)
- 使用分层实现业务处理
- 【jsp/servlet】使用分层实现业务处理
- 使用分层实现业务处理
- QQ登录器的分层实现之一(系统设计)
- 使用分层实现业务处理
- QQ登录器的分层实现之四(登录的实现以及快捷键的注册)
- 使用分层实现业务处理
- Web服务软件工厂(WSSF)演练之二:创建数据契约和实现业务实体
- Ibatis实现CRUD之二
- 分层架构,是否需要业务服务层
- Entity Framework 三层架构--业务层使用封装之实现类ServiceTemplate
- 大数据Spark “蘑菇云”行动第72课: 基于Spark 2.0.1项目实现之二. 实战 各种小bug修复及性能调优 200并行度调整为2个task
- 简单设计模式实现业务逻辑与流程逻辑的分离
- libcef学习最详细的入门资料系列之二 :libcef的编译和运行,以及MFC下的实现
- 实现业务系统中的用户权限管理--实现篇
- 白话经典算法系列之二 直接插入排序的三种实现
- 《解惑3G业务:概念、实现和规划》杂录2
- 移动跨平台开发中使用Lua实现业务逻辑多平台重用