Ver Fonte

修改测试方案

ltwork há 1 ano atrás
pai
commit
f1cda5496f

+ 4 - 0
BlankApp1/BizService/BasicPlcTestSchemeService.cs

@@ -18,5 +18,9 @@ namespace BizService
         {
             return base.GetFirst(x=>x.scheme_name==schemeName);
         }
+        public List<bas_plc_test_scheme> FindAllByKind(string typeName)
+        {
+            return base.GetList(x => x.devicekind_name == typeName);
+        }
     }
 }

+ 2 - 0
BlankApp1/BizService/IBasicPlcTestSchemeService.cs

@@ -10,5 +10,7 @@ namespace BizService
     public interface  IBasicPlcTestSchemeService : IBaseService<bas_plc_test_scheme>
     {
         public bas_plc_test_scheme FindByName(string schemeName);
+
+        public List<bas_plc_test_scheme> FindAllByKind(string typeName);
     }
 }

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

@@ -55,16 +55,25 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
             DeleteInCommand = new DelegateCommand<object>(DeleteIn);
             DeleteOutCommand = new DelegateCommand<object>(DeleteOut);
             OnLoadCommand = new DelegateCommand(OnLoad);
-            TxtLostFocusCommand = new DelegateCommand(LostFocusValue);
+            TxtLostFocusCommand = new DelegateCommand(GetExistSchs);
+            OpenExistCommand = new DelegateCommand<string>(OpenExist);
+            UpCommand = new DelegateCommand<object>(DataUp);
+            DownCommand = new DelegateCommand<object>(DataDown);
+            SaveAllSchCommand = new DelegateCommand<object>(SaveAllSch);
             BeforeConList = new ObservableCollection<BasPlcItemConfigDto>();
             InConList = new ObservableCollection<BasPlcItemConfigDto>();
             OutConList = new ObservableCollection<BasPlcItemConfigDto>();
+           
             //获取设备类型
             DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
             GetConfigOption();
         }
 
-        
+       
+
+
+
+
 
 
 
@@ -196,13 +205,96 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         #endregion
         #region 私有方法
