终端一体化运控平台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

245 lines
12 KiB

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