/// <summary> /// дXML�ĵ� /// </summary> /// <param name="name">���ݿ������������</param> /// <param name="con_str">���ݿ������Դ��Ϣ</param> public void writeXML(string name , ConfigStruct con_str) { try { //����һ��dataset System.Data.DataSet ds = new System.Data.DataSet("Autoconfig"); //�ж��Ƿ����config.xml�ļ�,������ڴӸ��ļ��ж�ȡ���ݵ�dataset if(System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName)) { ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); } //�ж��Ƿ���ڸñ�,���������ɾ���ñ� if(ds.Tables.IndexOf(name.ToUpper()) != -1 ) { ds.Tables.Remove(name.ToUpper()); } //����һ��datatable System.Data.DataTable dt = new System.Data.DataTable(name.ToUpper()); //Ϊ�¶���ı������� dt.Columns.Add("key"); dt.Columns.Add("value"); SymmetricMethod sm = new SymmetricMethod(); //���Ӽ�¼���¶���ı��� dt.Rows.Add(new object[2]{ sm.Encrypto( str_HA ), sm.Encrypto( con_str.hostAddress)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_UN ), sm.Encrypto( con_str.userName)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_PWD ), sm.Encrypto( con_str.password)}); dt.Rows.Add(new object[2]{ sm.Encrypto( str_DBN ), sm.Encrypto( con_str.DBName)}); //�������ӵ�������µ�dataset�� ds.Tables.Add(dt); //д��xml�ĵ� ds.WriteXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); //�ͷ�datatable �� dataset dt.Dispose(); ds.Dispose(); } catch(Exception exp) { //System.Windows.Forms.MessageBox.Show(exp.Message); throw exp; } }
/// <summary> /// ��XML�ĵ� /// </summary> /// <param name="name">Ҫȡ�������ļ��е�ָ������Դ������,��:��ϵͳ "oldsystem" </param> public ConfigStruct readXML(string name) { try { //�����µĽṹ���� ConfigStruct cfg = new ConfigStruct(); //����һ���µ�dataset System.Data.DataSet ds = new System.Data.DataSet(); //�ж��ļ��Ƿ����,��������ʾ������һ���յĽṹ���� if (System.IO.File.Exists(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\"+_FileName)) { //����������ȡconfig.xml�ļ������� ds.ReadXml(AppDomain.CurrentDomain.BaseDirectory.TrimEnd(new char[] {'\\'}) +"\\" +_FileName); } else { // System.Windows.Forms.MessageBox.Show("config.xml�ļ�������!" , "����", // System.Windows.Forms.MessageBoxButtons.OK , // System.Windows.Forms.MessageBoxIcon.Warning); return new ConfigStruct(); } //�жϱ��Ƿ����,��������ʾ������һ���յĽṹ���� if (ds.Tables.IndexOf(name.ToUpper())== -1 ) { // System.Windows.Forms.MessageBox.Show("��config.xml�в����ҵ���ص�����Դ��������Ϣ!" , "����", // System.Windows.Forms.MessageBoxButtons.OK , // System.Windows.Forms.MessageBoxIcon.Warning); return new ConfigStruct(); } SymmetricMethod sm = new SymmetricMethod(); // cfg.hostAddress = "CIT16-PC"; //cfg.userName ="******"; //cfg.password ="******"; //cfg.DBName = "AutoUpDateData"; //������ȡ��ֵ cfg.hostAddress = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_HA) + "'")[0]["value"].ToString()); cfg.userName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_UN) + "'")[0]["value"].ToString()); cfg.password = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_PWD) + "'")[0]["value"].ToString()); cfg.DBName = sm.Decrypto(ds.Tables[name.ToUpper()].Select("key='" + sm.Encrypto(str_DBN) + "'")[0]["value"].ToString()); ds.Dispose(); return cfg; } catch//(Exception exp) { //System.Windows.Forms.MessageBox.Show(exp.Message); return new ConfigStruct(); } }