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

修改查询结果

ltwork 1 éve
szülő
commit
67cbd94b13

+ 6 - 3
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditSchViewModel.cs

@@ -60,7 +60,9 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             UpCommand = new DelegateCommand<object>(DataUp);
             DownCommand = new DelegateCommand<object>(DataDown);
             SaveAllSchCommand = new DelegateCommand<object>(SaveAllSch);
-            EditDetailCommand = new DelegateCommand<object>(DataGridSelectChange);
+           // EditDetailCommand = new DelegateCommand<object>(DataGridSelectChange);
+
+            DgSelectChangeCommand = new DelegateCommand<object>(DataGridSelectChange);
             DisAnoCommand = new DelegateCommand<object>(DisAnomation);
 
              BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
@@ -239,7 +241,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         /// <param name="obj"></param>
         private void DataGridSelectChange(object obj)
         {
-            int schDtlId = Convert.ToInt32(obj);
+            SelectItemModel selectItemModel = (SelectItemModel)obj;
+            int schDtlId = Convert.ToInt32(selectItemModel.SchDtlId);
             schDtlMainId = schDtlId;//全局变量赋值,测试方案明细id
             GetDetaiMsg(schDtlId);
         }
@@ -941,7 +944,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         public DelegateCommand<object> UpCommand { set; get; }
         public DelegateCommand<object> SaveAllSchCommand { set; get; }
         public DelegateCommand<object> EditDetailCommand { set; get; }
-
+        public DelegateCommand<object> DgSelectChangeCommand { set; get; }
         public DelegateCommand<object> DisAnoCommand { set; get; }
         
         #endregion

+ 2 - 2
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/DeviceViewModel.cs

@@ -172,8 +172,8 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             conditionDevices = (from a in allDeviceList
                                    where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
                                    && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
-                                   && (DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName)
-                                   &&(ProjectName == "---") ? true : (a.ProjectName == ProjectName)
+                                   && ((DeviceKindName == "---") ? true : (a.DeviceKindName == DeviceKindName))
+                                   &&((ProjectName == "---") ? true : (a.ProjectName == ProjectName))
                                     && (EndTime == string.Empty ? true : (a.CreateTime < Convert.ToDateTime(EndTime)) && (Convert.ToDateTime(StartTime) < a.CreateTime))
                                 select a).ToList();
             //默认显示的第一页

+ 30 - 16
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ResultQueryViewModel.cs

@@ -222,6 +222,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         {
             allDeviceList.Clear();
             conditionDevices.Clear();
+           
             //所有测试方案
             var schlist = _basicPlcTestSchemeService.QueryList();
             var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
@@ -229,6 +230,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             var deviceIds=_iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
             foreach (var deviceId in deviceIds)
             {
+                List<DateTime> startDateTimes = new List<DateTime>();
                 var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
                 if(deviceMsg != null)
                 {
@@ -308,10 +310,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                         {
                             deviceCountResult++;
                         }
-
-
-                       
-
+                        //加入时间集合
+                        startDateTimes.Add(sch.start_test_time.Value);
                     }
                     //计算这个设备是否所有的方案都通过
                     if ((deviceCountResult!=0)&&(deviceCountResult == recordMsgs.Count))
@@ -325,23 +325,24 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
                     //这里不添加方案名称
                     allDeviceList.Add(new DeviceDtlWithResultModel()
                     {
-                   
+
                         DeviceId = deviceMsg.device_id,
                         DeviceNo = deviceMsg.device_no,
                         DeviceName = deviceMsg.device_name,
-                        DeviceKindName = deviceKindName,
+                        DeviceKindName = deviceKind,
                         ProjectName = projectName,
+                        StartTestTime = startDateTimes.Min(),//取最小时间
                         TestResult = deviceTestResult
-                    });
+                    }); ;
                     conditionDevices.Add(new DeviceDtlWithResultModel()
                     {
                   
                         DeviceId = deviceMsg.device_id,
                         DeviceNo = deviceMsg.device_no,
                         DeviceName = deviceMsg.device_name,
-                        DeviceKindName = deviceKindName,
+                        DeviceKindName = deviceKind,
                         ProjectName = projectName,
-    
+                        StartTestTime = startDateTimes.Min(),//取最小时间
                         TestResult = deviceTestResult
                     });
                 }
