using MeterVision.db; using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; namespace MeterVision.Patch { /// /// AddCompDlg2.xaml 的交互逻辑 /// public partial class AddCompDlg2 : Window, INotifyPropertyChanged { public event PropertyChangedEventHandler PropertyChanged; protected void OnPropertyChanged(string propertyName) { PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } public TComp NewComp { get; set; } //下拉框绑定的数据 public ObservableCollection NPatchList { get; set; } public ObservableCollection OPatchList { get; set; } public List mPatchList; public AddCompDlg2() { InitializeComponent(); NPatchList = new ObservableCollection(); OPatchList = new ObservableCollection(); lvNPatch.ItemsSource = NPatchList; lvOPatch.ItemsSource = OPatchList; this.DataContext = this; LoadNPatchList(); } private async void LoadNPatchList() { try { mPatchList = await Task.Run(() => DBPatch.GetAllVPatchs()); NPatchList.Clear(); foreach (VPatch patch in mPatchList) { NPatchList.Add(patch); } } catch (Exception ex) { MessageBox.Show($"加载数据失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } } private void BtnOK_Click(object sender, RoutedEventArgs e) { if (lvNPatch.SelectedItem == null || lvOPatch.SelectedItem == null) { MessageBox.Show("请先选择任务!"); return; } NewComp = new TComp { CompId = Guid.NewGuid().ToString(), CreateTime = ThisApp.GetNowTime_yyyyMMddHHmmss(), NPatchId = ((VPatch)lvNPatch.SelectedItem).PatchId, OPatchId = ((VPatch)lvOPatch.SelectedItem).PatchId, StandId = ((VPatch)lvNPatch.SelectedItem).StandId }; bool result = DBComp.InsertTComp(NewComp); if (result) { this.DialogResult = true; this.Close(); } else { MessageBox.Show("保存失败,请重试!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); } } private void LvNPatch_SelectionChanged(object sender, SelectionChangedEventArgs e) { var patchItem = lvNPatch.SelectedItem as VPatch; OPatchList.Clear(); if (patchItem != null) { foreach (VPatch patch in mPatchList) { if (patch.StandId == patchItem.StandId && double.Parse(patch.CreateTime) < double.Parse(patchItem.CreateTime)) { OPatchList.Add(patch); } }//foreach } } private void BtnClose_Click(object sender, RoutedEventArgs e) { this.DialogResult = false; this.Close(); } //----------------------------------------------------------------------------------------- } }