Ver Fonte

优化采购合同勾选多行导出功能

LT069288 há 3 meses atrás
pai
commit
cbe6784e6f

+ 63 - 50
UniformMaterialManagementSystem/ViewModels/ContractPageViewModel.cs

@@ -168,14 +168,14 @@ namespace UniformMaterialManagementSystem.ViewModels
                 contractList = _contractService.Query(x => !x.ExportStatus && x.Year == App.CurrentUser!.WorkYear)
                     .Include(x => x.ContractDetails).ThenInclude(x => x.Material)
                     .Include(x => x.Company)
-                    .Include(x => x.PurchaseCompany).ToList();
+                    .Include(x => x.PurchaseCompany).OrderBy(x=>x.EditDate).ToList();
             }
             else
             {
                 contractList = _contractService.Query(x => !x.ExportStatus && x.Year == App.CurrentUser!.WorkYear && (x.CompanyGuid == App.CurrentUser.CompanyGuid || x.PurchaseCompanyGuid == App.CurrentUser.CompanyGuid))
                     .Include(x => x.ContractDetails).ThenInclude(x => x.Material)
                     .Include(x => x.Company)
-                    .Include(x => x.PurchaseCompany).ToList();
+                    .Include(x => x.PurchaseCompany).OrderBy(x => x.EditDate).ToList();
             }
 
             UnExportContracts.Clear();