+        /// <summary>
+        /// 保存所有测试项
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void SaveAllSch(object obj)
+        {
+            //可能调整了测试项的顺序,所以先删除所有测试项
+            var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            if (findSche != null)
+            {
+              
+                //显示设备名称
+                DeviceKindName = findSche.devicekind_name;
+                long schID = findSche.scheme_id;
+                //查找此方案下的所有的测试项,并
+                var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
+                //先删除
+                foreach (var unit in schDtls)
+                {
+                    int id =Convert.ToInt32( unit.scheme_dtl_id);
+                    _basicPlcTestSchemeDtlService.Delete(id);
 
-        private void LostFocusValue()
+                 
+                }
+                //按照调整后的顺序添加
+                foreach(var item in SchProjectList)
+                {
+                    //测试项目名称
+                    string schItenName = item.ItemName;
+                    var dtl = schDtls.FirstOrDefault(x => x.item_name == schItenName);
+                    if(dtl!=null)
+                    {
+                        //要将主键改为0,否则还是原来的主键
+                        dtl.scheme_dtl_id = 0;
+                        _basicPlcTestSchemeDtlService.Add(dtl);
+                    }
+                  
+                }
+                MessageBox.Show("保存成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+            }
+        }
+        /// <summary>
+        /// 打开已有方案
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void OpenExist(string str)
         {
+            if(string.IsNullOrEmpty(DeviceKindName))
+            {
+                MessageBox.Show("请选择设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+
+            if (string.IsNullOrEmpty(ScheduleName))
+            {
+                MessageBox.Show("请填写方案名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            //设备类型名称
+
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", DeviceKindName);
+            parm.Add("Key2", ScheduleName);
+            //已有的测试项
+            parm.Add("Key3", SchProjectList);
+            //弹出详情对话框
+            _dialog.ShowDialog("CopySchView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    List<bas_plc_test_scheme_dtl> returnValue = callback.Parameters.GetValue<List<bas_plc_test_scheme_dtl>>("ReturnValue");
+                    //更新表格,重新获取
+                    GetExistSchs();
+                }
+
+            });
+        }
+        /// <summary>
+        /// 光标失去触发
+        /// </summary>
+        private void GetExistSchs()
+        {
+            SchProjectList.Clear();
             var findSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
             if (findSche != null)
             {
-                SchProjectList.Clear();
+               
                 //显示设备名称
                 DeviceKindName = findSche.devicekind_name;
                 long schID = findSche.scheme_id;
@@ -233,6 +325,57 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 }
             }
         }
+
+        /// <summary>
+        /// 下移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataDown(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.Id == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == SchProjectList.Count - 1)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index + 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+        }
+        /// <summary>
+        /// 上移
+        /// </summary>
+        /// <param name="obj"></param>
+        private void DataUp(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findScheExist = SchProjectList.FirstOrDefault(x => x.Id == id);
+            if (findScheExist != null)
+            {
+
+                int index = SchProjectList.IndexOf(findScheExist);
+                if (index != -1)
+                {
+                    if (index == 0)
+                        return;
+                    SchProjectList.RemoveAt(index);
+                    index = index - 1;
+                    SchProjectList.Insert(index, findScheExist);
+                }
+
+
+            }
+
+        }
+
         private void OnLoad()
         {
             
@@ -544,10 +687,10 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 long id = finsScheHave.scheme_id;
                 //增加或修改方案明细表
                 AddOrEditDetailsToDb(id);
-                RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
+               
             }
             //gen'x'g
-            LostFocusValue();
+            GetExistSchs();
 
         }
      
@@ -735,6 +878,11 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         public DelegateCommand OnLoadCommand { set; get; }
         public DelegateCommand TxtLostFocusCommand { set; get; }
+        public DelegateCommand<string> OpenExistCommand { set; get; }
+        public DelegateCommand<object> DownCommand { set; get; }
+        public DelegateCommand<object> UpCommand { set; get; }
+        public DelegateCommand<object> SaveAllSchCommand { set; get; }
+        
         #endregion
         #region 变量绑定
         /// <summary>

+ 87 - 59
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/CopySchViewModel.cs

@@ -30,7 +30,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private readonly ILogger _logger;
         private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
         private readonly IBasicPlcTestSchemeDtlService _basicPlcTestSchemeDtlService;
-        private string schNameAgo = String.Empty;
+        private string tyepName = String.Empty;
  
 
         public CopySchViewModel(IDialogService dialog, IEventAggregator aggregator, IOptionConfigService optionConfigService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IBasicPlcTestSchemeDtlService basicPlcTestSchemeDtlService, IMapper mapper, ILogger logger)
@@ -107,27 +107,25 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         }
 
+  
         private void Sure(string obj)
         {
             //查找是否有这个测试方案
-            var findExist = _basicPlcTestSchemeService.FindByName(ScheduleName);
-            if (findExist != null)
-            {
-                MessageBoxResult boxResult = MessageBox.Show("已有次测试方案,请填写其他方案名!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
-                return;
-            }
-            var findSelect= SchProjectList.FirstOrDefault(x=>x.IsSelected==true);
+         
+            var findSelect = SchProjectList.FirstOrDefault(x => x.IsSelected == true);
             if (findSelect == null)
             {
                 MessageBoxResult boxResult = MessageBox.Show("请勾选测试项!", "提示", MessageBoxButton.OK, MessageBoxImage.Warning);
                 return;
             }
-            //查找以前测试方案的信息
-            var finsSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
-            if (finsSche != null)
+            //查找的信息
+            var finsSche = _basicPlcTestSchemeService.FindByName(ScheduleName);
+            try
             {
-                try
+                //没有此测试方案,就增加
+                if (finsSche == null)
                 {
+               
                     //增加测试方案到数据库
                     bas_plc_test_scheme schDto = new bas_plc_test_scheme();
                     schDto.scheme_name = ScheduleName;
@@ -137,53 +135,54 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                     schDto.update_time = DateTime.Now;
                     schDto.update_by = Appsession.UserName;
                     _basicPlcTestSchemeService.Add(schDto);
-                    //以前复制的schID
-                    long schID = finsSche.scheme_id;
-                    //查找此方案下的所有的测试项,并增加到测试项详细表中
-                    long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
-                    //这里要注意顺序,所以用了SchProjectList循环
-                    foreach (var sch in SchProjectList)
+ 
+                }
+           
+                //查找此方案下id
+                long? schINewID = _basicPlcTestSchemeService.FindByName(ScheduleName)?.scheme_id;
+                //这里要注意顺序,所以用了SchProjectList循环
+                //增加测试方案明细
+                foreach (var sch in SchProjectList)
+                {
+                    if (sch.IsSelected)
                     {
-                        if (sch.IsSelected)
+                        int dtlId = Convert.ToInt32(sch.Id);
+                        var unit = _basicPlcTestSchemeDtlService.Find(dtlId);
+                        if (unit != null)
                         {
-                            int dtlId = Convert.ToInt32(sch.Id);
-                            var unit = _basicPlcTestSchemeDtlService.Find(dtlId);
-                            if (unit != null)
-                            {
-                                bas_plc_test_scheme_dtl schDtlDto = new bas_plc_test_scheme_dtl();
-                                schDtlDto.scheme_id = schINewID;
-                                schDtlDto.item_name = unit.item_name;
+                            bas_plc_test_scheme_dtl schDtlDto = new bas_plc_test_scheme_dtl();
+                            schDtlDto.scheme_id = schINewID;
+                            schDtlDto.item_name = unit.item_name;
 
-                                schDtlDto.item_type = unit.item_type;
-                                schDtlDto.precondition = unit.precondition;
-                                schDtlDto.precondition_describe = unit.precondition_describe;
-                                schDtlDto.action = unit.action;
-                                schDtlDto.action_describe = unit.action_describe;
-                                schDtlDto.judgement_result = unit.judgement_result;
-                                schDtlDto.judgement_result_describe = unit.judgement_result_describe;
-                                schDtlDto.create_by = Appsession.UserName;
-                                schDtlDto.create_time = DateTime.Now;
-                                schDtlDto.update_time = DateTime.Now;
-                                schDtlDto.update_by = Appsession.UserName;
-                                bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlDto);
+                            schDtlDto.item_type = unit.item_type;
+                            schDtlDto.precondition = unit.precondition;
+                            schDtlDto.precondition_describe = unit.precondition_describe;
+                            schDtlDto.action = unit.action;
+                            schDtlDto.action_describe = unit.action_describe;
+                            schDtlDto.judgement_result = unit.judgement_result;
+                            schDtlDto.judgement_result_describe = unit.judgement_result_describe;
+                            schDtlDto.create_by = Appsession.UserName;
+                            schDtlDto.create_time = DateTime.Now;
+                            schDtlDto.update_time = DateTime.Now;
+                            schDtlDto.update_by = Appsession.UserName;
+                            //先把方案明细添加到数据库中
+                            bool isAddSucc = _basicPlcTestSchemeDtlService.Add(schDtlDto);
 
-                            }
                         }
+                    }
 
 
-                    }
-                    _logger.LogInformation($"复制方案成功。方案名{ScheduleName}");
-                }
-                catch(Exception ex)
-                {
-                    _logger.LogError(ex.ToString());
                 }
-               
+
+            }
+            catch (Exception ex)
+            {
+                _logger.LogError(ex.ToString());
             }
             RequestClose?.Invoke(new DialogResult(ButtonResult.OK));
         }
 
