Selaa lähdekoodia

抽样登记表新增及保存

LT069288 3 kuukautta sitten
vanhempi
commit
7a1bb1bdb0

+ 1 - 1
UniformMaterialManagementSystem/App.xaml.cs

@@ -80,7 +80,7 @@ namespace UniformMaterialManagementSystem
             services.AddTransient<ContractPageViewModel>();
             services.AddTransient<DeliveryReceiptViewModel>();
             services.AddTransient<InspectionReportPageViewModel>();
-            services.AddTransient<SelectInspectApplyToReportWindowViewModel>();
+            services.AddTransient<SampleRegistrationPageViewModel>();
 
             // Service 注册
             services.AddScoped(typeof(IDataBaseService<>), typeof(DataBaseService<>));

+ 111 - 0
UniformMaterialManagementSystem/Models/SampleRegistrationModel.cs

@@ -0,0 +1,111 @@
+using System;
+using System.Collections.Generic;
+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 SampleRegistrationModel : ObservableObject
+    {
+        [ObservableProperty]
+        private Guid _guid;
+
+        [ObservableProperty]
+        private Guid _inspectApplyGuid;
+
+        [ObservableProperty]
+        private string _sampleNo = null!;
+
+        [ObservableProperty]
+        private string _department = null!;
+
+        [ObservableProperty]
+        private DateTime _editTime;
+
+        [ObservableProperty]
+        private DateTime _productDate;
+
+        [ObservableProperty]
+        private string _batchNo = null!;
+
+        [ObservableProperty]
+        private string _packetNo = null!;
+
+        [ObservableProperty]
+        private double _quantity;
+
+        [ObservableProperty]
+        private string _testingItem = null!;
+
+        [ObservableProperty]
+        private string? _singleIndexItem;
+
+        [ObservableProperty]
+        private string _inspectionOrganization = null!;
+
+        [ObservableProperty]
+        private string? _productUsers;
+
+        [ObservableProperty]
+        private string _editUser = null!;
+
+        [ObservableProperty]
+        private string? _telephone = null!;
+
+        [ObservableProperty]
+        private InspectApply _inspectApply = null!;
+
+        public SampleRegistrationModel()
+        {
+            Guid = Guid.NewGuid();
+        }
+
+        public SampleRegistrationModel(SampleRegistration sample)
+        {
+            Guid = sample.Guid;
+            InspectApplyGuid = sample.InspectApplyGuid;
+            SampleNo = sample.SampleNo;
+            Department = sample.Department;
+            EditTime = sample.EditTime;
+            ProductDate = sample.ProductDate;
+            BatchNo = sample.BatchNo;
+            PacketNo = sample.PacketNo;
+            Quantity = sample.Quantity;
+            TestingItem = sample.TestingItem;
+            SingleIndexItem = sample.SingleIndexItem;
+            InspectionOrganization = sample.InspectionOrganization;
+            ProductUsers = sample.ProductUsers;
+            EditUser = sample.EditUser;
+            Telephone = sample.Telephone;
+            InspectApply = sample.InspectApply;
+        }
+
+        public SampleRegistration ConvertToSampleRegistration()
+        {
+            SampleRegistration sample = new SampleRegistration
+            {
+                Guid = this.Guid,
+                InspectApplyGuid = this.InspectApplyGuid,
+                SampleNo = this.SampleNo,
+                Department = this.Department,
+                EditTime = this.EditTime,
+                ProductDate = this.ProductDate,
+                BatchNo = this.BatchNo,
+                PacketNo = this.PacketNo,
+                Quantity = this.Quantity,
+                TestingItem = this.TestingItem,
+                SingleIndexItem = this.SingleIndexItem,
+                InspectionOrganization = this.InspectionOrganization,
+                ProductUsers = this.ProductUsers,
+                EditUser = this.EditUser,
+                Telephone = this.Telephone,
+                InspectApply = this.InspectApply,
+            };
+            return sample;
+        }
+    }
+}

BIN
UniformMaterialManagementSystem/Resources/Pictures/DeliveryReceipt.png


+ 4 - 1
UniformMaterialManagementSystem/ViewModels/InspectionReportPageViewModel.cs

@@ -221,7 +221,10 @@ namespace UniformMaterialManagementSystem.ViewModels
             AskIsSave();
 
             /* 打开窗口,展示检验报告状态未生成的检验申请列表,选择检验申请,携带检验申请数据 */
-            SelectInspectApplyToReportWindow inspectApplyWindow = new SelectInspectApplyToReportWindow();
+            SelectInspectApplyWindowViewModel viewModel =
+                new SelectInspectApplyWindowViewModel(_inspectApplyService, "InspectionReport");
+            SelectInspectApplyWindow inspectApplyWindow = new SelectInspectApplyWindow(viewModel);
+
             var result = inspectApplyWindow.ShowDialog();
             if (result == null || !(bool)result) return;
 

+ 341 - 0
UniformMaterialManagementSystem/ViewModels/SampleRegistrationPageViewModel.cs

@@ -0,0 +1,341 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Microsoft.EntityFrameworkCore;
+using UniformMaterialManagementSystem.Entities;
+using UniformMaterialManagementSystem.Models;
+using UniformMaterialManagementSystem.Services;
+using UniformMaterialManagementSystem.Utils;
+using UniformMaterialManagementSystem.Views;
+using static Microsoft.EntityFrameworkCore.DbLoggerCategory;
+
+namespace UniformMaterialManagementSystem.ViewModels
+{
+    public partial class SampleRegistrationPageViewModel : ObservableObject
+    {
+        [ObservableProperty]
+        private List<int> _years = [];
+
+        [ObservableProperty]
+        private int _selectedYear = DateTime.Now.Year;
+
+        [ObservableProperty]
+        private ObservableCollection<SampleRegistrationModel> _sampleRegistrations = [];
+
+        [ObservableProperty]
+        private SampleRegistrationModel? _selectedSampleRegistration;
+
+        private readonly IDataBaseService<SampleRegistration> _sampleService;
+        private readonly IDataBaseService<InspectApply> _inspectApplyService;
+        private readonly IDataBaseService<InspectionOrganization> _organizationService;
+
+        public SampleRegistrationPageViewModel(IDataBaseService<SampleRegistration> sampleService, IDataBaseService<InspectApply> inspectApplyService, IDataBaseService<InspectionOrganization> organizationService)
+        {
+            _sampleService = sampleService;
+            _inspectApplyService = inspectApplyService;
+            _organizationService = organizationService;
+
+            //初始化年份
+            for (int i = DateTime.Now.Year - 10; i <= DateTime.Now.Year + 1; i++)
+            {
+                Years.Add(i);
+            }
+
+            //加载数据
+            LoadData();
+        }
+
+        /// <summary>
+        /// 加载数据
+        /// </summary>
+        [RelayCommand]
+        private void LoadData()
+        {
+            var sampleRegistrations = _sampleService.Query()
+                .Include(x => x.InspectApply)
+                .ThenInclude(x => x.Material)
+                .Where(x => x.InspectApply.Year == SelectedYear)
+                .ToList();
+
+            SampleRegistrations.Clear();
+            foreach (var sample in sampleRegistrations)
+            {
+                SampleRegistrations.Add(new SampleRegistrationModel(sample));
+            }
+        }
+
+        /// <summary>
+        /// 选择行改变事件
+        /// </summary>
+        [RelayCommand]
+        private void SampleRegistrationSelectionChanged(SampleRegistrationModel sample)
+        {
+            //询问是否保存修改内容
+            AskIsSave();
+
+            //切换行
+            SelectedSampleRegistration = sample;
+        }
+        
+        /// <summary>
+        /// 新增
+        /// </summary>
+        [RelayCommand]
+        private void AddSampleRegistration()
+        {
+            /* 打开窗口,展示抽样状态未生成的检验申请列表,选择检验申请,携带检验申请数据 */
+            SelectInspectApplyWindowViewModel viewModel =
+                new SelectInspectApplyWindowViewModel(_inspectApplyService, "SampleRegistration");
+            SelectInspectApplyWindow inspectApplyWindow = new SelectInspectApplyWindow(viewModel);
+
+            var result = inspectApplyWindow.ShowDialog();
+            if (result == null || !(bool)result) return;
+
+            var inspectApply = inspectApplyWindow.DataGridMain.SelectedItem as InspectApply;
+            if (inspectApply == null) return;
+
+            //新增抽样登记并设置默认值
+            SampleRegistrationModel sampleRegistration = new SampleRegistrationModel
+            {
+                InspectApply = inspectApply,
+                SampleNo = inspectApply.ApplyNo.Replace("申请", ""),
+                EditTime = DateTime.Now,
+                ProductDate = DateTime.Now,
+                BatchNo = inspectApply.BatchNo,
+                TestingItem = "全检",
+                Department = App.CurrentUser!.SupervisionUnit.Name,
+                EditUser = App.CurrentUser!.UserName,
+            };
+
+            SampleRegistrations.Add(sampleRegistration);
+
+            //选中当前行
+            SelectedSampleRegistration = sampleRegistration;
+        }
+
+        /// <summary>
+        /// 保存
+        /// </summary>
+        [RelayCommand]
+        private void SaveSampleRegistration()
+        {
+            if (SelectedSampleRegistration == null) return;
+
+            //自定义校验
+            var validateDictionary = CustomValidate();
+            if (validateDictionary.ContainsKey("result") && !string.IsNullOrEmpty(validateDictionary["result"]))
+            {
+                MessageBox.Show(validateDictionary["result"],"提示",MessageBoxButton.OK,MessageBoxImage.Error);
+                return;
+            }
+
+            //对新增或修改的抽样登记单进行保存
+            var sampleRegistration = _sampleService.Get(x => x.Guid == SelectedSampleRegistration.Guid);
+            if (sampleRegistration == null)  //新增
+            {
+                sampleRegistration = SelectedSampleRegistration.ConvertToSampleRegistration();
+                _sampleService.Insert(sampleRegistration);
+            }
+            else  //修改
+            {
+                ModifySampleRegistrationFromModel(sampleRegistration, SelectedSampleRegistration);
+            }
+
+            var state = _sampleService.Entry(sampleRegistration);
+
+            //反写检验申请单的抽样送检状态
+            var inspectApply = _inspectApplyService.Get(x => x.Guid == sampleRegistration.InspectApplyGuid);
+            if (inspectApply != null)
+            {
+                inspectApply.SampleStatus = true;
+            }
+
+            var result = _sampleService.SaveChanges();
+
+            if (result)
+            {
+                MessageBox.Show("保存成功!");
+            }
+
+        }
+
+        /// <summary>
+        /// 导出登记表
+        /// </summary>
+        [RelayCommand]
+        private void ExportSampleRegistration()
+        {
+
+        }
+
+        /// <summary>
+        /// 随机抽取检测机构
+        /// </summary>
+        [RelayCommand]
+        private void RandomInspectionOrg()
+        {
+            if (SelectedSampleRegistration == null) return;
+
+            //获取检测机构数量
+            var organizations = _organizationService.QueryNoTracking(x => x.IsEnabled).OrderBy(x => x.OrderNo).ToList();
+            if (organizations.Count == 0)
+            {
+                MessageBox.Show("没有要抽取的检测机构,请先维护检测机构信息!");
+                return;
+            }
+
+            //生成随机数
+            int random = RandomHelper.CreateRandom(organizations.Count);
+            int count = random == 0 ? organizations.Count : random;
+
+            MessageBox.Show($"系统生成随机数为{random},将使用第{count}家检测机构。", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+
+            InspectionOrganization? organization = organizations.Find(x => x.OrderNo == count);
+            if (organization == null)
+            {
+                MessageBox.Show($"第{count}家检测机构不存在,请确保检测机构序号正确!");
+                return;
+            }
+
+            StringBuilder sb = new StringBuilder();
+            sb.AppendLine("1.名称:" + organization.Name);
+            sb.AppendLine("2.地址:" + organization.Address);
+            sb.AppendLine("3.联系人:" + organization.Contacts);
+            sb.AppendLine("4.联系电话:" + organization.Telephone);
+
+            SelectedSampleRegistration.InspectionOrganization = sb.ToString();
+        }
+
+        /// <summary>
+        /// 询问是否保存
+        /// </summary>
+        private void AskIsSave()
+        {
+            if (SelectedSampleRegistration == null) return;
+            var sampleRegistration = _sampleService.Get(x => x.Guid == SelectedSampleRegistration.Guid);
+
+            bool isNew = false;
+            EntityState state = EntityState.Unchanged;
+            if (sampleRegistration == null)
+            {
+                isNew = true;
+            }
+            else
+            {
+                ModifySampleRegistrationFromModel(sampleRegistration, SelectedSampleRegistration);
+
+                state = _sampleService.Entry(sampleRegistration);
+            }
+
+            if (isNew || state == EntityState.Modified) //新增或修改
+            {
+                //询问是否保存
+                var result = MessageBox.Show($"抽样登记表编号:【{SelectedSampleRegistration.SampleNo}】数据已修改,是否保存?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Question);
+                if (result == MessageBoxResult.Yes)
+                {
+                    //保存修改
+                    SaveSampleRegistration();
+                }
+                else if (result == MessageBoxResult.No)
+                {
+                    if (isNew)
+                    {
+                        SampleRegistrations.Remove(SelectedSampleRegistration);
+                    }
+                    else if (state == EntityState.Modified)
+                    {
+                        _sampleService.SetEntryState(sampleRegistration, EntityState.Unchanged);
+                        ModifyModelFromSampleRegistration(SelectedSampleRegistration, sampleRegistration);
+                    }
+                }
+            }
+        }
+
+        private Dictionary<string, string> CustomValidate()
+        {
+            Dictionary<string, string> result = new Dictionary<string, string>();
+            StringBuilder errorMessage = new StringBuilder();
+
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.Department))
+            {
+                errorMessage.Append("单位不允许为空!\n");
+            }
+            if (SelectedSampleRegistration?.EditTime == null)
+            {
+                errorMessage.Append("时间不允许为空!\n");
+            }
+            if (SelectedSampleRegistration?.ProductDate == null)
+            {
+                errorMessage.Append("样品生产日期不允许为空!\n");
+            }
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.PacketNo))
+            {
+                errorMessage.Append("包号不允许为空!\n");
+            }
+            if (SelectedSampleRegistration?.Quantity <= 0)
+            {
+                errorMessage.Append("数量不允许小于等于0!\n");
+            }
+            if (SelectedSampleRegistration?.TestingItem == "单项指标" && string.IsNullOrEmpty(SelectedSampleRegistration?.SingleIndexItem))
+            {
+                errorMessage.Append("检测项目为“单项指标”,单项指标内容不允许为空!\n");
+            }
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.InspectionOrganization))
+            {
+                errorMessage.Append("检测机构不允许为空,请抽取检测机构!\n");
+            }
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.ProductUsers))
+            {
+                errorMessage.Append("生产企业人员不允许为空!\n");
+            }
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.EditUser))
+            {
+                errorMessage.Append("承办人不允许为空!\n");
+            }
+            if (string.IsNullOrEmpty(SelectedSampleRegistration?.Telephone))
+            {
+                errorMessage.Append("联系电话不允许为空!\n");
+            }
+            result.Add("result", errorMessage.ToString());
+            return result;
+        }
+
+        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;
+        }
+
+        private void ModifyModelFromSampleRegistration(SampleRegistrationModel model, SampleRegistration sampleRegistration)
+        {
+            model.Department = sampleRegistration.Department;
+            model.EditTime = sampleRegistration.EditTime;
+            model.ProductDate = sampleRegistration.ProductDate;
+            model.BatchNo = sampleRegistration.BatchNo;
+            model.PacketNo = sampleRegistration.PacketNo;
+            model.Quantity = sampleRegistration.Quantity;
+            model.TestingItem = sampleRegistration.TestingItem;
+            model.SingleIndexItem = sampleRegistration.SingleIndexItem;
+            model.InspectionOrganization = sampleRegistration.InspectionOrganization;
+            model.ProductUsers = sampleRegistration.ProductUsers;
+            model.EditUser = sampleRegistration.EditUser;
+            model.Telephone = sampleRegistration.Telephone;
+        }
+    }
+}

