Explorar el Código

修改设备界面

ltwork hace 1 año
padre
commit
281a51e7b2

+ 4 - 0
BlankApp1/BizService/BasicDeviceKindService.cs

@@ -9,5 +9,9 @@ namespace BizService
 {
     public class BasicDeviceKindService : BaseService<bas_device_kind>, IBasicDeviceKindService
     {
+        public List<string> FindAllDeviceKind()
+        {
+            return base.GetList().Select(x=>x.devicekind_name).ToList();
+        }
     }
 }

+ 4 - 0
BlankApp1/BizService/BasicProjectService.cs

@@ -10,5 +10,9 @@ namespace BizService
 
     public class BasicProjectService : BaseService<bas_project>, IBasicProjectService
     {
+        public List<string> FindAllProject()
+        {
+            return base.GetList().Select(x => x.project_name).ToList();
+        }
     }
 }

+ 1 - 0
BlankApp1/BizService/IBasicDeviceKindService.cs

@@ -10,5 +10,6 @@ namespace BizService
   
     public interface IBasicDeviceKindService : IBaseService<bas_device_kind>
     {
+        public List<string> FindAllDeviceKind();
     }
 }

+ 1 - 0
BlankApp1/BizService/IBasicProjectService.cs

@@ -10,5 +10,6 @@ namespace BizService
    
     public interface IBasicProjectService : IBaseService<bas_project>
     {
+        public List<string> FindAllProject();
     }
 }

+ 1 - 1
BlankApp1/BlankApp1/App.xaml.cs

@@ -76,7 +76,7 @@ namespace BlankApp1
             containerRegistry.RegisterDialog<CopySchView, CopySchViewModel>();
             containerRegistry.RegisterDialog<AddOrEditProjectView, AddOrEditProjectViewModel>();
             containerRegistry.RegisterDialog<AddOrEditDeviceKindView, AddOrEditDeviceKindViewModel>();
-            
+            containerRegistry.RegisterDialog<AddOrEditDeviceView, AddOrEditDeviceViewModel>();
         }
 
         private IMapper GetMapper(IContainerProvider container)

+ 3 - 2
BlankApp1/BlankApp1/Common/AutoMapper/AutoMapProfile.cs

@@ -88,11 +88,12 @@ namespace BlankApp1.Common.AutoMapper
                          .ForMember(dest => dest.Remark, opt => opt.MapFrom(src => src.remark)).ReverseMap();
 
             CreateMap<bas_device, BasDeviceDto>()
+                  .ForMember(dest => dest.DeviceId, opt => opt.MapFrom(src => src.device_id))
                  .ForMember(dest => dest.DeviceNo, opt => opt.MapFrom(src => src.device_no))
                .ForMember(dest => dest.DeviceNo, opt => opt.MapFrom(src => src.device_no))
                 .ForMember(dest => dest.DeviceName, opt => opt.MapFrom(src => src.device_name))
-                 .ForMember(dest => dest.ProjectId, opt => opt.MapFrom(src => src.project_id))
-                  .ForMember(dest => dest.DeviceKindId, opt => opt.MapFrom(src => src.device_kind_id))
+                 .ForMember(dest => dest.ProjectName, opt => opt.MapFrom(src => src.project_id))
+                  .ForMember(dest => dest.DeviceKindName, opt => opt.MapFrom(src => src.device_kind_id))
                       .ForMember(dest => dest.CreateBy, opt => opt.MapFrom(src => src.create_by))
                        .ForMember(dest => dest.CreateTime, opt => opt.MapFrom(src => src.create_time))
                         .ForMember(dest => dest.UpdateTime, opt => opt.MapFrom(src => src.update_time))

+ 1 - 1
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditDeviceKindViewModel.cs

@@ -21,7 +21,7 @@ namespace PLCTool.ViewModels.BasicConfigViewModel
         private readonly IBasicDeviceKindService _iBasicDeviceKindService;
 
         private readonly IMapper _mapper;
