PackageDescriptionWindow.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using Newtonsoft.Json.Linq;
  2. using PackingPress.Common;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Web;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Data;
  12. using System.Windows.Documents;
  13. using System.Windows.Input;
  14. using System.Windows.Media;
  15. using System.Windows.Media.Imaging;
  16. using System.Windows.Shapes;
  17. namespace PackingPress
  18. {
  19. /// <summary>
  20. /// PackageDescriptionWindow.xaml 的交互逻辑
  21. /// </summary>
  22. public partial class PackageDescriptionWindow : BaseWindow
  23. {
  24. SettingJsonGet _jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\DescriptionConfig.json");
  25. public PackageDescriptionWindow()
  26. {
  27. InitializeComponent();
  28. var selectValue = ((TextBlock)DescriptionType.SelectedValue).Text;
  29. if (!string.IsNullOrWhiteSpace(selectValue))
  30. {
  31. var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
  32. Chinese.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.ChineseDescription"));
  33. English.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.EnglishDescription"));
  34. Portugal.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.PortugalDescription"));
  35. Rumania.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.RumaniaDescription"));
  36. }
  37. }
  38. private void Button_Click(object sender, RoutedEventArgs e)
  39. {
  40. var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
  41. jsonRoot.AddChild(DescriptionType.Text,JToken.Parse($"{{ \"ChineseDescription\" : \"{ HttpUtility.UrlEncode(Chinese.Text)}\", \"EnglishDescription\" : \"{HttpUtility.UrlEncode(English.Text)}\", \"PortugalDescription\" : \"{HttpUtility.UrlEncode(Portugal.Text)}\", \"RumaniaDescription\" : \"{HttpUtility.UrlEncode(Rumania.Text)}\" }}"));
  42. _jObjectSystemConfig.SaveJson();
  43. }
  44. private void DescriptionType_SelectionChanged(object sender, SelectionChangedEventArgs e)
  45. {
  46. if (IsInitialized)
  47. {
  48. if (!string.IsNullOrWhiteSpace(Chinese.Text) || !string.IsNullOrWhiteSpace(English.Text) || !string.IsNullOrWhiteSpace(Portugal.Text) || !string.IsNullOrWhiteSpace(Rumania.Text))
  49. {
  50. var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
  51. jsonRoot.AddChild(DescriptionType.Text, JToken.Parse($"{{ \"ChineseDescription\" : \"{ HttpUtility.UrlEncode(Chinese.Text)}\", \"EnglishDescription\" : \"{HttpUtility.UrlEncode(English.Text)}\", \"PortugalDescription\" : \"{HttpUtility.UrlEncode(Portugal.Text)}\", \"RumaniaDescription\" : \"{HttpUtility.UrlEncode(Rumania.Text)}\" }}"));
  52. _jObjectSystemConfig.SaveJson();
  53. }
  54. var selectValue = ((TextBlock)DescriptionType.SelectedValue).Text;
  55. if (!string.IsNullOrWhiteSpace(selectValue))
  56. {
  57. var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
  58. Chinese.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.ChineseDescription"));
  59. English.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.EnglishDescription"));
  60. Portugal.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.PortugalDescription"));
  61. Rumania.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath<string>($"$.{selectValue}.RumaniaDescription"));
  62. }
  63. }
  64. }
  65. }
  66. }