| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288 | using System;using System.Collections.ObjectModel;using System.Data;using System.Linq;using System.Windows;using Aitex.Core.RT.Log;using MECF.Framework.Common.DataCenter;using OpenSEMI.ClientBase;using VirgoUI.Client.Models.Sys;namespace VirgoUI.Client.Models.History.ProcessHistory{    public class SelectDataViewModel : UiViewModelBase    {        #region         private const int MAX_PARAMETERS = 50;        public DateTime BeginDate { get; set; }        public DateTime StartDateTime { get; set; }        public DateTime EndDateTime { get; set; }                public ObservableCollection<RecipeItem> Recipes { get; set; }        public ObservableCollection<RecipeItem> SelectedRecipes { get; set; }        private ObservableCollection<ParameterNode> _ParameterNodes;        public ObservableCollection<ParameterNode> ParameterNodes        {            get { return _ParameterNodes; }            set { _ParameterNodes = value; NotifyOfPropertyChange("ParameterNodes"); }        }        public ObservableCollection<string> SelectedParameters { get; set; }        object _lockSelection = new object();        public ObservableCollection<string> SourcePM { get; set; }        public string SelectedValuePM { get; set; }        public string RecipeName { get; set; }        #endregion        #region Popup window        public SelectDataViewModel()        {            var now = DateTime.Now;            this.StartDateTime = now;            this.BeginDate = now;            this.StartDateTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);            this.EndDateTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);                   Recipes = new ObservableCollection<RecipeItem>();            SelectedRecipes = new ObservableCollection<RecipeItem>();            SelectedParameters = new ObservableCollection<string>();            ParameterNodes = ProcessHistoryProvider.Instance.GetParameters();            SourcePM = new ObservableCollection<string>(new[] { "PM2", "PM4", "PM6" });        }        protected override void OnActivate()        {            base.OnActivate();           ParameterNodes = ProcessHistoryProvider.Instance.GetParameters();            foreach (var recipeItem in Recipes)            {                recipeItem.Selected = false;            }        }         public void SearchRecipe()        {            Recipes.Clear();            //ObservableCollection<RecipeItem> items = ProcessHistoryProvider.Instance.SearchRecipe();            //foreach (RecipeItem item in items)            //    Recipes.Add(item);            try            {                string sql = $"SELECT * FROM \"process_data\" where \"process_begin_time\" >='{StartDateTime:yyyyMMdd HHmmss}' and \"process_end_time\" <='{EndDateTime:yyyyMMdd HHmmss}' ";                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.Chamber = dbData.Rows[i]["process_in"].ToString();                        item.Status = dbData.Rows[i]["process_status"].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.Write(e);            }        }        public void CheckAllRecipe()        {        }        public void CheckRecipe(RecipeItem recipe)        {            if (recipe.Selected)            {                SelectedRecipes.Add(recipe);            }            else            {                RecipeItem item = SelectedRecipes.FirstOrDefault(t => t.Recipe == recipe.Recipe);                if (item != null)                    SelectedRecipes.Remove(item);            }        }        public void Preset()        {        }        public void UnSelect()        {        }        public void ParameterCheck(ParameterNode node)        {            bool result = RefreshTreeStatusToChild(node);            if (!result)                node.Selected = !node.Selected;            else                RefreshTreeStatusToParent(node);        }        /// <summary>        /// Refresh tree node status from current to children, and add data to SelectedData        /// </summary>        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 //leaf node            {                lock (_lockSelection)                {                    bool flag = SelectedParameters.Contains(node.Name);                    if (node.Selected && !flag)                    {                        if (SelectedParameters.Count < MAX_PARAMETERS)                        {                            SelectedParameters.Add(node.Name);                        }                        else                        {                            DialogBox.ShowWarning("The max number of parameters is 20.");                            return false;                        }                    }                    else if (!node.Selected && flag)                    {                        SelectedParameters.Remove(node.Name);                    }                }            }            return true;        }        /// <summary>        /// Refresh tree node status from current to parent        /// </summary>        /// <param name="node"></param>        /// <returns></returns>        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);            }        }        public void OnTreeSelectedChanged(object obj)        {        }        public void OK()        {            this.TryClose(true);        }        public void Cancel()        {            this.TryClose(false);        }        //public void SelectColor(ChartParameter cp)        //{        //    if (cp == null)        //        return;        //    var dlg = new System.Windows.Forms.ColorDialog();        //    if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)        //    {        //        var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };        //        cp.Color = new SolidColorBrush(newColor);        //    }        //}        #endregion    }}
 |