修改界面样式,修复称重停止

20260122
zhaojian 2 years ago
parent 9350679d8f
commit fa9d630b9e

@ -123,7 +123,7 @@
<Border BorderThickness="1" CornerRadius="3" BorderBrush="#404040" Background="#2F82E7" Grid.Row="5" Height="32" Margin="88,0,304,8" Width="80">
<Button Content="称 重" BorderThickness="0" FontSize="16" Foreground="White" Background="#2F82E7" Click="Button_Click_1"/>
</Border>
<Border BorderThickness="1" CornerRadius="3" BorderBrush="#404040" Background="#2F82E7" Grid.Row="5" Height="32" Margin="200,-5,1,1" Width="80">
<Border BorderThickness="1" CornerRadius="3" Visibility="Hidden" BorderBrush="#404040" Background="#2F82E7" Grid.Row="5" Height="32" Margin="200,-5,1,1" Width="80">
<Button Content="去皮" BorderThickness="0" FontSize="16" Foreground="White" Background="#2F82E7"/>
</Border>
</Grid>
@ -137,10 +137,7 @@
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="FontSize" Value="18"/>
</Style>
<!-- 内容居中样式 -->
<Style TargetType="DataGridCell" >
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Style TargetType="DataGridCell">
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="BorderThickness" Value="0"/>
@ -148,9 +145,15 @@
</Style>
</DataGrid.Resources>
<DataGrid.Columns>
<!--<DataGridTextColumn Binding="{Binding RowNumber}" Width="*" IsReadOnly="True" Header="序号" />-->
<DataGridTextColumn Binding="{Binding material_name}" Width="0.8*" IsReadOnly="True" Header="重量(g)">
<DataGridTextColumn.ElementStyle>
<Style TargetType="TextBlock">
<Setter Property="HorizontalAlignment" Value="Center"/>
<Setter Property="VerticalAlignment" Value="Center"/>
</Style>
</DataGridTextColumn.ElementStyle>
</DataGridTextColumn>
<DataGridTextColumn Binding="{Binding material_name}" Width="0.8*" IsReadOnly="True" Header="重量(g)" />
<DataGridTemplateColumn Width="0.2*" Header="操作">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
@ -159,6 +162,9 @@
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
</Border>
</Grid>
@ -210,12 +216,22 @@
</Style>
<!-- 内容居中样式 -->
<Style TargetType="DataGridCell" >
<Setter Property="HorizontalContentAlignment" Value="Center"/>
<Setter Property="VerticalContentAlignment" Value="Center"/>
<Setter Property="Foreground" Value="Black"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Padding" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type DataGridCell}">
<Border Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Padding="{TemplateBinding Padding}">
<TextBlock Text="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Text}" TextAlignment="Center" VerticalAlignment="Center" HorizontalAlignment="Center"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</DataGrid.Resources>
<DataGrid.RowStyle>
@ -232,7 +248,7 @@
</DataGrid.RowStyle>
<DataGrid.Columns>
<!--<DataGridTextColumn Binding="{Binding RowNumber}" Width="*" IsReadOnly="True" Header="序号" />-->
<DataGridTextColumn Binding="{Binding check_name}" Width="*" IsReadOnly="True" Header="检验节点"/>
<DataGridTextColumn Binding="{Binding check_name}" Width="*" IsReadOnly="True" Header="检验节点" />
<DataGridTextColumn Binding="{Binding income_time,StringFormat='{}{0:yyyy-MM-dd HH:mm:ss}'}" IsReadOnly="True" Width="*" Header="检验日期" />
<DataGridTextColumn Binding="{Binding check_no}" Width="*" IsReadOnly="True" Header="任务编号" />
<DataGridTextColumn Binding="{Binding material_code}" Width="*" IsReadOnly="True" Header="检验物料" />

