您的位置:首页 > 其它

条码手持设备对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个小时的时间,大家有什么好的这方面的知识可向我推荐,在此照清有礼了~~~~)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: