WPF_Rule.xaml.cs
5.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
using BLL;
using Model;
using SmartScan.SetControl.WPF.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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 static SmartScan.SetControl.WPF.Model.NeoAlertBox;
namespace SmartScan.SetControl.WPF
{
/// <summary>
/// WPF_Rule.xaml 的交互逻辑
/// </summary>
public partial class WPF_Rule : Window
{
// 新增事件,用于返回生成的关键字
public event EventHandler<string> KeywordGenerated;
// 添加数据结构保存配置
private int digitPlaces;
private bool fillZero;
private int resetStrategy;
public WPF_Rule()
{
InitializeComponent();
this.Loaded += (s, e) => {
if (logos is Image img)
{
// 将WinForms资源转换为WPF可用的BitmapSource
System.Drawing.Bitmap winFormsBitmap = global::SmartScan.Properties.Resources.App;
if (winFormsBitmap != null)
{
var bitmapSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap(
winFormsBitmap.GetHbitmap(),
IntPtr.Zero,
Int32Rect.Empty,
BitmapSizeOptions.FromEmptyOptions());
img.Source = bitmapSource;
}
}
};
// 从配置文件加载现有设置
LoadConfigSettings();
}
private void LoadConfigSettings()
{
// 加载配置到控件
NumReelIDPlaces.Text = BLLCommon.config.ReelIDPlaces.ToString();
ChkReelIDFillZero.IsChecked = BLLCommon.config.ReelIDFillZero;
CmbResetidBy.SelectedIndex = Config.REEL_ID_AutoResetStrategy;
}
private void Button_Click(object sender, RoutedEventArgs e)
{
string text = LanguageWwitchover.Dialog("NeedSave", "是否保存?");
bool result = NeoAlertBox.Show("", text, AlertType.Success, "NEO SCAN", true);
if (result)
{
// 保存配置
SaveSettings();
// 关闭窗口
DialogResult = true;
}
}
private void SaveSettings()
{
try
{
// 保存数字位数
if (int.TryParse(NumReelIDPlaces.Text, out digitPlaces))
{
BLLCommon.config.ReelIDPlaces = digitPlaces;
}
// 保存补零设置
BLLCommon.config.ReelIDFillZero = ChkReelIDFillZero.IsChecked ?? false;
// 保存重置策略
Config.REEL_ID_AutoResetStrategy = CmbResetidBy.SelectedIndex;
// 保存配置到文件
BLLCommon.config.Save();
}
catch (Exception ex)
{
MessageBox.Show("保存配置时出错:" + ex.Message, "错误", MessageBoxButton.OK, MessageBoxImage.Error);
}
}
private void Generate_keywords_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrWhiteSpace(keyname.Text))
{
MessageBox.Show("请输入关键字内容", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
return;
}
// 触发事件,传递关键字回主窗口
KeywordGenerated?.Invoke(this, keyname.Text);
// 清空输入
keyname.Clear();
keyname.Focus();
}
private void UsrMacro_btn_1_Click(object sender, RoutedEventArgs e)
{
int a = int.Parse(NumReelIDPlaces.Text.ToString());
if (a <= 0)
{
return;
}
else
{
a = a - 1;
NumReelIDPlaces.Text = a.ToString();
}
}
private void UsrMacro_btn_2_Click(object sender, RoutedEventArgs e)
{
int a = int.Parse(NumReelIDPlaces.Text.ToString());
a = a + 1;
NumReelIDPlaces.Text = a.ToString();
}
private void MinimizeButton_Click(object sender, RoutedEventArgs e)
{
this.WindowState = WindowState.Minimized;
}
private void MaximizeRestoreButton_Click(object sender, RoutedEventArgs e)
{
if (this.WindowState == WindowState.Maximized)
this.WindowState = WindowState.Normal;
else
this.WindowState = WindowState.Maximized;
}
private void CloseButton_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
// 如果您想要支持通过点击标题栏拖动窗口
private void Border_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left)
this.DragMove();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LanguageWwitchover.LoadPath(FilePath.LANGUAGE_DIR);
LanguageWwitchover.LoadLanguage(BLLCommon.config.Language);
LanguageWwitchover.SetLanguage(this);
}
}
}