/// <summary> /// TreeView改变事件 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tvCoor_SelectedItemChanged(object sender, RoutedPropertyChangedEventArgs <object> e) { if (tvCoor.SelectedItem != null) { if (GetTreeViewSelected() is Sensor) { Sensor sensor = GetTreeViewSelectedSensor(); lstRefer.ItemsSource = ShowRefer.ShowReferSensorList(sensor); lblNumber.Content = "数量:" + lstRefer.Items.Count; } if (GetTreeViewSelected() is Coordinator) { Coordinator coordinator = GetTreeViewSelectedCoor(); lstRefer.ItemsSource = ShowRefer.ShowReferCoorList(coordinator); lblNumber.Content = "数量:" + lstRefer.Items.Count; } } }
/// <summary> /// 删除历史记录 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void BtnDelete_OnClick(object sender, RoutedEventArgs e) { if (lstRefer.SelectedItems != null) { if (GetListviewSelected() != null) { if (MessageBox.Show("是否删除该项", "询问", MessageBoxButton.YesNo) == MessageBoxResult.Yes) { OperationResult result = null; ShowRefer showRefer = GetListviewSelected(); if (showRefer != null) { if (startDatePicker.Text != "" && endDatePicker.Text != "") { DateTime dateStart = Convert.ToDateTime(startDatePicker.Text); DateTime dateEnd = Convert.ToDateTime(endDatePicker.Text); SensorData sensorData = SensorDataApp.GetList().Where(p => p.Time == showRefer.Time).First(); result = SensorDataApp.Delete(sensorData); if (result.ResultType != OperationResultType.Success) { MessageBox.Show(result.Message); } else { if (GetTreeViewSelected() is Coordinator) { Coordinator coordinator = GetTreeViewSelectedCoor(); lstRefer.ItemsSource = ShowRefer.ShowCoorTimeList(coordinator, dateStart, dateEnd); lblNumber.Content = "数量:" + lstRefer.Items.Count; } else { Sensor sensor = GetTreeViewSelectedSensor(); lstRefer.ItemsSource = ShowRefer.ShowSensorDataTimeList(sensor, dateStart, dateEnd); lblNumber.Content = "数量:" + lstRefer.Items.Count; } } } else { SensorData sensorData = SensorDataApp.GetList().Where(p => p.Time == showRefer.Time).First(); result = SensorDataApp.Delete(sensorData); if (result.ResultType != OperationResultType.Success) { MessageBox.Show(result.Message); } else { if (GetTreeViewSelected() is Coordinator) { Coordinator coordinator = GetTreeViewSelectedCoor(); lstRefer.ItemsSource = ShowRefer.ShowReferCoorList(coordinator); lblNumber.Content = "数量:" + lstRefer.Items.Count; } else { Sensor sensor = GetTreeViewSelectedSensor(); lstRefer.ItemsSource = ShowRefer.ShowReferSensorList(sensor); lblNumber.Content = "数量:" + lstRefer.Items.Count; } } } } else { MessageBox.Show("请选择删除的传感器数据信息!"); } } } else { MessageBox.Show("请选择删除的传感器数据信息!"); } } }