protected override void RelayMethod(object obj) { string command = obj.ToString(); Debug.WriteLine(command); // Do:初始化 if (command == "init") { this.TaskModelList.CollectionChanged += (l, k) => { for (int i = 0; i < this.TaskModelList.Count; i++) { this.TaskModelList[i].SeriaNumber = (i + 1).ToString().PadLeft(2, '0'); } }; } // Message:刪除 if (command == "btn_delete") { this.TaskModelList.Remove(this.SelectItem); } // Do:添加 else if (command == "btn_add") { if (this.AddItem == null) { return; } if (this.AddItem.StartLine == null || this.AddItem.EndLine == null || this.AddItem.Analyst == null) { MessageBox.Show("信息不完整,请选择有效信息"); return; } AddItem.StartDate = DateTime.Now; this.TaskModelList.Add(AddItem); // Do:复制一个新数据 AddItem = this.AddItem.Clone(); // Message:刷新可选杆号 this.RefreshCanSelection(); } // Do:保存 else if (command == "btn_sumit") { if (this.TaskModelList == null || this.TaskModelList.Count == 0) { MessageWindow.ShowDialogWithSumit("列表中没有数据,请先分工"); return; } string err; if (!this.IsVaild(out err)) { //var result = MessageBox.Show(err + "是否继续保存?", "提示!", MessageBoxButton.YesNo, MessageBoxImage.Error); //err = "是否继续保存是否继续保存是否继续保存是否继续保存是否继续保存是否继续保存是否继续保存是否继续保存是否继续保存"; if (err.Length > 40) { err = err.Substring(0, 40) + "..."; } var result = MessageWindow.ShowDialog(err + "是否继续保存?"); //if (result == MessageBoxResult.No) return; if (!result) { return; } } this.IsBuzy = true; Task.Run(() => { ObservableCollection <TaskModel_2C> models = new ObservableCollection <TaskModel_2C>(); foreach (var item in this.TaskModelList) { models.Add(item.ConvertTo()); } // Message:触发保存事件 this.SaveEvent?.Invoke(models); this.IsBuzy = false; }); } }