Forráskód Böngészése

优化检验报告、抽样登记

LT069288 3 hónapja
szülő
commit
746e4cdce1

+ 106 - 0
UniformMaterialManagementSystem/Models/InspectionReportModel.cs

@@ -0,0 +1,106 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using CommunityToolkit.Mvvm.ComponentModel;
+using UniformMaterialManagementSystem.Entities;
+
+namespace UniformMaterialManagementSystem.Models
+{
+    public partial class InspectionReportModel : ObservableObject
+    {
+        [ObservableProperty]
+        private Guid _guid;
+
+        [ObservableProperty]
+        private Guid _inspectApplyGuid;
+
+        [ObservableProperty]
+        private string _reportNo = null!;
+
+        [ObservableProperty]
+        private string _department = null!;
+
+        [ObservableProperty]
+        private DateTime _reportTime;
+
+        [ObservableProperty]
+        private string _reportBasis = null!;
+
+        [ObservableProperty] 
+        private bool _isSample;
+
+        [ObservableProperty]
+        private string _reportDesc = null!;
+
+        [ObservableProperty]
+        private string _conclusion = null!;
+
+        [ObservableProperty]
+        private string _conclusionDesc = null!;
+
+        [ObservableProperty]
+        private string _editUser = null!;
+
+        [ObservableProperty]
+        private InspectApply _inspectApply = null!;
+
+        [ObservableProperty]
+        private string _purchaseCompanyNames = null!;
+
+        [ObservableProperty]
+        private string _contractNos = null!;
+
+        [ObservableProperty]
+        private ObservableCollection<InspectionReportDetail> _inspectionReportDetails = null!;
+
+        public InspectionReportModel(InspectionReport report)
+        {
+            Guid = report.Guid;
+            InspectApplyGuid = report.InspectApplyGuid;
+            ReportNo = report.ReportNo;
+            Department = report.Department;
+            ReportTime = report.ReportTime;
+            ReportBasis = report.ReportBasis;
+            IsSample = report.IsSample;
+            ReportDesc = report.ReportDesc;
+            Conclusion = report.Conclusion;
+            ConclusionDesc = report.ConclusionDesc;
+            EditUser = report.EditUser;
+            InspectApply = report.InspectApply;
+            InspectionReportDetails = report.InspectionReportDetails;
+
+            StringBuilder companyNames = new StringBuilder();
+            StringBuilder contractNos = new StringBuilder();
+            foreach (var detail in report.InspectApply.InspectApplyContractDetails)
+            {
+                companyNames.AppendLine(detail.PurchaseCompany);
+                contractNos.AppendLine(detail.ContractNo);
+            }
+            PurchaseCompanyNames = companyNames.ToString();
+            ContractNos = contractNos.ToString();
+        }
+
+        public void ModifyInspectionReport(InspectionReport report)
+        {
+            report.Guid = Guid;
+            report.InspectApplyGuid = InspectApplyGuid ;
+            report.ReportNo = ReportNo;
+            report.Department = Department;
+            report.ReportTime = ReportTime ;
+            report.ReportBasis = ReportBasis;
+            report.IsSample = IsSample;
+            report.ReportDesc = ReportDesc;
+            report.Conclusion = Conclusion;
+            report.ConclusionDesc = ConclusionDesc;
+            report.EditUser = EditUser;
+            report.InspectApply = InspectApply;
+            report.InspectionReportDetails = InspectionReportDetails;
+
+        }
+
+    }
+}

BIN
UniformMaterialManagementSystem/Template/军需物资质量监督检验报告模板.docx


+ 39 - 0
UniformMaterialManagementSystem/Utils/EnumUtil.cs

@@ -0,0 +1,39 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace UniformMaterialManagementSystem.Utils
+{
+    //检测项目
+    public enum TestingItem
+    {
+        TestAll, 
+        MandatoryTest, 
+        ColorFastness,
+        Spectrum, 
+        Reference, 
+        SingleRadio
+    }
+    public static class EnumUtil
+    {
+        private static readonly Dictionary<TestingItem, string> TestingItemMap = new Dictionary<TestingItem, string>
+        {
+            { TestingItem.TestAll, "全检" },
+            { TestingItem.MandatoryTest, "强制性检测" },
+            { TestingItem.ColorFastness, "色牢度" },
+            { TestingItem.Spectrum, "光谱" },
+            { TestingItem.Reference, "参考性指标" },
+            { TestingItem.SingleRadio, "单项指标" },
+        };
+
+        public static string GetTestingItemString(TestingItem testingItem)
+        {
+            return TestingItemMap[testingItem];
+        }
+
+        
+
+    }
+}

