RecipeEditorControl.xaml.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. /// <summary>
  37. /// indicate whether recipe modified
  38. /// </summary>
  39. public bool IsRecipeModified
  40. {
  41. get { return ControlViewModel.IsRecipeModified; }
  42. }
  43. /// <summary>
  44. /// RecipeEditor's view model
  45. /// </summary>
  46. public RecipeEditorControlViewModel ControlViewModel { get; set; }
  47. /// <summary>
  48. /// mask recipe item display
  49. /// </summary>
  50. /// <param name="maskedTechNames"></param>
  51. public void SetDisplayMask(HashSet<string> maskedTechNames = null, HashSet<string> maskedCatalogNames = null)
  52. {
  53. if (ControlViewModel != null)
  54. {
  55. ControlViewModel.MaskedTechNames = maskedTechNames;
  56. ControlViewModel.MaskedCatalogNames = maskedCatalogNames;
  57. ControlViewModel.RefreshCellsDisplay(false);
  58. }
  59. }
  60. public void SetEnableBarcode(bool enabled)
  61. {
  62. if (ControlViewModel != null)
  63. {
  64. ControlViewModel.EnableBarcode(enabled);
  65. }
  66. }
  67. public void SetUser(string user)
  68. {
  69. if (ControlViewModel != null)
  70. {
  71. ControlViewModel.SetCurrentUser(user);
  72. }
  73. }
  74. public void SetEndPointDefaultValue(string defaultValue)
  75. {
  76. if (ControlViewModel != null)
  77. {
  78. ControlViewModel.SetEndPointDefaultValue(defaultValue);
  79. }
  80. }
  81. /// <summary>
  82. /// loaded handling
  83. /// </summary>
  84. /// <param name="sender"></param>
  85. /// <param name="e"></param>
  86. void RecipeEditorView_Loaded(object sender, RoutedEventArgs e)
  87. {
  88. grid1.DataContext = ControlViewModel;
  89. }
  90. /// <summary>
  91. /// open recipe file
  92. /// </summary>
  93. /// <param name="sender"></param>
  94. /// <param name="e"></param>
  95. private void OpenButtonPanelLoaded(object sender, RoutedEventArgs e)
  96. {
  97. try
  98. {
  99. string variation = (string)((Button)sender).Tag;
  100. ControlViewModel.OpenLocalRecipe(variation);
  101. }
  102. catch (Exception ex)
  103. {
  104. System.Diagnostics.Debug.WriteLine(ex.Message);
  105. }
  106. }
  107. /// <summary>
  108. /// update recipe variations
  109. /// </summary>
  110. /// <param name="sender"></param>
  111. /// <param name="e"></param>
  112. private void NewButtonPanelLoaded(object sender, RoutedEventArgs e)
  113. {
  114. try
  115. {
  116. string variation = (string)((Button)sender).Tag;
  117. newButton.IsOpen = false;
  118. XmlDocument doc = new XmlDocument();
  119. var dir = new System.IO.FileInfo(Process.GetCurrentProcess().MainModule.FileName).Directory;
  120. string xmlPath = dir + "\\Config\\" + variation + ".xml";
  121. doc.Load(xmlPath);
  122. ControlViewModel.LoadRecipe(doc.SelectSingleNode("/Aitex/TableRecipeFormat").OuterXml, doc.SelectSingleNode("/Aitex/TableRecipeData").OuterXml);
  123. }
  124. catch (Exception ex)
  125. {
  126. System.Diagnostics.Debug.WriteLine(ex.Message);
  127. }
  128. }
  129. public void UpdateCultureResource(string culture)
  130. {
  131. return;
  132. ////string culture = language == 2 ? "zh-CN" : "en-US";
  133. ////Copy all MergedDictionarys into a auxiliar list.
  134. //var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
  135. ////Search for the specified culture.
  136. //string requestedCulture = string.Format(@"/RecipeEditorControl;component/Resources/StringResources.{0}.xaml", culture);
  137. //var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  138. //if (resourceDictionary == null)
  139. //{
  140. // //If not found, select our default language.
  141. // requestedCulture = "StringResources.xaml";
  142. // resourceDictionary = dictionaryList.
  143. // FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
  144. //}
  145. ////If we have the requested resource, remove it from the list and place at the end.
  146. ////Then this language will be our string table to use.
  147. //if (resourceDictionary != null)
  148. //{
  149. // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
  150. // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
  151. //}
  152. ////Inform the threads of the new culture.
  153. //Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
  154. //Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
  155. }
  156. private void UIElement_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
  157. {
  158. e.Handled = !IsTextAllowed(e.Text);
  159. }
  160. private static bool IsTextAllowed(string text)
  161. {
  162. return true;
  163. //Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
  164. //return !regex.IsMatch(text);
  165. }
  166. }
  167. }