private void DataGrid_CellEditEnding(object sender, DataGridCellEditEndingEventArgs e) { NetObject netObject = (NetObject)e.Row.Item; if (netObject != null && e.Column.SortMemberPath != null) { int recipientId = 0; if (e.Row.Item.GetType() == typeof(Project)) { recipientId = 12; } else if (e.Row.Item.GetType() == typeof(Todo)) { recipientId = 10; } else { throw new Exception("Unknown New Type"); } DataItemChanged data = new DataItemChanged() { PK = netObject.pId, PropertyName = e.Column.SortMemberPath, Value = ((TextBox)e.EditingElement).Text, Type = netObject.GetType().ToString() }; tornado14Observer.Send(new Package(SENDERID, recipientId, (int)EventMapping.DataItemChanged_13, Method.PUT, XmlSerializationHelper.Serialize(data))); } else { throw new Exception("Todo or Property Name is Empty."); } }
public static void OnDataItemChanged(NetConfigDataItem changedItem) { //specific data changed event DataItemChanged?.Invoke(changedItem); //also trigger generic data changed event DataChanged?.Invoke(); }
private void TextResultPublicInfo_LostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e) { Todo todo = (Todo)todoViewSource.View.CurrentItem; if (todo != null) { string propertyName = string.Empty; switch (((Control)sender).Name) { case "TextEditorPublicInfo": propertyName = "PublicText"; break; case "TextEditorCurrentState": propertyName = "CurrentState"; break; case "TextEditorResult": propertyName = "Result"; break; case "TextEditorTargetState": propertyName = "Description"; break; default: break; } DataItemEndChanging data = new DataItemEndChanging() { PK = todo.pId, Type = todo.GetType().ToString(), PropertyName = propertyName }; tornado14Observer.Send(new Package(SENDERID, 10, (int)EventMapping.DataItemEndChanging_17, Method.PUT, XmlSerializationHelper.Serialize(data))); DataItemChanged data2 = new DataItemChanged() { PK = todo.pId, PropertyName = propertyName, Value = ((Tornado14.WPFControls.TEditor)(sender)).Text2, Type = todo.GetType().ToString(), }; tornado14Observer.Send(new Package(SENDERID, 12, (int)EventMapping.DataItemChanged_13, Method.PUT, XmlSerializationHelper.Serialize(data2))); } }
private void HandlePUT(Package package) { if (package.Event == (int)EventMapping.DataItemChanged_13) { DataItemChanged putParams = XmlSerializationHelper.Desirialize <DataItemChanged>(package.Data); if (putParams.Type == typeof(Todo).ToString()) { Todo currentTodo = null; foreach (Todo todo in TodoList) { if (todo.pId == putParams.PK) { currentTodo = todo; break; } } Todo.SetPropValue(currentTodo, putParams.PropertyName, putParams.Value); currentTodo.DidNotReadLoL = true; } else if (putParams.Type == typeof(Project).ToString()) { Project currentProject = null; foreach (Project project in ProjectList) { if (project.pId == putParams.PK) { currentProject = project; break; } } Project.SetPropValue(currentProject, putParams.PropertyName, putParams.Value); currentProject.DidNotReadLoL = true; selectedProject = currentProject; } } else if (package.Event == (int)EventMapping.CurrentItemChanged_15) { CurrentItemChanged putParams = XmlSerializationHelper.Desirialize <CurrentItemChanged>(package.Data); if (putParams.Type == typeof(Todo).ToString()) { object pk = TodoList.Where(todo => todo.pId == putParams.PK).First(); SelectedDataItemChanged(pk, putParams.Type); selectedTodo = (Todo)pk; } else if (putParams.Type == typeof(Project).ToString()) { object pk = ProjectList.Where(project => project.pId == putParams.PK).First(); SelectedDataItemChanged(pk, putParams.Type); selectedProject = (Project)pk; } else { throw new Exception("Unknown Type"); } } else if (package.Event == (int)EventMapping.DataItemBeginChanging_16) { DataItemBeginChanging putParams = XmlSerializationHelper.Desirialize <DataItemBeginChanging>(package.Data); DataItemStartChanging(putParams); } else if (package.Event == (int)EventMapping.DataItemEndChanging_17) { DataItemEndChanging putParams = XmlSerializationHelper.Desirialize <DataItemEndChanging>(package.Data); DataItemEndChanging(putParams); } }
private void DataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e) { if (e.NewItem != null) { int recipientId = 0; NetObject netObject = (NetObject)e.NewItem; netObject.pId = Guid.NewGuid(); List <NetObject> objectList = new List <NetObject>(); if (e.NewItem.GetType() == typeof(Project)) { objectList = ProjectList.ToList <NetObject>(); recipientId = 12; } else if (e.NewItem.GetType() == typeof(Todo)) { objectList = TodoList.ToList <NetObject>(); ((Todo)e.NewItem).ProjectPid = selectedProject.pId; recipientId = 10; } else { throw new Exception("Unknown New Type"); } int maxCount = 0; string prefix = ""; foreach (NetObject p in objectList) { try { string[] idSplit = p.Id.Split('-'); int value = int.Parse(idSplit[1]); if (maxCount < value) { maxCount = value; if (idSplit[0].Length > 0) { prefix = idSplit[0] + "-"; } } } catch (Exception ex) { } } maxCount++; string newId = string.Format("{0}{1}", prefix, maxCount); ((NetObject)e.NewItem).Id = newId; DataItemAdded data = new DataItemAdded() { PK = netObject.pId, Id = newId, Type = netObject.GetType().ToString() }; tornado14Observer.Send(new Package(SENDERID, recipientId, (int)EventMapping.DataItemAdded_18, Method.POST, XmlSerializationHelper.Serialize(data))); if (e.NewItem.GetType() == typeof(Todo)) { DataItemChanged dataChanged = new DataItemChanged() { PK = netObject.pId, PropertyName = "ProjectPid", Type = typeof(Todo).ToString(), Value = selectedProject.pId }; tornado14Observer.Send(new Package(SENDERID, recipientId, (int)EventMapping.DataItemChanged_13, Method.PUT, XmlSerializationHelper.Serialize(dataChanged))); } } }