+ 138 - 99
UniformMaterialManagementSystem/ViewModels/InspectionReportPageViewModel.cs

@@ -11,6 +11,7 @@ using UniformMaterialManagementSystem.Services;
 using UniformMaterialManagementSystem.Views;
 using UniformMaterialManagementSystem.Utils;
 using DocumentFormat.OpenXml.Office2016.Drawing.ChartDrawing;
+using UniformMaterialManagementSystem.Models;
 
 namespace UniformMaterialManagementSystem.ViewModels
 {
@@ -18,16 +19,10 @@ namespace UniformMaterialManagementSystem.ViewModels
     {
 
         [ObservableProperty]
-        private ObservableCollection<InspectionReport> _inspectionReports = [];
+        private ObservableCollection<InspectionReportModel> _inspectionReports = [];
 
         [ObservableProperty]
-        private InspectionReport? _selectedInspectionReport;
-
-        [ObservableProperty]
-        private string? _purchaseCompanyNames;
-
-        [ObservableProperty]
-        private string? _contractNos;
+        private InspectionReportModel? _selectedInspectionReport;
 
         [ObservableProperty]
         private List<int> _years = [];
@@ -85,7 +80,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         private void LoadData()
         {
             //询问是否保存
-            AskIsSave();
+            //AskIsSave();
 
             var inspectionReports = _inspectionReportService.Query()
                 .Include(x => x.InspectionReportDetails)
@@ -99,37 +94,49 @@ namespace UniformMaterialManagementSystem.ViewModels
             InspectionReports.Clear();
             foreach (var report in inspectionReports)
             {
-                InspectionReports.Add(report);
+                InspectionReports.Add(new InspectionReportModel(report));
             }
         }
 
         /// <summary>
-        /// 判断单据是否有修改
+        ///判断单据是否有修改,true:已修改 false:未修改
         /// </summary>
-        private bool IsSelectedChanged()
+        private bool IsCurrentReportChanged(InspectionReportModel inspectionReportModel)
         {
-            if (SelectedInspectionReport == null) return false;
-            var state = _inspectionReportService.Entry(SelectedInspectionReport);
-            if (state != EntityState.Unchanged) return true;
-
-            var reportDetails = SelectedInspectionReport.InspectionReportDetails;
-            var existDetails = _inspectionReportDetailService.Query(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
-
-            foreach (var detail in reportDetails)  //新增行或修改行操作
+            var inspectionReport = _inspectionReportService.Get(x => x.Guid == inspectionReportModel.Guid);
+            if (inspectionReport == null) //新增
+            {
+                return true;
+            }
+            else
             {
-                var detailState = _inspectionReportDetailService.Entry(detail);
-                if (detailState != EntityState.Unchanged)
+                inspectionReportModel.ModifyInspectionReport(inspectionReport);
+                var state = _inspectionReportService.Entry(inspectionReport);
+                if (state == EntityState.Modified)
                 {
                     return true;
                 }
-            }
 
-            foreach (var detail in existDetails) //删除行操作
-            {
-                var detailState = _inspectionReportDetailService.Entry(detail);
-                if (detailState == EntityState.Deleted)
+                //判断明细表是否新增、修改或删除
+                var reportDetails = inspectionReportModel.InspectionReportDetails;
+                var existDetails = _inspectionReportDetailService.Query(x => x.InspectionReportGuid == inspectionReportModel.Guid).ToList();
+
+                foreach (var detail in reportDetails)  //新增行或修改行操作
                 {
-                    return true;
+                    var detailState = _inspectionReportDetailService.Entry(detail);
+                    if (detailState != EntityState.Unchanged)
+                    {
+                        return true;
+                    }
+                }
+
+                foreach (var detail in existDetails) //删除行操作
+                {
+                    var detailState = _inspectionReportDetailService.Entry(detail);
+                    if (detailState == EntityState.Deleted)
+                    {
+                        return true;
+                    }
                 }
             }
 
@@ -139,57 +146,57 @@ namespace UniformMaterialManagementSystem.ViewModels
         /// <summary>
         /// 选择行改变事件
         /// </summary>
-        [RelayCommand]
-        private void InspectionReportSelectionChanged(InspectionReport inspectionReport)
-        {
-            AskIsSave();
+        //[RelayCommand]
+        //private void InspectionReportSelectionChanged(InspectionReport inspectionReport)
+        //{
+        //    AskIsSave();
 
-            /* 绑定当前行数据*/
-            SelectedInspectionReport = inspectionReport;
+        //    /* 绑定当前行数据*/
+        //    SelectedInspectionReport = inspectionReport;
 
-            //获取合同信息
-            var dictionary = GetContractInformation(SelectedInspectionReport);
+        //    //获取合同信息
+        //    var dictionary = GetContractInformation(SelectedInspectionReport);
 
-            PurchaseCompanyNames = dictionary.ContainsKey("CompanyNames") ? dictionary["CompanyNames"] : string.Empty;
+        //    PurchaseCompanyNames = dictionary.ContainsKey("CompanyNames") ? dictionary["CompanyNames"] : string.Empty;
 
-            ContractNos = dictionary.ContainsKey("ContractNos") ? dictionary["ContractNos"] : string.Empty;
-        }
+        //    ContractNos = dictionary.ContainsKey("ContractNos") ? dictionary["ContractNos"] : string.Empty;
+        //}
 
         /// <summary>
         /// 询问是否保存更改
         /// </summary>
-        private void AskIsSave()
-        {
-            var changed = IsSelectedChanged();
-            if (changed)
-            {
-                var result = MessageBox.Show($"检验报告编号【{SelectedInspectionReport?.ReportNo}】已修改,是否保存修改?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
-                if (result == MessageBoxResult.Yes)
-                {
-                    //保存上一行的修改
-                    SaveInspectionReport();
-                }
-                else
-                {
-                    //放弃更改
-                    var state = _inspectionReportService.Entry(SelectedInspectionReport);
-                    if (state == EntityState.Detached) //新增行直接移除
-                    {
-                        InspectionReports.Remove(SelectedInspectionReport);
-                    }
-
-                    _inspectionReportService.SetEntryState(SelectedInspectionReport, EntityState.Unchanged);
-
-                    var details = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
-                    SelectedInspectionReport.InspectionReportDetails.Clear();
-                    foreach (var detail in details) //重新将数据库的数据赋值过来,并设置跟踪状态Unchanged
-                    {
-                        SelectedInspectionReport.InspectionReportDetails.Add(detail);
-                        _inspectionReportDetailService.SetEntryState(detail, EntityState.Unchanged);
-                    }
-                }
-            }
-        }
+        //private void AskIsSave()
+        //{
+        //    var changed = IsCurrentReportChanged();
+        //    if (changed)
+        //    {
+        //        var result = MessageBox.Show($"检验报告编号【{SelectedInspectionReport?.ReportNo}】已修改,是否保存修改?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
+        //        if (result == MessageBoxResult.Yes)
+        //        {
+        //            //保存上一行的修改
+        //            SaveInspectionReport();
+        //        }
+        //        else
+        //        {
+        //            //放弃更改
+        //            var state = _inspectionReportService.Entry(SelectedInspectionReport);
+        //            if (state == EntityState.Detached) //新增行直接移除
+        //            {
+        //                InspectionReports.Remove(SelectedInspectionReport);
+        //            }
+
+        //            _inspectionReportService.SetEntryState(SelectedInspectionReport, EntityState.Unchanged);
+
+        //            var details = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
+        //            SelectedInspectionReport.InspectionReportDetails.Clear();
+        //            foreach (var detail in details) //重新将数据库的数据赋值过来,并设置跟踪状态Unchanged
+        //            {
+        //                SelectedInspectionReport.InspectionReportDetails.Add(detail);
+        //                _inspectionReportDetailService.SetEntryState(detail, EntityState.Unchanged);
+        //            }
+        //        }
+        //    }
+        //}
 
         /// <summary>
         /// 根据检验申请-合同信息拼接采购机构名称
@@ -218,7 +225,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         [RelayCommand]
         public void AddInspectionReport()
         {
-            AskIsSave();
+            //AskIsSave();
 
             /* 打开窗口,展示检验报告状态未生成的检验申请列表,选择检验申请,携带检验申请数据 */
             SelectInspectApplyWindowViewModel viewModel =
@@ -235,6 +242,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             InspectionReport inspectionReport = new InspectionReport
             {
                 InspectApply = inspectApply,
+                InspectApplyGuid = inspectApply.Guid,
                 ReportNo = inspectApply.ApplyNo.Replace("申请", ""),
                 Department = App.CurrentUser!.SupervisionUnit.Name,
                 ReportTime = DateTime.Now,
@@ -244,10 +252,11 @@ namespace UniformMaterialManagementSystem.ViewModels
                 InspectionReportDetails = []
             };
 
-            InspectionReports.Add(inspectionReport);
+            InspectionReportModel model = new InspectionReportModel(inspectionReport);
+            InspectionReports.Add(model);
 
             //选中当前行
-            InspectionReportSelectionChanged(inspectionReport);
+            SelectedInspectionReport = model;
         }
 
         /// <summary>
@@ -307,30 +316,54 @@ namespace UniformMaterialManagementSystem.ViewModels
                 return;
             }
 
-            var state = _inspectionReportService.Entry(SelectedInspectionReport);
-            switch (state)
+            var inspectionReport = _inspectionReportService.Get(x => x.Guid == SelectedInspectionReport.Guid);
+            if (inspectionReport == null) //新增行
             {
-                case EntityState.Detached:
-                case EntityState.Added:
-                    _inspectionReportService.Insert(SelectedInspectionReport);
-                    break;
-
-                case EntityState.Modified:
-                    _inspectionReportService.Update(SelectedInspectionReport);
-                    break;
+                InspectionReport newInspectionReport = new InspectionReport(); 
+                SelectedInspectionReport.ModifyInspectionReport(newInspectionReport);
+                _inspectionReportService.Insert(newInspectionReport);
             }
-
-            //处理明细表新增行(无法跟踪明细表的新增行)
-            var existReportDetails = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
-            foreach (var detail in SelectedInspectionReport.InspectionReportDetails)
+            else  //判断是否修改
             {
-                var existDetail = existReportDetails.FirstOrDefault(x => x.Guid == detail.Guid);
-                if (existDetail == null)
+                SelectedInspectionReport.ModifyInspectionReport(inspectionReport);
+                var state = _inspectionReportService.Entry(inspectionReport);//主表修改状态
+
+                ////处理明细表新增行(无法跟踪明细表的新增行)
+                var existReportDetails = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == inspectionReport.Guid).ToList();
+                foreach (var detail in SelectedInspectionReport.InspectionReportDetails)
                 {
-                    _inspectionReportDetailService.Insert(detail);
+                    var existDetail = existReportDetails.FirstOrDefault(x => x.Guid == detail.Guid);
+                    if (existDetail == null)
+                    {
+                        _inspectionReportDetailService.Insert(detail);
+                    }
                 }
             }
 
+            //var state = _inspectionReportService.Entry(SelectedInspectionReport);
+            //switch (state)
+            //{
+            //    case EntityState.Detached:
+            //    case EntityState.Added:
+            //        _inspectionReportService.Insert(SelectedInspectionReport);
+            //        break;
+
+            //    case EntityState.Modified:
+            //        _inspectionReportService.Update(SelectedInspectionReport);
+            //        break;
+            //}
+
+            ////处理明细表新增行(无法跟踪明细表的新增行)
+            //var existReportDetails = _inspectionReportDetailService.GetAll(x => x.InspectionReportGuid == SelectedInspectionReport.Guid).ToList();
+            //foreach (var detail in SelectedInspectionReport.InspectionReportDetails)
+            //{
+            //    var existDetail = existReportDetails.FirstOrDefault(x => x.Guid == detail.Guid);
+            //    if (existDetail == null)
+            //    {
+            //        _inspectionReportDetailService.Insert(detail);
+            //    }
+            //}
+
             /* 反写检验申请单的检验报告状态为true */
             var inpecApply = _inspectApplyService.Get(x => x.Guid == SelectedInspectionReport.InspectApplyGuid);
             if (inpecApply != null)
@@ -345,6 +378,8 @@ namespace UniformMaterialManagementSystem.ViewModels
             }
         }
 
+       
+
         /// <summary>
         /// 导出检验报告
         /// </summary>
@@ -353,6 +388,13 @@ namespace UniformMaterialManagementSystem.ViewModels
         {
             if (SelectedInspectionReport == null) return;
 
+            bool isChanged = IsCurrentReportChanged(SelectedInspectionReport);
+            if (isChanged)
+            {
+                MessageBox.Show($"检验报告编号【{SelectedInspectionReport.ReportNo}】未保存,请保存后再导出!","提示",MessageBoxButton.OK,MessageBoxImage.Warning);
+                return;
+            }
+
             const string templateFilePath = "Template\\军需物资质量监督检验报告模板.docx";
             SaveFileDialog saveFileDialog = new SaveFileDialog()
             {
@@ -364,7 +406,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             var destinationFile = saveFileDialog.FileName;
 
             var dictionary = CreateDictionary(SelectedInspectionReport);
-            var tempFile = "Template\\temp.docx";
+            var tempFile = $"Template\\temp_{WordUtil.GenerateFileSerialNumber()}.docx";
 
             WordUtil.GenerateWordByTemplate(templateFilePath, tempFile, dictionary);
             WordUtil.SaveWordToPdf(tempFile, destinationFile);
@@ -373,12 +415,9 @@ namespace UniformMaterialManagementSystem.ViewModels
             File.Delete(tempFile);
 
             MessageBox.Show("文档已生成!");
-
-
-
         }
 
-        private Dictionary<string, string> CreateDictionary(InspectionReport inspectionReport)
+        private Dictionary<string, string> CreateDictionary(InspectionReportModel inspectionReport)
         {
             Dictionary<string, string> dictionary = new Dictionary<string, string>();
             dictionary.Add("ReportNo", inspectionReport.ReportNo);
@@ -403,15 +442,15 @@ namespace UniformMaterialManagementSystem.ViewModels
             dictionary.Add("ProductName", inspectionReport.InspectApply.ProductName);
             dictionary.Add("Company", inspectionReport.InspectApply.Company);
             dictionary.Add("InspQuantity", inspectionReport.InspectApply.InspQuantity + inspectionReport.InspectApply.Material.MeasureUnit);
-            dictionary.Add("ProductDate", inspectionReport.InspectApply.StartProductDate.ToString("yyyy-MM") + "至" + inspectionReport.InspectApply.EndProductDate.ToString("yyyy-MM"));
+            dictionary.Add("ProductDate", inspectionReport.InspectApply.StartProductDate.ToString("yyyy-MM-dd") + "至" + inspectionReport.InspectApply.EndProductDate.ToString("yyyy-MM-dd"));
 
             //采购机构、合同号
             StringBuilder purchaseCompanies = new StringBuilder();
             StringBuilder contractNos = new StringBuilder();
             foreach (var detail in inspectionReport.InspectApply.InspectApplyContractDetails)
             {
-                purchaseCompanies.Append(detail.PurchaseCompanyShortName).Append("");
-                contractNos.Append(detail.ContractNo).Append("");
+                purchaseCompanies.Append(detail.PurchaseCompanyShortName).Append(" ");
+                contractNos.Append(detail.ContractNo).Append(";");
             }
             dictionary.Add("PurchaseCompany", purchaseCompanies.ToString().Substring(0, purchaseCompanies.Length - 1));
             dictionary.Add("ContractNumber", contractNos.ToString().Substring(0, contractNos.Length - 1));

+ 9 - 9
UniformMaterialManagementSystem/ViewModels/SampleRegistrationPageViewModel.cs

@@ -75,15 +75,15 @@ namespace UniformMaterialManagementSystem.ViewModels
         /// <summary>
         /// 选择行改变事件
         /// </summary>
-        [RelayCommand]
-        private void SampleRegistrationSelectionChanged(SampleRegistrationModel sample)
-        {
-            //询问是否保存修改内容
-            AskIsSave();
-
-            //切换行
-            SelectedSampleRegistration = sample;
-        }
+        //[RelayCommand]
+        //private void SampleRegistrationSelectionChanged(SampleRegistrationModel sample)
+        //{
+        //    //询问是否保存修改内容
+        //    AskIsSave();
+
+        //    //切换行
+        //    SelectedSampleRegistration = sample;
+        //}
 
         /// <summary>
         /// 新增

+ 38 - 25
UniformMaterialManagementSystem/Views/InspectionReportPage.xaml

@@ -226,7 +226,7 @@
                                         </ControlTemplate>
                                     </Button.Template>
                                 </Button>
-                                <Button Command="{Binding SaveInspectionReportCommand}">
+                                <Button Command="{Binding SaveInspectionReportCommand}" x:Name="SaveButton" Click="SaveButton_OnClick">
                                     <Button.Template>
                                         <ControlTemplate>
                                             <Border
@@ -297,17 +297,18 @@
                 ItemsSource="{Binding InspectionReports, Mode=TwoWay}"
                 RowHeaderStyle="{StaticResource CustomRowHeaderStyle}"
                 RowStyle="{StaticResource CustomRowStyle}"
+                SelectedItem="{Binding SelectedInspectionReport, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                 SelectionMode="Single"
                 ShowRowsCount="True"
                 ShowStatusBar="True"
                 VerticalGridLinesBrush="LightSlateGray">
 
                 <!--  选择行事件  -->
-                <b:Interaction.Triggers>
+                <!--<b:Interaction.Triggers>
                     <b:EventTrigger EventName="SelectionChanged">
                         <b:InvokeCommandAction Command="{Binding InspectionReportSelectionChangedCommand}" CommandParameter="{Binding ElementName=DataGridMain, Path=SelectedItem}" />
                     </b:EventTrigger>
-                </b:Interaction.Triggers>
+                </b:Interaction.Triggers>-->
 
                 <control:FilterDataGrid.Resources>
                     <!--  非编辑模式下文本居中的样式  -->
@@ -385,23 +386,23 @@
                 <Grid Background="White">
                     <Grid.RowDefinitions>
                         <RowDefinition Height="50" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="60" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="150" />
                         <RowDefinition Height="170" />
                         <RowDefinition Height="200" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
                     </Grid.RowDefinitions>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
+                        <ColumnDefinition Width="3*" />
+                        <ColumnDefinition Width="3*" />
+                        <ColumnDefinition Width="3*" />
                         <ColumnDefinition Width="*" />
                     </Grid.ColumnDefinitions>
 
@@ -417,11 +418,12 @@
                         Grid.Row="1"
                         Grid.Column="0"
                         HorizontalAlignment="Right"
-                        Text="检验报告编号:" />
-                    <TextBox
+                        Text="检验报告编号:"
+                        TextWrapping="Wrap" />
+                    <TextBlock
                         Grid.Row="1"
                         Grid.Column="1"
-                        IsReadOnly="True"
+                        Grid.ColumnSpan="3"
                         Text="{Binding SelectedInspectionReport.ReportNo}" />
                     <TextBlock
                         Grid.Row="2"
@@ -498,7 +500,8 @@
                     <TextBlock
                         Grid.Row="4"
                         Grid.Column="1"
-                        Text="{Binding SelectedInspectionReport.InspectApply.Material.Name}" />
+                        Text="{Binding SelectedInspectionReport.InspectApply.Material.Name}"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="4"
                         Grid.Column="2"
@@ -507,12 +510,14 @@
                     <TextBlock
                         Grid.Row="4"
                         Grid.Column="3"
-                        Text="{Binding SelectedInspectionReport.InspectApply.Company}" />
+                        Text="{Binding SelectedInspectionReport.InspectApply.Company}"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="5"
                         Grid.Column="0"
                         HorizontalAlignment="Right"
-                        Text="产品数量:" />
+                        Text="产品数量:"
+                        TextWrapping="Wrap" />
                     <Grid
                         Grid.Row="5"
                         Grid.Column="1"
@@ -534,13 +539,19 @@
                         Grid.Column="3"
                         Background="White">
                         <Grid.ColumnDefinitions>
-                            <ColumnDefinition Width="Auto" />
+                            <ColumnDefinition Width="*" />
                             <ColumnDefinition Width="Auto" />
                             <ColumnDefinition Width="*" />
                         </Grid.ColumnDefinitions>
-                        <TextBlock Grid.Column="0" Text="{Binding SelectedInspectionReport.InspectApply.StartProductDate, StringFormat=yyyy年MM月}" />
+                        <TextBlock
+                            Grid.Column="0"
+                            Text="{Binding SelectedInspectionReport.InspectApply.StartProductDate, StringFormat=yyyy-MM-dd}"
+                            TextWrapping="Wrap" />
                         <TextBlock Grid.Column="1" Text="至" />
-                        <TextBlock Grid.Column="2" Text="{Binding SelectedInspectionReport.InspectApply.EndProductDate, StringFormat=yyyy年MM月}" />
+                        <TextBlock
+                            Grid.Column="2"
+                            Text="{Binding SelectedInspectionReport.InspectApply.EndProductDate, StringFormat=yyyy-MM-dd}"
+                            TextWrapping="Wrap" />
                     </Grid>
                     <TextBlock
                         Grid.Row="6"
@@ -552,7 +563,7 @@
                         Grid.Column="1"
                         Height="60"
                         IsReadOnly="True"
-                        Text="{Binding PurchaseCompanyNames}"
+                        Text="{Binding SelectedInspectionReport.PurchaseCompanyNames}"
                         TextWrapping="Wrap"
                         VerticalScrollBarVisibility="Auto" />
                     <TextBlock
@@ -565,7 +576,7 @@
                         Grid.Column="3"
                         Height="60"
                         IsReadOnly="True"
-                        Text="{Binding ContractNos}"
+                        Text="{Binding SelectedInspectionReport.ContractNos}"
                         TextWrapping="Wrap"
                         VerticalScrollBarVisibility="Auto" />
                     <TextBlock
@@ -577,7 +588,9 @@
                         Grid.Row="7"
                         Grid.Column="1"
                         Grid.ColumnSpan="3"
-                        Text="{Binding SelectedInspectionReport.ReportBasis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                        HorizontalScrollBarVisibility="Auto"
+                        Text="{Binding SelectedInspectionReport.ReportBasis, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="8"
                         Grid.Column="0"

+ 4 - 0
UniformMaterialManagementSystem/Views/InspectionReportPage.xaml.cs

@@ -91,5 +91,9 @@ namespace UniformMaterialManagementSystem.Views
             comboBox.SelectedItem = text;
         }
 
+        private void SaveButton_OnClick(object sender, RoutedEventArgs e)
+        {
+            DataGridDetail.CommitEdit();
+        }
     }
 }