-        private List<BasPlcItemConfigDto> plcConfigs = new List<BasPlcItemConfigDto>();
+        
         private long id = 0;
         public AddOrEditDeviceKindViewModel(IEventAggregator aggregator, IBasicDeviceKindService iBasicDeviceKindService, IMapper mapper)
         {

+ 199 - 0
BlankApp1/BlankApp1/ViewModels/BasicConfigViewModel/AddOrEditDeviceViewModel.cs

@@ -0,0 +1,199 @@
+using AutoMapper;
+using BizService;
+using Model.Dto;
+using Prism.Commands;
+using Prism.Events;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+
+namespace PLCTool.ViewModels.BasicConfigViewModel
+{
+   
+
+    public class AddOrEditDeviceViewModel : BindableBase, IDialogAware
+    {
+        private readonly IEventAggregator _aggregator;
+        private readonly IBasicDeviceService _iBasicDeviceService;
+
+        private readonly IMapper _mapper;
+
+        private long id = 0;
+        public AddOrEditDeviceViewModel(IEventAggregator aggregator, IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService,IBasicProjectService iBasicProjectService, IMapper mapper)
+        {
+            _aggregator = aggregator;
+            _iBasicDeviceService = iBasicDeviceService;
+            _mapper = mapper;
+            CloseCommand = new DelegateCommand(Close);
+            SureCommand = new DelegateCommand<string>(Sure);
+            CancelCommand = new DelegateCommand(Close);
+            DeviceKindNameList= iBasicDeviceKindService.FindAllDeviceKind();
+            ProjectNameList = iBasicProjectService.FindAllProject();
+        }
+
+
+
+
+
+
+        #region idialog接口实现
+        public string Title { set; get; } = "新增设备";
+
+        public event Action<IDialogResult> RequestClose;
+
+        public bool CanCloseDialog()
+        {
+            return true;
+        }
+
+        public void OnDialogClosed()
+        {
+
+        }
+
+        public void OnDialogOpened(IDialogParameters parameters)
+        {
+            var getMsg = parameters.GetValues<BasDeviceDto>("Key");
+            ///值不为空,表示修改
+            if (getMsg != null)
+            {
+                foreach (var item in getMsg)
+                {
+                    if (item != null)
+                    {
+                        Title = "修改设备";
+
+                        DeviceName = item.DeviceName;
+                        DeviceNo = item.DeviceNo;
+                        ProjectName = item.ProjectName;
+                        DeviceKindName= item.DeviceKindName;
+                        Remark = item.Remark;
+
+                    }
+
+                }
+
+            }
+        }
+
+        #endregion
+        #region 私有方法
+
+
+        private void Close()
+        {
+            RequestClose?.Invoke(new DialogResult(ButtonResult.Cancel));
+        }
+        /// <summary>
+        /// 确认
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Sure(string obj)
+        {
+            if (string.IsNullOrEmpty(DeviceName))
+            {
+                MessageBox.Show("请填写设备名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            if (string.IsNullOrEmpty(DeviceNo))
+            {
+                MessageBox.Show("请填写设备编号!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            if (string.IsNullOrEmpty(ProjectName))
+            {
+                MessageBox.Show("请选择项目名称!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            if (string.IsNullOrEmpty(DeviceKindName))
+            {
+                MessageBox.Show("请填写设备类型!", "提示", MessageBoxButton.OK, MessageBoxImage.Information);
+                return;
+            }
+            BasDeviceDto basDevice = new BasDeviceDto();
+            basDevice.DeviceName = DeviceName;
+            basDevice.DeviceNo = DeviceNo;
+            basDevice.ProjectName= ProjectName;
+            basDevice.DeviceKindName= DeviceKindName;
+            basDevice.Remark = Remark;
+            DialogParameters parm = new DialogParameters();
+            parm.Add("ReturnValue", basDevice);
+            RequestClose?.Invoke(new DialogResult(ButtonResult.OK, parm));
+        }
+        /// <summary>
+        /// 重置
+        /// </summary>
+        /// <param name="obj"></param>
+        private void ResetMethod(string obj)
+        {
+
+        }
+
+        #endregion
+
+
+
+        #region 命令绑定
+        public DelegateCommand CloseCommand { set; get; }
+        public DelegateCommand<string> SureCommand { set; get; }
+        public DelegateCommand CancelCommand { set; get; }
+        public DelegateCommand TxtLostFocusCommand { set; get; }
+        public DelegateCommand TxtPLCValueLostFocusCommand { set; get; }
+
+
+        #endregion
+        #region 变量绑定
+        private string deviceName;
+        public string DeviceName
+        {
+            get { return deviceName; }
+            set { deviceName = value; RaisePropertyChanged(); }
+        }
+
+        private string deviceNo;
+        public string DeviceNo
+        {
+            get { return deviceNo; }
+            set { deviceNo = value; RaisePropertyChanged(); }
+        }
+        private string projectName;
+        public string ProjectName
+        {
+            get { return projectName; }
+            set { projectName = value; RaisePropertyChanged(); }
+        }
+        private string deviceKindName;
+        public string DeviceKindName
+        {
+            get { return deviceKindName; }
+            set { deviceKindName = value; RaisePropertyChanged(); }
+        }
+
+
+        private List<string> projectNameList;
+        public List<string> ProjectNameList
+        {
+            get { return projectNameList; }
+            set { projectNameList = value; RaisePropertyChanged(); }
+        }
+        private List<string> deviceKindNameList;
+        public List<string> DeviceKindNameList
+        {
+            get { return deviceKindNameList; }
+            set { deviceKindNameList = value; RaisePropertyChanged(); }
+        }
+        private string remark;
+        public string Remark
+        {
+            get { return remark; }
+            set { remark = value; RaisePropertyChanged(); }
+        }
+
+        #endregion
+    }
+}

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

@@ -1,12 +1,382 @@
-using System;
+using AutoMapper;
+using BizService;
+using Microsoft.Extensions.Logging;
+using MiniExcelLibs;
+using Model.Dto;
+using Model.Entities;
+using PLCTool.Common;
+using Prism.Commands;
+using Prism.Mvvm;
+using Prism.Services.Dialogs;
+using System;
 using System.Collections.Generic;
+using System.Collections.ObjectModel;
 using System.Linq;
 using System.Text;
 using System.Threading.Tasks;
+using System.Windows;
 
 namespace PLCTool.ViewModels.BasicConfigViewModel
 {
-    class DeviceViewModel
+   
+    public class DeviceViewModel : BindableBase
     {
+        private readonly IBasicDeviceService _iBasicDeviceService;
+        private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+        private readonly IBasicProjectService _iBasicProjectService;
+        private readonly IMapper _mapper;
+        private readonly IDialogService _dialog;
+        private readonly ILogger _logger;
+        private List<BasDeviceDto> allDeviceList = new List<BasDeviceDto>();//所有方案
+        private List<BasDeviceDto> conditionDevices = new List<BasDeviceDto>();//符合条件的方案
+        public DeviceViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IMapper mapper, IDialogService dialog, ILogger logger)
+        {
+            _iBasicDeviceService = iBasicDeviceService;
+            _iBasicDeviceKindService = iBasicDeviceKindService;
+            _iBasicProjectService = iBasicProjectService;
+            _mapper = mapper;
+            _dialog = dialog;
+            _logger = logger;
+            QueryCommand = new DelegateCommand<object>(Query);
+            AddCommand = new DelegateCommand<object>(Add);
+            ExportCommand = new DelegateCommand<string>(Export);
+            EditCommand = new DelegateCommand<object>(Edit);
+            DeleteCommand = new DelegateCommand<object>(Delete);
+            ResetCommand = new DelegateCommand<object>(Reset);
+            OnLoadCommand = new DelegateCommand(OnLoad);
+          
+            GetPprojectConfig();
+        }
+
+
+
+
+
+
+
+
+        #region 私有方法
+        private void OnLoad()
+        {
+            DeviceKindNameList = _iBasicDeviceKindService.FindAllDeviceKind();
+            ProjectNameList = _iBasicProjectService.FindAllProject();
+        }
+        private void Reset(object obj)
+        {
+            DeviceNo = string.Empty;
+            DeviceName = string.Empty;
+
+
+        }
+        /// <summary>
+        /// 修改
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Edit(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            var findDevice = allDeviceList.FirstOrDefault(x => (x.DeviceId == id));
+            DialogParameters parm = new DialogParameters();
+            parm.Add("Key", findDevice);
+            //弹出详情对话框
+            _dialog.ShowDialog("AddOrEditDeviceView", parm, async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
+
+                    if (returnValue != null)
+                    {
+                        //更新时间
+                        returnValue.UpdateTime = DateTime.Now;
+                        returnValue.UpdateBy = Appsession.UserName;
+                        //创建时间
+                        returnValue.CreateTime = findDevice.CreateTime;
+                        returnValue.CreateBy = findDevice?.CreateBy;
+
+                        var deviceKindCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
+                        var findPlcs = allDeviceList.FindAll(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
+                        foreach (var item in findPlcs)
+                        {
+                            if (item.DeviceId != id)
+                            {
+                                MessageBox.Show("已有此设备编号,请更改名称!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
+                                return;
+                            }
+                        }
+
+                        //修改
+                        deviceKindCon.device_id = id;
+                        bool isSucc = _iBasicDeviceService.Edit(deviceKindCon);
+                        if (isSucc)
+                        {
+                            //重新读取PLC
+                            GetPprojectConfig();
+                            _logger.LogInformation($"修改项目成功");
+                            MessageBox.Show("修改项目成功", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                        }
+                    }
+                }
+
+            });
+        }
+
+        private void Delete(object obj)
+        {
+            int id = Convert.ToInt32(obj);
+            MessageBoxResult boxResult = MessageBox.Show("确认删除此条数据?", "确认", MessageBoxButton.OKCancel, MessageBoxImage.Question);
+            if (boxResult == MessageBoxResult.OK)
+            {
+                var del = _iBasicDeviceService.Delete(id);
+                if (del)
+                {
+                    MessageBox.Show("删除成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                    GetPprojectConfig();
+                }
+
+            }
+        }
+
+        /// <summary>
+        /// 查询
+        /// </summary>
+        /// <param name="obj"></param>
+        private void Query(object obj)
+        {
+            conditionDevices = (from a in allDeviceList
+                                   where (string.IsNullOrEmpty(DeviceName) ? true : (a.DeviceName == DeviceName))
+                                   && (string.IsNullOrEmpty(DeviceNo) ? true : (a.DeviceNo == DeviceNo))
+
+                                   select a).ToList();
+            //默认显示的第一页
+            conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
+            Getpage();
+        }
+
+        private void Export(string obj)
+        {
+            using (System.Windows.Forms.SaveFileDialog saveFileDialog = new System.Windows.Forms.SaveFileDialog()
+            {
+                //设置文件类型
+                //书写规则例如:txt files(*.txt)|*.txt
+                Filter = "Excel files(*.xlsx)|*.xlsx|All files(*.*)|*.*",
+                //设置默认文件名(可以不设置)
+                FileName = "项目配置表",
+
+                //获取或设置一个值,该值指示如果用户省略扩展名,文件对话框是否自动在文件名中添加扩展名。(可以不设置)
+                AddExtension = true,
+
+                //保存对话框是否记忆上次打开的目录
+                RestoreDirectory = true
+            })
+            {
+                // Show save file dialog box
+
+                //点了保存按钮进入
+                if (saveFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
+                {
+                    try
+                    {
+                        //获得文件路径
+                        string localFilePath = saveFileDialog.FileName.ToString();
+
+                        //获取文件内容
+                        MiniExcel.SaveAs(localFilePath, DeviceItemList);
+                    }
+                    catch (Exception ex)
+                    {
+                        _logger.LogError(ex.ToString());
+                    }
+
+
+                }
+
+            }
+        }
+        /// <summary>
+        /// 添加PLC变量
+        /// </summary>
+        /// <param name="obj"></param>
+        /// <exception cref="NotImplementedException"></exception>
+        private void Add(object obj)
+        {
+
+            //弹出详情对话框
+            _dialog.ShowDialog("AddOrEditDeviceView", async callback =>
+            {
+                if (callback.Result == ButtonResult.OK)
+                {
+                    BasDeviceDto returnValue = callback.Parameters.GetValue<BasDeviceDto>("ReturnValue");
+                    if (returnValue != null)
+                    {
+                        returnValue.CreateTime = DateTime.Now;
+                        returnValue.CreateBy = Appsession.UserName;
+                        returnValue.UpdateTime = DateTime.Now;
+                        returnValue.UpdateBy = Appsession.UserName;
+                        var deviceCon = _mapper.Map<BasDeviceDto, bas_device>(returnValue);
+                        var findPlc = allDeviceList.FirstOrDefault(x => (x.DeviceName == returnValue.DeviceName) || (x.DeviceNo == returnValue.DeviceNo));
+                        if (findPlc != null)
+                        {
+                            MessageBox.Show("已有此项目名称或编号,请更改!", "提示", MessageBoxButton.OKCancel, MessageBoxImage.Warning);
+                            return;
+                        }
+                        bool isSucc = _iBasicDeviceService.Add(deviceCon);
+                        if (isSucc)
+                        {
+                            //重新读取PLC
+                            GetPprojectConfig();
+                            _logger.LogInformation($"添加项目成功");
+                            MessageBox.Show("添加项目成功!", "确认", MessageBoxButton.OK, MessageBoxImage.Information);
+                        }
+                    }
+                }
+
+            });
+        }
+        /// <summary>
+        /// 获取所有项目
+        /// </summary>
+        private void GetPprojectConfig()
+        {
+            allDeviceList.Clear();
+            conditionDevices.Clear();
+            var projectlist = _iBasicDeviceService.QueryList();
+            var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(projectlist);
+            foreach (var plc in allDeviceKinds)
+            {
+                allDeviceList.Add(plc);
+                conditionDevices.Add(plc);
+            }
+            conditionDevices = conditionDevices.OrderBy(x => x.DeviceId).ToList();
+            Getpage();
+        }
+        /// <summary>
+        /// 获取页面
+        /// </summary>
+        private void Getpage()
+        {
+            CurrentPage = 1;
+            TotalCount = conditionDevices.Count;
+            CurrentPageChanged();
+
+
+        }
+        /// <summary>
+        /// 页面变化
+        /// </summary>
+        private void CurrentPageChanged()
+        {
+
+            DeviceItemList.Clear();
+
+            foreach (var i in conditionDevices.Skip((CurrentPage - 1) * CountPerPage).Take(CountPerPage))
+            {
+                DeviceItemList.Add(i);
+            }
+        }
+
+        #endregion
+        #region 命令绑定
+
+        public DelegateCommand<object> QueryCommand { set; get; }
+        public DelegateCommand<object> AddCommand { set; get; }
+        public DelegateCommand<string> ExportCommand { set; get; }
+
+        /// <summary>
+        /// 表格删除
+        /// </summary>
+        public DelegateCommand<Object> DeleteCommand { set; get; }
+        /// <summary>
+        /// 表格编辑按钮
+        /// </summary>
+        public DelegateCommand<Object> EditCommand { set; get; }
+        public DelegateCommand<object> ResetCommand { set; get; }
+
+        public DelegateCommand OnLoadCommand { set; get; }
+        #endregion
+
+        #region 数据绑定
+        private ObservableCollection<BasDeviceDto> deviceItemList = new ObservableCollection<BasDeviceDto>();
+        public ObservableCollection<BasDeviceDto> DeviceItemList
+        {
+            get { return deviceItemList; }
+            set { deviceItemList = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 设备编号
+        /// </summary>
+        private string devicedNo;
+        public string DeviceNo
+        {
+            get { return devicedNo; }
+            set { devicedNo = value; RaisePropertyChanged(); }
+        }
+
+        /// <summary>
+        /// 设备类型名称
+        /// </summary>
+        private string deviceName;
+        public string DeviceName
+        {
+            get { return deviceName; }
+            set { deviceName = value; RaisePropertyChanged(); }
+        }
+
+        private string projectName;
+        public string ProjectName
+        {
+            get { return projectName; }
+            set { projectName = value; RaisePropertyChanged(); }
+        }
+        private string deviceKindName;
+        public string DeviceKindName
+        {
+            get { return deviceKindName; }
+            set { deviceKindName = value; RaisePropertyChanged(); }
+        }
+
+
+        private List<string> projectNameList;
+        public List<string> ProjectNameList
+        {
+            get { return projectNameList; }
+            set { projectNameList = value; RaisePropertyChanged(); }
+        }
+        private List<string> deviceKindNameList;
+        public List<string> DeviceKindNameList
+        {
+            get { return deviceKindNameList; }
+            set { deviceKindNameList = value; RaisePropertyChanged(); }
+        }
+        /// <summary>
+        /// 总条数
+        /// </summary>
+        private int totalCount;
+        public int TotalCount
+        {
+            get { return totalCount; }
+            set { totalCount = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 每页数量
+        /// </summary>
+        private int countPerPage = 15;
+        public int CountPerPage
+        {
+            get { return countPerPage; }
+            set { countPerPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+        /// <summary>
+        /// 单前页
+        /// </summary>
+        private int currentPage = 1;
+        public int CurrentPage
+        {
+            get { return currentPage; }
+            set { currentPage = value; RaisePropertyChanged(); CurrentPageChanged(); }
+        }
+
+        #endregion
     }
 }

+ 62 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/AddOrEditDeviceView.xaml

@@ -0,0 +1,62 @@
+<UserControl x:Class="PLCTool.Views.BasicConfigView.AddOrEditDeviceView"
+             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
+             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
+             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
+             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
+             xmlns:local="clr-namespace:PLCTool.Views.BasicConfigView"
+             xmlns:prism="http://prismlibrary.com/"
+             xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
+             Height="300" Width="400" BorderBrush="#CBCBCB" BorderThickness="1">
+    <!--<prism:Dialog.WindowStyle>
+        <Style TargetType="Window">
+            <Setter Property="SizeToContent" Value="WidthAndHeight" />
+            <Setter Property="ResizeMode" Value="NoResize" />
+            <Setter Property="prism:Dialog.WindowStartupLocation" Value="CenterScreen" />
+            <Setter Property="WindowStyle" Value="None" />
+        </Style>
+    </prism:Dialog.WindowStyle>-->
+    <Grid>
+        <Grid.RowDefinitions>
+            <RowDefinition Height="20"/>
+            <RowDefinition />
+            <RowDefinition />
+            <RowDefinition />
+            <RowDefinition />
+            <RowDefinition />
+            <RowDefinition />
+        </Grid.RowDefinitions>
+
+        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
+            <TextBlock Text="设备名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+            <TextBox  Height="28" Width="120" Text="{Binding DeviceName}" >
+
+
+            </TextBox>
+        </StackPanel>
+        <StackPanel Orientation="Horizontal" Grid.Row="2" HorizontalAlignment="Center">
+            <TextBlock Text="设备编号:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+            <!--<ComboBox  Height="28" Width="120" ItemsSource="{Binding PLCVars}" SelectedItem="{Binding SelectPLCVar}" />-->
+            <TextBox  Height="28" Width="120" Text="{Binding DeviceNo}" />
+        </StackPanel>
+        <StackPanel Orientation="Horizontal"  Grid.Row="3" HorizontalAlignment="Center">
+            <TextBlock Text="所属项目:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+            <ComboBox  Height="28" Width="120" ItemsSource="{Binding ProjectNameList}" SelectedItem="{Binding ProjectName}" />
+        </StackPanel>
+        <StackPanel Orientation="Horizontal"  Grid.Row="4" HorizontalAlignment="Center">
+            <TextBlock Text="所属设备类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+            <ComboBox  Height="28" Width="120" ItemsSource="{Binding DeviceKindNameList}" SelectedItem="{Binding DeviceKindName}" />
+        </StackPanel>
+        <StackPanel Orientation="Horizontal" Grid.Row="5" HorizontalAlignment="Center">
+            <TextBlock Text="描述:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80" />
+            <TextBox  Height="28" Width="220" Text="{Binding Remark}" />
+        </StackPanel>
+        <StackPanel Orientation="Horizontal" Grid.Row="6" HorizontalAlignment="Center">
+
+            <Button  Content="取消" Width="80"  Margin="5,0"  Command="{Binding CancelCommand}" Opacity="0.7" Style="{StaticResource NormalButtonStyle}" />
+            <Button  Content="确认" Width="80"  Margin="5,0"  Command="{Binding SureCommand}" Style="{StaticResource NormalButtonStyle}" />
+        </StackPanel>
+
+
+    </Grid>
+</UserControl>
+

+ 28 - 0
BlankApp1/BlankApp1/Views/BasicConfigView/AddOrEditDeviceView.xaml.cs

@@ -0,0 +1,28 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Navigation;
+using System.Windows.Shapes;
+
+namespace PLCTool.Views.BasicConfigView
+{
+    /// <summary>
+    /// AddOrEditDeviceView.xaml 的交互逻辑
+    /// </summary>
+    public partial class AddOrEditDeviceView : UserControl
+    {
+        public AddOrEditDeviceView()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 8 - 3
BlankApp1/BlankApp1/Views/BasicConfigView/DeviceKindView.xaml

@@ -17,7 +17,7 @@
             <RowDefinition Height="40"/>
 
         </Grid.RowDefinitions>
-        <UniformGrid Grid.Row="0" Columns="3">
+        <UniformGrid Grid.Row="0" Columns="2">
             <StackPanel Orientation="Horizontal">
                 <TextBlock Text="设备类型编号:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
                 <TextBox  Height="28" Width="120" Text="{Binding DeviceKindNo}" />
@@ -62,7 +62,7 @@
                 <DataGridTextColumn Header="描述" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
 
                 <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTemplateColumn Header="操作" Width="180" CellStyle="{StaticResource MyDataGridCellStyle}">
+                <DataGridTemplateColumn Header="操作" Width="220" CellStyle="{StaticResource MyDataGridCellStyle}">
                     <DataGridTemplateColumn.CellTemplate>
                         <DataTemplate>
                             <StackPanel Orientation="Horizontal">
@@ -80,7 +80,12 @@
                                         <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>
                                 </Button>
-                               
+                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
+                                    Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding DeviceKindId}" Cursor="Hand" Margin="0,0,10,0" >
+                                    <StackPanel Orientation="Horizontal">
+                                        <TextBlock  Text="查看测试方案" VerticalAlignment="Center" Foreground="Blue"/>
+                                    </StackPanel>
+                                </Button>
                             </StackPanel>
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>

+ 19 - 21
BlankApp1/BlankApp1/Views/BasicConfigView/DeviceView.xaml

@@ -17,18 +17,22 @@
             <RowDefinition Height="40"/>
 
         </Grid.RowDefinitions>
-        <UniformGrid Grid.Row="0" Columns="3">
+        <UniformGrid Grid.Row="0" Columns="4">
             <StackPanel Orientation="Horizontal">
                 <TextBlock Text="设备编号:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120" Text="{Binding ScheduleName}" />
+                <TextBox  Height="28" Width="120" Text="{Binding DeviceNo}" />
             </StackPanel>
             <StackPanel Orientation="Horizontal">
                 <TextBlock Text="设备名称:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
                 <TextBox  Height="28" Width="120" Text="{Binding DeviceName}"/>
             </StackPanel>
-            <StackPanel Orientation="Horizontal" >
-                <TextBlock Text="创建人:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
-                <TextBox  Height="28" Width="120" Text="{Binding DeviceName}"/>
+            <StackPanel Orientation="Horizontal"  Grid.Row="3" HorizontalAlignment="Center">
+                <TextBlock Text="所属项目:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+                <ComboBox  Height="28" Width="120" ItemsSource="{Binding ProjectNameList}" SelectedItem="{Binding ProjectName}" />
+            </StackPanel>
+            <StackPanel Orientation="Horizontal"  Grid.Row="4" HorizontalAlignment="Center">
+                <TextBlock Text="所属设备类型:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0" TextAlignment="Right" Width="80"/>
+                <ComboBox  Height="28" Width="120" ItemsSource="{Binding DeviceKindNameList}" SelectedItem="{Binding DeviceKindName}" />
             </StackPanel>
 
 
@@ -53,21 +57,21 @@
 
                 <Button  Content="查询" Width="80"  Margin="5,0"  Command="{Binding QueryCommand}" Style="{StaticResource NormalButtonStyle}" />
                 <Button  Content="重置" Width="80"  Margin="5,0"  Command="{Binding ResetCommand}" Style="{StaticResource NormalButtonStyle}" />
-                <Button  Content="新增" Width="80"  Margin="5,0"  Command="{Binding AddPlanCommand}" Style="{StaticResource NormalButtonStyle}"/>
+                <Button  Content="新增" Width="80"  Margin="5,0"  Command="{Binding AddCommand}" Style="{StaticResource NormalButtonStyle}"/>
 
                 <Button Content="导出Excel" Width="80"  Margin="5,0"  Command="{Binding ExportCommand}" Style="{StaticResource NormalButtonStyle}" />
             </StackPanel>
         </Grid>
         <DataGrid  Grid.Row="2"  ColumnWidth="*" AutoGenerateColumns="False" HeadersVisibility="All" CanUserAddRows="False"  SelectionUnit="FullRow" SelectionMode="Single"   RowHeaderWidth="0"
                   ColumnHeaderStyle="{StaticResource ColumnHeaderStyle}"  RowHeaderStyle="{StaticResource RowHeaderStyle}" RowStyle="{StaticResource DataGridRowtyle}"  AlternationCount="2"
-                 ItemsSource="{Binding BaseConfigList}" IsReadOnly="True" Padding="0"  >
+                 ItemsSource="{Binding DeviceItemList}" IsReadOnly="True" Padding="0"  >
             <DataGrid.Columns >
-                <DataGridTextColumn Header="序号" Width="50" Binding="{Binding SchemeId}" CellStyle="{StaticResource MyDataGridCellStyle}" />
-                <DataGridTextColumn Header="设备编号" Binding="{Binding SchemeName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <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 DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="所属设备类型" Binding="{Binding DeviceName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
-                <DataGridTextColumn Header="描述" Binding="{Binding ItemName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="所属项目编号" Binding="{Binding ProjectName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="所属设备类型" Binding="{Binding DeviceKindName}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
+                <DataGridTextColumn Header="描述" Binding="{Binding Remark}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="创建者" Binding="{Binding CreateBy}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTextColumn Header="创建时间" Binding="{Binding CreateTime,StringFormat={}{0:yyyy-MM-dd HH:mm:ss}}" CellStyle="{StaticResource MyDataGridCellStyle}"/>
                 <DataGridTemplateColumn Header="操作" Width="180" CellStyle="{StaticResource MyDataGridCellStyle}">
@@ -75,26 +79,20 @@
                         <DataTemplate>
                             <StackPanel Orientation="Horizontal">
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,10,0" >
+                                        Command="{Binding DataContext.EditCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding DeviceId}" Cursor="Hand" Margin="0,0,10,0" >
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="编辑" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>
                                 </Button>
                                 <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-                                        Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeId}" Cursor="Hand" Margin="0,0,10,0">
+                                        Command="{Binding DataContext.DeleteCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding DeviceId}" Cursor="Hand" Margin="0,0,10,0">
 
                                     <StackPanel Orientation="Horizontal">
                                         <TextBlock  Text="删除" VerticalAlignment="Center" Foreground="Blue"/>
                                     </StackPanel>
                                 </Button>
-                                <Button  Width="auto" Background="Transparent" HorizontalContentAlignment ="Left" Foreground="Black" Height="25" BorderThickness="0"
-       Command="{Binding DataContext.CopyCommand, RelativeSource={RelativeSource Mode=FindAncestor,AncestorType=DataGrid}}" CommandParameter="{Binding SchemeName}" Cursor="Hand" >
-
-                                    <StackPanel Orientation="Horizontal">
-                                        <TextBlock  Text="复制方案" VerticalAlignment="Center" Foreground="Blue"/>
-                                    </StackPanel>
-                                </Button>
+                             
                             </StackPanel>
                         </DataTemplate>
                     </DataGridTemplateColumn.CellTemplate>

+ 9 - 19
BlankApp1/Model/Dto/BasDeviceDto.cs

@@ -48,34 +48,24 @@ namespace Model.Dto
         /// Default:
         /// Nullable:True
         /// </summary>           
-        private string projectId { get; set; }
-        public string ProjectId
+        private string projectName { get; set; }
+        public string ProjectName
         {
-            get { return projectId; }
-            set { projectId = value; OnPropertyChanged(); }
+            get { return projectName; }
+            set { projectName = value; OnPropertyChanged(); }
         }
         /// <summary>
         /// Desc:所属设备类型编号
         /// Default:
         /// Nullable:False
         /// </summary>           
-        private string deviceKindId { get; set; }
-        public string DeviceKindId
+        private string deviceKindName { get; set; }
+        public string DeviceKindName
         {
-            get { return deviceKindId; }
-            set { deviceKindId = value; OnPropertyChanged(); }
-        }
-        /// <summary>
-        /// Desc:描述
-        /// Default:
-        /// Nullable:False
-        /// </summary>           
-        private  string describe { get; set; }
-        public string Describe
-        {
-            get { return describe; }
-            set { describe = value; OnPropertyChanged(); }
+            get { return deviceKindName; }
+            set { deviceKindName = value; OnPropertyChanged(); }
         }
+       
         /// <summary>
         /// Desc:创建者
         /// Default:

+ 1 - 6
BlankApp1/Model/Entities/bas_device.cs

@@ -51,12 +51,7 @@ namespace Model.Entities
            /// </summary>           
            public string device_kind_id {get;set;}
 
-           /// <summary>
-           /// Desc:描述
-           /// Default:
-           /// Nullable:False
-           /// </summary>           
-           public string describe {get;set;}
+      
 
            /// <summary>
            /// Desc:创建者