终端一体化运控平台
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

245 linhas
12 KiB

  1. using BPASmartClient.Helper;
  2. using FryPot_DosingSystem.FryPotStatus;
  3. using Microsoft.Toolkit.Mvvm.ComponentModel;
  4. using Microsoft.Toolkit.Mvvm.Input;
  5. using System;
  6. using System.Collections.Generic;
  7. using System.Collections.ObjectModel;
  8. using System.IO;
  9. using System.Linq;
  10. using System.Runtime.Serialization.Formatters.Binary;
  11. using System.Text;
  12. using System.Threading.Tasks;
  13. using System.Windows;
  14. using System.Windows.Forms;
  15. namespace FryPot_DosingSystem.ViewModel
  16. {
  17. internal class SqliteDataViewModel : ObservableObject
  18. {
  19. public ObservableCollection<PotOneStatus> StatusOne { get; set; } = new ObservableCollection<PotOneStatus>();
  20. public ObservableCollection<PotTwoStatus> StatusTwo { get; set; } = new ObservableCollection<PotTwoStatus>();
  21. public ObservableCollection<PotThreeStatus> StatusThree { get; set; } = new ObservableCollection<PotThreeStatus>();
  22. public ObservableCollection<PotFourStatus> StatusFour { get; set; } = new ObservableCollection<PotFourStatus>();
  23. public ObservableCollection<PotFiveStatus> StatusFive { get; set; } = new ObservableCollection<PotFiveStatus>();
  24. public ObservableCollection<object> Status { get; set; } = new ObservableCollection<object>();
  25. public Visibility fryOneDataVisible { get { return _fryOneDataVisible; } set { _fryOneDataVisible = value; OnPropertyChanged(); } }
  26. private Visibility _fryOneDataVisible = Visibility.Visible;
  27. public Visibility fryTwoDataVisible { get { return _fryTwoDataVisible; } set { _fryTwoDataVisible = value; OnPropertyChanged(); } }
  28. private Visibility _fryTwoDataVisible = Visibility.Collapsed;
  29. public Visibility fryThreeDataVisible { get { return _fryThreeDataVisible; } set { _fryThreeDataVisible = value; OnPropertyChanged(); } }
  30. private Visibility _fryThreeDataVisible = Visibility.Collapsed;
  31. public Visibility fryFourDataVisible { get { return _fryFourDataVisible; } set { _fryFourDataVisible = value; OnPropertyChanged(); } }
  32. private Visibility _fryFourDataVisible = Visibility.Collapsed;
  33. public Visibility fryFiveDataVisible { get { return _fryFiveDataVisible; } set { _fryFiveDataVisible = value; OnPropertyChanged(); } }
  34. private Visibility _fryFiveDataVisible = Visibility.Collapsed;
  35. public List<string> list { get; set; } = new List<string>() { "1号炒锅", "2号炒锅", "3号炒锅", "4号炒锅", "5号炒锅" };
  36. public string SelectedDate { get; set; }
  37. public string cboSelectedValue { get; set; }
  38. public RelayCommand SelectCommand { get; set; }
  39. public SqliteDataViewModel()
  40. {
  41. SelectCommand = new RelayCommand(() =>
  42. {
  43. #region 旧版本
  44. //if (SelectedDate != string.Empty && SelectedDate != "" && SelectedDate != null && cboSelectedValue != null && cboSelectedValue != string.Empty && cboSelectedValue != "")
  45. //{
  46. // if (cboSelectedValue == "1号炒锅")
  47. // {
  48. // List<PotOneStatus> listOne = Sqlite<PotOneStatus>.GetInstance.Base.ToList();
  49. // var list = listOne.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
  50. // if (list != null && list.Count() != 0)
  51. // {
  52. // if (StatusOne.Count > 0)
  53. // {
  54. // StatusOne.Clear();
  55. // }
  56. // foreach (var item in list)
  57. // {
  58. // StatusOne.Add(item);
  59. // }
  60. // fryOneDataVisible = Visibility.Visible;
  61. // fryTwoDataVisible = Visibility.Collapsed;
  62. // fryThreeDataVisible = Visibility.Collapsed;
  63. // fryFourDataVisible = Visibility.Collapsed;
  64. // fryFiveDataVisible = Visibility.Collapsed;
  65. // }
  66. // else
  67. // {
  68. // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  69. // }
  70. // }
  71. // if (cboSelectedValue == "2号炒锅")
  72. // {
  73. // List<PotTwoStatus> listTwo = Sqlite<PotTwoStatus>.GetInstance.Base.ToList();
  74. // var list = listTwo.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
  75. // if (list != null && list.Count() != 0)
  76. // {
  77. // if (StatusTwo.Count > 0)
  78. // {
  79. // StatusTwo.Clear();
  80. // }
  81. // foreach (var item in list)
  82. // {
  83. // StatusTwo.Add(item);
  84. // }
  85. // fryOneDataVisible = Visibility.Collapsed;
  86. // fryTwoDataVisible = Visibility.Visible;
  87. // fryThreeDataVisible = Visibility.Collapsed;
  88. // fryFourDataVisible = Visibility.Collapsed;
  89. // fryFiveDataVisible = Visibility.Collapsed;
  90. // }
  91. // else
  92. // {
  93. // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  94. // }
  95. // }
  96. // if (cboSelectedValue == "3号炒锅")
  97. // {
  98. // List<PotThreeStatus> listThree = Sqlite<PotThreeStatus>.GetInstance.Base.ToList();
  99. // var list = listThree.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
  100. // if (list != null && list.Count() != 0)
  101. // {
  102. // if (StatusThree.Count > 0)
  103. // {
  104. // StatusThree.Clear();
  105. // }
  106. // foreach (var item in list)
  107. // {
  108. // StatusThree.Add(item);
  109. // }
  110. // fryOneDataVisible = Visibility.Collapsed;
  111. // fryTwoDataVisible = Visibility.Collapsed;
  112. // fryThreeDataVisible = Visibility.Visible;
  113. // fryFourDataVisible = Visibility.Collapsed;
  114. // fryFiveDataVisible = Visibility.Collapsed;
  115. // }
  116. // else
  117. // {
  118. // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  119. // }
  120. // }
  121. // if (cboSelectedValue == "4号炒锅")
  122. // {
  123. // List<PotFourStatus> listFour = Sqlite<PotFourStatus>.GetInstance.Base.ToList();
  124. // var list = listFour.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
  125. // if (list != null && list.Count() != 0)
  126. // {
  127. // if (StatusFour.Count > 0)
  128. // {
  129. // StatusFour.Clear();
  130. // }
  131. // foreach (var item in list)
  132. // {
  133. // StatusFour.Add(item);
  134. // }
  135. // fryOneDataVisible = Visibility.Collapsed;
  136. // fryTwoDataVisible = Visibility.Collapsed;
  137. // fryThreeDataVisible = Visibility.Collapsed;
  138. // fryFourDataVisible = Visibility.Visible;
  139. // fryFiveDataVisible = Visibility.Collapsed;
  140. // }
  141. // else
  142. // {
  143. // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  144. // }
  145. // }
  146. // if (cboSelectedValue == "5号炒锅")
  147. // {
  148. // List<PotFiveStatus> listFive = Sqlite<PotFiveStatus>.GetInstance.Base.ToList();
  149. // var list = listFive.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
  150. // if (list != null && list.Count() != 0)
  151. // {
  152. // if (StatusFive.Count > 0)
  153. // {
  154. // StatusFive.Clear();
  155. // }
  156. // foreach (var item in list)
  157. // {
  158. // StatusFive.Add(item);
  159. // }
  160. // fryOneDataVisible = Visibility.Collapsed;
  161. // fryTwoDataVisible = Visibility.Collapsed;
  162. // fryThreeDataVisible = Visibility.Collapsed;
  163. // fryFourDataVisible = Visibility.Collapsed;
  164. // fryFiveDataVisible = Visibility.Visible;
  165. // }
  166. // else
  167. // {
  168. // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
  169. // }
  170. // }
  171. //}
  172. #endregion
  173. using (OpenFileDialog openFile = new OpenFileDialog())
  174. {
  175. openFile.Title = "请选择对应数据文件";
  176. openFile.Filter = "*.BIN|*.bin";
  177. openFile.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\" + "DB\\";
  178. openFile.Multiselect = false;
  179. DialogResult res = openFile.ShowDialog();
  180. if (res == DialogResult.OK)
  181. {
  182. string file = openFile.FileName;
  183. if (Path.GetExtension(file).Equals(".bin"))
  184. {
  185. if (Status.Count > 0)
  186. {
  187. Status.Clear();
  188. }
  189. using (FileStream readStream = new FileStream(file, FileMode.Open, FileAccess.Read))
  190. {
  191. readStream.Position = 0;
  192. while (readStream.Position < readStream.Length)
  193. {
  194. BinaryFormatter bf = new BinaryFormatter();
  195. object a = bf.Deserialize(readStream);
  196. if (a is PotOneStatus p1)
  197. {
  198. Status.Add(p1);
  199. }
  200. if (a is PotTwoStatus p2)
  201. {
  202. Status.Add(p2);
  203. }
  204. if (a is PotThreeStatus p3)
  205. {
  206. Status.Add(p3);
  207. }
  208. if (a is PotFourStatus p4)
  209. {
  210. Status.Add(p4);
  211. }
  212. if (a is PotFiveStatus p5)
  213. {
  214. Status.Add(p5);
  215. }
  216. }
  217. }
  218. }
  219. }
  220. }
  221. });
  222. }
  223. }
  224. }