@@ -400,67 +400,80 @@ namespace UniformMaterialManagementSystem.ViewModels
         [RelayCommand]
         private void DeleteUnExportContract()
         {
-            //if (SelectedUnExportContract == null)
-            //{
-            //    MessageBox.Show("请选中一行,再进行删除操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
-            //    return;
-            //}
-
-            //if (SelectedUnExportContract.ChangedStatus)
-            //{
-            //    MessageBox.Show("合同正在变更,不可删除!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
-            //    return;
-            //}
-            /* 确认删除提示 */
-            //var result = MessageBox.Show($"确认删除材料合同号:{SelectedUnExportContract.ContractNo}的材料采购合同吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
-            //if (result != MessageBoxResult.OK) return;
-
-            //_contractService?.Delete(x => x.Guid == SelectedUnExportContract.Guid);
-            //_contractService?.SaveChanges();
-            
-
-            var selectedContracts = new List<ContractModel>();
-            var changedContracts = new List<ContractModel>();
-            foreach (var contract in UnExportContracts)
+            if (SelectedUnExportContract == null)
             {
-                if (!contract.IsSelected) continue;
-                if (contract.ChangedStatus)
-                {
-                    changedContracts.Add(contract);
-                }
-                else
-                {
-                    selectedContracts.Add(contract);
-                }
-            }
-
-            if (selectedContracts.Count + changedContracts.Count == 0)
-            {
-                MessageBox.Show($"没有选中任何行", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                MessageBox.Show("请选中一行,再进行删除操作!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
-            if (selectedContracts.Count == 0)
+
+            if (SelectedUnExportContract.ChangedStatus)
             {
-                MessageBox.Show($"变更状态的合同不允许删除,请选择未变更的合同进行删除!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+                MessageBox.Show("合同正在变更,不可删除!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
-
             /* 确认删除提示 */
-            var result = MessageBox.Show($"您选中了{selectedContracts.Count + changedContracts.Count}条合同,将有{changedContracts.Count}条合同被删除,确认继续?(变更状态的合同不允许删除)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            var result = MessageBox.Show($"确认删除材料合同号:{SelectedUnExportContract.ContractNo}的材料采购合同吗?", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
             if (result != MessageBoxResult.OK) return;
 
-            //删除选中行
-            foreach (var contract in selectedContracts)
-            {
-                _contractService?.Delete(x => x.Guid == contract.Guid);
-            }
-
+            _contractService?.Delete(x => x.Guid == SelectedUnExportContract.Guid);
             _contractService?.SaveChanges();
 
+
+            //var selectedContracts = new List<ContractModel>();
+            //var changedContracts = new List<ContractModel>();
+            //foreach (var contract in UnExportContracts)
+            //{
+            //    if (!contract.IsSelected) continue;
+            //    if (contract.ChangedStatus)
+            //    {
+            //        changedContracts.Add(contract);
+            //    }
+            //    else
+            //    {
+            //        selectedContracts.Add(contract);
+            //    }
+            //}
+
+            //if (selectedContracts.Count + changedContracts.Count == 0)
+            //{
+            //    MessageBox.Show($"没有选中任何行", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+            //    return;
+            //}
+            //if (selectedContracts.Count == 0)
+            //{
+            //    MessageBox.Show($"变更状态的合同不允许删除,请选择未变更的合同进行删除!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
+            //    return;
+            //}
+
+            ///* 确认删除提示 */
+            //var result = MessageBox.Show($"您选中了{selectedContracts.Count + changedContracts.Count}条合同,将有{changedContracts.Count}条合同被删除,确认继续?(变更状态的合同不允许删除)", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            //if (result != MessageBoxResult.OK) return;
+
+            ////删除选中行
+            //foreach (var contract in selectedContracts)
+            //{
+            //    _contractService?.Delete(x => x.Guid == contract.Guid);
+            //}
+
+            //_contractService?.SaveChanges();
+
             /* 重新加载数据 */
             LoadUnExportData();
         }
 
+        /// <summary>
+        /// 全部选中或取消全选
+        /// </summary>
+        /// <param name="isChecked"></param>
+        [RelayCommand]
+        private void SelectAll(bool isChecked)
+        {
+            foreach (var contract in UnExportContracts)
+            {
+                contract.IsSelected = isChecked;
+            }
+        }
+
         /// <summary>
         /// 导出上报附件1
         /// </summary>
@@ -847,7 +860,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                     .Include(x => x.Company)
                     .Include(x => x.PurchaseCompany)
                     .Include(x => x.ContractDetails)
-                    .ThenInclude(d => d.Material).ToList();
+                    .ThenInclude(d => d.Material).OrderBy(x => x.EditDate).ToList();
             }
             else
             {
@@ -855,7 +868,7 @@ namespace UniformMaterialManagementSystem.ViewModels
                     .Include(x => x.Company)
                     .Include(x => x.PurchaseCompany)
                     .Include(x => x.ContractDetails)
-                    .ThenInclude(d => d.Material).ToList();
+                    .ThenInclude(d => d.Material).OrderBy(x => x.EditDate).ToList();
             }
 
             Contracts.Clear();

+ 1 - 1
UniformMaterialManagementSystem/ViewModels/InspectionOrganizationPageViewModel.cs

@@ -22,7 +22,7 @@ namespace UniformMaterialManagementSystem.ViewModels
         {
             _service = service;
 
-            var inspectionOrganizations = _service.GetAll().ToList();
+            var inspectionOrganizations = _service.GetAll().OrderBy(x=>x.OrderNo).ToList();
             foreach (var organization in inspectionOrganizations)
             {
                 InspectionOrganizations.Add(organization);

+ 22 - 3
UniformMaterialManagementSystem/Views/ContractPage.xaml

@@ -320,7 +320,7 @@
                         RowHeaderStyle="{StaticResource CustomRowHeaderStyle}"
                         RowStyle="{StaticResource CustomRowStyle}"
                         SelectionChanged="DataGridUnExportContractList_SelectionChanged"
-                        SelectionMode="Extended"
+                        SelectionMode="Single"
                         ShowRowsCount="True"
                         ShowStatusBar="True"
                         VerticalGridLinesBrush="LightSlateGray">
@@ -358,11 +358,30 @@
                             </Style>
                         </control:FilterDataGrid.Resources>
                         <control:FilterDataGrid.Columns>
-                            <DataGridCheckBoxColumn
+                            <!--<DataGridCheckBoxColumn
                                 Width="50"
                                 Binding="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                 ElementStyle="{StaticResource CheckBoxColumnElementStyleEnable}"
-                                Header="选择" />
+                                Header="选择" />-->
+
+                            <DataGridTemplateColumn>
+                                <DataGridTemplateColumn.HeaderTemplate>
+                                    <DataTemplate>
+                                        <CheckBox
+                                            Command="{Binding RelativeSource={RelativeSource AncestorType=DataGrid}, Path=DataContext.SelectAllCommand}"
+                                            CommandParameter="{Binding IsChecked, RelativeSource={RelativeSource Self}}"
+                                            IsChecked="False" />
+                                    </DataTemplate>
+                                </DataGridTemplateColumn.HeaderTemplate>
+                                <DataGridTemplateColumn.CellTemplate>
+                                    <DataTemplate>
+                                        <CheckBox
+                                            x:Name="IsCheckedCheckBox"
+                                            IsChecked="{Binding IsSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
+                                            Style="{StaticResource CheckBoxColumnElementStyleEnable}" />
+                                    </DataTemplate>
+                                </DataGridTemplateColumn.CellTemplate>
+                            </DataGridTemplateColumn>
                             <control:FilterDataGridTextColumn
                                 Width="300"
                                 Binding="{Binding Company.Name}"

+ 10 - 9
UniformMaterialManagementSystem/Views/ContractPage.xaml.cs

@@ -89,16 +89,16 @@ namespace UniformMaterialManagementSystem.Views
             //用户选择多行时,自动勾选
             var grid = sender as FilterDataGrid.FilterDataGrid;
             if (grid == null) return;
-            var selectedItems = grid.SelectedItems;
+            //var selectedItems = grid.SelectedItems;
 
-            var itemsSource = grid.ItemsSource;
-            foreach (var contract in itemsSource)
-            {
-                var contains = selectedItems.Contains(contract);
-                var model = contract as ContractModel;
-                if (model == null) continue;
-                model.IsSelected = contains ? true : false;
-            }
+            //var itemsSource = grid.ItemsSource;
+            //foreach (var contract in itemsSource)
+            //{
+            //    var contains = selectedItems.Contains(contract);
+            //    var model = contract as ContractModel;
+            //    if (model == null) continue;
+            //    model.IsSelected = contains ? true : false;
+            //}
 
             //根据选中合同的变更状态控制控件的可编辑性
             var selectedItem = grid.SelectedItem as ContractModel;
@@ -215,6 +215,7 @@ namespace UniformMaterialManagementSystem.Views
             }
         }
 
+
         //private void DataGridUnExportContractList_CurrentCellChanged(object sender, EventArgs e)
         //{
         //    var grid = sender as FilterDataGrid.FilterDataGrid;