using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;
using System.Xml;
namespace WinOA
{
/// <summary>
/// SettingSystem 的摘要说明。
/// </summary>
public class SettingSystem : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Button btnOK;
private System.Windows.Forms.Button btnCancel;
private System.Windows.Forms.TextBox txtUserName;
private System.Windows.Forms.TextBox txtPassWord;
private System.Windows.Forms.TextBox txtFolderName;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox txtServerIP;
private System.ComponentModel.Container components = null;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.Collections.Specialized.NameValueCollection mAppSet;
private string mstrCFGFile;
private XmlNode xAS;
private XmlNode xNode;
private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.Label lblUserName;
private System.Windows.Forms.Label lblFolderName;
private System.Windows.Forms.Label lblPassWord;
private System.Windows.Forms.Label lblServerIP;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button btnClose;
private XmlDocument cfg=new XmlDocument();
public SettingSystem()
{
InitializeComponent();
}
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.txtUserName = new System.Windows.Forms.TextBox();
this.label2 = new System.Windows.Forms.Label();
this.label3 = new System.Windows.Forms.Label();
this.txtPassWord = new System.Windows.Forms.TextBox();
this.txtFolderName = new System.Windows.Forms.TextBox();
this.btnOK = new System.Windows.Forms.Button();
this.btnCancel = new System.Windows.Forms.Button();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.label5 = new System.Windows.Forms.Label();
this.txtServerIP = new System.Windows.Forms.TextBox();
this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel();
this.btnClose = new System.Windows.Forms.Button();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.lblServerIP = new System.Windows.Forms.Label();
this.lblPassWord = new System.Windows.Forms.Label();
this.lblFolderName = new System.Windows.Forms.Label();
this.lblUserName = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.label7 = new System.Windows.Forms.Label();
this.label6 = new System.Windows.Forms.Label();
this.label4 = new System.Windows.Forms.Label();
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
this.SuspendLayout();
//
// label1
//
this.label1.Location = new System.Drawing.Point(0, 19);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(72, 23);
this.label1.TabIndex = 0;
this.label1.Text = "用户名:";
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtUserName
//
this.txtUserName.Location = new System.Drawing.Point(72, 19);
this.txtUserName.Name = "txtUserName";
this.txtUserName.Size = new System.Drawing.Size(121, 21);
this.txtUserName.TabIndex = 0;
this.txtUserName.Text = "";
//
// label2
//
this.label2.Location = new System.Drawing.Point(216, 19);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(72, 23);
this.label2.TabIndex = 2;
this.label2.Text = "密码:";
this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label3
//
this.label3.Location = new System.Drawing.Point(0, 59);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(72, 23);
this.label3.TabIndex = 3;
this.label3.Text = "文件夹名:";
this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtPassWord
//
this.txtPassWord.Location = new System.Drawing.Point(288, 19);
this.txtPassWord.Name = "txtPassWord";
this.txtPassWord.Size = new System.Drawing.Size(121, 21);
this.txtPassWord.TabIndex = 1;
this.txtPassWord.Text = "";
//
// txtFolderName
//
this.txtFolderName.Location = new System.Drawing.Point(72, 59);
this.txtFolderName.Name = "txtFolderName";
this.txtFolderName.Size = new System.Drawing.Size(121, 21);
this.txtFolderName.TabIndex = 2;
this.txtFolderName.Text = "";
//
// btnOK
//
this.btnOK.Location = new System.Drawing.Point(240, 109);
this.btnOK.Name = "btnOK";
this.btnOK.TabIndex = 4;
this.btnOK.Text = "确定";
this.btnOK.Click += new System.EventHandler(this.btnOK_Click);
//
// btnCancel
//
this.btnCancel.Location = new System.Drawing.Point(336, 109);
this.btnCancel.Name = "btnCancel";
this.btnCancel.TabIndex = 5;
this.btnCancel.Text = "取消";
this.btnCancel.Click += new System.EventHandler(this.btnCancel_Click);
//
// groupBox1
//
this.groupBox1.Location = new System.Drawing.Point(8, 96);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(400, 2);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
//
// label5
//
this.label5.Location = new System.Drawing.Point(216, 59);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(72, 23);
this.label5.TabIndex = 11;
this.label5.Text = "服务器IP:";
this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// txtServerIP
//
this.txtServerIP.Location = new System.Drawing.Point(288, 59);
this.txtServerIP.Name = "txtServerIP";
this.txtServerIP.Size = new System.Drawing.Size(121, 21);
this.txtServerIP.TabIndex = 3;
this.txtServerIP.Text = "";
//
// panel1
//
this.panel1.Controls.Add(this.txtFolderName);
this.panel1.Controls.Add(this.btnOK);
this.panel1.Controls.Add(this.btnCancel);
this.panel1.Controls.Add(this.groupBox1);
this.panel1.Controls.Add(this.label5);
this.panel1.Controls.Add(this.txtServerIP);
this.panel1.Controls.Add(this.label1);
this.panel1.Controls.Add(this.txtUserName);
this.panel1.Controls.Add(this.label2);
this.panel1.Controls.Add(this.label3);
this.panel1.Controls.Add(this.txtPassWord);
this.panel1.Location = new System.Drawing.Point(0, 0);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(432, 144);
this.panel1.TabIndex = 12;
//
// panel2
//
this.panel2.Controls.Add(this.btnClose);
this.panel2.Controls.Add(this.groupBox2);
this.panel2.Controls.Add(this.lblServerIP);
this.panel2.Controls.Add(this.lblPassWord);
this.panel2.Controls.Add(this.lblFolderName);
this.panel2.Controls.Add(this.lblUserName);
this.panel2.Controls.Add(this.label8);
this.panel2.Controls.Add(this.label7);
this.panel2.Controls.Add(this.label6);
this.panel2.Controls.Add(this.label4);
this.panel2.Location = new System.Drawing.Point(0, 0);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(432, 144);
this.panel2.TabIndex = 13;
//
// btnClose
//
this.btnClose.Location = new System.Drawing.Point(179, 104);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 12;
this.btnClose.Text = "确定";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// groupBox2
//
this.groupBox2.Location = new System.Drawing.Point(8, 88);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(400, 2);
this.groupBox2.TabIndex = 11;
this.groupBox2.TabStop = false;
//
// lblServerIP
//
this.lblServerIP.Location = new System.Drawing.Point(288, 56);
this.lblServerIP.Name = "lblServerIP";
this.lblServerIP.Size = new System.Drawing.Size(121, 23);
this.lblServerIP.TabIndex = 7;
this.lblServerIP.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblPassWord
//
this.lblPassWord.Location = new System.Drawing.Point(288, 16);
this.lblPassWord.Name = "lblPassWord";
this.lblPassWord.Size = new System.Drawing.Size(121, 23);
this.lblPassWord.TabIndex = 6;
this.lblPassWord.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblFolderName
//
this.lblFolderName.Location = new System.Drawing.Point(72, 56);
this.lblFolderName.Name = "lblFolderName";
this.lblFolderName.Size = new System.Drawing.Size(121, 23);
this.lblFolderName.TabIndex = 5;
this.lblFolderName.TextAlign =
System.Drawing.ContentAlignment.MiddleLeft;
//
// lblUserName
//
this.lblUserName.Location = new System.Drawing.Point(72, 16);
this.lblUserName.Name = "lblUserName";
this.lblUserName.Size = new System.Drawing.Size(121, 23);
this.lblUserName.TabIndex = 4;
this.lblUserName.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// label8
//
this.label8.Location = new System.Drawing.Point(216, 56);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(72, 23);
this.label8.TabIndex = 3;
this.label8.Text = "服务器IP:";
this.label8.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label7
//
this.label7.Location = new System.Drawing.Point(0, 56);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(72, 23);
this.label7.TabIndex = 2;
this.label7.Text = "文件夹名:";
this.label7.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label6
//
this.label6.Location = new System.Drawing.Point(216, 16);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(72, 23);
this.label6.TabIndex = 1;
this.label6.Text = "密码:";
this.label6.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// label4
//
this.label4.Location = new System.Drawing.Point(0, 16);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(72, 23);
this.label4.TabIndex = 0;
this.label4.Text = "用户名:";
this.label4.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// SettingSystem
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 141);
this.Controls.Add(this.panel1);
this.Controls.Add(this.panel2);
this.MaximizeBox = false;
this.MaximumSize = new System.Drawing.Size(432, 168);
this.MinimumSize = new System.Drawing.Size(432, 168);
this.Name = "SettingSystem";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "系统设置";
this.Load += new System.EventHandler(this.SettingSystem_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private void SettingSystem_Load(object sender, System.EventArgs e)
{
LoadConfigFile();
AppDomain ad=AppDomain.CurrentDomain;
mstrCFGFile=ad.SetupInformation.ConfigurationFile;
}
private void btnOK_Click(object sender, System.EventArgs e)
{
//确定
SaveCinfigKey(txtFolderName.Text ,"WinOAFolder");
SaveCinfigKey(txtPassWord.Text ,"WinOAPassword");
SaveCinfigKey(txtServerIP.Text ,"WinOAServer");
SaveCinfigKey(txtUserName.Text ,"WinOAUser");
panel1.Visible=false;
panel2.Visible=true;
LoadNewSetting();
}
private void btnCancel_Click(object sender, System.EventArgs e)
{
//取消
this.Close();
}
private void LoadConfigFile()
{
//读取configurationFile
if(mAppSet==null)
{
mAppSet=ConfigurationSettings.AppSettings;
txtFolderName.Text=mAppSet["WinOAFolder"].ToString();
txtPassWord.Text=mAppSet["WinOAPassword"].ToString();
txtServerIP.Text=mAppSet["WinOAServer"].ToString();
txtUserName.Text=mAppSet["WinOAUser"].ToString();
}
else
{
mAppSet=null;
mAppSet=ConfigurationSettings.AppSettings;
txtFolderName.Text=mAppSet["WinOAFolder"].ToString();
txtPassWord.Text=mAppSet["WinOAPassword"].ToString();
txtServerIP.Text=mAppSet["WinOAServer"].ToString();
txtUserName.Text=mAppSet["WinOAUser"].ToString();
}
}
//获取Config值
public string GetConfigValue(String strConfigKey)
{
string strReturn = "";
try
{
//根据指定路径获取节点
XmlNode xAS1 = cfg.SelectSingleNode("configuration//appSettings");
XmlNode xmlNode =
xAS1.SelectSingleNode(String.Format("//add[@key='{0}']", strConfigKey));
strReturn=xmlNode.Attributes.Item(1).Value.ToString();
}
catch(XmlException xmle)
{
MessageBox.Show( xmle.Message.ToString());
}
return strReturn;
}
//保存configwf值
private void SaveCinfigKey(String strConfig,String strKey)
{
cfg.Load(mstrCFGFile);
xAS = cfg.SelectSingleNode("configuration//appSettings");
xNode = xAS.SelectSingleNode(String.Format("//add[@key='{0}']", strKey));
//
if(strConfig!=string.Empty)
{
xNode.Attributes.Item(1).Value =strConfig;
}
else
{
xNode.Attributes.Item(1).Value ="(Nothing)";
}
try
{
//保存设置的结果
cfg.Save(mstrCFGFile);
}
catch(XmlException xmle)
{
MessageBox.Show( xmle.Message.ToString());
}
}
private void LoadNewSetting()
{
lblFolderName.Text=GetConfigValue("WinOAFolder");
lblPassWord.Text=GetConfigValue("WinOAPassword");
lblServerIP.Text=GetConfigValue("WinOAServer");
lblUserName.Text=GetConfigValue("WinOAUser");
}
private void btnClose_Click(object sender, System.EventArgs e)
{
if(MessageBox.Show("是否退出系统?","退出系统
",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)==DialogResult.Yes)
{
Application.Exit();
}
else
{
this.Close();
MessageBox.Show("请重新启动程序","重启程序
",MessageBoxButtons.OK,MessageBoxIcon.Warning);
}
}
}
}
--
=====================================================
* 梦幻如真! *
* 我很真诚,但我生活在谎言之中。 *
* *
* 我抛弃了所有的忧伤与疑虑,去追逐那无家的潮水, *
* 终于找到了一个爱我的女人,从此失去了自由! *
*[csharp] 斑竹 汤建军 *
=====================================================
"CodingPCPiG" <anon...@discussions.microsoft.com> 写入消息
news:a70801c435cc$3674a0b0$a501...@phx.gbl...
> AppDomain有着代码执行隔绝的特性。每一个appDomain可以单独被
> 调试、启动、停止,有着自己的默认的异常处理,一个appDomain崩
> 溃了,不会影响其他的appDomain。
>
> 我对上面这句话不是很理解,谁能给我举个例子??
> 最好是能运行的工程,我的邮箱
> l...@lonwin.com.cn
> 谢谢
没有中文的文档,只好用英文的连接。
不知道你引用的话从何得到,不过这个理解是不正确的。AppDomain提供的是隔离的空
间,在每个隔离的空间可以独立运行程序。AppDomain自己是不能被运行,启动,停
止,和调试的。运行是靠Thread。下面的连接讨论了AppDomain和Thread的关系
http://msdn.microsoft.com/library/en-us/cpguide/html/cpconapplicationdomainsthreads.asp
"CodingPCPiG" <anon...@discussions.microsoft.com> wrote in message
ÎÒÖ÷ÒªÊÇÏëÎÊ¡°Ã¿¸öAppDomainÓÐ×Å×Ô¼ºµÄĬÈϵÄÒì³£´¦Àí£¬Ò»¸ö
appDomain±ÀÀ£ÁË£¬²»»áÓ°ÏìÆäËûµÄappDomain¡£¡±Õâ¾ä»°ÈçºÎÀí
½â£¿Äܹ»¸øÎÒÒ»¸öÕâÑùµÄʵÀý£¿£¿¾ÍÊÇÒ»¸ö±ÀÀ£Á˲»»áÓ°ÏìÁíÒ»
¸ö£¿£¿
ÒòΪÎÒÏÖÔÚÓкܶà×Óϵͳ£¬ÎÒÏë°ÑËüÃÇÕûºÏÆðÀ´£¬ÔÚÕûºÏµÄʱºòÎÒ
Ïë°Ñÿһ¸ö×Óϵͳ¶¼·Åµ½Ò»¸öµ¥¶ÀµÄAppDomainÖУ¬²¢Ìṩ×Ô¼ºµÄÒì
³£´¦Àí£¬Ò»¸ö×Óϵͳ±ÀÀ££¬²»»áÓ°ÏìÆäËüµÄ£¬¾ÍÏñÔÚVS.NETÖÐÌí¼Ó
Ò»¸ö²å¼þ£¬µ«²å¼þ·¢ÉúÒì³£²»»áÓ°ÏìIDEÒ»Ñù¡£
лл
>-----ÔʼÏûÏ¢-----
>ÄãºÃ£¡ÏÂÃæÊÇÒ»¸öÎÒÀûÓÃappDomainдµÄÒ»¸öС³ÌÐò£¬ËüÖ÷ÒªÊÇÈ¡
app.configÎļþµÄ£®
>AppDomain ad=AppDomain.CurrentDomain;
> mstrCFGFile=ad.SetupInformation.ConfigurationFile;
>////////////////////////////////////////
>
>using System;
>using System.Drawing;
>using System.Collections;
>using System.ComponentModel;
>using System.Windows.Forms;
>using System.Configuration;
>using System.Xml;
>
>namespace WinOA
>{
> /// <summary>
> /// SettingSystem µÄժҪ˵Ã÷¡£
> /// </summary>
> public class SettingSystem : System.Windows.Forms.Form
> {
> private System.Windows.Forms.Label label1;
> private System.Windows.Forms.Label label2;
> private System.Windows.Forms.Label label3;
> private System.Windows.Forms.GroupBox groupBox1;
> private System.Windows.Forms.Button btnOK;
> private System.Windows.Forms.Button btnCancel;
> private System.Windows.Forms.TextBox txtUserName;
> private System.Windows.Forms.TextBox txtPassWord;
> private System.Windows.Forms.TextBox txtFolderName;
> private System.Windows.Forms.Label label5;
> private System.Windows.Forms.TextBox txtServerIP;
> private System.ComponentModel.Container components =
null;
>
> /// <summary>
> /// ±ØÐèµÄÉè¼ÆÆ÷±äÁ¿¡£
> #region Windows ´°ÌåÉè¼ÆÆ÷Éú³ÉµÄ´úÂë
> /// <summary>
> /// Éè¼ÆÆ÷Ö§³ÖËùÐèµÄ·½·¨ - ²»ÒªÊ¹ÓôúÂë±à¼Æ÷ÐÞ¸Ä
> /// ´Ë·½·¨µÄÄÚÈÝ¡£
> this.label1.Text = "Óû§Ãû£º";
> this.label1.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // txtUserName
> //
> this.txtUserName.Location = new System.Drawing.Point
(72, 19);
> this.txtUserName.Name = "txtUserName";
> this.txtUserName.Size = new System.Drawing.Size(121,
21);
> this.txtUserName.TabIndex = 0;
> this.txtUserName.Text = "";
> //
> // label2
> //
> this.label2.Location = new System.Drawing.Point(216,
19);
> this.label2.Name = "label2";
> this.label2.Size = new System.Drawing.Size(72, 23);
> this.label2.TabIndex = 2;
> this.label2.Text = "ÃÜÂ룺";
> this.label2.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // label3
> //
> this.label3.Location = new System.Drawing.Point(0, 59);
> this.label3.Name = "label3";
> this.label3.Size = new System.Drawing.Size(72, 23);
> this.label3.TabIndex = 3;
> this.label3.Text = "Îļþ¼ÐÃû£º";
> this.btnOK.Text = "È·¶¨";
> this.btnOK.Click += new System.EventHandler
(this.btnOK_Click);
> //
> // btnCancel
> //
> this.btnCancel.Location = new System.Drawing.Point
(336, 109);
> this.btnCancel.Name = "btnCancel";
> this.btnCancel.TabIndex = 5;
> this.btnCancel.Text = "È¡Ïû";
> this.btnCancel.Click += new System.EventHandler
(this.btnCancel_Click);
> //
> // groupBox1
> //
> this.groupBox1.Location = new System.Drawing.Point(8,
96);
> this.groupBox1.Name = "groupBox1";
> this.groupBox1.Size = new System.Drawing.Size(400, 2);
> this.groupBox1.TabIndex = 10;
> this.groupBox1.TabStop = false;
> //
> // label5
> //
> this.label5.Location = new System.Drawing.Point(216,
59);
> this.label5.Name = "label5";
> this.label5.Size = new System.Drawing.Size(72, 23);
> this.label5.TabIndex = 11;
> this.label5.Text = "·þÎñÆ÷IP£º";
> this.btnClose.Text = "È·¶¨";
> this.btnClose.Click += new System.EventHandler
> this.label8.Text = "·þÎñÆ÷IP£º";
> this.label8.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // label7
> //
> this.label7.Location = new System.Drawing.Point(0, 56);
> this.label7.Name = "label7";
> this.label7.Size = new System.Drawing.Size(72, 23);
> this.label7.TabIndex = 2;
> this.label7.Text = "Îļþ¼ÐÃû£º";
> this.label7.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // label6
> //
> this.label6.Location = new System.Drawing.Point(216,
16);
> this.label6.Name = "label6";
> this.label6.Size = new System.Drawing.Size(72, 23);
> this.label6.TabIndex = 1;
> this.label6.Text = "ÃÜÂ룺";
> this.label6.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // label4
> //
> this.label4.Location = new System.Drawing.Point(0, 16);
> this.label4.Name = "label4";
> this.label4.Size = new System.Drawing.Size(72, 23);
> this.label4.TabIndex = 0;
> this.label4.Text = "Óû§Ãû£º";
> this.label4.TextAlign =
System.Drawing.ContentAlignment.MiddleRight;
> //
> // SettingSystem
> //
> this.AutoScaleBaseSize = new System.Drawing.Size(6,
14);
> this.ClientSize = new System.Drawing.Size(424, 141);
> this.Controls.Add(this.panel1);
> this.Controls.Add(this.panel2);
> this.MaximizeBox = false;
> this.MaximumSize = new System.Drawing.Size(432, 168);
> this.MinimumSize = new System.Drawing.Size(432, 168);
> this.Name = "SettingSystem";
> this.StartPosition =
System.Windows.Forms.FormStartPosition.CenterScreen;
> this.Text = "ϵͳÉèÖÃ";
> this.Load += new System.EventHandler
(this.SettingSystem_Load);
> this.panel1.ResumeLayout(false);
> this.panel2.ResumeLayout(false);
> this.ResumeLayout(false);
>
> }
> #endregion
>
> private void SettingSystem_Load(object sender,
System.EventArgs e)
> {
> LoadConfigFile();
> AppDomain ad=AppDomain.CurrentDomain;
> mstrCFGFile=ad.SetupInformation.ConfigurationFile;
> }
>
> private void btnOK_Click(object sender,
System.EventArgs e)
> {
> //È·¶¨
> SaveCinfigKey(txtFolderName.Text ,"WinOAFolder");
> SaveCinfigKey(txtPassWord.Text ,"WinOAPassword");
> SaveCinfigKey(txtServerIP.Text ,"WinOAServer");
> SaveCinfigKey(txtUserName.Text ,"WinOAUser");
>
> panel1.Visible=false;
> panel2.Visible=true;
> LoadNewSetting();
> }
>
> private void btnCancel_Click(object sender,
System.EventArgs e)
> {
> //È¡Ïû
> this.Close();
> }
>
> private void LoadConfigFile()
> {
> //¶ÁÈ¡configurationFile
> if(mAppSet==null)
> {
> mAppSet=ConfigurationSettings.AppSettings;
>
> txtFolderName.Text=mAppSet["WinOAFolder"].ToString();
> txtPassWord.Text=mAppSet["WinOAPassword"].ToString();
> txtServerIP.Text=mAppSet["WinOAServer"].ToString();
> txtUserName.Text=mAppSet["WinOAUser"].ToString();
> }
> else
> {
> mAppSet=null;
> mAppSet=ConfigurationSettings.AppSettings;
>
> txtFolderName.Text=mAppSet["WinOAFolder"].ToString();
> txtPassWord.Text=mAppSet["WinOAPassword"].ToString();
> txtServerIP.Text=mAppSet["WinOAServer"].ToString();
> txtUserName.Text=mAppSet["WinOAUser"].ToString();
> }
> }
>
> //»ñÈ¡ConfigÖµ
> public string GetConfigValue(String strConfigKey)
> {
> string strReturn = "";
> try
> {
> //¸ù¾ÝÖ¸¶¨Â·¾¶»ñÈ¡½Úµã
> XmlNode xAS1 = cfg.SelectSingleNode
("configuration//appSettings");
> XmlNode xmlNode =
>xAS1.SelectSingleNode(String.Format("//add[@key='{0}']",
strConfigKey));
> strReturn=xmlNode.Attributes.Item(1).Value.ToString();
> }
> catch(XmlException xmle)
> {
> MessageBox.Show( xmle.Message.ToString());
> }
> return strReturn;
> }
>
> //±£´æconfigwfÖµ
> private void SaveCinfigKey(String strConfig,String
strKey)
> {
> cfg.Load(mstrCFGFile);
> xAS = cfg.SelectSingleNode
("configuration//appSettings");
> xNode = xAS.SelectSingleNode(String.Format("//add
[@key='{0}']", strKey));
> //
> if(strConfig!=string.Empty)
> {
> xNode.Attributes.Item(1).Value =strConfig;
> }
> else
> {
> xNode.Attributes.Item(1).Value ="(Nothing)";
> }
>
> try
> {
> //±£´æÉèÖõĽá¹û
> cfg.Save(mstrCFGFile);
> }
> catch(XmlException xmle)
> {
> MessageBox.Show( xmle.Message.ToString());
> }
> }
>
> private void LoadNewSetting()
> {
> lblFolderName.Text=GetConfigValue("WinOAFolder");
> lblPassWord.Text=GetConfigValue("WinOAPassword");
> lblServerIP.Text=GetConfigValue("WinOAServer");
> lblUserName.Text=GetConfigValue("WinOAUser");
> }
>
> private void btnClose_Click(object sender,
System.EventArgs e)
> {
> if(MessageBox.Show("ÊÇ·ñÍ˳öϵͳ£¿","Í˳öϵͳ
>",MessageBoxButtons.YesNo,MessageBoxIcon.Warning)
==DialogResult.Yes)
> {
> Application.Exit();
> }
> else
> {
> this.Close();
> MessageBox.Show("ÇëÖØÐÂÆô¶¯³ÌÐò","ÖØÆô³ÌÐò
>",MessageBoxButtons.OK,MessageBoxIcon.Warning);
> }
> }
>
> }
>}
>
>--
>=====================================================
>* ÃλÃÈçÕæ£¡ ¡¡¡¡*
>* ÎÒºÜÕæ³Ï£¬µ«ÎÒÉú»îÔÚ»ÑÑÔÖ®ÖС£ ¡¡¡¡*
>* ¡¡¡¡*
>* ÎÒÅׯúÁËËùÓеÄÓÇÉËÓëÒÉÂÇ£¬È¥×·ÖðÄÇÎ޼ҵij±Ë®£¬ *
>* ÖÕÓÚÕÒµ½ÁËÒ»¸ö°®ÎÒµÄÅ®ÈË£¬´Ó´ËʧȥÁË×ÔÓÉ£¡ ¡¡ *
>*[csharp] °ßÖñ ÌÀ½¨¾ü ¡¡ ¡¡*
>=====================================================
>"CodingPCPiG" <anon...@discussions.microsoft.com> дÈëÏû
Ï¢
>news:a70801c435cc$3674a0b0$a501...@phx.gbl...
>.
>