AddCompDlg2.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. using MeterVision.db;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Collections.ObjectModel;
  5. using System.ComponentModel;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace MeterVision.Patch
  18. {
  19. /// <summary>
  20. /// AddCompDlg2.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class AddCompDlg2 : Window, INotifyPropertyChanged
  23. {
  24. public event PropertyChangedEventHandler PropertyChanged;
  25. protected void OnPropertyChanged(string propertyName)
  26. {
  27. PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
  28. }
  29. public TComp NewComp { get; set; }
  30. //下拉框绑定的数据
  31. public ObservableCollection<VPatch> NPatchList { get; set; }
  32. public ObservableCollection<VPatch> OPatchList { get; set; }
  33. public List<VPatch> mPatchList;
  34. public AddCompDlg2()
  35. {
  36. InitializeComponent();
  37. NPatchList = new ObservableCollection<VPatch>();
  38. OPatchList = new ObservableCollection<VPatch>();
  39. lvNPatch.ItemsSource = NPatchList;
  40. lvOPatch.ItemsSource = OPatchList;
  41. this.DataContext = this;
  42. LoadNPatchList();
  43. }
  44. private async void LoadNPatchList()
  45. {
  46. try
  47. {
  48. mPatchList = await Task.Run(() => DBPatch.GetAllVPatchs());
  49. NPatchList.Clear();
  50. foreach (VPatch patch in mPatchList)
  51. {
  52. NPatchList.Add(patch);
  53. }
  54. }
  55. catch (Exception ex)
  56. {
  57. MessageBox.Show($"加载数据失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  58. }
  59. }
  60. private void BtnOK_Click(object sender, RoutedEventArgs e)
  61. {
  62. if (lvNPatch.SelectedItem == null || lvOPatch.SelectedItem == null)
  63. {
  64. MessageBox.Show("请先选择任务!");
  65. return;
  66. }
  67. NewComp = new TComp
  68. {
  69. CompId = Guid.NewGuid().ToString(),
  70. CreateTime = ThisApp.GetNowTime_yyyyMMddHHmmss(),
  71. NPatchId = ((VPatch)lvNPatch.SelectedItem).PatchId,
  72. OPatchId = ((VPatch)lvOPatch.SelectedItem).PatchId,
  73. StandId = ((VPatch)lvNPatch.SelectedItem).StandId
  74. };
  75. bool result = DBComp.InsertTComp(NewComp);
  76. if (result)
  77. {
  78. this.DialogResult = true;
  79. this.Close();
  80. }
  81. else
  82. {
  83. MessageBox.Show("保存失败,请重试!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  84. }
  85. }
  86. private void LvNPatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
  87. {
  88. var patchItem = lvNPatch.SelectedItem as VPatch;
  89. OPatchList.Clear();
  90. if (patchItem != null)
  91. {
  92. foreach (VPatch patch in mPatchList)
  93. {
  94. if (patch.StandId == patchItem.StandId &&
  95. double.Parse(patch.CreateTime) < double.Parse(patchItem.CreateTime))
  96. {
  97. OPatchList.Add(patch);
  98. }
  99. }//foreach
  100. }
  101. }
  102. private void BtnClose_Click(object sender, RoutedEventArgs e)
  103. {
  104. this.DialogResult = false;
  105. this.Close();
  106. }
  107. //-----------------------------------------------------------------------------------------
  108. }
  109. }