+ 0 - 49
UniformMaterialManagementSystem/ViewModels/SelectInspectApplyToReportWindowViewModel.cs

@@ -1,49 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Collections.ObjectModel;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
-using CommunityToolkit.Mvvm.ComponentModel;
-using CommunityToolkit.Mvvm.Input;
-using Microsoft.EntityFrameworkCore;
-using UniformMaterialManagementSystem.Entities;
-using UniformMaterialManagementSystem.Services;
-
-namespace UniformMaterialManagementSystem.ViewModels
-{
-    public partial class SelectInspectApplyToReportWindowViewModel :ObservableObject
-    {
-        
-        [ObservableProperty] 
-        private ObservableCollection<InspectApply>  _inspectApplies = [];
-
-        private InspectApply? _selectedInspectApply;
-
-        private readonly IDataBaseService<InspectApply> _inspectApplyService;
-            
-        public SelectInspectApplyToReportWindowViewModel(IDataBaseService<InspectApply> inspectApplyService)
-        {
-            _inspectApplyService = inspectApplyService;
-
-            var inspectApplyList = _inspectApplyService.Query(x => !x.ReportStatus)
-                .Include(x=>x.InspectApplyContractDetails)
-                .Include(x=>x.Material).ToList();
-            foreach (var inspectApply in inspectApplyList)
-            {
-                InspectApplies.Add(inspectApply);
-            }
-        }
-
-        /// <summary>
-        /// 选择行改变事件
-        /// </summary>
-        [RelayCommand]
-        private void InspectApplySelectionChanged(InspectApply inspectApply)
-        {
-            _selectedInspectApply = inspectApply;
-        }
-
-    }
-}