+ 30 - 20
UniformMaterialManagementSystem/Views/SampleRegistrationPage.xaml

@@ -296,17 +296,19 @@
                 ItemsSource="{Binding SampleRegistrations, Mode=TwoWay}"
                 RowHeaderStyle="{StaticResource CustomRowHeaderStyle}"
                 RowStyle="{StaticResource CustomRowStyle}"
+                SelectedItem="{Binding SelectedSampleRegistration, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                SelectionChanged="DataGridMain_OnSelectionChanged"
                 SelectionMode="Single"
                 ShowRowsCount="True"
                 ShowStatusBar="True"
                 VerticalGridLinesBrush="LightSlateGray">
 
                 <!--  选择行事件  -->
-                <b:Interaction.Triggers>
+                <!--<b:Interaction.Triggers>
                     <b:EventTrigger EventName="SelectionChanged">
                         <b:InvokeCommandAction Command="{Binding SampleRegistrationSelectionChangedCommand}" CommandParameter="{Binding ElementName=DataGridMain, Path=SelectedItem}" />
                     </b:EventTrigger>
-                </b:Interaction.Triggers>
+                </b:Interaction.Triggers>-->
 
                 <control:FilterDataGrid.Resources>
                     <!--  非编辑模式下文本居中的样式  -->
