Public configuration underlayer code

zhaozj2021-02-16  106

Using system.data; using system.windows.form; using system.collections;

Namespace Datalibrary {///

/// Configuring the underlying /// public class configmanagerkeyValue {private string pstroyal; private object pobjvalue; /// /// configuration management key value /// < / summary> /// /// public configmanagerkeyValue (string key, object value) {pstrkey = key; POBJVALUE = Value }

///

/// /// public string key {get {return pstroyal;} set {pstr ready = value;}}

///

// / value /// public object value {get {return pobjvalue;} set {pobjvalue = value;}}}

///

/// Configuration Management Service /// Public Class DisposalconductService {Private String PstrFileName; Private Dataset DSDataView; /// /// Configuration Management Service /// /// public disposalconductService (string filename) {pstrfilename = filename; initOgiTOTOBJECTS ();

///

/// Configuration Management Service /// 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 /// /// key name /// Default /// value 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 /// /// value 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 /// /// key /// value /// Success: true; failed: false 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 /// /// < Param name = "keyname"> key /// success: true; failed: false 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 /// /// key /// Value /// success: true; failure: false 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 /// public string filename {get {return pstrfilename;}}}}

转载请注明原文地址:https://www.9cbs.com/read-10711.html

New Post(0)