+ 76 - 0
UniformMaterialManagementSystem/ViewModels/SelectInspectApplyWindowViewModel.cs

@@ -0,0 +1,76 @@
+using System;
+using System.Collections.Generic;
+using System.Collections.ObjectModel;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using CommunityToolkit.Mvvm.ComponentModel;
+using CommunityToolkit.Mvvm.Input;
+using Microsoft.EntityFrameworkCore;
+using UniformMaterialManagementSystem.Entities;
+using UniformMaterialManagementSystem.Services;
+
+namespace UniformMaterialManagementSystem.ViewModels
+{
+    public partial class SelectInspectApplyWindowViewModel :ObservableObject
+    {
+        
+        [ObservableProperty] 
+        private ObservableCollection<InspectApply>  _inspectApplies = [];
+
+        private InspectApply? _selectedInspectApply;
+
+        private readonly string? _targetPage;
+
+        private readonly IDataBaseService<InspectApply> _inspectApplyService;
+            
+        public SelectInspectApplyWindowViewModel(IDataBaseService<InspectApply> inspectApplyService,string targetPage)
+        {
+            _inspectApplyService = inspectApplyService;
+
+            _targetPage = targetPage;
+
+            LoadData();
+        }
+
+        /// <summary>
+        /// 选择行改变事件
+        /// </summary>
+        [RelayCommand]
+        private void InspectApplySelectionChanged(InspectApply inspectApply)
+        {
+            _selectedInspectApply = inspectApply;
+        }
+
+        private void LoadData()
+        {
+            List<InspectApply>? inspectApplyList;
+            switch (_targetPage)
+            {
+                case "InspectionReport":
+                    inspectApplyList = _inspectApplyService.Query(x => !x.ReportStatus)
+                        .Include(x => x.InspectApplyContractDetails)
+                        .Include(x => x.Material).ToList();
+                    foreach (var inspectApply in inspectApplyList)
+                    {
+                        InspectApplies.Add(inspectApply);
+                    }
+                    break;
+                case "SampleRegistration":
+                    inspectApplyList = _inspectApplyService.Query(x => !x.SampleStatus)
+                        .Include(x => x.InspectApplyContractDetails)
+                        .Include(x => x.Material).ToList();
+                    foreach (var inspectApply in inspectApplyList)
+                    {
+                        InspectApplies.Add(inspectApply);
+                    }
+                    break;
+                case ""://许可证
+                    break;
+            }
+            
+        }
+
+    }
+}