@@ -401,24 +403,24 @@
                 <Grid Background="White">
                     <Grid.RowDefinitions>
                         <RowDefinition Height="50" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="45" />
                         <RowDefinition Height="40" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="80" />
                         <RowDefinition Height="40" />
                         <RowDefinition Height="150" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="40" />
+                        <RowDefinition Height="40" />
 
                     </Grid.RowDefinitions>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
-                        <ColumnDefinition Width="2*" />
+                        <ColumnDefinition Width="3*" />
+                        <ColumnDefinition Width="3*" />
+                        <ColumnDefinition Width="3*" />
                         <ColumnDefinition Width="*" />
                     </Grid.ColumnDefinitions>
 
@@ -439,7 +441,7 @@
                     <TextBlock
                         Grid.Row="1"
                         Grid.Column="1"
-                        Grid.ColumnSpan="2"
+                        Grid.ColumnSpan="3"
                         Text="{Binding SelectedSampleRegistration.SampleNo}" />
                     <TextBlock
                         Grid.Row="2"
@@ -500,7 +502,8 @@
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="样品名称:" />
+                        Text="样品名称:"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="4"
                         Grid.Column="1"
@@ -511,17 +514,20 @@
                         Grid.Column="2"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="生产企业:" />
+                        Text="生产企业:"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="4"
                         Grid.Column="3"
