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

合同管理导出数据包

LT069288 3 hónapja
szülő
commit
bb6a5b2f87

BIN
UniformMaterialManagementSystem/Resources/Pictures/InspectApply.png


BIN
UniformMaterialManagementSystem/Resources/Pictures/InspectionRecord.png


BIN
UniformMaterialManagementSystem/Resources/Pictures/InspectionReport.png


BIN
UniformMaterialManagementSystem/Resources/Pictures/SampleRegistration.png


+ 2 - 4
UniformMaterialManagementSystem/UniformMaterialManagementSystem.csproj

@@ -28,7 +28,6 @@
 		<None Remove="Resources\Pictures\DeliveryReceipt.png" />
 		<None Remove="Resources\Pictures\FactoryLicense.png" />
 		<None Remove="Resources\Pictures\InspectApply.png" />
-		<None Remove="Resources\Pictures\InspectionRecord.png" />
 		<None Remove="Resources\Pictures\InspectionReport.png" />
 		<None Remove="Resources\Pictures\SampleRegistration.png" />
 		<None Remove="Resources\Pictures\TeamLogo.jpg" />
@@ -53,13 +52,12 @@
 		<Resource Include="Resources\Pictures\InspectApply.png">
 		  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
 		</Resource>
-		<Resource Include="Resources\Pictures\InspectionRecord.png">
+		<Resource Include="Resources\Pictures\InspectionReport.png">
 		  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
 		</Resource>
-		<Resource Include="Resources\Pictures\InspectionReport.png">
+		<Resource Include="Resources\Pictures\SampleRegistration.png">
 		  <CopyToOutputDirectory>Always</CopyToOutputDirectory>
 		</Resource>
-		<Resource Include="Resources\Pictures\SampleRegistration.png" />
 		<Resource Include="Resources\Pictures\TeamLogo.jpg" />
 		<Resource Include="Resources\Pictures\MaterialDelivery.png" />
 		<Resource Include="Resources\Pictures\MaterialReceipt.png" />

+ 94 - 3
UniformMaterialManagementSystem/ViewModels/ContractPageViewModel.cs

@@ -1,5 +1,6 @@
 using CommunityToolkit.Mvvm.ComponentModel;
 using CommunityToolkit.Mvvm.Input;
+using DocumentFormat.OpenXml.Spreadsheet;
 using Microsoft.EntityFrameworkCore;
 using Microsoft.Win32;
 using System.Collections.ObjectModel;
@@ -231,7 +232,7 @@ namespace UniformMaterialManagementSystem.ViewModels
             Attachment = SelectedUnExportContract.Attachment;
             ApplyAttachment = SelectedUnExportContract.ApplyAttachment;
 
-            var existDetails = _contractDetailService.QueryNoTracking(x => x.ContractGuid == SelectedUnExportContract.Guid).Include(x=>x.Material).ToList();
+            var existDetails = _contractDetailService.QueryNoTracking(x => x.ContractGuid == SelectedUnExportContract.Guid).Include(x => x.Material).ToList();
             ContractDetails.Clear();
             foreach (var detail in existDetails)
             {
@@ -570,6 +571,98 @@ namespace UniformMaterialManagementSystem.ViewModels
             }
         }
 