+ 296 - 17
UniformMaterialManagementSystem/Views/SampleRegistrationPage.xaml

@@ -201,7 +201,7 @@
                                     </Button.Template>
                                 </Button>
                                 <Separator />
-                                <Button Command="{Binding AddInspectionReportCommand}">
+                                <Button Command="{Binding AddSampleRegistrationCommand}">
                                     <Button.Template>
                                         <ControlTemplate>
                                             <Border
@@ -225,7 +225,7 @@
                                         </ControlTemplate>
                                     </Button.Template>
                                 </Button>
-                                <Button Command="{Binding SaveInspectionReportCommand}">
+                                <Button Command="{Binding SaveSampleRegistrationCommand}">
                                     <Button.Template>
                                         <ControlTemplate>
                                             <Border
@@ -250,7 +250,7 @@
                                     </Button.Template>
                                 </Button>
                                 <Separator />
-                                <Button Command="{Binding ExportInspectionReportCommand}">
+                                <Button Command="{Binding ExportSampleRegistrationCommand}">
                                     <Button.Template>
                                         <ControlTemplate>
                                             <Border
@@ -293,7 +293,7 @@
                 FilterLanguage="SimplifiedChinese"
                 HeadersVisibility="All"
                 HorizontalGridLinesBrush="LightSlateGray"
-                ItemsSource="{Binding InspectionReports, Mode=TwoWay}"
+                ItemsSource="{Binding SampleRegistrations, Mode=TwoWay}"
                 RowHeaderStyle="{StaticResource CustomRowHeaderStyle}"
                 RowStyle="{StaticResource CustomRowStyle}"
                 SelectionMode="Single"
@@ -304,7 +304,7 @@
                 <!--  选择行事件  -->
                 <b:Interaction.Triggers>
                     <b:EventTrigger EventName="SelectionChanged">
-                        <b:InvokeCommandAction Command="{Binding SelectionChangedCommand}" CommandParameter="{Binding ElementName=DataGridMain, Path=SelectedItem}" />
+                        <b:InvokeCommandAction Command="{Binding SampleRegistrationSelectionChangedCommand}" CommandParameter="{Binding ElementName=DataGridMain, Path=SelectedItem}" />
                     </b:EventTrigger>
                 </b:Interaction.Triggers>
 
@@ -340,23 +340,31 @@
                         IsReadOnly="True" />
                     <control:FilterDataGridTextColumn
                         Width="300"
-                        Binding="{Binding}"
+                        Binding="{Binding SampleNo}"
                         EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                         ElementStyle="{StaticResource TextColumnElementStyle}"
                         Header="抽样登记表编号"
                         IsColumnFiltered="True"
                         IsReadOnly="True" />
+                    <control:FilterDataGridTextColumn
+                        Width="200"
+                        Binding="{Binding InspectApply.Company}"
+                        EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
+                        ElementStyle="{StaticResource TextColumnElementStyle}"
+                        Header="生产企业"
+                        IsColumnFiltered="True"
+                        IsReadOnly="True" />
                     <control:FilterDataGridTextColumn
                         Width="120"
-                        Binding="{Binding}"
+                        Binding="{Binding EditTime, StringFormat=yyyy-MM-dd}"
                         EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                         ElementStyle="{StaticResource TextColumnElementStyle}"
                         Header="抽样时间"
                         IsColumnFiltered="True"
                         IsReadOnly="True" />
                     <control:FilterDataGridTextColumn
