using Newtonsoft.Json.Linq;
using PackingPress.Common;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web;
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.Shapes;
namespace PackingPress
{
///
/// PackageDescriptionWindow.xaml 的交互逻辑
///
public partial class PackageDescriptionWindow : BaseWindow
{
SettingJsonGet _jObjectSystemConfig = new SettingJsonGet(AppDomain.CurrentDomain.BaseDirectory + "\\DescriptionConfig.json");
public PackageDescriptionWindow()
{
InitializeComponent();
var selectValue = ((TextBlock)DescriptionType.SelectedValue).Text;
if (!string.IsNullOrWhiteSpace(selectValue))
{
var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
Chinese.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.ChineseDescription"));
English.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.EnglishDescription"));
Portugal.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.PortugalDescription"));
Rumania.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.RumaniaDescription"));
}
}
private void Button_Click(object sender, RoutedEventArgs e)
{
var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
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)}\" }}"));
_jObjectSystemConfig.SaveJson();
}
private void DescriptionType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (IsInitialized)
{
if (!string.IsNullOrWhiteSpace(Chinese.Text) || !string.IsNullOrWhiteSpace(English.Text) || !string.IsNullOrWhiteSpace(Portugal.Text) || !string.IsNullOrWhiteSpace(Rumania.Text))
{
var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
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)}\" }}"));
_jObjectSystemConfig.SaveJson();
}
var selectValue = ((TextBlock)DescriptionType.SelectedValue).Text;
if (!string.IsNullOrWhiteSpace(selectValue))
{
var jsonRoot = (JObject)_jObjectSystemConfig.GetJsonRoot();
Chinese.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.ChineseDescription"));
English.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.EnglishDescription"));
Portugal.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.PortugalDescription"));
Rumania.Text = HttpUtility.UrlDecode(jsonRoot.GetJPropertyValueByPath($"$.{selectValue}.RumaniaDescription"));
}
}
}
}
}