+        /// <summary>
+        /// 导出数据包
+        /// </summary>
+        [RelayCommand]
+        private void ExportDataPacket()
+        {
+            if (UnExportContracts.Count == 0) return;
+
+            List<ContractModel> selectedContracts = new List<ContractModel>();
+            foreach (var contract in UnExportContracts)
+            {
+                if (contract.IsSelected)
+                {
+                    selectedContracts.Add(contract);
+                }
+            }
+
+            if (selectedContracts.Count == 0) return;
+
+            var result = MessageBox.Show($"共选中{selectedContracts.Count}行合同数据,确认导出为合同数据包吗?(导出后将无法修改和删除)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+
+            if (result != MessageBoxResult.OK) return;
+
+            var contractList = _contractService.Query(x => !x.ExportStatus)
+                .Include(x => x.Company)
+                .Include(x => x.PurchaseCompany)
+                .Include(x => x.ContractDetails)
+                .ThenInclude(x => x.Material)
+                .ToList();
+
+            //移除未勾选
+            for (int i = contractList.Count - 1; i >= 0; i--)
+            {
+                var contains = selectedContracts.Any(x => x.Guid == contractList[i].Guid);
+                if (!contains)
+                {
+                    contractList.Remove(contractList[i]);
+                }
+            }
+
+            //导出合同数据包
+            var contracts = contractList.ToArray();
+            var materialCompanies = contracts.Select(x => x.Company).Distinct().ToArray();//材料企业
+            var purchaseCompanies = contracts.Select(x => x.PurchaseCompany).Distinct().ToArray();//成品企业
+            var companies = materialCompanies.Concat(purchaseCompanies).ToArray(); //合并材料企业、成品企业
+            //获取合同明细
+            List<ContractDetail> details = [];
+            foreach (var contract in contracts)
+            {
+                foreach (var detail in contract.ContractDetails)
+                {
+                    details.Add(detail);
+                }
+            }
+
+            var materials = details.ToArray().Select(x => x.Material).Distinct().ToArray();
+
+            //(材料+成品)企业->合同->材料->合同明细
+            if (companies is { Length: > 0 })
+            {
+                DataBaseUtil.ExportTable(companies, "Companies", true);
+            }
+            if (contracts is { Length: > 0 })
+            {
+                DataBaseUtil.ExportTable(contracts, "Contracts");
+            }
+            if (materials is { Length: > 0 })
+            {
+                DataBaseUtil.ExportTable(materials, "Materials");
+            }
+            if (details is { Count: > 0 })
+            {
+                DataBaseUtil.ExportTable(details, "ContractDetails");
+            }
+
+            //对导出数据进行加密,用户选择保存位置
+            DataBaseUtil.ExportData();
+        }
+
+        /// <summary>
+        /// 导入数据包
+        /// </summary>
+        [RelayCommand]
+        private void ImportDataPacket()
+        {
+            var path = DataBaseUtil.ImportData();
+
+            var result = DataBaseUtil.QueryAll<Contract>(path, q =>
+                            q.Include(x => x.Company)
+                                .Include(x => x.PurchaseCompany));
+        }
+
         /// <summary>
         /// 修改采购合同的导出状态
         /// </summary>
@@ -998,8 +1091,6 @@ namespace UniformMaterialManagementSystem.ViewModels
             ExportAttachment(attachment, fileName);
         }
 
-
-
         #endregion
 
         #region 公用私有方法

+ 50 - 1
UniformMaterialManagementSystem/Views/ContractPage.xaml

@@ -277,7 +277,7 @@
                                         <Button.Template>
                                             <ControlTemplate>
                                                 <Border
-                                                    Width="80"
+                                                    Width="85"
                                                     Background="{TemplateBinding Background}"
                                                     CornerRadius="5">
                                                     <StackPanel HorizontalAlignment="Center" Orientation="Vertical">
@@ -297,6 +297,55 @@
                                             </ControlTemplate>
                                         </Button.Template>
                                     </Button>
+                                    <Separator />
+                                    <Button Command="{Binding ExportDataPacketCommand}">
+                                        <Button.Template>
+                                            <ControlTemplate>
+                                                <Border
+                                                    Width="70"
+                                                    Background="{TemplateBinding Background}"
+                                                    CornerRadius="5">
+                                                    <StackPanel HorizontalAlignment="Center" Orientation="Vertical">
+                                                        <TextBlock
+                                                            HorizontalAlignment="Center"
+                                                            FontFamily="{StaticResource FluentSystemIconsRegular}"
+                                                            FontSize="20"
+                                                            Text="{x:Static utils:RegularFontUtil.Folder_Arrow_Up_24}" />
+                                                        <TextBlock Text="导出数据包" />
+                                                    </StackPanel>
+                                                </Border>
+                                                <ControlTemplate.Triggers>
+                                                    <Trigger Property="IsMouseOver" Value="True">
+                                                        <Setter Property="Background" Value="LightGray" />
+                                                    </Trigger>
+                                                </ControlTemplate.Triggers>
+                                            </ControlTemplate>
+                                        </Button.Template>
+                                    </Button>
+                                    <Button Command="{Binding ImportDataPacketCommand}">
+                                        <Button.Template>
+                                            <ControlTemplate>
+                                                <Border
+                                                    Width="70"
+                                                    Background="{TemplateBinding Background}"
+                                                    CornerRadius="5">
+                                                    <StackPanel HorizontalAlignment="Center" Orientation="Vertical">
+                                                        <TextBlock
+                                                            HorizontalAlignment="Center"
+                                                            FontFamily="{StaticResource FluentSystemIconsRegular}"
+                                                            FontSize="20"
+                                                            Text="{x:Static utils:RegularFontUtil.Folder_Add_24}" />
+                                                        <TextBlock Text="导入数据包" />
+                                                    </StackPanel>
+                                                </Border>
+                                                <ControlTemplate.Triggers>
+                                                    <Trigger Property="IsMouseOver" Value="True">
+                                                        <Setter Property="Background" Value="LightGray" />
+                                                    </Trigger>
+                                                </ControlTemplate.Triggers>
+                                            </ControlTemplate>
+                                        </Button.Template>
+                                    </Button>
 
                                 </ToolBar>
                             </ToolBarPanel>