-                        Width="120"
-                        Binding="{Binding}"
+                        Width="200"
+                        Binding="{Binding BatchNo}"
                         EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                         ElementStyle="{StaticResource TextColumnElementStyle}"
                         Header="批号"
@@ -364,7 +372,7 @@
                         IsReadOnly="True" />
                     <control:FilterDataGridTextColumn
                         Width="120"
-                        Binding="{Binding}"
+                        Binding="{Binding PacketNo}"
                         EditingElementStyle="{StaticResource TextColumnEditingElementStyle}"
                         ElementStyle="{StaticResource TextColumnElementStyle}"
                         Header="包号"
@@ -396,14 +404,15 @@
                         <RowDefinition Height="35" />
                         <RowDefinition Height="35" />
                         <RowDefinition Height="35" />
+                        <RowDefinition Height="45" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="35" />
-                        <RowDefinition Height="35" />
-                        <RowDefinition Height="60" />
-                        <RowDefinition Height="35" />
+                        <RowDefinition Height="80" />
+                        <RowDefinition Height="40" />
                         <RowDefinition Height="150" />
-                        <RowDefinition Height="170" />
-                        <RowDefinition Height="200" />
                         <RowDefinition Height="35" />
+                        <RowDefinition Height="35" />
+
                     </Grid.RowDefinitions>
                     <Grid.ColumnDefinitions>
                         <ColumnDefinition Width="2*" />
@@ -421,9 +430,279 @@
                         VerticalAlignment="Center"
                         FontSize="25"
                         Text="被装材料产品抽样信息登记表" />
+                    <TextBlock
+                        Grid.Row="1"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="编号:" />
+                    <TextBlock
+                        Grid.Row="1"
+                        Grid.Column="1"
+                        Grid.ColumnSpan="2"
+                        Text="{Binding SelectedSampleRegistration.SampleNo}" />
+                    <TextBlock
+                        Grid.Row="2"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*单位:" />
+                    <TextBox
+                        Grid.Row="2"
+                        Grid.Column="1"
+                        Text="{Binding SelectedSampleRegistration.Department, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="2"
+                        Grid.Column="2"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*时间:" />
+                    <DatePicker
+                        Grid.Row="2"
+                        Grid.Column="3"
+                        Text="{Binding SelectedSampleRegistration.EditTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="3"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="类别:" />
+                    <Grid
+                        Grid.Row="3"
+                        Grid.Column="1"
+                        Grid.ColumnSpan="3"
+                        Background="White">
+                        <Grid.ColumnDefinitions>
+                            <ColumnDefinition Width="*" />
+                            <ColumnDefinition Width="*" />
+                        </Grid.ColumnDefinitions>
+                        <TextBox
+                            x:Name="InspectCategory"
+                            Grid.Column="0"
+                            Text="{Binding SelectedSampleRegistration.InspectApply.InspCategory}"
+                            TextChanged="InspectCategory_TextChanged"
+                            Visibility="Collapsed" />
+                        <RadioButton
+                            x:Name="FirstSelected"
+                            Grid.Column="0"
+                            HorizontalAlignment="Center"
+                            Content="首批检验"
+                            GroupName="CategoryGroup" />
+                        <RadioButton
+                            x:Name="SecondSelected"
+                            Grid.Column="1"
+                            HorizontalAlignment="Center"
+                            Content="出厂检验"
+                            GroupName="CategoryGroup" />
+                    </Grid>
+                    <TextBlock
+                        Grid.Row="4"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="样品名称:" />
+                    <TextBlock
+                        Grid.Row="4"
+                        Grid.Column="1"
+                        Text="{Binding SelectedSampleRegistration.InspectApply.Material.Name}"
+                        TextWrapping="Wrap" />
+                    <TextBlock
+                        Grid.Row="4"
+                        Grid.Column="2"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="生产企业:" />
+                    <TextBlock
+                        Grid.Row="4"
+                        Grid.Column="3"
+                        Text="{Binding SelectedSampleRegistration.InspectApply.Company}" />
+                    <TextBlock
+                        Grid.Row="5"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="样品生产日期:" />
+                    <DatePicker
+                        Grid.Row="5"
+                        Grid.Column="1"
+                        Text="{Binding SelectedSampleRegistration.EditTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="5"
+                        Grid.Column="2"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*批号:" />
+                    <TextBlock
+                        Grid.Row="5"
+                        Grid.Column="3"
+                        Text="{Binding SelectedSampleRegistration.BatchNo}"
+                        TextWrapping="Wrap" />
+                    <TextBlock
+                        Grid.Row="6"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="包号:" />
+                    <TextBox
+                        Grid.Row="6"
+                        Grid.Column="1"
+                        Text="{Binding SelectedSampleRegistration.PacketNo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="6"
+                        Grid.Column="2"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="数量:" />
+                    <TextBox
+                        Grid.Row="6"
+                        Grid.Column="3"
+                        Text="{Binding SelectedSampleRegistration.Quantity, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="7"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="检测项目:" />
+                    <GroupBox
+                        Grid.Row="7"
+                        Grid.Column="1"
+                        Grid.ColumnSpan="3"
+                        VerticalAlignment="Center"
+                        Header="检测项目">
 