-                        Text="{Binding SelectedSampleRegistration.InspectApply.Company}" />
+                        Text="{Binding SelectedSampleRegistration.InspectApply.Company}"
+                        TextWrapping="Wrap" />
                     <TextBlock
                         Grid.Row="5"
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="样品生产日期:" />
+                        Text="样品生产日期:"
+                        TextWrapping="Wrap" />
                     <DatePicker
                         Grid.Row="5"
                         Grid.Column="1"
@@ -562,7 +568,8 @@
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="检测项目:" />
+                        Text="检测项目:"
+                        TextWrapping="Wrap" />
                     <GroupBox
                         Grid.Row="7"
                         Grid.Column="1"
@@ -662,7 +669,8 @@
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="检测机构:" />
+                        Text="检测机构:"
+                        TextWrapping="Wrap" />
                     <TextBox
                         Grid.Row="9"
                         Grid.Column="1"
@@ -677,7 +685,8 @@
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="*生产企业人员:" />
+                        Text="*生产企业人员:"
+                        TextWrapping="Wrap" />
                     <TextBox
                         Grid.Row="10"
                         Grid.Column="1"
@@ -688,7 +697,8 @@
                         Grid.Column="0"
                         HorizontalAlignment="Right"
                         VerticalAlignment="Center"
