SelectDataViewModel.cs 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. using System;
  2. using System.Collections.ObjectModel;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Windows;
  6. using Aitex.Core.RT.Log;
  7. using MECF.Framework.Common.DataCenter;
  8. using OpenSEMI.ClientBase;
  9. using VirgoUI.Client.Models.Sys;
  10. namespace VirgoUI.Client.Models.History.ProcessHistory
  11. {
  12. public class SelectDataViewModel : UiViewModelBase
  13. {
  14. #region
  15. private const int MAX_PARAMETERS = 50;
  16. public DateTime BeginDate { get; set; }
  17. public DateTime StartDateTime { get; set; }
  18. public DateTime EndDateTime { get; set; }
  19. public ObservableCollection<RecipeItem> Recipes { get; set; }
  20. public ObservableCollection<RecipeItem> SelectedRecipes { get; set; }
  21. private ObservableCollection<ParameterNode> _ParameterNodes;
  22. public ObservableCollection<ParameterNode> ParameterNodes
  23. {
  24. get { return _ParameterNodes; }
  25. set { _ParameterNodes = value; NotifyOfPropertyChange("ParameterNodes"); }
  26. }
  27. public ObservableCollection<string> SelectedParameters { get; set; }
  28. object _lockSelection = new object();
  29. public ObservableCollection<string> SourcePM { get; set; }
  30. public string SelectedValuePM { get; set; }
  31. public string RecipeName { get; set; }
  32. #endregion
  33. #region Popup window
  34. public SelectDataViewModel()
  35. {
  36. var now = DateTime.Now;
  37. this.StartDateTime = now;
  38. this.BeginDate = now;
  39. this.StartDateTime = new DateTime(now.Year, now.Month, now.Day, 0, 0, 0, 0);
  40. this.EndDateTime = new DateTime(now.Year, now.Month, now.Day, 23, 59, 59, 999);
  41. Recipes = new ObservableCollection<RecipeItem>();
  42. SelectedRecipes = new ObservableCollection<RecipeItem>();
  43. SelectedParameters = new ObservableCollection<string>();
  44. ParameterNodes = ProcessHistoryProvider.Instance.GetParameters();
  45. SourcePM = new ObservableCollection<string>(new[] { "PM2", "PM4", "PM6" });
  46. }
  47. protected override void OnActivate()
  48. {
  49. base.OnActivate();
  50. ParameterNodes = ProcessHistoryProvider.Instance.GetParameters();
  51. foreach (var recipeItem in Recipes)
  52. {
  53. recipeItem.Selected = false;
  54. }
  55. }
  56. public void SearchRecipe()
  57. {
  58. Recipes.Clear();
  59. //ObservableCollection<RecipeItem> items = ProcessHistoryProvider.Instance.SearchRecipe();
  60. //foreach (RecipeItem item in items)
  61. // Recipes.Add(item);
  62. try
  63. {
  64. string sql = $"SELECT * FROM \"process_data\" where \"process_begin_time\" >='{StartDateTime:yyyyMMdd HHmmss}' and \"process_end_time\" <='{EndDateTime:yyyyMMdd HHmmss}' ";
  65. if (!string.IsNullOrEmpty(SelectedValuePM))
  66. {
  67. string[] pms = SelectedValuePM.Split(',');
  68. if (pms.Length > 0)
  69. {
  70. sql += " and (FALSE ";
  71. foreach (var pm in pms)
  72. {
  73. sql += $" OR \"process_in\"='{pm}' ";
  74. }
  75. sql += " ) ";
  76. }
  77. }
  78. if (!string.IsNullOrEmpty(RecipeName))
  79. {
  80. sql += string.Format(" and lower(\"recipe_name\") like '%{0}%'", RecipeName.ToLower());
  81. }
  82. sql += " order by \"process_begin_time\" ASC;";
  83. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  84. Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  85. {
  86. if (dbData == null || dbData.Rows.Count == 0)
  87. return;
  88. for (int i = 0; i < dbData.Rows.Count; i++)
  89. {
  90. RecipeItem item = new RecipeItem();
  91. item.Recipe = dbData.Rows[i]["recipe_name"].ToString();
  92. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  93. item.Status = dbData.Rows[i]["process_status"].ToString();
  94. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  95. item.StartTime = ((DateTime)dbData.Rows[i]["process_begin_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
  96. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  97. item.EndTime = ((DateTime)dbData.Rows[i]["process_end_time"]).ToString("yyyy-MM-dd HH:mm:ss.fff");
  98. Recipes.Add(item);
  99. }
  100. }));
  101. }
  102. catch (Exception e)
  103. {
  104. LOG.Write(e);
  105. }
  106. }
  107. public void CheckAllRecipe()
  108. {
  109. }
  110. public void CheckRecipe(RecipeItem recipe)
  111. {
  112. if (recipe.Selected)
  113. {
  114. SelectedRecipes.Add(recipe);
  115. }
  116. else
  117. {
  118. RecipeItem item = SelectedRecipes.FirstOrDefault(t => t.Recipe == recipe.Recipe);
  119. if (item != null)
  120. SelectedRecipes.Remove(item);
  121. }
  122. }
  123. public void Preset()
  124. {
  125. }
  126. public void UnSelect()
  127. {
  128. }
  129. public void ParameterCheck(ParameterNode node)
  130. {
  131. bool result = RefreshTreeStatusToChild(node);
  132. if (!result)
  133. node.Selected = !node.Selected;
  134. else
  135. RefreshTreeStatusToParent(node);
  136. }
  137. /// <summary>
  138. /// Refresh tree node status from current to children, and add data to SelectedData
  139. /// </summary>
  140. private bool RefreshTreeStatusToChild(ParameterNode node)
  141. {
  142. if (node.ChildNodes.Count > 0)
  143. {
  144. for (int i = 0; i < node.ChildNodes.Count; i++)
  145. {
  146. ParameterNode n = node.ChildNodes[i];
  147. n.Selected = node.Selected;
  148. if (!RefreshTreeStatusToChild(n))
  149. {
  150. //uncheck left node
  151. for (int j = i; j < node.ChildNodes.Count; j++)
  152. {
  153. node.ChildNodes[j].Selected = !node.Selected;
  154. }
  155. node.Selected = !node.Selected;
  156. return false;
  157. }
  158. }
  159. }
  160. else //leaf node
  161. {
  162. lock (_lockSelection)
  163. {
  164. bool flag = SelectedParameters.Contains(node.Name);
  165. if (node.Selected && !flag)
  166. {
  167. if (SelectedParameters.Count < MAX_PARAMETERS)
  168. {
  169. SelectedParameters.Add(node.Name);
  170. }
  171. else
  172. {
  173. DialogBox.ShowWarning("The max number of parameters is 20.");
  174. return false;
  175. }
  176. }
  177. else if (!node.Selected && flag)
  178. {
  179. SelectedParameters.Remove(node.Name);
  180. }
  181. }
  182. }
  183. return true;
  184. }
  185. /// <summary>
  186. /// Refresh tree node status from current to parent
  187. /// </summary>
  188. /// <param name="node"></param>
  189. /// <returns></returns>
  190. private void RefreshTreeStatusToParent(ParameterNode node)
  191. {
  192. if (node.ParentNode != null)
  193. {
  194. if (node.Selected)
  195. {
  196. bool flag = true;
  197. for (int i = 0; i < node.ParentNode.ChildNodes.Count; i++)
  198. {
  199. if (!node.ParentNode.ChildNodes[i].Selected)
  200. {
  201. flag = false; //as least one child is unselected
  202. break;
  203. }
  204. }
  205. if (flag)
  206. node.ParentNode.Selected = true;
  207. }
  208. else
  209. {
  210. node.ParentNode.Selected = false;
  211. }
  212. RefreshTreeStatusToParent(node.ParentNode);
  213. }
  214. }
  215. public void OnTreeSelectedChanged(object obj)
  216. {
  217. }
  218. public void OK()
  219. {
  220. this.TryClose(true);
  221. }
  222. public void Cancel()
  223. {
  224. this.TryClose(false);
  225. }
  226. //public void SelectColor(ChartParameter cp)
  227. //{
  228. // if (cp == null)
  229. // return;
  230. // var dlg = new System.Windows.Forms.ColorDialog();
  231. // if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
  232. // {
  233. // var newColor = new System.Windows.Media.Color() { A = dlg.Color.A, B = dlg.Color.B, G = dlg.Color.G, R = dlg.Color.R };
  234. // cp.Color = new SolidColorBrush(newColor);
  235. // }
  236. //}
  237. #endregion
  238. }
  239. }