-
-
+                        <WrapPanel
+                            AllowDrop="True"
+                            FlowDirection="LeftToRight"
+                            Orientation="Horizontal">
+                            <RadioButton
+                                x:Name="TestAllRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="全检"
+                                GroupName="TestingItemGroup" />
+                            <RadioButton
+                                x:Name="MandatoryTestRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="强制性指标"
+                                GroupName="TestingItemGroup" />
+                            <RadioButton
+                                x:Name="ColorFastnessRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="色牢度"
+                                GroupName="TestingItemGroup" />
+                            <RadioButton
+                                x:Name="SpectrumRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="光谱"
+                                GroupName="TestingItemGroup" />
+                            <RadioButton
+                                x:Name="ReferenceRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="参考性指标"
+                                GroupName="TestingItemGroup" />
+                            <RadioButton
+                                x:Name="SingleRadioButton"
+                                Padding="10,0,10,0"
+                                VerticalContentAlignment="Center"
+                                Checked="RadioButton_Checked"
+                                Content="单项指标"
+                                GroupName="TestingItemGroup" />
+                            <TextBox Width="200" Text="{Binding SelectedSampleRegistration.SingleIndexItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                            <TextBox
+                                x:Name="TestingItemTextBox"
+                                Text="{Binding SelectedSampleRegistration.TestingItem, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                TextChanged="TestingItemTextBox_TextChanged"
+                                Visibility="Collapsed" />
+                        </WrapPanel>
+                    </GroupBox>
+                    <Button
+                        Grid.Row="8"
+                        Grid.Column="1"
+                        HorizontalAlignment="Left"
+                        Command="{Binding RandomInspectionOrgCommand}">
+                        <Button.Template>
+                            <ControlTemplate>
+                                <Border
+                                    Width="140"
+                                    Height="30"
+                                    Background="{TemplateBinding Background}"
+                                    CornerRadius="5">
+                                    <StackPanel
+                                        HorizontalAlignment="Center"
+                                        VerticalAlignment="Center"
+                                        Orientation="Horizontal">
+                                        <TextBlock VerticalAlignment="Center" Text="抽取检测机构" />
+                                        <TextBlock
+                                            HorizontalAlignment="Center"
+                                            VerticalAlignment="Center"
+                                            FontFamily="{StaticResource FluentSystemIconsRegular}"
+                                            FontSize="20"
+                                            Text="{x:Static utils:RegularFontUtil.Tap_Double_24}" />
+                                    </StackPanel>
+                                </Border>
+                                <ControlTemplate.Triggers>
+                                    <Trigger Property="IsMouseOver" Value="True">
+                                        <Setter Property="Background" Value="LightGray" />
+                                    </Trigger>
+                                </ControlTemplate.Triggers>
+                            </ControlTemplate>
+                        </Button.Template>
+                    </Button>
+                    <TextBlock
+                        Grid.Row="9"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="检测机构:" />
+                    <TextBox
+                        Grid.Row="9"
+                        Grid.Column="1"
+                        Grid.ColumnSpan="3"
+                        Height="150"
+                        AcceptsReturn="True"
+                        Text="{Binding SelectedSampleRegistration.InspectionOrganization, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                        TextWrapping="Wrap"
+                        VerticalScrollBarVisibility="Auto" />
+                    <TextBlock
+                        Grid.Row="10"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*生产企业人员:" />
+                    <TextBox
+                        Grid.Row="10"
+                        Grid.Column="1"
+                        Grid.ColumnSpan="3"
+                        Text="{Binding SelectedSampleRegistration.ProductUsers, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="11"
+                        Grid.Column="0"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*承办人:" />
+                    <TextBox
+                        Grid.Row="11"
+                        Grid.Column="1"
+                        Text="{Binding SelectedSampleRegistration.EditUser, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
+                    <TextBlock
+                        Grid.Row="11"
+                        Grid.Column="2"
+                        HorizontalAlignment="Right"
+                        VerticalAlignment="Center"
+                        Text="*联系电话:" />
+                    <TextBox
+                        Grid.Row="11"
+                        Grid.Column="3"
+                        Text="{Binding SelectedSampleRegistration.Telephone, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
                 </Grid>
             </ScrollViewer>
 

+ 61 - 13
UniformMaterialManagementSystem/Views/SampleRegistrationPage.xaml.cs

