|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244 |
- using BPA.Helper;
- using FryPot_DosingSystem.FryPotStatus;
- using BPA.Helper;
-
- using System;
- using System.Collections.Generic;
- using System.Collections.ObjectModel;
- using System.IO;
- using System.Linq;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Forms;
-
- namespace FryPot_DosingSystem.ViewModel
- {
- internal class SqliteDataViewModel : NotifyBase
- {
-
- public ObservableCollection<PotOneStatus> StatusOne { get; set; } = new ObservableCollection<PotOneStatus>();
- public ObservableCollection<PotTwoStatus> StatusTwo { get; set; } = new ObservableCollection<PotTwoStatus>();
- public ObservableCollection<PotThreeStatus> StatusThree { get; set; } = new ObservableCollection<PotThreeStatus>();
- public ObservableCollection<PotFourStatus> StatusFour { get; set; } = new ObservableCollection<PotFourStatus>();
- public ObservableCollection<PotFiveStatus> StatusFive { get; set; } = new ObservableCollection<PotFiveStatus>();
-
- public ObservableCollection<object> Status { get; set; } = new ObservableCollection<object>();
-
- public Visibility fryOneDataVisible { get { return _fryOneDataVisible; } set { _fryOneDataVisible = value; OnPropertyChanged(); } }
- private Visibility _fryOneDataVisible = Visibility.Visible;
-
- public Visibility fryTwoDataVisible { get { return _fryTwoDataVisible; } set { _fryTwoDataVisible = value; OnPropertyChanged(); } }
- private Visibility _fryTwoDataVisible = Visibility.Collapsed;
-
- public Visibility fryThreeDataVisible { get { return _fryThreeDataVisible; } set { _fryThreeDataVisible = value; OnPropertyChanged(); } }
- private Visibility _fryThreeDataVisible = Visibility.Collapsed;
- public Visibility fryFourDataVisible { get { return _fryFourDataVisible; } set { _fryFourDataVisible = value; OnPropertyChanged(); } }
- private Visibility _fryFourDataVisible = Visibility.Collapsed;
- public Visibility fryFiveDataVisible { get { return _fryFiveDataVisible; } set { _fryFiveDataVisible = value; OnPropertyChanged(); } }
- private Visibility _fryFiveDataVisible = Visibility.Collapsed;
-
- public List<string> list { get; set; } = new List<string>() { "1号炒锅", "2号炒锅", "3号炒锅", "4号炒锅", "5号炒锅" };
- public string SelectedDate { get; set; }
- public string cboSelectedValue { get; set; }
- public BPARelayCommand SelectCommand { get; set; }
- public SqliteDataViewModel()
- {
- SelectCommand = new BPARelayCommand(() =>
- {
- #region 旧版本
- //if (SelectedDate != string.Empty && SelectedDate != "" && SelectedDate != null && cboSelectedValue != null && cboSelectedValue != string.Empty && cboSelectedValue != "")
- //{
- // if (cboSelectedValue == "1号炒锅")
- // {
- // List<PotOneStatus> listOne = Sqlite<PotOneStatus>.GetInstance.Base.ToList();
- // var list = listOne.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
- // if (list != null && list.Count() != 0)
- // {
- // if (StatusOne.Count > 0)
- // {
- // StatusOne.Clear();
- // }
- // foreach (var item in list)
- // {
- // StatusOne.Add(item);
- // }
- // fryOneDataVisible = Visibility.Visible;
- // fryTwoDataVisible = Visibility.Collapsed;
- // fryThreeDataVisible = Visibility.Collapsed;
- // fryFourDataVisible = Visibility.Collapsed;
- // fryFiveDataVisible = Visibility.Collapsed;
- // }
- // else
- // {
- // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- // }
-
- // }
- // if (cboSelectedValue == "2号炒锅")
- // {
- // List<PotTwoStatus> listTwo = Sqlite<PotTwoStatus>.GetInstance.Base.ToList();
- // var list = listTwo.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
- // if (list != null && list.Count() != 0)
- // {
- // if (StatusTwo.Count > 0)
- // {
- // StatusTwo.Clear();
- // }
- // foreach (var item in list)
- // {
- // StatusTwo.Add(item);
- // }
- // fryOneDataVisible = Visibility.Collapsed;
- // fryTwoDataVisible = Visibility.Visible;
- // fryThreeDataVisible = Visibility.Collapsed;
- // fryFourDataVisible = Visibility.Collapsed;
- // fryFiveDataVisible = Visibility.Collapsed;
- // }
- // else
- // {
- // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- // }
- // }
- // if (cboSelectedValue == "3号炒锅")
- // {
- // List<PotThreeStatus> listThree = Sqlite<PotThreeStatus>.GetInstance.Base.ToList();
- // var list = listThree.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
- // if (list != null && list.Count() != 0)
- // {
- // if (StatusThree.Count > 0)
- // {
- // StatusThree.Clear();
- // }
- // foreach (var item in list)
- // {
- // StatusThree.Add(item);
- // }
- // fryOneDataVisible = Visibility.Collapsed;
- // fryTwoDataVisible = Visibility.Collapsed;
- // fryThreeDataVisible = Visibility.Visible;
- // fryFourDataVisible = Visibility.Collapsed;
- // fryFiveDataVisible = Visibility.Collapsed;
- // }
- // else
- // {
- // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- // }
- // }
- // if (cboSelectedValue == "4号炒锅")
- // {
- // List<PotFourStatus> listFour = Sqlite<PotFourStatus>.GetInstance.Base.ToList();
- // var list = listFour.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
- // if (list != null && list.Count() != 0)
- // {
- // if (StatusFour.Count > 0)
- // {
- // StatusFour.Clear();
- // }
- // foreach (var item in list)
- // {
- // StatusFour.Add(item);
- // }
- // fryOneDataVisible = Visibility.Collapsed;
- // fryTwoDataVisible = Visibility.Collapsed;
- // fryThreeDataVisible = Visibility.Collapsed;
- // fryFourDataVisible = Visibility.Visible;
- // fryFiveDataVisible = Visibility.Collapsed;
- // }
- // else
- // {
- // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- // }
- // }
- // if (cboSelectedValue == "5号炒锅")
- // {
- // List<PotFiveStatus> listFive = Sqlite<PotFiveStatus>.GetInstance.Base.ToList();
- // var list = listFive.Where(p => p.Time.Equals(Convert.ToDateTime(SelectedDate).ToShortDateString()));
- // if (list != null && list.Count() != 0)
- // {
- // if (StatusFive.Count > 0)
- // {
- // StatusFive.Clear();
- // }
- // foreach (var item in list)
- // {
- // StatusFive.Add(item);
- // }
- // fryOneDataVisible = Visibility.Collapsed;
- // fryTwoDataVisible = Visibility.Collapsed;
- // fryThreeDataVisible = Visibility.Collapsed;
- // fryFourDataVisible = Visibility.Collapsed;
- // fryFiveDataVisible = Visibility.Visible;
- // }
- // else
- // {
- // MessageBox.Show("未找到对应数据", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
- // }
- // }
- //}
- #endregion
-
- using (OpenFileDialog openFile = new OpenFileDialog())
- {
- openFile.Title = "请选择对应数据文件";
- openFile.Filter = "*.BIN|*.bin";
- openFile.InitialDirectory = AppDomain.CurrentDomain.BaseDirectory + "AccessFile\\" + "DB\\";
- openFile.Multiselect = false;
- DialogResult res = openFile.ShowDialog();
- if (res == DialogResult.OK)
- {
- string file = openFile.FileName;
- if (Path.GetExtension(file).Equals(".bin"))
- {
- if (Status.Count > 0)
- {
- Status.Clear();
- }
- using (FileStream readStream = new FileStream(file, FileMode.Open, FileAccess.Read))
- {
- readStream.Position = 0;
- while (readStream.Position < readStream.Length)
- {
- BinaryFormatter bf = new BinaryFormatter();
- object a = bf.Deserialize(readStream);
- if (a is PotOneStatus p1)
- {
-
- Status.Add(p1);
-
- }
- if (a is PotTwoStatus p2)
- {
-
- Status.Add(p2);
-
- }
- if (a is PotThreeStatus p3)
- {
-
- Status.Add(p3);
-
- }
- if (a is PotFourStatus p4)
- {
-
- Status.Add(p4);
-
- }
- if (a is PotFiveStatus p5)
- {
-
- Status.Add(p5);
-
- }
- }
- }
- }
- }
- }
-
- });
- }
- }
- }
|