private BaseTable _loadClientDb(string file) { AbstractDb <int> db = AllTables.First(p => p.Value.DbSource == ServerDbs.CItems).Value.To <int>().Copy(); db.DummyInit(this); if (db.DbSource == ServerDbs.CItems) { if (file.IsExtension(".lua", ".lub")) { db.DbLoader = (d, idb) => DbIOClientItems.LoadEntry(db, file); } else { db.DbLoader = (d, idb) => DbIOClientItems.LoadData(db, file, _getMappingField(file), _getAllowcutLine(file)); } } var method = db.DbLoader; db.DbLoader = (d, idb) => { db.Table.EnableRawEvents = false; method(d, idb); db.Table.Commands.ClearCommands(); }; try { DebugStreamReader.ToClientEncoding = true; db.LoadFromClipboard(file); } finally { DebugStreamReader.ToClientEncoding = false; } return(db.Table); }
public void Map <TKey>(GDbTabWrapper <TKey, ReadableTuple <TKey> > tab, string file, DbAttribute[] mappedFields) { AbstractDb <TKey> db = GetCopyDb <TKey>(DbImport); db.DummyInit(tab.ProjectDatabase); if (db.DbSource == ServerDbs.CItems) { if (file.IsExtension(".lua", ".lub")) { db.DbLoader = (d, idb) => DbIOClientItems.LoadEntry((AbstractDb <int>)(object) db, file); } else { db.DbLoader = (d, idb) => DbIOClientItems.LoadData((AbstractDb <int>)(object) db, file, mappedFields[0], _allowCutLine); } } var method = db.DbLoader; db.DbLoader = (d, idb) => { db.Table.EnableRawEvents = false; method(d, idb); }; try { if ((tab.DbComponent.DbSource & ServerDbs.CItems) != ServerDbs.CItems) { DebugStreamReader.ToServerEncoding = true; } else { DebugStreamReader.ToClientEncoding = true; } db.LoadFromClipboard(file); } finally { DebugStreamReader.ToServerEncoding = false; DebugStreamReader.ToClientEncoding = false; } var table = tab.Table; table.Commands.Begin(); try { foreach (var cTuple in db.Table.FastItems) { var sTuple = table.TryGetTuple(cTuple.Key); if (sTuple == null) { continue; } for (int i = 0; i < mappedFields.Length; i += 2) { var cValue = cTuple.GetValue <string>(mappedFields[i]); var sValue = sTuple.GetValue <string>(mappedFields[i + 1]); if (cValue != sValue) { if (_isNoEmptyFields(mappedFields[i + 1], cValue, sValue)) { continue; } table.Commands.Set(sTuple, mappedFields[i + 1], cValue); } } } } catch (Exception err) { ErrorHandler.HandleException(err); table.Commands.CancelEdit(); } finally { table.Commands.EndEdit(); } }