@@ -379,20 +380,33 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// <param name="obj"></param>
         public void CreatePdf(object obj)
         {
+            List<biz_test_record_dtl> allRecordDtls = new List<biz_test_record_dtl>();
             object[] multiObj = obj as object[];
 
-            //测试方案名称和设备id
-            string schemeName = (string)multiObj[0];
+            //测试结果和设备id
+            string testResult = (string)multiObj[0];
             long deviceId = (long)multiObj[1];
             //查找recordid
-            long recordId=(long)_iBizTestRecordService.FindRecorddByDeviceIdAndSchname((int)deviceId, schemeName)?.record_id;
+            var recordMsgs=_iBizTestRecordService.FindRecordByDeviceId((int)deviceId);
+            //查找这个id的所有测试记录
+            foreach(var recordMsg in recordMsgs)
+            {
+                //一条reoordid对应可能有多次测试记录
+                var recordDtls = _iBizTestRecordDtlService.FindRecordDetailByRecordID(recordMsg.record_id);
+                foreach(var record in recordDtls)
+                {
+                    allRecordDtls.Add(record);
+
+                }
+               
+            }
             //查找详细记录
-            var recordDtls = _iBizTestRecordDtlService.FindRecordDetailByRecordID(recordId);
+            
             string deviceName = _iBasicDeviceService.Find((int)deviceId).device_name;
             try
             {
                 Settings.License = LicenseType.Community;
-                var model = GetReportPLCInfo(schemeName,deviceName, recordDtls);
+                var model = GetReportPLCInfo("123",deviceName, allRecordDtls,testResult);
                 var document = new InvoiceDocument(model);
                 //pdf名称为轴编号+时间
 
@@ -443,7 +457,7 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
         /// </summary>
         /// <param name="schDtlId"></param>
         /// <returns></returns>
-        private InvoiceModel GetReportPLCInfo(string schName,string deviceName,List<biz_test_record_dtl> recordDtls)
+        private InvoiceModel GetReportPLCInfo(string schName,string deviceName,List<biz_test_record_dtl> recordDtls,string testResult)
         {
             //测试方案明细主键ID
 
@@ -578,8 +592,8 @@ namespace PLCTool.ViewModels.BusinessManageViewModel
             //{
             //    invoiceModel.FinalReuslt = "不通过";
             //}
+            invoiceModel.FinalReuslt = testResult;
 
-           
             return invoiceModel;
         }
         #endregion

+ 73 - 29
BlankApp1/BlankApp1/ViewModels/StatisticsViewModel.cs

@@ -67,7 +67,7 @@ namespace BlankApp1.ViewModels
             GetPieSeriesEveryDay();
             GetPieSeriesFail();
         }
- 
+
         /// <summary>
         /// 获取所有项目
         /// </summary>
@@ -75,6 +75,7 @@ namespace BlankApp1.ViewModels
         {
             allDeviceList.Clear();
             conditionDevices.Clear();
+          
             //所有测试方案
             var schlist = _basicPlcTestSchemeService.QueryList();
             var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
@@ -82,17 +83,22 @@ namespace BlankApp1.ViewModels
             var deviceIds = _iBizTestRecordService.QueryList().Select(X => X.device_id).Distinct();
             foreach (var deviceId in deviceIds)
             {
+                List<DateTime> startDateTimes = new List<DateTime>();
                 var deviceMsg = _iBasicDeviceService.Find(((int)deviceId));
                 if (deviceMsg != null)
                 {
+                    string deviceKind = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
+                    string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
+                    //记录设备下的方案通过个数
+                    int deviceCountResult = 0;
+                    string deviceTestResult = string.Empty;
                     //查找哦记录有的方案
 
                     var recordMsgs = _iBizTestRecordService.FindRecordByDeviceId(deviceId);
                     foreach (var sch in recordMsgs)
                     {
-                        string deviceKindName = _iBasicDeviceKindService.Find((int)deviceMsg.device_kind_id)?.devicekind_name;
-                        string projectName = _iBasicProjectService.Find((int)deviceMsg.project_id)?.project_name;
-                        long schId = (long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKindName)?.scheme_id;
+
+                        long schId = (long)_basicPlcTestSchemeService.FindByNameAndType(sch.scheme_name, deviceKind)?.scheme_id;
                         //计算测试结果
                         string testResult = string.Empty;
                         int countResult = 0;
@@ -126,34 +132,72 @@ namespace BlankApp1.ViewModels
                         }
 
 
-                        allDeviceList.Add(new DeviceDtlWithResultModel()
-                        {
-                            RecordId = sch.record_id,
-                            DeviceId = deviceMsg.device_id,
-                            DeviceNo = deviceMsg.device_no,
-                            DeviceName = deviceMsg.device_name,
-                            DeviceKindName = deviceKindName,
-                            ProjectName = projectName,
-                            SchemeName = sch.scheme_name,
-                            SchemeId = schId,
-                            StartTestTime = sch.start_test_time.Value,
-                            TestResult = testResult
-                        });
-                        conditionDevices.Add(new DeviceDtlWithResultModel()
+                        //allDeviceList.Add(new DeviceDtlWithResultModel()
+                        //{
+                        //    RecordId = sch.record_id,
+                        //    DeviceId = deviceMsg.device_id,
+                        //    DeviceNo = deviceMsg.device_no,
+                        //    DeviceName = deviceMsg.device_name,
+                        //    DeviceKindName = deviceKindName,
+                        //    ProjectName = projectName,
+                        //    SchemeName = sch.scheme_name,
+                        //    SchemeId= schId,
+                        //    StartTestTime = sch.start_test_time.Value,
+                        //    TestResult=testResult
+                        //}); 
+                        //conditionDevices.Add(new DeviceDtlWithResultModel()
+                        //{
+                        //    RecordId = sch.record_id,
+                        //    DeviceId = deviceMsg.device_id,
+                        //    DeviceNo = deviceMsg.device_no,
+                        //    DeviceName = deviceMsg.device_name,
+                        //    DeviceKindName = deviceKindName,
+                        //    ProjectName = projectName,
+                        //    SchemeName = sch.scheme_name,
+                        //    SchemeId = schId,
+                        //    StartTestTime = sch.start_test_time.Value,
+                        //    TestResult = testResult
+                        //});
+                        //计算这个设备是否通过
+                        if (testResult == "通过")
                         {
-                            RecordId = sch.record_id,
-                            DeviceId = deviceMsg.device_id,
-                            DeviceNo = deviceMsg.device_no,
-                            DeviceName = deviceMsg.device_name,
-                            DeviceKindName = deviceKindName,
-                            ProjectName = projectName,
-                            SchemeName = sch.scheme_name,
-                            SchemeId = schId,
-                            StartTestTime = sch.start_test_time.Value,
-                            TestResult = testResult
-                        });
+                            deviceCountResult++;
+                        }
+                        //加入时间集合
+                        startDateTimes.Add(sch.start_test_time.Value);
+                    }
+                    //计算这个设备是否所有的方案都通过
+                    if ((deviceCountResult != 0) && (deviceCountResult == recordMsgs.Count))
+                    {
+                        deviceTestResult = "通过";
                     }
+                    else
+                    {
+                        deviceTestResult = "不通过";
+                    }
+                    //这里不添加方案名称
+                    allDeviceList.Add(new DeviceDtlWithResultModel()
+                    {
+
+                        DeviceId = deviceMsg.device_id,
+                        DeviceNo = deviceMsg.device_no,
+                        DeviceName = deviceMsg.device_name,
+                        DeviceKindName = deviceKind,
+                        ProjectName = projectName,
+                        StartTestTime = startDateTimes.Min(),//取最小时间
+                        TestResult = deviceTestResult
+                    }); ;
+                    conditionDevices.Add(new DeviceDtlWithResultModel()
+                    {
 
+                        DeviceId = deviceMsg.device_id,
+                        DeviceNo = deviceMsg.device_no,
+                        DeviceName = deviceMsg.device_name,
+                        DeviceKindName = deviceKind,
+                        ProjectName = projectName,
+                        StartTestTime = startDateTimes.Min(),//取最小时间
+                        TestResult = deviceTestResult
+                    });
                 }
 
             }