@ -5,27 +5,16 @@ using System;
using System.Collections.Generic;
using System.Data;
using System.IO.Ports;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
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.Markup;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using System.Windows.Shapes;
using System.Windows.Threading;
using XGL.Dats.DBServiceFinishProd;
using XGL.Models;
using XGL.Models.Model.OrderPrepare;
using System.Text.RegularExpressions;
using System.Configuration;
using CommonFunc;
namespace XGLFinishPro.Views
{
@ -34,7 +23,7 @@ namespace XGLFinishPro.Views
/// </summary>
public partial class weighWindows : UserControl
{
Dispatcher dispatcher;
Dispatcher dispatcher ;
FinishProdDBService userDbWareHouse = new FinishProdDBService();
static SerialPort serialPort;
public CheckTaskModel checkTaskModel = new CheckTaskModel();//当前选择的任务
@ -49,6 +38,8 @@ namespace XGLFinishPro.Views
/// <param name="sender"></param>
/// <param name="e"></param>
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{
try
{
var dataTable = userDbWareHouse.WeighingTask("");
@ -63,6 +54,11 @@ namespace XGLFinishPro.Views
WeighingTaskDateTable.ItemsSource = null;
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("初始化发生异常:" + ex.Message);
}
}
/// <summary>
/// 重置
/// </summary>
@ -85,7 +81,6 @@ namespace XGLFinishPro.Views
}
Button_Click_2(null, null);
}
/// <summary>
/// 称重
/// </summary>
@ -94,6 +89,8 @@ namespace XGLFinishPro.Views
private void Button_Click_1(object sender, RoutedEventArgs e)
{
try
{
if (jianyanwuliao.Text.IsNullOrEmpty() || jianyanjiedian.Text.IsNullOrEmpty() || renwubianhao.Text.IsNullOrEmpty() || guizemingcheng.Text.IsNullOrEmpty())
{
MessageBox.Show("数据不完整,无法称重!!");
@ -169,8 +166,6 @@ namespace XGLFinishPro.Views
zhongliang.Text = data;
});
}
void ClosePort()
{
if (serialPort != null && serialPort.IsOpen)
@ -184,14 +179,24 @@ namespace XGLFinishPro.Views
}
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("称重发生异常:" + ex.Message);
}
}
/// <summary>
/// 称重更新数据库
/// </summary>
/// <param name="Date"></param>
public void upDateDate(string Date)
{
try
{
// 将数据保存
CheckTaskModel newItem = new CheckTaskModel() { material_name = Date };
// 获取当前应用程序的Dispatcher
dispatcher = Application.Current.Dispatcher;
Dispatcher.Invoke(() =>
{
zhongDate.Items.Add(newItem);
@ -211,6 +216,11 @@ namespace XGLFinishPro.Views
userDbWareHouse.InsertCheckTaskDetail(checkTaskModel.actual_value, checkTaskModel.record_id);//保存称重数据
Button_Click_2(null, null);
}
catch (Exception ex)
{
LogHelper.instance.log.Error("称重更新数据库发生异常:" + ex.Message);
}
}
/// <summary>
/// 查询数据
/// </summary>
@ -219,6 +229,10 @@ namespace XGLFinishPro.Views
private void Button_Click_2(object sender, RoutedEventArgs e)
{
string wher = "";
try
{
// 获取当前应用程序的Dispatcher
dispatcher = Application.Current.Dispatcher;
// 使用Dispatcher.Invoke确保在UI线程上执行更新操作
dispatcher.Invoke(() =>
{
@ -252,8 +266,11 @@ namespace XGLFinishPro.Views
WeighingTaskDateTable.ItemsSource = null;
}
});
}
catch (Exception ex)
{
LogHelper.instance.log.Error("查询数据发生异常:" + ex.Message);
}
}
/// <summary>
/// 表格双击事件
@ -261,6 +278,8 @@ namespace XGLFinishPro.Views
/// <param name="sender"></param>
/// <param name="e"></param>
private void DataGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
try
{
// 获取选中行的索引
int selectedIndex = WeighingTaskDateTable.SelectedIndex;
@ -303,8 +322,12 @@ namespace XGLFinishPro.Views
}
}
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error("表格双击事件发生异常:" + ex.Message);
}
}
/// <summary>
/// 表格删除按钮
@ -312,6 +335,8 @@ namespace XGLFinishPro.Views
/// <param name="sender"></param>
/// <param name="e"></param>
private void DeleteButton_Click(object sender, RoutedEventArgs e)
{
try
{
var button = sender as Button;
var dataContext = button?.DataContext;
@ -322,7 +347,7 @@ namespace XGLFinishPro.Views
// 从 DataGrid 的 ItemsSource 中移除该项
zhongDate.Items.Remove(item); // 从 actual_value 中移除 materialName
checkTaskModel.actual_value = RemoveMaterialNameFromActualValue(checkTaskModel.actual_value, materialName);
if (checkTaskModel.actual_value=="[]")
if (checkTaskModel.actual_value == "[]")
{
checkTaskModel.actual_value = null;
}
@ -331,6 +356,11 @@ namespace XGLFinishPro.Views
// 从数据源中移除该项
}
}
catch (Exception ex)
{
LogHelper.instance.log.Error(" 表格删除按钮发生异常:" + ex.Message);
}
}
private string RemoveMaterialNameFromActualValue(string actualValue, string materialName)
{
// 解析 actualValue移除 materialName并返回更新后的值
@ -341,7 +371,6 @@ namespace XGLFinishPro.Views
private void pickerstart_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
{
}
}
public class motre

@ -2,5 +2,12 @@
<Project ToolsVersion="Current" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<PublishUrlHistory />
<InstallUrlHistory />
<SupportUrlHistory />
<UpdateUrlHistory />
<BootstrapperUrlHistory />
<ErrorReportUrlHistory />
<FallbackCulture>zh-CN</FallbackCulture>
<VerifyUploadedFiles>false</VerifyUploadedFiles>
</PropertyGroup>
</Project>
Loading…
Cancel
Save