private void HandleAddData() { var msg = new NotificationMessageAction <DateTime>("请输入新增数据的日期及时间", (result) => { try { //检查是否有数据存在 if (DbContext.CheckExistData(_appInfo.CurrentApp.Id, result)) { throw new Exception("该时刻的数据已存在,无法添加"); } DataRow newRow = AppDataTable.NewRow(); newRow[PubConstant.timeColumnName] = result; AppDataTable.Rows.Add(newRow); AppDataTable.AcceptChanges(); } catch (Exception ex) { Messenger.Default.Send <Exception>(ex); } }); Messenger.Default.Send <NotificationMessageAction <DateTime> >(msg); }
private void HandleDeleteSelectedData() { var msg = new DialogMessage(string.Format("确定要删选定时间的数据吗?"), result => { if (result == System.Windows.MessageBoxResult.Yes) { try { var delRows = (from i in Selection select i.Row).ToList(); Selection.Clear(); foreach (var row in delRows) { //从appInfo中删除数据 var date = (DateTime)(row[PubConstant.timeColumnName]); _appInfo.DeleteValuesByDate(date); //删除构造表中的行 AppDataTable.Rows.Remove(row); } AppDataTable.AcceptChanges(); _appInfo.Update(); //让当前时刻为第一个 } catch (Exception ex) { Messenger.Default.Send <Exception>(ex); } } }); msg.Caption = "确定要删除吗?"; msg.Button = MessageBoxButton.YesNo; msg.Icon = MessageBoxImage.Question; Messenger.Default.Send <DialogMessage>(msg); }