+ 4 - 3
BlankApp1/BlankApp1/Views/BasicConfigView/AddOrEditSchView.xaml

@@ -400,7 +400,8 @@ Command="{Binding DataContext.DeleteOutCommand, RelativeSource={RelativeSource M
 ItemsSource="{Binding SchProjectList}" IsReadOnly="True" Margin="5" Padding="0" VerticalScrollBarVisibility="Visible" HorizontalScrollBarVisibility="Visible" >
                     <b:Interaction.Triggers>
                         <b:EventTrigger EventName="SelectionChanged">
-                            <b:InvokeCommandAction Command="{Binding DgSelectChangeCommand}" CommandParameter="{Binding SchDtlId}"/>
+                            <b:InvokeCommandAction Command="{Binding DgSelectChangeCommand}" 
+                                                   CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/> 
                         </b:EventTrigger>
                     </b:Interaction.Triggers>
                     <DataGrid.Columns >
@@ -423,12 +424,12 @@ ItemsSource="{Binding SchProjectList}" IsReadOnly="True" Margin="5" Padding="0"
                                                 <TextBlock  Text="下移↓" VerticalAlignment="Center" Foreground="Blue"/>
                                             </StackPanel>
                                         </Button>
-                                        <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+                                        <!--<Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
                                       Command="{Binding DataContext.EditDetailCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchDtlId}" Cursor="Hand" Margin="0,0,10,0">
                                             <StackPanel Orientation="Horizontal">
                                                 <TextBlock  Text="编辑" VerticalAlignment="Center" Foreground="Blue"/>
                                             </StackPanel>
