向数据库读写用户自定义的全局数据,通过扩展记录实体
C#开发|大少爷|2017-07-27 11:49
-
回答:
void wirteVer(String sName, String sVal) { MxDrawDatabase database = (MxDrawDatabase)axMxDrawX1.GetDatabase(); MxDrawDictionary dict = database.GetNamedObjectsDictionary(); MxDrawDictionary myDict = (MxDrawDictionary)dict.GetAt("MyExDataDictName"); if (myDict == null) { myDict = (MxDrawDictionary)dict.AddObject("MyExDataDictName", "McDbDictionary"); } MxDrawXRecord rec = (MxDrawXRecord)myDict.GetAt(sName); if (rec == null) { rec = myDict.AddXRecord(sName); } MxDrawResbuf res = new MxDrawResbuf(); res.AddString(sVal); rec.SetXRecordData(res); } String readVar(String sName) { MxDrawDatabase database = (MxDrawDatabase)axMxDrawX1.GetDatabase(); MxDrawDictionary dict = database.GetNamedObjectsDictionary(); MxDrawDictionary myDict = (MxDrawDictionary)dict.GetAt("MyExDataDictName"); if (myDict == null) { return ""; } MxDrawXRecord rec = (MxDrawXRecord)myDict.GetAt(sName); if (rec == null) { return ""; } MxDrawResbuf ret = rec.GetXRecordData(); if (ret == null) return ""; return ret.AtString(0); } private void buttondict_Click(object sender, EventArgs e) { wirteVer("MyName", "666666"); } private void buttonreaddict_Click(object sender, EventArgs e) { String sRet = readVar("MyName"); if (sRet == "") { MessageBox.Show("没有数据"); } else { MessageBox.Show(sRet); } }