RecipeEditorControl.xaml.cs 6.4 KB

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