123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- using System;
- using System.Collections.Generic;
- using System.Globalization;
- using System.Linq;
- using System.Text;
- using System.Text.RegularExpressions;
- using System.Threading;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- using System.Collections.ObjectModel;
- using Xceed.Wpf.DataGrid;
- using System.Xml;
- using System.IO;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.Diagnostics;
- namespace Aitex.UI.RecipeEditor
- {
- /// <summary>
- /// Interaction logic for RecipeEditorControl.xaml
- /// </summary>
- public partial class RecipeEditorControl : UserControl
- {
- public RecipeEditorControl()
- {
- InitializeComponent();
- ControlViewModel = new RecipeEditorControlViewModel() { DataGridControl = this.dataGrid1 };
- Loaded += new RoutedEventHandler(RecipeEditorView_Loaded);
- }
- /// <summary>
- /// indicate whether recipe modified
- /// </summary>
- public bool IsRecipeModified
- {
- get { return ControlViewModel.IsRecipeModified; }
- }
- /// <summary>
- /// RecipeEditor's view model
- /// </summary>
- public RecipeEditorControlViewModel ControlViewModel { get; set; }
- /// <summary>
- /// mask recipe item display
- /// </summary>
- /// <param name="maskedTechNames"></param>
- public void SetDisplayMask(HashSet<string> maskedTechNames = null, HashSet<string> maskedCatalogNames = null)
- {
- if (ControlViewModel != null)
- {
- ControlViewModel.MaskedTechNames = maskedTechNames;
- ControlViewModel.MaskedCatalogNames = maskedCatalogNames;
- ControlViewModel.RefreshCellsDisplay(false);
- }
- }
- public void SetEnableBarcode(bool enabled)
- {
- if (ControlViewModel != null)
- {
- ControlViewModel.EnableBarcode(enabled);
- }
- }
- public void SetUser(string user)
- {
- if (ControlViewModel != null)
- {
- ControlViewModel.SetCurrentUser(user);
- }
- }
- public void SetEndPointDefaultValue(string defaultValue)
- {
- if (ControlViewModel != null)
- {
- ControlViewModel.SetEndPointDefaultValue(defaultValue);
- }
- }
- /// <summary>
- /// loaded handling
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- void RecipeEditorView_Loaded(object sender, RoutedEventArgs e)
- {
- grid1.DataContext = ControlViewModel;
- }
- /// <summary>
- /// open recipe file
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void OpenButtonPanelLoaded(object sender, RoutedEventArgs e)
- {
- try
- {
- string variation = (string)((Button)sender).Tag;
- ControlViewModel.OpenLocalRecipe(variation);
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- }
- }
- /// <summary>
- /// update recipe variations
- /// </summary>
- /// <param name="sender"></param>
- /// <param name="e"></param>
- private void NewButtonPanelLoaded(object sender, RoutedEventArgs e)
- {
- try
- {
- string variation = (string)((Button)sender).Tag;
- newButton.IsOpen = false;
- XmlDocument doc = new XmlDocument();
- var dir = new System.IO.FileInfo(Process.GetCurrentProcess().MainModule.FileName).Directory;
- string xmlPath = dir + "\\Config\\" + variation + ".xml";
- doc.Load(xmlPath);
- ControlViewModel.LoadRecipe(doc.SelectSingleNode("/Aitex/TableRecipeFormat").OuterXml, doc.SelectSingleNode("/Aitex/TableRecipeData").OuterXml);
- }
- catch (Exception ex)
- {
- System.Diagnostics.Debug.WriteLine(ex.Message);
- }
- }
- public void UpdateCultureResource(string culture)
- {
- return;
- ////string culture = language == 2 ? "zh-CN" : "en-US";
- ////Copy all MergedDictionarys into a auxiliar list.
- //var dictionaryList = Application.Current.Resources.MergedDictionaries.ToList();
- ////Search for the specified culture.
- //string requestedCulture = string.Format(@"/RecipeEditorControl;component/Resources/StringResources.{0}.xaml", culture);
- //var resourceDictionary = dictionaryList.FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
- //if (resourceDictionary == null)
- //{
- // //If not found, select our default language.
- // requestedCulture = "StringResources.xaml";
- // resourceDictionary = dictionaryList.
- // FirstOrDefault(d => d.Source.OriginalString == requestedCulture);
- //}
- ////If we have the requested resource, remove it from the list and place at the end.
- ////Then this language will be our string table to use.
- //if (resourceDictionary != null)
- //{
- // Application.Current.Resources.MergedDictionaries.Remove(resourceDictionary);
- // Application.Current.Resources.MergedDictionaries.Add(resourceDictionary);
- //}
- ////Inform the threads of the new culture.
- //Thread.CurrentThread.CurrentCulture = new CultureInfo(culture);
- //Thread.CurrentThread.CurrentUICulture = new CultureInfo(culture);
- }
- private void UIElement_OnPreviewTextInput(object sender, TextCompositionEventArgs e)
- {
- e.Handled = !IsTextAllowed(e.Text);
- }
- private static bool IsTextAllowed(string text)
- {
- return true;
- //Regex regex = new Regex("[^0-9.-]+"); //regex that matches disallowed text
- //return !regex.IsMatch(text);
- }
- }
- }
|