存入进行中
This commit is contained in:
parent
9f1db152eb
commit
57f870ae49
|
|
@ -74,6 +74,7 @@
|
|||
|
||||
<ItemGroup>
|
||||
<Folder Include="src\public\Excel\" />
|
||||
<Folder Include="src\model\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
|
|||
|
|
@ -63,10 +63,10 @@
|
|||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<CheckBox Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" Margin="5"/>
|
||||
<CheckBox Grid.Row="0" Grid.Column="1" Content="数字传感器2" IsChecked="True" Margin="5"/>
|
||||
<CheckBox Grid.Row="1" Grid.Column="0" Content="数字传感器3" IsChecked="True" Margin="5"/>
|
||||
<CheckBox Grid.Row="1" Grid.Column="1" Content="数字传感器4" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor1" Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor2" Grid.Row="0" Grid.Column="1" Content="数字传感器2" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor3" Grid.Row="1" Grid.Column="0" Content="数字传感器3" IsChecked="True" Margin="5"/>
|
||||
<CheckBox x:Name="chkDigitalSensor4" Grid.Row="1" Grid.Column="1" Content="数字传感器4" Margin="5"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
|
@ -141,10 +141,10 @@
|
|||
<ColumnDefinition Width="*"/>
|
||||
<ColumnDefinition Width="*"/>
|
||||
</Grid.ColumnDefinitions>
|
||||
<RadioButton Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton Grid.Row="0" Grid.Column="1" Content="数字传感器2" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton Grid.Row="1" Grid.Column="0" Content="数字传感器3" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton Grid.Row="1" Grid.Column="1" Content="数字传感器4" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor1" Grid.Row="0" Grid.Column="0" Content="数字传感器1" IsChecked="True" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor2" Grid.Row="0" Grid.Column="1" Content="数字传感器2" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor3" Grid.Row="1" Grid.Column="0" Content="数字传感器3" GroupName="MainSensor" Margin="5"/>
|
||||
<RadioButton x:Name="chkDigitalMainSensor4" Grid.Row="1" Grid.Column="1" Content="数字传感器4" GroupName="MainSensor" Margin="5"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
|
|
|||
|
|
@ -3,8 +3,6 @@ using SqlSugar;
|
|||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using static WpfApp.MainWindow;
|
||||
|
||||
namespace WpfApp.src.view;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -23,7 +21,6 @@ public partial class ConfigPage : Page
|
|||
{
|
||||
InitializeComponent();
|
||||
InitializeLevelData();
|
||||
InitializeSensorData();
|
||||
log = logService;
|
||||
db = databaseService;
|
||||
even = eventService;
|
||||
|
|
@ -34,6 +31,13 @@ public partial class ConfigPage : Page
|
|||
scope.guokeCheckToCreate<MainSensorSelection>();
|
||||
scope.guokeCheckToCreate<LevelInfo>();
|
||||
|
||||
// 传感器选择
|
||||
LoadSensorSelectionFromDb();
|
||||
// 传感器公差
|
||||
InitializeSensorData();
|
||||
// 主传感器选择
|
||||
LoadMainSensorSelectionFromDb();
|
||||
|
||||
// 注册等级标签按钮点击事件
|
||||
LevelTabUnder.Click += LevelTab_Click;
|
||||
LevelTabA.Click += LevelTab_Click;
|
||||
|
|
@ -49,6 +53,257 @@ public partial class ConfigPage : Page
|
|||
LevelTabUnder.RaiseEvent(new RoutedEventArgs(Button.ClickEvent));
|
||||
}
|
||||
|
||||
|
||||
#region 第二部分 多选
|
||||
// 从数据库加载传感器选择
|
||||
private void LoadSensorSelectionFromDb()
|
||||
{
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
// 假设只取第一个产品的主传感器数据
|
||||
var mainSensor = scope.Queryable<SensorSelection>().First();
|
||||
if (mainSensor != null)
|
||||
{
|
||||
LoadSensorSelection(mainSensor);
|
||||
}
|
||||
}
|
||||
|
||||
// 每次 CheckBox 状态改变保存到数据库
|
||||
private void Sensor_CheckedChanged(object sender, RoutedEventArgs e)
|
||||
{
|
||||
SaveSensorToDb();
|
||||
}
|
||||
/// <summary>
|
||||
/// 将数据库中的主传感器数据加载到界面 CheckBox
|
||||
/// </summary>
|
||||
private void LoadSensorSelection(SensorSelection data)
|
||||
{
|
||||
chkDigitalSensor1.IsChecked = data.Sensor1;
|
||||
chkDigitalSensor2.IsChecked = data.Sensor2;
|
||||
chkDigitalSensor3.IsChecked = data.Sensor3;
|
||||
chkDigitalSensor4.IsChecked = data.Sensor4;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存界面 CheckBox 状态到数据库
|
||||
/// </summary>
|
||||
private void SaveSensorToDb()
|
||||
{
|
||||
var data = new SensorSelection
|
||||
{
|
||||
Sensor1 = chkDigitalSensor1.IsChecked == true,
|
||||
Sensor2 = chkDigitalSensor2.IsChecked == true,
|
||||
Sensor3 = chkDigitalSensor3.IsChecked == true,
|
||||
Sensor4 = chkDigitalSensor4.IsChecked == true,
|
||||
ProductName = "默认产品名" // 可以根据实际情况设置
|
||||
};
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
|
||||
// 如果数据库已存在该产品的主传感器数据,则更新,否则插入
|
||||
var exist = scope.Queryable<SensorSelection>()
|
||||
.Where(s => s.ProductName == data.ProductName)
|
||||
.First();
|
||||
|
||||
if (exist != null)
|
||||
{
|
||||
data.Id = exist.Id; // 设置 Id 才能更新
|
||||
scope.Updateable(data).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(data).ExecuteCommand();
|
||||
}
|
||||
|
||||
log.Info($"保存传感器选择:{data.ProductName}");
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第三部分 公差
|
||||
// 初始化传感器数据
|
||||
private void InitializeSensorData()
|
||||
{
|
||||
sensorData = new Dictionary<int, SensorToleranceData>();
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
if (scope == null)
|
||||
{
|
||||
MessageBox.Show("SqlSugarScope 获取失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
string productName = "DFPV C15TE"; // TODO: 根据实际选择的产品替换
|
||||
|
||||
// 查询数据库
|
||||
var sensors = scope.Queryable<SensorToleranceData>()
|
||||
.Where(s => s.ProductName == productName)
|
||||
.ToList();
|
||||
|
||||
for (int i = 1; i <= 4; i++)
|
||||
{
|
||||
var sensor = sensors.FirstOrDefault(s => s.SensorName == $"传感器{i}");
|
||||
sensorData[i] = sensor ?? new SensorToleranceData
|
||||
{
|
||||
SensorName = $"传感器{i}",
|
||||
MaxTolerance = "0.00",
|
||||
BaseTolerance = "0.00",
|
||||
MinTolerance = "0.00",
|
||||
ProductName = productName
|
||||
};
|
||||
}
|
||||
|
||||
// 加载第一个传感器数据到界面
|
||||
LoadSensorData(1);
|
||||
}
|
||||
|
||||
// 标签切换事件(只加载,不保存)
|
||||
private void SensorTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (sender is Button clickedButton && int.TryParse(clickedButton.Tag?.ToString(), out int sensorIndex))
|
||||
{
|
||||
UpdateTabStyles(sensorIndex);
|
||||
LoadSensorData(sensorIndex);
|
||||
}
|
||||
}
|
||||
|
||||
// 更新标签页样式
|
||||
private void UpdateTabStyles(int selectedIndex)
|
||||
{
|
||||
var buttons = new[] { SensorTab1, SensorTab2, SensorTab3, SensorTab4 };
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
{
|
||||
buttons[i].Background = (i + 1 == selectedIndex)
|
||||
? new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"))
|
||||
: new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据到界面
|
||||
private void LoadSensorData(int sensorIndex)
|
||||
{
|
||||
if (sensorData.ContainsKey(sensorIndex) &&
|
||||
MaxToleranceTextBox != null &&
|
||||
BaseToleranceTextBox != null &&
|
||||
MinToleranceTextBox != null)
|
||||
{
|
||||
var data = sensorData[sensorIndex];
|
||||
MaxToleranceTextBox.Text = data.MaxTolerance;
|
||||
BaseToleranceTextBox.Text = data.BaseTolerance;
|
||||
MinToleranceTextBox.Text = data.MinTolerance;
|
||||
}
|
||||
}
|
||||
|
||||
// 保存按钮事件
|
||||
private void SaveButton_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
int currentSensorIndex = GetCurrentSelectedSensorIndex();
|
||||
|
||||
// 保存当前界面数据到字典
|
||||
if (sensorData.ContainsKey(currentSensorIndex))
|
||||
{
|
||||
sensorData[currentSensorIndex].MaxTolerance = MaxToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].BaseTolerance = BaseToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].MinTolerance = MinToleranceTextBox.Text;
|
||||
}
|
||||
|
||||
// 写回数据库
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
foreach (var sensor in sensorData.Values)
|
||||
{
|
||||
var exist = scope.Queryable<SensorToleranceData>()
|
||||
.Where(s => s.ProductName == sensor.ProductName && s.SensorName == sensor.SensorName)
|
||||
.First();
|
||||
if (exist != null)
|
||||
{
|
||||
sensor.Id = exist.Id;
|
||||
scope.Updateable(sensor).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(sensor).ExecuteCommand();
|
||||
}
|
||||
}
|
||||
|
||||
MessageBox.Show("保存成功!");
|
||||
}
|
||||
|
||||
// 获取当前选中的传感器索引
|
||||
private int GetCurrentSelectedSensorIndex()
|
||||
{
|
||||
if (SensorTab1.Background is SolidColorBrush brush1 && brush1.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 1;
|
||||
if (SensorTab2.Background is SolidColorBrush brush2 && brush2.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 2;
|
||||
if (SensorTab3.Background is SolidColorBrush brush3 && brush3.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 3;
|
||||
if (SensorTab4.Background is SolidColorBrush brush4 && brush4.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 4;
|
||||
return 1;
|
||||
}
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第四部分 单选
|
||||
// 主传感器
|
||||
private void LoadMainSensorSelectionFromDb()
|
||||
{
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
// 假设只取第一个产品的主传感器数据
|
||||
var mainSensor = scope.Queryable<MainSensorSelection>().First();
|
||||
if (mainSensor != null)
|
||||
{
|
||||
LoadMainSensorSelection(mainSensor);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将数据库中的主传感器数据加载到界面 CheckBox
|
||||
/// </summary>
|
||||
private void LoadMainSensorSelection(MainSensorSelection data)
|
||||
{
|
||||
chkDigitalMainSensor1.IsChecked = data.DigitalSensor1;
|
||||
chkDigitalMainSensor2.IsChecked = data.DigitalSensor2;
|
||||
chkDigitalMainSensor3.IsChecked = data.DigitalSensor3;
|
||||
chkDigitalMainSensor4.IsChecked = data.DigitalSensor4;
|
||||
}
|
||||
/// <summary>
|
||||
/// 保存界面 CheckBox 状态到数据库
|
||||
/// </summary>
|
||||
private void SaveMainSensorToDb()
|
||||
{
|
||||
var data = new MainSensorSelection
|
||||
{
|
||||
DigitalSensor1 = chkDigitalMainSensor1.IsChecked == true,
|
||||
DigitalSensor2 = chkDigitalMainSensor2.IsChecked == true,
|
||||
DigitalSensor3 = chkDigitalMainSensor3.IsChecked == true,
|
||||
DigitalSensor4 = chkDigitalMainSensor4.IsChecked == true,
|
||||
ProductName = "默认产品名" // 可以根据实际情况设置
|
||||
};
|
||||
|
||||
SqlSugarScope scope = db.GetScope("D1");
|
||||
|
||||
// 如果数据库已存在该产品的主传感器数据,则更新,否则插入
|
||||
var exist = scope.Queryable<SensorSelection>()
|
||||
.Where(s => s.ProductName == data.ProductName)
|
||||
.First();
|
||||
|
||||
if (exist != null)
|
||||
{
|
||||
data.Id = exist.Id; // 设置 Id 才能更新
|
||||
scope.Updateable(data).ExecuteCommand();
|
||||
}
|
||||
else
|
||||
{
|
||||
scope.Insertable(data).ExecuteCommand();
|
||||
}
|
||||
|
||||
log.Info($"保存传感器选择:{data.ProductName}");
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region 第五部分 等级
|
||||
// 初始化等级数据
|
||||
private void InitializeLevelData()
|
||||
{
|
||||
|
|
@ -67,8 +322,6 @@ public partial class ConfigPage : Page
|
|||
};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 等级标签按钮点击事件
|
||||
private void LevelTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
|
|
@ -167,102 +420,7 @@ public partial class ConfigPage : Page
|
|||
}
|
||||
}
|
||||
}
|
||||
// 初始化传感器数据
|
||||
private void InitializeSensorData()
|
||||
{
|
||||
sensorData = new Dictionary<int, SensorToleranceData>
|
||||
{
|
||||
{ 1, new SensorToleranceData { MaxTolerance = "9.00", BaseTolerance = "72.9410", MinTolerance = "-9.00" } },
|
||||
{ 2, new SensorToleranceData { MaxTolerance = "8.50", BaseTolerance = "72.8500", MinTolerance = "-8.50" } },
|
||||
{ 3, new SensorToleranceData { MaxTolerance = "7.80", BaseTolerance = "72.7800", MinTolerance = "-7.80" } },
|
||||
{ 4, new SensorToleranceData { MaxTolerance = "6.90", BaseTolerance = "72.6900", MinTolerance = "-6.90" } }
|
||||
};
|
||||
}
|
||||
// 传感器标签页点击事件处理
|
||||
private void SensorTab_Click(object sender, RoutedEventArgs e)
|
||||
{
|
||||
Button clickedButton = sender as Button;
|
||||
if (clickedButton == null) return;
|
||||
|
||||
int sensorIndex = int.Parse(clickedButton.Tag.ToString());
|
||||
|
||||
// 保存当前传感器的数据
|
||||
SaveCurrentSensorData();
|
||||
|
||||
// 更新标签页样式
|
||||
UpdateTabStyles(sensorIndex);
|
||||
|
||||
// 加载选中传感器的数据
|
||||
LoadSensorData(sensorIndex);
|
||||
}
|
||||
// 保存当前传感器的数据
|
||||
private void SaveCurrentSensorData()
|
||||
{
|
||||
// 获取当前选中的传感器索引
|
||||
int currentSensorIndex = GetCurrentSelectedSensorIndex();
|
||||
|
||||
if (sensorData.ContainsKey(currentSensorIndex))
|
||||
{
|
||||
sensorData[currentSensorIndex].MaxTolerance = MaxToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].BaseTolerance = BaseToleranceTextBox.Text;
|
||||
sensorData[currentSensorIndex].MinTolerance = MinToleranceTextBox.Text;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// 获取当前选中的传感器索引
|
||||
private int GetCurrentSelectedSensorIndex()
|
||||
{
|
||||
if (SensorTab1.Background is SolidColorBrush brush1 && brush1.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 1;
|
||||
if (SensorTab2.Background is SolidColorBrush brush2 && brush2.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 2;
|
||||
if (SensorTab3.Background is SolidColorBrush brush3 && brush3.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 3;
|
||||
if (SensorTab4.Background is SolidColorBrush brush4 && brush4.Color == ((SolidColorBrush)new BrushConverter().ConvertFrom("#E6F3FF")).Color)
|
||||
return 4;
|
||||
return 1; // 默认返回传感器1
|
||||
}
|
||||
|
||||
// 更新标签页样式
|
||||
private void UpdateTabStyles(int selectedIndex)
|
||||
{
|
||||
// 重置所有标签页样式
|
||||
SensorTab1.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
SensorTab2.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
SensorTab3.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
SensorTab4.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#F0F0F0"));
|
||||
|
||||
// 设置选中标签页样式
|
||||
switch (selectedIndex)
|
||||
{
|
||||
case 1:
|
||||
SensorTab1.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||||
break;
|
||||
case 2:
|
||||
SensorTab2.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||||
break;
|
||||
case 3:
|
||||
SensorTab3.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||||
break;
|
||||
case 4:
|
||||
SensorTab4.Background = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#E6F3FF"));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// 加载传感器数据
|
||||
private void LoadSensorData(int sensorIndex)
|
||||
{
|
||||
if (sensorData.ContainsKey(sensorIndex))
|
||||
{
|
||||
var data = sensorData[sensorIndex];
|
||||
MaxToleranceTextBox.Text = data.MaxTolerance;
|
||||
BaseToleranceTextBox.Text = data.BaseTolerance;
|
||||
MinToleranceTextBox.Text = data.MinTolerance;
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user