|
@@ -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; }
|