-        public string Title { set; get; } ="复制方案";
+        public string Title { set; get; } ="选择测试项";
 
         public event Action<IDialogResult> RequestClose;
 
@@ -199,6 +198,20 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
 
         public void OnDialogOpened(IDialogParameters parameters)
         {
+            ObservableCollection<SelectItemModel> existItems = new ObservableCollection<SelectItemModel>();
+
+           ///获取已有的测试项
+           var getMsg3 = parameters.GetValues<ObservableCollection<SelectItemModel>>("Key3");
+
+            if (getMsg3 != null)
+            {
+                foreach (var item in getMsg3)
+                {
+                    existItems = item;
+                }
+            }
+
+            //设备类型
             var getMsg = parameters.GetValues<string>("Key");
             
             if (getMsg != null)
@@ -207,14 +220,13 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 {
                     foreach (var item in getMsg)
                     {
-                        schNameAgo = item.ToString();
-                        ScheduleName = schNameAgo + "_copy";
-
-                        var findSche = _basicPlcTestSchemeService.FindByName(schNameAgo);
-                        if (findSche != null)
+                        tyepName = item.ToString();
+                        DeviceKindName = tyepName;
+                        var findSchs = _basicPlcTestSchemeService.FindAllByKind(tyepName);
+                        foreach(var findSche in findSchs)
                         {
-                            //显示设备名称
-                            DeviceKindName = findSche.devicekind_name;
+                            //显示方案id
+                    
                             long schID = findSche.scheme_id;
                             //查找此方案下的所有的测试项,并增加到表格
                             var schDtls = _basicPlcTestSchemeDtlService.QueryList()?.FindAll(x => x.scheme_id == schID);
@@ -233,12 +245,18 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                                         itemType = "Robot动作测试";
                                         break;
                                 }
-                                SchProjectList.Add(new SelectItemModel
+                                //添加列举此测试方案下没有的测试项
+                                var resu = existItems.FirstOrDefault(x => x.ItemName == unit.item_name);
+                                if(resu==null)
                                 {
-                                    Id = unit.scheme_dtl_id,
-                                    ItemName = unit.item_name,
-                                    ItemType = itemType,
-                                }); ;
+                                    SchProjectList.Add(new SelectItemModel
+                                    {
+                                        Id = unit.scheme_dtl_id,
+                                        ItemName = unit.item_name,
+                                        ItemType = itemType,
+                                    });
+                                }
+                           
 
                             }
                         }
