Using system.data; using system.windows.form; using system.collections;
Namespace Datalibrary {/// /// Configuring the underlying /// summary> public class configmanagerkeyValue {private string pstroyal; private object pobjvalue; /// /// configuration management key value /// < / summary> /// param> /// param> public configmanagerkeyValue (string key, object value) {pstrkey = key; POBJVALUE = Value }
/// /// /// summary> public string key {get {return pstroyal;} set {pstr ready = value;}}
/// // / value /// summary> public object value {get {return pobjvalue;} set {pobjvalue = value;}}}
/// /// Configuration Management Service /// Summary> Public Class DisposalconductService {Private String PstrFileName; Private Dataset DSDataView; /// /// Configuration Management Service /// summary> /// param> public disposalconductService (string filename) {pstrfilename = filename; initOgiTOTOBJECTS ();
/// /// Configuration Management Service /// Summary> Public DisposalconductService () {pstrfilename = system.reflection.assembly.getexecutingassembly (). Tostring () ".exe.config"; appdomain ad = Appdomain.currentdomain; pstrfilename = ad.basedirectory pstrfilename; initOgiCTs ();
private void initObjects () {initDataSource ();} private void initDataSource () {dsDataSet = new DataSet (); try {dsDataSet.ReadXml (pstrFilename); dvDataView = dsDataSet.Tables [0] .DefaultView; dvDataView.AllowEdit = true; dvDataView.AllowDelete = true; dvDataView.AllowNew = true;} catch (Exception) {dsDataSet.Tables.Add (createDataTable ()); dsDataSet.DataSetName = "Application"; try {saveData (); dvDataView = dsDataSet.Tables [0 ] .DefaultView; dvDataView.AllowEdit = true; dvDataView.AllowDelete = true; dvDataView.AllowNew = true;} catch (Exception e) {MessageBox.Show (e.Message);}}} /// /// Number /// summary> /// key name param> /// Default param> /// value returns> public object GetValue (string KeyName, object Default) {object strResult = Default; DataRowView Row; dvDataView.RowFilter = "key = '" KeyName "'"; if (dvDataVie W.count! = 0) {row = DVDataView [0]; strresult = row ["value"];} else {addValue (keyname, default);} return (strresult);}
/// /// acquisition value /// summary> /// value returns> public arraylist getValues () {arraylist list = new arraylist (); try {dvdataview.rowfilter = " "; DATAROWVIEW ROW IN DVDataView) {list.add (New ConfigManagerKeyValue ((String) Row [" key "], row [" value "]));}} catCh {} returnit;}
/// /// Add a value /// summary> /// key param> /// value param > /// Success: true; failed: false returns> public bool addvalue (string keyname, object value) {DATAROWVIEW ROW; try {DVDataView.rowFilter = "key = '" keyname "'"; IF (DVDataView.count == 0) {row = DVDataView.addNew (); row ["key"] = keyName; row ["value"] = value; row.endedit (); savedata (); returnide;} Else {Return False;}} Catch (Exception E) {MessageBox.Show (E.MESSAGE); Return False;}} /// /// Delete one value /// summary> /// < Param name = "keyname"> key param> /// success: true; failed: false returns> public bool removevalue (String Keyname) {DATAROWVIEW ROW; DVDataView.RowFilter = "key = '" Keyname "'"; if (DVDataView.count! = 0) {row = DVDataView [0]; Row.delete (); Return true;} else {return false;}}
/// /// update /// summary> /// key param> /// Value param> /// success: true; failure: false returns> public bool updateValue (string KeyName, object Value) {removeValue (KeyName); return AddValue (KeyName, Value);} private void saveData () {dsDataSet. WriteXml (pstrFilename);} private DataTable createDataTable () {DataTable tbl = new DataTable (); tbl.TableName = "Configuration"; tbl.Columns.Add ( "key", typeof (string)); tbl.Columns.Add ( "Value", TypeOf (String); Return (TBL);} /// /// file name /// summary> public string filename {get {return pstrfilename;}}}}