-                                        </Button>
+                                        </Button>-->
                                     </StackPanel>
                                 </DataTemplate>
                             </DataGridTemplateColumn.CellTemplate>

+ 1 - 1
BlankApp1/BlankApp1/Views/BusinessManageView/ResultQueryView.xaml

@@ -111,7 +111,7 @@
                                 Command="{Binding DataContext.PdfReportCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" Cursor="Hand" >
                                     <Button.CommandParameter>
                                         <MultiBinding Converter="{ StaticResource ResourceKey=TwoParConverter}">
-                                            <Binding Path="SchemeName"  ></Binding>
+                                            <Binding Path="TestResult"  ></Binding>
                                             <Binding Path="DeviceId"></Binding>
                                         </MultiBinding>
                                     </Button.CommandParameter>

+ 2 - 3
BlankApp1/BlankApp1/Views/StatisticsView.xaml

@@ -72,13 +72,12 @@
             ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
             ItemsSource="{Binding DeviceResultItemList}" IsReadOnly="True" Padding="0"  >
                 <DataGrid.Columns >
-                    <DataGridTextColumn Header="序号" Width="50" Binding="{Binding DeviceId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
+                   
                     <DataGridTextColumn Header="设备编号" Binding="{Binding DeviceNo}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="设备名称" Binding="{Binding DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="项目名称" Binding="{Binding ProjectName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="设备类型" Binding="{Binding DeviceKindName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                    <DataGridTextColumn Header="测试方案名称" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-
+                    
                     <DataGridTextColumn Header="测试时间" Width="150" Binding="{Binding StartTestTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                     <DataGridTextColumn Header="测试结果" Binding="{Binding TestResult}" CellStyle="{StaticResource MyDataGridCellStyle}"/>