-                        Text="*承办人:" />
+                        Text="*承办人:"
+                        TextWrapping="Wrap" />
                     <TextBox
                         Grid.Row="11"
                         Grid.Column="1"

+ 63 - 1
UniformMaterialManagementSystem/Views/SampleRegistrationPage.xaml.cs

@@ -1,6 +1,13 @@
-using Microsoft.Extensions.DependencyInjection;
+using System.Collections.ObjectModel;
+using System.Windows;
+using Microsoft.Extensions.DependencyInjection;
 using System.Windows.Controls;
+using Microsoft.EntityFrameworkCore;
+using UniformMaterialManagementSystem.Data;
+using UniformMaterialManagementSystem.Models;
 using UniformMaterialManagementSystem.ViewModels;
+using UniformMaterialManagementSystem.Entities;
+using UniformMaterialManagementSystem.Services;
 
 namespace UniformMaterialManagementSystem.Views
 {
@@ -72,5 +79,60 @@ namespace UniformMaterialManagementSystem.Views
             }
         }
 
+        private void DataGridMain_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
+        {
+            var itemsSource = DataGridMain.ItemsSource as ObservableCollection<SampleRegistrationModel>;
+            var count = e.RemovedItems.Count;
+
+            //判断移除选中的行是否需要保存
+            if (count == 0) return;
+            SampleRegistrationModel? preSampleRegistration = e.RemovedItems[0] as SampleRegistrationModel;
+            if (preSampleRegistration == null) return;
+
+            using SqliteContext context = new();
+            var sampleRegistration = context.SampleRegistrations.Where(x => x.Guid == preSampleRegistration.Guid).ToList().FirstOrDefault();
+            //if (sampleRegistration == null)//新增行
+            //{
+            //    MessageBox.Show("数据已新增,请保存后切换行!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+
+            //    //选中原来行
+            //    //e.AddedItems.Clear();
+            //    DataGridMain.SelectedItem = preSampleRegistration;
+            //}
+            //else
+            //{
+            //    //判断是否修改
+            //    IDataBaseService<SampleRegistration> service = new DataBaseService<SampleRegistration>(context);
+            //    ModifySampleRegistrationFromModel(sampleRegistration, preSampleRegistration);
+            //    var state = service.Entry(sampleRegistration);
+            //    if (state == EntityState.Modified)
+            //    {
+            //        MessageBox.Show("数据已修改,请保存后切换行!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+
+            //        //选中原来行
+            //        //if (e.AddedItems.Count > 0)
+            //        //{
+            //        //    e.AddedItems[0] = preSampleRegistration;
+            //        //}
+            //        DataGridMain.SelectedItem = preSampleRegistration;
+            //    }
+            //}
+        }
+
+        private void ModifySampleRegistrationFromModel(SampleRegistration sampleRegistration, SampleRegistrationModel model)
+        {
+            sampleRegistration.Department = model.Department;
+            sampleRegistration.EditTime = model.EditTime;
+            sampleRegistration.ProductDate = model.ProductDate;
+            sampleRegistration.BatchNo = model.BatchNo;
+            sampleRegistration.PacketNo = model.PacketNo;
+            sampleRegistration.Quantity = model.Quantity;
+            sampleRegistration.TestingItem = model.TestingItem;
+            sampleRegistration.SingleIndexItem = model.SingleIndexItem;
+            sampleRegistration.InspectionOrganization = model.InspectionOrganization;
+            sampleRegistration.ProductUsers = model.ProductUsers;
+            sampleRegistration.EditUser = model.EditUser;
+            sampleRegistration.Telephone = model.Telephone;
+        }
     }
 }