RecipeEditorControl.xaml.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Globalization;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using System.Threading;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. using System.Windows.Documents;
  12. using System.Windows.Input;
  13. using System.Windows.Media;
  14. using System.Windows.Media.Imaging;
  15. using System.Windows.Navigation;
  16. using System.Windows.Shapes;
  17. using System.Collections.ObjectModel;
  18. using Xceed.Wpf.DataGrid;
  19. using System.Xml;
  20. using System.IO;
  21. using System.Runtime.Serialization.Formatters.Binary;
  22. using System.Diagnostics;
  23. namespace Aitex.UI.RecipeEditor
  24. {
  25. /// <summary>
  26. /// Interaction logic for RecipeEditorControl.xaml
  27. /// </summary>
  28. public partial class RecipeEditorControl : UserControl
  29. {
  30. public RecipeEditorControl()
  31. {
  32. InitializeComponent();
  33. ControlViewModel = new RecipeEditorControlViewModel() { DataGridControl = this.dataGrid1 };
  34. Loaded += new RoutedEventHandler(RecipeEditorView_Loaded);
  35. }
  36. #if false
  37. /// <summary>
  38. /// TEST MASK DISPLAY
  39. /// </summary>
  40. /// <param name="sender"></param>
  41. /// <param name="e"></param>
  42. void RecipeEditorView_MouseDoubleClick(object sender, MouseButtonEventArgs e)
  43. {
  44. var ss = new HashSet<string>();
  45. ss.Add("M_NH3_E_Push_H2");
  46. ss.Add("CZone.Setpoint");
  47. ss.Add("VentMO.Mode");
  48. var tt = new HashSet<string>();
  49. tt.Add("吹扫");
  50. tt.Add("MO源");
  51. SetDisplayMask(ss, tt);
  52. }
  53. #endif
  54. /// <summary>
  55. /// indicate whether recipe modified
  56. /// </summary>
  57. public bool IsRecipeModified
  58. {
  59. get { return ControlViewModel.IsRecipeModified; }
  60. }
  61. /// <summary>
  62. /// RecipeEditor's view model
  63. /// </summary>
  64. public RecipeEditorControlViewModel ControlViewModel { get; set; }
  65. /// <summary>
  66. /// mask recipe item display
  67. /// </summary>
  68. /// <param name="maskedTechNames"></param>
  69. public void SetDisplayMask(HashSet<string> maskedTechNames = null, HashSet<string> maskedCatalogNames = null)
  70. {
  71. if (ControlViewModel != null)
  72. {
  73. ControlViewModel.MaskedTechNames = maskedTechNames;
  74. ControlViewModel.MaskedCatalogNames = maskedCatalogNames;
  75. ControlViewModel.RefreshCellsDisplay(false);
  76. }
  77. }
  78. public void SetEnableBarcode(bool enabled)
  79. {
  80. if (ControlViewModel != null)
  81. {
  82. ControlViewModel.EnableBarcode(enabled);
  83. }
  84. }
  85. public void SetUser(string user)
  86. {
  87. if (ControlViewModel != null)
  88. {
  89. ControlViewModel.SetCurrentUser(user);
  90. }
  91. }
  92. /// <summary>
  93. /// loaded handling
  94. /// </summary>
  95. /// <param name="sender"></param>
  96. /// <param name="e"></param>
  97. void RecipeEditorView_Loaded(object sender, RoutedEventArgs e)
  98. {
  99. grid1.DataContext = ControlViewModel;
  100. }
  101. /// <summary>
  102. /// open recipe file
  103. /// </summary>
  104. /// <param name="sender"></param>
  105. /// <param name="e"></param>
  106. private void OpenButtonPanelLoaded(object sender, RoutedEventArgs e)
  107. {
  108. try
  109. {
  110. string variation = (string)((Button)sender).Tag;
  111. ControlViewModel.OpenLocalRecipe(variation);
  112. }
  113. catch (Exception ex)
  114. {
  115. System.Diagnostics.Debug.WriteLine(ex.Message);
  116. }
  117. }
  118. /// <summary>
  119. /// update recipe variations
  120. /// </summary>
  121. /// <param name="sender"></param>
  122. /// <param name="e"></param>
  123. private void NewButtonPanelLoaded(object sender, RoutedEventArgs e)
  124. {
  125. try
  126. {
  127. string variation = (string)((Button)sender).Tag;
  128. newButton.IsOpen = false;
  129. XmlDocument doc = new XmlDocument();
  130. var dir = new System.IO.FileInfo(Process.GetCurrentProcess().MainModule.FileName).Directory;
  131. string xmlPath = dir + "\\Config\\" + variation + ".xml";
  132. doc.Load(xmlPath);
  133. ControlViewModel.LoadRecipe(doc.SelectSingleNode("/Aitex/TableRecipeFormat").OuterXml, doc.SelectSingleNode("/Aitex/TableRecipeData").OuterXml);
  134. }
  135. catch (Exception ex)
  136. {
  137. System.Diagnostics.Debug.WriteLine(ex.Message);
  138. }
  139. }
  140. public void UpdateCultureResource(string culture)
  141. {
  142. //string culture = language == 2 ? "zh-CN" : "en-US";
  143. //Copy all MergedDictionarys into a auxiliar list.
  144. var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
  145. //Search for the specified culture.
  146. string requestedCulture = string.Format(@"/RecipeEditorControl;component/Resources/StringResources.{0}.xaml", culture);
  147. var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  148. if (resourceDictionary == null)
  149. {
  150. //If not found, select our default language.
  151. requestedCulture = "StringResources.xaml";
  152. resourceDictionary = dictionaryList.
  153. FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  154. }
  155. //If we have the requested resource, remove it from the list and place at the end.
  156. //Then this language will be our string table to use.
  157. if (resourceDictionary != null)
  158. {
  159. Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
  160. Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
  161. }
  162. //Inform the threads of the new culture.
  163. Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
  164. Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
  165. }
  166. private void UIElement_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  167. {
  168. e.Handled = !IsTextAllowed(e.Text);
  169. }
  170. private static bool IsTextAllowed(string text)
  171. {
  172. return true;
  173. //Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
  174. //return !regex.IsMatch(text);
  175. }
  176. }
  177. }