/// <summary> /// 追加処理を実行します。 /// </summary> /// <returns>Task</returns> private async Task <bool> ExecuteAdd() { var item = new TaskItem(); KeyInfo groupKey = null; if (this.ShowingGroup != null) { groupKey = this.ShowingGroup.Key; } item.Key = KeyInfo.CreateKeyInfoTask(groupKey); var win = new TaskEditForm(); win.Initialize(this.ShowingGroup, item); var ret = await win.ShowWindow(ResourceManager.Instance.MainForm); if (ret == SubWindowResult.Submit) { if (item.Group != null) { if (item.Group.Equals(groupKey) || this.ShowingGroup == null) { ResourceManager.Instance.AddTaskItem(item.Group, item); this.AddRow(item); } } return(true); } return(false); }
/// <summary> /// 複製処理を実行します。 /// </summary> /// <param name="taskItem">タスク</param> /// <returns>Task</returns> private bool ExecuteCopy(TaskItem taskItem) { var newItem = new TaskItem(); newItem.Group = taskItem.Group; newItem.Title = taskItem.Title; newItem.Memo = taskItem.Memo; newItem.DateTimeLimit = taskItem.DateTimeLimit; newItem.Key = KeyInfo.CreateKeyInfoTask(taskItem.Group); this.AddRow(newItem); if (taskItem.Group != null) { ResourceManager.Instance.AddTaskItem(taskItem.Group, newItem); } this.RefleshTaskItemsOnCurrentGroup(); return(true); }
/// <summary> /// 初期化処理 /// </summary> /// <returns>実行結果</returns> public bool Initialize() { this.taskInfoRoot = new TaskInfoRoot(); KeyInfo.Initialize(); var path = Utils.GetFullPath(TaskListSavePath); if (File.Exists(path)) { var text = File.ReadAllText(path); var jsonObj = JsonConvert.DeserializeObject <TaskInfoRoot>(text); instance.taskInfoRoot = jsonObj; var rootGroupKey = TaskGroupInfo.GetRootGroup().Key; if (instance.taskInfoRoot.TaskGroupListJsonObj.Any(x => x.Key.Equals(rootGroupKey))) { var item = instance.taskInfoRoot.TaskGroupListJsonObj.First(x => x.Key.Equals(rootGroupKey)); TaskGroupInfo.OverriteRootGroup(item); } var defaultGroupKey = TaskGroupInfo.GetDefaultGroup().Key; if (instance.taskInfoRoot.TaskGroupListJsonObj.Any(x => x.Key.Equals(defaultGroupKey))) { var item = instance.taskInfoRoot.TaskGroupListJsonObj.First(x => x.Key.Equals(defaultGroupKey)); TaskGroupInfo.OverriteDefaultGroup(item); } // 全グループに対してキーの再生成 foreach (var taskGroupInfo in instance.taskInfoRoot.TaskGroupListJsonObj) { if (!KeyInfo.IsCreatedKeyGroup(taskGroupInfo.Key)) { var keyGroup = KeyInfo.CreateKeyInfoGroup(); taskGroupInfo.ChildGroups.Clear(); var filetered = instance.taskInfoRoot.TaskGroupListJsonObj.Where(x => x.ParentGroup != null && x.ParentGroup.Equals(taskGroupInfo.Key)).ToList(); if (filetered.Any()) { foreach (var groupInfo in filetered) { if (!KeyInfo.IsCreatedKeyGroup(groupInfo.Key)) { var keyGroupChildGroup = KeyInfo.CreateKeyInfoGroup(); groupInfo.Key = keyGroupChildGroup; } groupInfo.ParentGroup = keyGroup; taskGroupInfo.ChildGroups.Add(groupInfo.Key); } } taskGroupInfo.Key = keyGroup; } foreach (var childTaskItem in taskGroupInfo.ChildTaskItems) { if (!KeyInfo.IsCreatedKeyTask(taskGroupInfo.Key, childTaskItem.Key)) { var keyGroup = KeyInfo.CreateKeyInfoTask(taskGroupInfo.Key); childTaskItem.Key = keyGroup; } childTaskItem.Group = taskGroupInfo.Key; } if (!instance.taskInfoRoot.TaskGroupList.ContainsKey(taskGroupInfo.Key)) { instance.taskInfoRoot.TaskGroupList.Add(taskGroupInfo.Key, taskGroupInfo); } } } else { instance.taskInfoRoot.AddTaskGroup(TaskGroupInfo.GetRootGroup(), null); instance.taskInfoRoot.AddTaskGroup(TaskGroupInfo.GetDefaultGroup(), TaskGroupInfo.GetRootGroup()); } return(true); }