@@ -250,6 +268,16 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
                 }
                 
             }
+            //获取测试方案名称
+            var getMsg2 = parameters.GetValues<string>("Key2");
+            if(getMsg2 != null) 
+            {
+                foreach (var item in getMsg2)
+                {
+                    ScheduleName = item;
+                }
+            }
+
         }
         #region 命令绑定
         public DelegateCommand<string> SureCommand { set; get; }

+ 16 - 12
BlankApp1/BlankApp1/Views/BasicConfigView/AddOrEditSchView.xaml

@@ -7,7 +7,7 @@
              xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
              xmlns:prism="http://prismlibrary.com/" 
              BorderBrush="#CBCBCB" BorderThickness="1"
-             Height="800" Width="1000" >
+             Height="600" Width="1000" >
     <!--<prism:Dialog.WindowStyle>
         <Style TargetType="Window">
             <Setter Property="SizeToContent" Value="WidthAndHeight" />
@@ -60,15 +60,8 @@
                 </TextBox>
             </StackPanel>
             
-            <StackPanel Orientation="Horizontal" >
-                <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <ComboBox  Height="28" Width="120" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
-            </StackPanel>
-            <StackPanel Orientation="Horizontal">
-                <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120"  Text="{Binding TestName}"/>
-            </StackPanel>
-            <Button  Content="确认" Width="80"  Margin="5,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
+          
+            <Button  Content="保存测试方案" Width="80"  Margin="5,0"  Command="{Binding SaveAllSchCommand}" Style="{StaticResource NormalButtonStyle}" />
             <Button  Content="重置" Width="80"  Margin="5,0"  Command="{Binding ResetCommand}" Style="{StaticResource NormalButtonStyle}" />
         </StackPanel>
         <Border Grid.Row="0"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
@@ -122,7 +115,18 @@
                     <RowDefinition/>
                     <RowDefinition Height="50"/>
                 </Grid.RowDefinitions>
-                <Button Grid.Row="0" HorizontalAlignment="Left"  Content="选择已有测试项" Width="100"  Margin="5,0"  Command="{Binding OpenCurrentCommand}" Style="{StaticResource NormalButtonStyle}"  />
+                <StackPanel Grid.Row="0" Orientation="Horizontal">
+                    <Button HorizontalAlignment="Left"  Content="选择已有测试项" Width="100"  Margin="5,0"  Command="{Binding OpenExistCommand}" CommandParameter="{Binding DeviceKindName}" Style="{StaticResource NormalButtonStyle}"  />
+                    <StackPanel Orientation="Horizontal" >
+                        <TextBlock Text="测试项类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                        <ComboBox  Height="28" Width="120" ItemsSource="{Binding TestKinds}" SelectedItem="{Binding SelectTest}" />
+                    </StackPanel>
+                    <StackPanel Orientation="Horizontal">
+                        <TextBlock Text="测试项名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                        <TextBox  Height="28" Width="120"  Text="{Binding TestName}"/>
+                    </StackPanel>
+                </StackPanel>
+             
                 <Border Grid.Row="0"  BorderBrush="#CBCBCB" BorderThickness="1" />
                 <Grid Grid.Row="1">
                     <Grid.ColumnDefinitions>
@@ -373,7 +377,7 @@ Command="{Binding DataContext.DeleteOutCommand, RelativeSource={RelativeSource M
                     </Grid>
                 </Grid>
                 <Border Grid.Row="3"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
-                <Button Grid.Row="4" HorizontalAlignment="Left" Content="确认" Width="80"  Margin="5,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
+                <Button Grid.Row="4" HorizontalAlignment="Right" Content="保存测试项" Width="80"  Margin="5,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
             </Grid>
           
         </Expander>