@@ -1,17 +1,6 @@
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Text;
-using System.Threading.Tasks;
-using System.Windows;
+using Microsoft.Extensions.DependencyInjection;
 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 UniformMaterialManagementSystem.ViewModels;
 
 namespace UniformMaterialManagementSystem.Views
 {
@@ -23,6 +12,65 @@ namespace UniformMaterialManagementSystem.Views
         public SampleRegistrationPage()
         {
             InitializeComponent();
+
+            this.DataContext = App.Current.Services.GetService<SampleRegistrationPageViewModel>();
+        }
+
+        private void InspectCategory_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            var category = sender as TextBox;
+            if (category != null)
+            {
+                switch (category.Text)
+                {
+                    case "首批检验":
+                        FirstSelected.IsChecked = true;
+                        break;
+                    case "出厂检验":
+                        SecondSelected.IsChecked = true;
+                        break;
+                }
+            }
         }
+
+        private void TestingItemTextBox_TextChanged(object sender, TextChangedEventArgs e)
+        {
+            var testingItem = sender as TextBox;
+            if (testingItem != null)
+            {
+                switch (testingItem.Text)
+                {
+                    case "全检":
+                        TestAllRadioButton.IsChecked = true;
+                        break;
+                    case "强制性指标":
+                        MandatoryTestRadioButton.IsChecked = true;
+                        break;
+                    case "色牢度":
+                        ColorFastnessRadioButton.IsChecked = true;
+                        break;
+                    case "光谱":
+                        SpectrumRadioButton.IsChecked = true;
+                        break;
+                    case "参考性指标":
+                        ReferenceRadioButton.IsChecked = true;
+                        break;
+                    case "单项指标":
+                        SingleRadioButton.IsChecked = true;
+                        break;
+                }
+            }
+        }
+
+        private void RadioButton_Checked(object sender, System.Windows.RoutedEventArgs e)
+        {
+            var testingItem = sender as RadioButton;
+            if (testingItem != null && testingItem.Content != null)
+            {
+                var testingItemText = testingItem.Content.ToString();
+                TestingItemTextBox.Text = testingItemText == null ? "" : testingItemText;
+            }
+        }
+
     }
 }

+ 18 - 4
UniformMaterialManagementSystem/Views/SelectInspectApplyToReportWindow.xaml → UniformMaterialManagementSystem/Views/SelectInspectApplyWindow.xaml

@@ -1,5 +1,5 @@
 <Window
-    x:Class="UniformMaterialManagementSystem.Views.SelectInspectApplyToReportWindow"
+    x:Class="UniformMaterialManagementSystem.Views.SelectInspectApplyWindow"
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
@@ -10,9 +10,9 @@
     xmlns:local="clr-namespace:UniformMaterialManagementSystem.Views"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:utils="clr-namespace:UniformMaterialManagementSystem.Utils"
-    Title="选择检验申请单生成检验报告"
-    Width="1000"
-    Height="600"
+    Title="选择检验申请单"
+    Width="1200"
+    Height="800"
     mc:Ignorable="d">
     <Window.Resources>
         <ControlTemplate x:Key="CustomColumnHeaderTemplate" TargetType="DataGridColumnHeader">
@@ -287,6 +287,20 @@
                     Header="检验报告生成状态"
                     IsColumnFiltered="True"
                     IsReadOnly="True" />
+                <control:FilterDataGridCheckBoxColumn
+                    Width="150"
+                    Binding="{Binding SampleStatus, Mode=OneTime}"
+                    ElementStyle="{StaticResource CheckBoxColumnElementStyle}"
+                    Header="抽样登记生成状态"
+                    IsColumnFiltered="True"
+                    IsReadOnly="True" />
+                <control:FilterDataGridCheckBoxColumn
+                    Width="150"
+                    Binding="{Binding LicenseStatus, Mode=OneTime}"
+                    ElementStyle="{StaticResource CheckBoxColumnElementStyle}"
+                    Header="许可证生成状态"
+                    IsColumnFiltered="True"
+                    IsReadOnly="True" />
 
             </control:FilterDataGrid.Columns>
         </filterDataGrid:FilterDataGrid>

+ 4 - 3
UniformMaterialManagementSystem/Views/SelectInspectApplyToReportWindow.xaml.cs → UniformMaterialManagementSystem/Views/SelectInspectApplyWindow.xaml.cs

@@ -19,13 +19,14 @@ namespace UniformMaterialManagementSystem.Views
     /// <summary>
     /// SelectInspectApplyToReportWindow.xaml 的交互逻辑
     /// </summary>
-    public partial class SelectInspectApplyToReportWindow : Window
+    public partial class SelectInspectApplyWindow : Window
     {
-        public SelectInspectApplyToReportWindow()
+        public SelectInspectApplyWindow(SelectInspectApplyWindowViewModel viewModel)
         {
             InitializeComponent();
 
-            this.DataContext = App.Current.Services.GetService(typeof(SelectInspectApplyToReportWindowViewModel));
+            this.DataContext = viewModel;
+
         }
 
         private void ConfirmButton_Click(object sender, RoutedEventArgs e)