123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341 |
- 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;
- namespace Venus_MainPages.ViewModels
- {
- public class ProcessHistoryViewModel : BindableBase
- {
- private ProcessHistoryView view;
- List<string> keys = new List<string>();
- RealtimeProvider _provider = new RealtimeProvider();
- private ObservableCollection<ParameterNode> _ParameterNodes;
- DispatcherTimer timer = new DispatcherTimer();
- public List<string> RecipesAdd=new List<string>();
- DateTime currentTime;
- 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 string _starttime;
- //public string starttime
- //{ get { return _starttime; } set { SetProperty(ref _starttime, value); } }
- // public string starttime { get; set; }
- public List<HistoryDataItem> ProcessData { get; set; }
- //public List<Recipeslist> CheboxRecipes = new List<Recipeslist>();
- public ProcessHistoryViewModel()
- {
- ProcessChartData = new ProcessDataChartDataItem(60000);
- ParameterNodes = _provider.GetParameters();
- Recipes = new ObservableCollection<RecipeItem>();
- timer.Interval = TimeSpan.FromSeconds(0.5);
- CheboxRecipes = new List<Recipeslist>();
- //CheboxRecipes.Add(new Recipeslist { BoxName = "test" });
- // CheboxRecipes.Add(new Recipeslist { BoxName = "test2" });
- //CheboxRecipes.Add(new Recipeslist { BoxName = "test3" });
- //starttime = "1999-10-01";
- }
- public List<Recipeslist> CheboxRecipes { get; set; }
- public ProcessDataChartDataItem ProcessChartData
- {
- get;
- set;
- }
- 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()
- {
- string path= Path.Combine(QueryDataClient.Instance.Service.GetData("GetRTPath").ToString(), "Recipes","PMA");
- 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])});
- }
- }
- }
- //Path.GetFileName(dir[i]).ToString()
- public DateTime StartDateTime { get; set; }
- public DateTime EndDateTime { get; set; }
- public string SelectedValuePM { get; set; }
- public string RecipeName { get; set; }
- 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 Recipeslist
- {
- public string BoxName { get; set; }
- }
- public class RecipeAdd
- {
- public string Recipesname { get; set; }
- }
- public ObservableCollection<RecipeItem> Recipes { get; set; }
- public ObservableCollection<ParameterNode> ParameterNodes
- {
- get { return _ParameterNodes; }
- set { SetProperty(ref _ParameterNodes, value); }
- }
- public void SearchRecipe()
- {
- //if (MenuPermission != 3) return;
- Console.WriteLine("er");
- 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);
-
- 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.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;
- }
- 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();
- }
-
-
- }
- }
|