123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517 |
- using MECF.Framework.Common.DataCenter;
- using System;
- using System.Collections.Generic;
- using System.Data;
- using System.Windows.Media;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using Venus_Core;
- using Prism.Commands;
- using Prism.Mvvm;
- using Venus_MainPages.Unity;
- using Venus_MainPages.Views;
- using System.Collections.ObjectModel;
- using System.Windows.Threading;
- using System.Windows;
- using Aitex.Core.RT.Log;
- using Aitex.Core.UI.ControlDataContext;
- using WPF.Themes.UserControls;
- using System.IO;
- using System.Diagnostics;
- using Aitex.Core.RT.Routine;
- using System.Xml.Linq;
- using System.Windows.Forms;
- namespace Venus_MainPages.ViewModels
- {
- public class ProcessHistoryViewModel : BindableBase
- {
- #region 私有字段
- private ProcessHistoryView view;
- List<string> keys = new List<string>();
- RealtimeProvider _provider = new RealtimeProvider();
- private ObservableCollection<ParameterNode> _ParameterNodes;
- DispatcherTimer timer = new DispatcherTimer();
- ObservableCollection<PdKeyData>_PdKeyDataObservation= new ObservableCollection<PdKeyData>();
- public List<string> RecipesAdd=new List<string>();
- public List<SolidColorBrush> solidColorBrushes = new List<SolidColorBrush>();
- DateTime currentTime;
- private RecipeItem selectedRecipeItem;
- #endregion
- #region 属性
- public List<HistoryDataItem> ProcessData { get; set; }
- public List<Recipeslist> CheboxRecipes { get; set; }
- public ProcessDataChartDataItem ProcessChartData{ get; set; }
- public DateTime StartDateTime { get; set; }
- public DateTime EndDateTime { get; set; }
- public string SelectedValuePM { get; set; }
- public string RecipeName { get; set; }
- public ObservableCollection<RecipeItem> Recipes { get; set; }
-
- public class Recipeslist
- {
- public string BoxName { get; set; }
- }
- public class RecipeAdd
- {
- public string Recipesname { get; set; }
- }
- public ObservableCollection<ParameterNode> ParameterNodes
- {
- get { return _ParameterNodes; }
- set { SetProperty(ref _ParameterNodes, value); }
- }
- public ObservableCollection<PdKeyData> PdKeyDataCollection
- {
- get { return _PdKeyDataObservation; }
- set { SetProperty(ref _PdKeyDataObservation,value); }
- }
- #endregion
- #region 命令
- private DelegateCommand<object> _LoadCommandPD;
- public DelegateCommand<object> LoadCommandPD =>
- _LoadCommandPD ?? (_LoadCommandPD = new DelegateCommand<object>(OnLoadPd));
- private DelegateCommand _SearchRecipeCommand;
- public DelegateCommand SearchRecipeCommand =>
- _SearchRecipeCommand ?? (_SearchRecipeCommand = new DelegateCommand(SearchRecipe));
- private DelegateCommand<object> _PdParameterCheckCommand;
- public DelegateCommand<object> PdParameterCheckCommand=>
- _PdParameterCheckCommand??(_PdParameterCheckCommand=new DelegateCommand<object>(OnParameterCheck));
- private DelegateCommand<object> _DataGridSelectionChangedCommand;
- public DelegateCommand<object> DataGridSelectionChangedCommand =>
- _DataGridSelectionChangedCommand ?? (_DataGridSelectionChangedCommand = new DelegateCommand<object>(OnDataGridSelectionChanged));
- private DelegateCommand _SearchDataCommand;
- public DelegateCommand SearchDataCommand =>
- _SearchDataCommand ?? (_SearchDataCommand = new DelegateCommand(OnSearchData));
- private DelegateCommand _ClearDataCommand;
- public DelegateCommand ClearDataCommand =>
- _ClearDataCommand ?? (_ClearDataCommand = new DelegateCommand(OnClearData));
- #endregion
- #region 构造函数
- public ProcessHistoryViewModel()
- {
- ProcessChartData = new ProcessDataChartDataItem(60000);
-
- Recipes = new ObservableCollection<RecipeItem>();
- timer.Interval = TimeSpan.FromSeconds(0.5);
- CheboxRecipes = new List<Recipeslist>();
- solidColorBrushes.Add(new SolidColorBrush(Colors.Green));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Red));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Blue));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Orange));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Yellow));
- solidColorBrushes.Add(new SolidColorBrush(Colors.YellowGreen));
- solidColorBrushes.Add(new SolidColorBrush(Colors.AliceBlue));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Chocolate));
- solidColorBrushes.Add(new SolidColorBrush(Colors.Cyan));
- solidColorBrushes.Add(new SolidColorBrush(Colors.DarkGreen));
- }
- #endregion
- #region 命令方法
- private void OnLoadPd(Object eventView)
- {
- this.view = (ProcessHistoryView)eventView;
- this.view.wfTimeFrom.Value = DateTime.Today;
- this.view.wfTimeTo.Value = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.Today.Day, 23, 59, 59, 999);
- this.LoadRecipeCheckBox();
- }
- private void LoadRecipeCheckBox()
- {
- List<string> chamber = new List<string>() { "PMA","PMB","PMC","PMD"};
- CheboxRecipes.Clear();
- foreach (string item in chamber)
- {
- string path = Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes", item);
- if (Directory.Exists(path))
- {
- string[] dir = Directory.GetFiles(path);
- for (int i = 0; i < dir.Length; i++)
- {
- CheboxRecipes.Add(new Recipeslist { BoxName = Path.GetFileName(dir[i]) });
- }
- }
- }
- }
- public void SearchRecipe()
- {
- this.StartDateTime = this.view.wfTimeFrom.Value;
- this.EndDateTime = this.view.wfTimeTo.Value;
- Recipes.Clear();
- try
- {
- string sql = $"SELECT * FROM \"process_data\" where \"process_begin_time\" >='{StartDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff")}' and \"process_begin_time\" <='{EndDateTime.ToString("yyyy/MM/dd HH:mm:ss.fff")}' ";
- if (!string.IsNullOrEmpty(SelectedValuePM))
- {
- string[] pms = SelectedValuePM.Split(',');
- if (pms.Length > 0)
- {
- sql += " and (FALSE ";
- foreach (var pm in pms)
- {
- sql += $" OR \"process_in\"='{pm}' ";
- }
- sql += " ) ";
- }
- }
- if (!string.IsNullOrEmpty(RecipeName))
- {
- sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
- }
- sql += " order by \"process_begin_time\" ASC;";
-
- DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
- System.Windows.Application.Current.Dispatcher.BeginInvoke(new Action(() =>
- {
- if (dbData == null || dbData.Rows.Count == 0) return;
- for (int i = 0; i < dbData.Rows.Count; i++)
- {
- RecipeItem item = new RecipeItem();
- item.Selected = false;
- item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
- item.Guid = dbData.Rows[i]["guid"].ToString();
- item.RecipeRunGuid = dbData.Rows[i]["wafer_data_guid"].ToString();
- item.Chamber = dbData.Rows[i]["process_in"].ToString();
- item.Status = dbData.Rows[i]["process_status"].ToString();
- item.SlotID = dbData.Rows[i]["slot_id"].ToString();
- item.LotID = dbData.Rows[i]["lot_id"].ToString();
- if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
- item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
- item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
- Recipes.Add(item);
- }
- }));
- }
- catch (Exception e)
- {
- LOG.WriteExeption(e);
- }
- }
- private void CalKeys(ParameterNode parameterNode)
- {
- if (parameterNode.ChildNodes.Count > 0)
- {
- foreach (var item in parameterNode.ChildNodes)
- {
- CalKeys(item);
- }
- }
- else
- {
- if (parameterNode.Selected == true)
- {
- keys.Add(parameterNode.Name);
- }
- }
- }
- private Dictionary<string, List<HistoryDataItem>> GetData(List<string> keys, DateTime from, DateTime to)
- {
- string sql = "select time AS InternalTimeStamp";
- foreach (var dataId in keys)
- {
- sql += "," + string.Format("\"{0}\"", dataId);
- }
- sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc",
- from.ToString("yyyyMMdd") + "." + "Data", from.Ticks, to.Ticks);
- DataTable dataTable = QueryDataClient.Instance.Service.QueryData(sql);
- Dictionary<string, List<HistoryDataItem>> historyData = new Dictionary<string, List<HistoryDataItem>>();
- if (dataTable == null || dataTable.Rows.Count == 0)
- return null;
- DateTime dt = new DateTime();
- Dictionary<int, string> colName = new Dictionary<int, string>();
- for (int colNo = 0; colNo < dataTable.Columns.Count; colNo++)
- {
- colName.Add(colNo, dataTable.Columns[colNo].ColumnName);
- historyData[dataTable.Columns[colNo].ColumnName] = new List<HistoryDataItem>();
- }
- for (int rowNo = 0; rowNo < dataTable.Rows.Count; rowNo++)
- {
- PointCollection points = new PointCollection();
- var row = dataTable.Rows[rowNo];
- for (int i = 0; i < dataTable.Columns.Count; i++)
- {
- HistoryDataItem data = new HistoryDataItem();
- if (i == 0)
- {
- long ticks = (long)row[i];
- dt = new DateTime(ticks);
- continue;
- }
- else
- {
- string dataId = colName[i];
- if (row[i] is DBNull || row[i] == null)
- {
- data.dateTime = dt;
- data.dbName = colName[i];
- data.value = 0;
- }
- else if (row[i] is bool)
- {
- data.dateTime = dt;
- data.dbName = colName[i];
- data.value = (bool)row[i] ? 1 : 0;
- }
- else
- {
- data.dateTime = dt;
- data.dbName = colName[i];
- data.value = float.Parse(row[i].ToString());
- }
- }
- historyData[data.dbName].Add(data);
- }
- }
- foreach (var item in historyData)
- {
- item.Value.Sort((x, y) => DateTime.Compare(x.dateTime, y.dateTime));
- }
- return historyData;
- }
- private bool RefreshTreeStatusToChild(ParameterNode node)
- {
- if (node.ChildNodes.Count > 0)
- {
- for (int i = 0; i < node.ChildNodes.Count; i++)
- {
- ParameterNode n = node.ChildNodes[i];
- n.Selected = node.Selected;
- if (!RefreshTreeStatusToChild(n))
- {
- //uncheck left node
- for (int j = i; j < node.ChildNodes.Count; j++)
- {
- node.ChildNodes[j].Selected = !node.Selected;
- }
- //node.Selected = !node.Selected;
- return false;
- }
- }
- }
- //else
- //{
- // if (node.Selected == true)
- // {
- // keys.Add(node.Name);
- // }
- // else
- // {
- // keys.Remove(node.Name);
- // }
- //}
- return true;
- }
- private void RefreshTreeStatusToParent(ParameterNode node)
- {
- if (node.ParentNode != null)
- {
- if (node.Selected)
- {
- bool flag = true;
- for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
- {
- if (!node.ParentNode.ChildNodes[i].Selected)
- {
- flag = false; //as least one child is unselected
- break;
- }
- }
- if (flag)
- node.ParentNode.Selected = true;
- }
- else
- {
- node.ParentNode.Selected = false;
- }
- RefreshTreeStatusToParent(node.ParentNode);
- }
- }
- private void OnParameterCheck(object obj)
- {
- ParameterNode node = obj as ParameterNode;
- if (!RefreshTreeStatusToChild(node))
- {
- node.Selected = !node.Selected;
- }
- else
- {
- RefreshTreeStatusToParent(node);
- }
- keys.Clear();
- for (int i = 0; i < ParameterNodes.Count; i++)
- {
- CalKeys(ParameterNodes[i]);
- }
- if (keys.Count > 10)
- {
- WPFMessageBox.ShowWarning("最多显示10个数据");
- return;
- }
- PdKeyDataCollection.Clear();
- for (int i = 0; i < keys.Count; i++)
- {
- if (i == 10)
- {
- break;
- }
- PdKeyDataCollection.Add(new PdKeyData() { Key = keys[i], Color = solidColorBrushes[i] });
- }
- }
- public void UpdateData(RecipeItem dataLog)
- {
- if (dataLog == null)
- {
- this.view.MyDrawGraphicsControl.ClearPlotPoints();
- return;
- }
- keys.Clear();
- for (int i = 0; i < ParameterNodes.Count; i++)
- {
- CalKeys(ParameterNodes[i]);
- }
- if (keys.Count > 10)
- {
- WPFMessageBox.ShowWarning("最多显示10个数据");
- return;
- }
- //Application.Current.Dispatcher.Invoke(new Action(() =>
- //{
- // string type = "A";
- // string s = dataLog.Chamber;
- // if (dataLog.Chamber == "PMA")
- // {
- // //keys = new List<string> { "IO.PMA.AI_Chamber_Pressure", "PMA.Rf.PowerSetPoint", "PMA.Rf.ForwardPower", "PMA.Rf.ReflectPower", "PMA.IoMfc.MfcGas1.FeedBack", "PMA.IoMfc.MfcGas1.SetPoint", "PMA.IoMfc.MfcGas2.FeedBack", "PMA.IoMfc.MfcGas2.SetPoint", "PMA.IoMfc.MfcGas3.FeedBack", "PMA.IoMfc.MfcGas3.SetPoint" };
- // if ((bool)QueryDataClient.Instance.Service.GetConfig($"PMA.BiasRf.EnableBiasRF"))
- // type = "A";
- // }
- // else if (dataLog.Chamber == "PMB")
- // {
- // // keys = new List<string> { "IO.PMB.AI_Chamber_Pressure", "PMB.Rf.PowerSetPoint", "PMB.Rf.ForwardPower", "PMB.Rf.ReflectPower", "PMB.IoMfc.MfcGas1.FeedBack", "PMB.IoMfc.MfcGas1.SetPoint", "PMB.IoMfc.MfcGas2.FeedBack", "PMB.IoMfc.MfcGas2.SetPoint", "PMB.IoMfc.MfcGas3.FeedBack", "PMB.IoMfc.MfcGas3.SetPoint" };
- // if ((bool)QueryDataClient.Instance.Service.GetConfig($"PMB.BiasRf.EnableBiasRF"))
- // type = "B";
- // }
- //}));
- this.view.MyDrawGraphicsControl.ClearPlotPoints();
- DateTime dtFrom = Convert.ToDateTime(dataLog.StartTime);
- DateTime dtTo = dtFrom.AddMinutes(10);
- if (!string.IsNullOrEmpty(dataLog.EndTime))
- {
- dtTo = Convert.ToDateTime(dataLog.EndTime);
- }
- var result = GetData(keys.Distinct().ToList(), dtFrom, dtTo);
- //var result = GetData(keys.Distinct().ToList(), this.view.wfTimeFrom.Value, this.view.wfTimeTo.Value);
- List<PointCollection> cls = new List<PointCollection>();
- for (int i = 0; i < keys.Count; i++)
- {
- PointCollection points = new PointCollection();
- int k = 1;
- result[keys[i]].ForEach(point =>
- {
- points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
- k += 1;
- });
- cls.Add(points);
- }
- this.view.MyDrawGraphicsControl.PointCollections = cls;
- this.view.MyDrawGraphicsControl.FitControl();
- }
- private void OnDataGridSelectionChanged(object obj)
- {
- selectedRecipeItem = obj as RecipeItem;
- ParameterNodes = new ObservableCollection<ParameterNode>(_provider.GetParameters().Where(x => x.Name == selectedRecipeItem?.Chamber));
- }
- private void OnSearchData()
- {
- this.view.MyDrawGraphicsControl.ClearPlotPoints();
- var Keys = new List<string>();
- PdKeyDataCollection.ToList().ForEach(key =>
- {
- Keys.Add(key.Key);
- });
- if (keys.Count == 0)
- {
- return;
- }
- var result = GetData(Keys.Distinct().ToList(), Convert.ToDateTime(selectedRecipeItem?.StartTime) , Convert.ToDateTime(selectedRecipeItem?.EndTime) );
- if (result == null)
- {
- return;
- }
- List<PointCollection> cls = new List<PointCollection>();
- for (int i = 0; i < Keys.Count; i++)
- {
- PointCollection points = new PointCollection();
- int k = 1;
- result[Keys[i]].ForEach(point =>
- {
- points.Add(new Point() { X = point.dateTime.ToOADate(), Y = point.value });
- k += 1;
- });
- cls.Add(points);
- }
- this.view.MyDrawGraphicsControl.PointCollections = cls;
- this.view.MyDrawGraphicsControl.FitControl();
- }
- private void OnClearData()
- {
-
- }
- }
- #endregion
- #region 数据类
- public class RecipeItem
- {
- public bool Selected { get; set; }
- public string Recipe { get; set; }
- public string Guid { get; set; }
- public string RecipeRunGuid { get; set; }
- public string Chamber { get; set; }
- public string Status { get; set; }
- public string StartTime { get; set; }
- public string EndTime { get; set; }
- public string LotID { get; set; }
- public string SlotID { get; set; }
- }
- public class PdKeyData
- {
- public string Key { get; set; }
- public SolidColorBrush Color { get; set; }
- }
- #endregion
- }
|