条码手持设备对XML配置文件的获取与更新保存(条码系列二)
2008-06-13 09:10
369 查看
上篇关于条码信息数据的下载发出之后,得到了广大博友的"好评"(有点阿Q~~哈哈~~),为此本菜鸟再次把整个系统中的部分内容与大家分享,一起讨论学习~~~A ZA~~。(对于系统的操作手册近期将发出,以便大家了解系统的整个功能)
以下部分代码实现的是对手持设备的配置信息(连接的数据库服务器、数据库名、登陆ID及登陆PASSWORD)的读取和更新保存。(功能权限所属角色为管理员)
第一部分:基础配置的读取
private void frm_config_Load(object sender, EventArgs e)
{
fun_inlog();
//获取配置文件
string codepath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
codepath = codepath.Substring(0, codepath.LastIndexOf(@"\"));
xd.Load(codepath+@"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/dbpath");
txt_server.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/database");
txt_base.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/uid");
txt_uid.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/password");
txt_pass.Text = node.InnerText.Trim();
txt_server.Focus();
}
第二部分:基础配置的更新保存
private void btn_sub_Click(object sender, EventArgs e)
{
//保存配置文件
string codepath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
codepath = codepath.Substring(0, codepath.LastIndexOf(@"\"));
if ((txt_server.Text.Trim() != "") && (txt_base.Text.Trim() != "") && (txt_uid.Text.Trim() != "") && (txt_pass.Text.Trim() != ""))
{
node = xd.SelectSingleNode("/configuration/dbpath");
node.InnerText = txt_server.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/database");
node.InnerText = txt_base.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/uid");
node.InnerText = txt_uid.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/password");
node.InnerText = txt_pass.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
MessageBox.Show("系统配置已更改,请重新启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
this.Close();
this.Dispose();
Application.Exit();
}
else
{
MessageBox.Show("确保以上四项都不为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
return;
}
}
(对XML的认识和学习可费了我共17个小时的时间,大家有什么好的这方面的知识可向我推荐,在此照清有礼了~~~~)
以下部分代码实现的是对手持设备的配置信息(连接的数据库服务器、数据库名、登陆ID及登陆PASSWORD)的读取和更新保存。(功能权限所属角色为管理员)
第一部分:基础配置的读取
private void frm_config_Load(object sender, EventArgs e)
{
fun_inlog();
//获取配置文件
string codepath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
codepath = codepath.Substring(0, codepath.LastIndexOf(@"\"));
xd.Load(codepath+@"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/dbpath");
txt_server.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/database");
txt_base.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/uid");
txt_uid.Text = node.InnerText.Trim();
node = xd.SelectSingleNode("/configuration/password");
txt_pass.Text = node.InnerText.Trim();
txt_server.Focus();
}
第二部分:基础配置的更新保存
private void btn_sub_Click(object sender, EventArgs e)
{
//保存配置文件
string codepath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
codepath = codepath.Substring(0, codepath.LastIndexOf(@"\"));
if ((txt_server.Text.Trim() != "") && (txt_base.Text.Trim() != "") && (txt_uid.Text.Trim() != "") && (txt_pass.Text.Trim() != ""))
{
node = xd.SelectSingleNode("/configuration/dbpath");
node.InnerText = txt_server.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/database");
node.InnerText = txt_base.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/uid");
node.InnerText = txt_uid.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
node = xd.SelectSingleNode("/configuration/password");
node.InnerText = txt_pass.Text.Trim();
xd.Save(codepath + @"\config\setting.xml");
MessageBox.Show("系统配置已更改,请重新启动!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
this.Close();
this.Dispose();
Application.Exit();
}
else
{
MessageBox.Show("确保以上四项都不为空!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Hand, MessageBoxDefaultButton.Button1);
return;
}
}
(对XML的认识和学习可费了我共17个小时的时间,大家有什么好的这方面的知识可向我推荐,在此照清有礼了~~~~)
相关文章推荐
- xml 方式更新和获取 配置文件 appSettings 节点 解决办法
- solr更新schema.xml后,重新把配置文件注入到zookeeper
- 【Struts1.2总结系列】validation.xml验证文件的配置
- Spring代码实例系列-09:通过Spring PropertyPlaceholderConfigurer将properties配置的属性注入到xml配置文件中
- C#使用单例模式类获取本地程序目录下XML文件中的配置信息
- INI的替代品--XML配置文件读取与保存
- C# XML配置文件读写类(用于程序配置保存)
- mybatis系列-XML 映射配置文件(二)
- 使用WWW获取本地文件夹的XML配置文件
- C#针对xml基本操作及保存配置文件应用实例
- 服务器自动宕机后,自动更新了web.xml配置文件
- 初学python-获取网络设备配置文件接口IP信息
- 路由器交换机密码恢复、IOS与配置文件更新、IOS灾难恢复(网络设备的维护和管理)
- PHP获取XML配置文件
- 保存NHibernate配置xml文件信息的源代码
- maven系列四 —— maven配置文件详解(setting.xml 和 pom.xml)
- DropDownList从XML配置文件动态获取下拉列表值
- SSH框架系列:Spring读取配置文件以及获取Spring注入的Bean
- 使用Spring中Src下 -context.xml : 用资源文件夹保存数据库的链接信息 并在配置文件里读取
- 关于spring MVC web.xml配置文件的编写总结(持续更新)