private void _addRange() { var tab = _tab.To <int>(); var range = FormatConverters.IntOrHexConverter(_tbRange.Text); var from = FormatConverters.IntOrHexConverter(_tbFrom.Text); var table = tab.GetDb <int>((ServerDbs)_destTable.SelectedItem).Table; try { table.Commands.Begin(); for (int i = 0; i < range; i++) { var tuple = new ReadableTuple <int>(i + from, tab.DbComponent.AttributeList); if (_based != null) { tuple.Copy(_based); tuple.SetRawValue(0, i + from); } tuple.Added = true; table.Commands.AddTuple(i + from, tuple); } } catch (Exception err) { table.Commands.CancelEdit(); ErrorHandler.HandleException(err); } finally { table.Commands.End(); tab.Filter(); } }
private void _setSelectedItem(DbAttribute attribute, object value) { var item = (ItemView)_lv.SelectedItem; ReadableTuple <int> newValue = new ReadableTuple <int>(item.ID, ServerItemGroupSubAttributes.AttributeList); newValue.Copy(item.SubTuple); newValue.SetValue(attribute, value); newValue.Modified = true; _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >( _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, item.ID, newValue, item.ID)); item.VisualUpdate(); }
private void _buttonApply_Click(object sender, RoutedEventArgs e) { Result = true; if (_item == null) { return; } Item = new ReadableTuple <int>(_item.GetValue <int>(0), ClientItemAttributes.AttributeList); Item.Copy(_item); Output = _trimReturns(_generateDescription()); OnApply(null); }
public override void ImportFromFile(string fileDefault = null, bool autoIncrement = false) { try { string file = fileDefault ?? PathRequest.OpenFileCde("filter", "All db files|*.conf;*.txt"); if (file == "clipboard") { if (!Clipboard.ContainsText()) { return; } file = TemporaryFilesManager.GetTemporaryFilePath("clipboard_{0:0000}.txt"); File.WriteAllText(file, Clipboard.GetText()); } if (file != null) { try { Table.Commands.Begin(); ProjectDatabase.GetDb <TKey>(Settings.DbData).LoadFromClipboard(file); } catch { Table.Commands.CancelEdit(); } finally { Table.Commands.EndEdit(); if (autoIncrement && typeof(TKey) == typeof(int)) { var cmds = Table.Commands.GetUndoCommands(); if (cmds.Count > 0) { var lastCmd = cmds.Last() as GroupCommand <TKey, TValue>; if (lastCmd != null) { if (lastCmd.Commands.Count > 0 && lastCmd.Commands.OfType <ChangeTupleProperties <TKey, TValue> >().Count() == 1) { var firstKey = lastCmd.Commands.First().Key; var tuple = new ReadableTuple <TKey>(firstKey, Table.AttributeList); var oldTuple = (ReadableTuple <TKey>)(object) Table.TryGetTuple(firstKey); tuple.Copy(oldTuple); tuple.Added = true; ProjectDatabase.Commands.Undo(); Table.Commands.AddTuple(tuple.GetKey <TKey>(), (TValue)(object)tuple, false, true, null); } } } } } _listView_SelectionChanged(this, null); } } catch (Exception err) { ErrorHandler.HandleException(err); } }
public static void Writer2 <TKey>(ReadableTuple <TKey> item, ServerType destServer, StringBuilder builder, BaseDb db, List <string> aegisNames, List <string> names) { var itemCopy = new ReadableTuple <TKey>(item.GetKey <TKey>(), item.Attributes); itemCopy.Copy(item); item = itemCopy; int key = item.GetKey <int>(); if (destServer == ServerType.RAthena) { var itemDb = db.GetMeta <int>(ServerDbs.Items); ServerType source = DbPathLocator.GetServerType(); if (source == ServerType.Hercules) { List <string> constantsList = Constants.Keys.ToList(); Table <int, ReadableTuple <int> > table = db.GetMeta <int>(ServerDbs.Items); var tuple = item; var res2 = table.TryGetTuple(key); if (res2 != null) { string name = res2.GetValue(ServerItemAttributes.AegisName).ToString(); int low = Int32.MaxValue; int index = -1; for (int j = 0; j < Constants.Count; j++) { int dist = Methods.LevenshteinDistance(name, constantsList[j]); if (dist < low) { low = dist; index = j; } } string closestString = constantsList[index]; int groupId = Constants[closestString]; tuple.SetRawValue(0, groupId); } } Dictionary <int, ReadableTuple <int> > dico = (Dictionary <int, ReadableTuple <int> >)item.GetRawValue(1); key = item.GetKey <int>(); foreach (var pair in dico.OrderBy(p => p.Key)) { var dbTuple = itemDb.TryGetTuple(pair.Key); List <string> items = ServerItemGroupSubAttributes.AttributeList.Attributes.Select(p => pair.Value.GetValue <string>(p)).ToList(); RemoveDefaultValues(items); builder.AppendLine(key + "," + string.Join(",", items.ToArray()) + (dbTuple == null ? "" : "\t// " + dbTuple.GetValue(ServerItemAttributes.Name))); } builder.AppendLine(); } else if (destServer == ServerType.Hercules) { builder.AppendLine(ItemGroupParser.ToHerculesDbEntry(db, item.GetKey <int>(), aegisNames, names)); builder.AppendLine(); } }
private void _setSelectedItem(int id, object rate, DicoModifs modif) { if (modif == DicoModifs.Delete) { var p = (ReadableTuple <int>)_tab.List.SelectedItem; _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >( p, ServerItemGroupAttributes.Table, ((ItemView)_lv.SelectedItem).ID)); return; } ItemView selectedItem = null; ReadableTuple <int> newValue = new ReadableTuple <int>(id, ServerItemGroupSubAttributes.AttributeList); if (modif != DicoModifs.Add) { selectedItem = (ItemView)_lv.SelectedItem; newValue.Copy(selectedItem.SubTuple); } newValue.SetValue(ServerItemGroupSubAttributes.Rate, rate); newValue.SetValue(ServerItemGroupSubAttributes.Id, id); Dictionary <int, ReadableTuple <int> > dico = ((ReadableTuple <int>)_tab.List.SelectedItem).GetRawValue <Dictionary <int, ReadableTuple <int> > >(ServerItemGroupAttributes.Table); if (dico.ContainsKey(id)) { if (selectedItem != null) { int selectedId = selectedItem.ID; if (selectedId != id) { var coll = ((RangeObservableCollection <ItemView>)_lv.ItemsSource); coll.Remove(coll.FirstOrDefault(p => p.ID == id)); } } } if (modif == DicoModifs.Add) { newValue.Added = true; if (dico.ContainsKey(id)) { ErrorHandler.HandleException("The item ID already exists."); return; } _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >( _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, id, newValue, id, _addedItem)); } else if (modif == DicoModifs.Edit) { newValue.Modified = true; int oldId = selectedItem.ID; selectedItem.ID = id; _itemGroupsTable.Commands.StoreAndExecute(new ChangeTupleDicoProperty <int, ReadableTuple <int>, int, ReadableTuple <int> >( _tab.List.SelectedItem as ReadableTuple <int>, ServerItemGroupAttributes.Table, oldId, newValue, id)); selectedItem.VisualUpdate(); } ((RangeObservableCollection <ItemView>)_lv.ItemsSource).ToList().ForEach(p => p.VisualUpdate()); }