AddCompDlg.xaml.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  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. /// AddCompDlg.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class AddCompDlg : 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 AddCompDlg()
  35. {
  36. InitializeComponent();
  37. NPatchList = new ObservableCollection<VPatch>();
  38. cmbNPatch.ItemsSource = NPatchList;
  39. OPatchList = new ObservableCollection<VPatch>();
  40. cmbOPatch.ItemsSource = OPatchList;
  41. lvNPatch.ItemsSource = NPatchList;
  42. this.DataContext = this;
  43. LoadNPatchList();
  44. }
  45. private async void LoadNPatchList()
  46. {
  47. try
  48. {
  49. mPatchList = await Task.Run(() => DBPatch.GetAllVPatchs());
  50. NPatchList.Clear();
  51. foreach(VPatch patch in mPatchList)
  52. {
  53. NPatchList.Add(patch);
  54. }
  55. }
  56. catch(Exception ex)
  57. {
  58. MessageBox.Show($"加载数据失败:{ex.Message}", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  59. }
  60. }
  61. private void CmbNPatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
  62. {
  63. var patchItem = cmbNPatch.SelectedItem as VPatch;
  64. OPatchList.Clear();
  65. if (patchItem != null)
  66. {
  67. foreach(VPatch patch in mPatchList)
  68. {
  69. if( patch.StandId == patchItem.StandId &&
  70. double.Parse(patch.CreateTime) < double.Parse(patchItem.CreateTime))
  71. {
  72. OPatchList.Add(patch);
  73. }
  74. }//foreach
  75. }
  76. }
  77. private void CmbOPatch_SelectionChanged(object sender, SelectionChangedEventArgs e)
  78. {
  79. }
  80. private void BtnOK_Click(object sender, RoutedEventArgs e)
  81. {
  82. if(cmbNPatch.SelectedItem == null || cmbOPatch.SelectedItem == null)
  83. {
  84. MessageBox.Show("请先选择任务!");
  85. return;
  86. }
  87. NewComp = new TComp
  88. {
  89. CompId = Guid.NewGuid().ToString(),
  90. CreateTime = ThisApp.GetNowTime_yyyyMMddHHmmss(),
  91. NPatchId = ((VPatch)cmbNPatch.SelectedItem).PatchId,
  92. OPatchId = ((VPatch)cmbOPatch.SelectedItem).PatchId,
  93. StandId = ((VPatch)cmbNPatch.SelectedItem).StandId
  94. };
  95. bool result = DBComp.InsertTComp(NewComp);
  96. if (result)
  97. {
  98. this.DialogResult = true;
  99. this.Close();
  100. }
  101. else
  102. {
  103. MessageBox.Show("保存失败,请重试!", "错误", MessageBoxButton.OK, MessageBoxImage.Error);
  104. }
  105. }
  106. private void BtnClose_Click(object sender, RoutedEventArgs e)
  107. {
  108. this.DialogResult = false;
  109. this.Close();
  110. }
  111. }
  112. }