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

修改卡片样式

ltwork 1 éve
szülő
commit
3fae58c4ba

+ 3 - 0
BlankApp1/BlankApp1/App.xaml.cs

@@ -71,6 +71,9 @@ namespace BlankApp1
             containerRegistry.RegisterForNavigation<ResultQueryView, ResultQueryViewModel>();
             containerRegistry.RegisterForNavigation<RetryTestView, RetryTestViewModel>();
             containerRegistry.RegisterForNavigation<AddOrEditSchView, AddOrEditSchViewModel>();
+
+            containerRegistry.RegisterForNavigation<DeviceTestCardView, DeviceTestCardViewModel>();
+            containerRegistry.RegisterForNavigation<ProjectTestView, ProjectTestViewModel>();
             containerRegistry.RegisterDialog<AddDetailView, AddDetailViewModel>();
             containerRegistry.RegisterDialog<AutoTestView, AutoTestViewModel>();
             containerRegistry.RegisterDialog<ManualTestView, ManualTestViewModel>();

+ 115 - 0
BlankApp1/BlankApp1/Controls/MyWrapPanel.cs

@@ -0,0 +1,115 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows;
+
+namespace PLCTool.Controls
+{
+    public class MyWrapPanel : Panel
+    {
+        protected override System.Windows.Size MeasureOverride(System.Windows.Size availableSize)
+        {
+            Size currentLineSize = new Size();
+            Size panelSize = new Size();
+
+            foreach (UIElement element in base.InternalChildren)
+            {
+                element.Measure(availableSize);
+                Size desiredSize = element.DesiredSize;
+
+                if (currentLineSize.Width + desiredSize.Width > availableSize.Width)
+                {
+                    panelSize.Width = Math.Max(currentLineSize.Width, panelSize.Width);
+                    panelSize.Height += currentLineSize.Height;
+                    currentLineSize = desiredSize;
+
+                    if (desiredSize.Width > availableSize.Width)
+                    {
+                        panelSize.Width = Math.Max(desiredSize.Width, panelSize.Width);
+                        panelSize.Height += desiredSize.Height;
+                        currentLineSize = new Size();
+                    }
+                }
+                else
+                {
+                    currentLineSize.Width += desiredSize.Width;
+                    currentLineSize.Height = Math.Max(desiredSize.Height, currentLineSize.Height);
+                }
+            }
+
+            panelSize.Width = Math.Max(currentLineSize.Width, panelSize.Width);
+            panelSize.Height += currentLineSize.Height;
+
+            return panelSize;
+        }
+
+        protected override System.Windows.Size ArrangeOverride(System.Windows.Size finalSize)
+        {
+            int firstInLine = 0;
+            int lineCount = 0;
+
+            Size currentLineSize = new Size();
+
+            double accumulatedHeight = 0;
+
+            UIElementCollection elements = base.InternalChildren;
+            double interval = 0.0;
+            for (int i = 0; i < elements.Count; i++)
+            {
+
+                Size desiredSize = elements[i].DesiredSize;
+
+                if (currentLineSize.Width + desiredSize.Width > finalSize.Width) //need to switch to another line
+                {
+                    interval = (finalSize.Width - currentLineSize.Width) / (i - firstInLine + 2);
+                    arrangeLine(accumulatedHeight, currentLineSize.Height, firstInLine, i, interval);
+
+                    accumulatedHeight += currentLineSize.Height;
+                    currentLineSize = desiredSize;
+
+                    if (desiredSize.Width > finalSize.Width) //the element is wider then the constraint - give it a separate line
+                    {
+                        arrangeLine(accumulatedHeight, desiredSize.Height, i, ++i, 0);
+                        accumulatedHeight += desiredSize.Height;
+                        currentLineSize = new Size();
+                    }
+                    firstInLine = i;
+                    lineCount++;
+                }
+                else //continue to accumulate a line
+                {
+                    currentLineSize.Width += desiredSize.Width;
+                    currentLineSize.Height = Math.Max(desiredSize.Height, currentLineSize.Height);
+                }
+            }
+
+            if (firstInLine < elements.Count)
+            {
+                if (lineCount == 0)
+                {
+                    interval = (finalSize.Width - currentLineSize.Width) / (elements.Count - firstInLine + 1);
+                }
+                arrangeLine(accumulatedHeight, currentLineSize.Height, firstInLine, elements.Count, interval);
+            }
+
+
+            return finalSize;
+        }
+
+        private void arrangeLine(double y, double lineHeight, int start, int end, double interval)
+        {
+            double x = 0;
+            UIElementCollection children = InternalChildren;
+            for (int i = start; i < end; i++)
+            {
+                x += interval;
+                UIElement child = children[i];
+                child.Arrange(new Rect(x, y, child.DesiredSize.Width, lineHeight));
+                x += child.DesiredSize.Width;
+            }
+        }
+    }
+}

+ 44 - 0
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/DeviceTestCardViewModel.cs

@@ -0,0 +1,44 @@
+using Prism.Commands;
+using Prism.Mvvm;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using System.Windows.Controls;
+using System.Windows;
+
+namespace PLCTool.ViewModels.BusinessManageViewModel
+{
+    public  class DeviceTestCardViewModel : BindableBase
+    {
+        public DeviceTestCardViewModel()
+        {
+            DoubleClickCommand = new DelegateCommand<object>(DoubleClickCard);
+        }
+
+        private void DoubleClickCard(object obj)
+        {
+            if (obj == null)
+            {
+                MessageBox.Show("参数为空!", "确认", MessageBoxButton.OK, MessageBoxImage.Warning);
+
+                return;
+            }
+            try
+            {
+
+
+                //参数转换
+                TextBlock txtbl = obj as TextBlock;
+            }
+            catch
+            {
+
+            }
+        }
+        #region 命令绑定
+        public DelegateCommand<object> DoubleClickCommand { get; set; }
+        #endregion
+    }
+}

+ 137 - 0
BlankApp1/BlankApp1/ViewModels/BusinessManageViewModel/ProjectTestViewModel.cs

@@ -0,0 +1,137 @@
+using AutoMapper;
+using BizService;
+using Microsoft.Extensions.Logging;
+using Model.Dto;
+using Model.Entities;
+using PLCTool.Views.BusinessManageView;
+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;
+
+namespace PLCTool.ViewModels.BusinessManageViewModel
+{
+    public  class ProjectTestViewModel:BindableBase
+    {
+        
+
+        private readonly IBasicDeviceService _iBasicDeviceService;
+        private readonly IBasicDeviceKindService _iBasicDeviceKindService;
+        private readonly IBasicProjectService _iBasicProjectService;
+        private readonly IBasicPlcTestSchemeService _basicPlcTestSchemeService;
+        private readonly IMapper _mapper;
+        private readonly IDialogService _dialog;
+        private readonly ILogger _logger;
+        private List<BasDeviceWithSchModel> allDeviceList = new List<BasDeviceWithSchModel>();//所有方案
+
+        public ProjectTestViewModel(IBasicDeviceService iBasicDeviceService, IBasicDeviceKindService iBasicDeviceKindService, IBasicProjectService iBasicProjectService, IBasicPlcTestSchemeService basicPlcTestSchemeService, IMapper mapper, IDialogService dialog, ILogger logger)
+        {
+            _iBasicDeviceService = iBasicDeviceService;
+            _iBasicDeviceKindService = iBasicDeviceKindService;
+            _iBasicProjectService = iBasicProjectService;
+            _basicPlcTestSchemeService = basicPlcTestSchemeService;
+            _mapper = mapper;
+            _dialog = dialog;
+            _logger = logger;
+            OnLoadCommand = new DelegateCommand(OnLoad);
+        }
+
+        private void OnLoad()
+        {
+            GetProjectConfig();
+        }
+
+        /// <summary>
+        /// 获取所有项目
+        /// </summary>
+        private void GetProjectConfig()
+        {
+            allDeviceList.Clear();
+     
+            var devicelist = _iBasicDeviceService.QueryList();
+            var allDeviceKinds = _mapper.Map<List<bas_device>, List<BasDeviceDto>>(devicelist);
+            //所有测试方案
+            var schlist = _basicPlcTestSchemeService.QueryList();
+            var schDtoList = _mapper.Map<List<bas_plc_test_scheme>, List<BasicPlcTestSchemeDto>>(schlist);
+
+
+            foreach (var item in allDeviceKinds)
+            {
+                string deviceKind = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name;
+                //在测试方案中查找此设备类型的所有方案
+                var schs = schDtoList.FindAll(x => x.DeviceKindName == deviceKind);
+                //设备方案
+                foreach (var sch in schs)
+                {
+                    allDeviceList.Add(new BasDeviceWithSchModel()
+                    {
+                        DeviceId = item.DeviceId,
+                        DeviceNo = item.DeviceNo,
+                        DeviceName = item.DeviceName,
+                        DeviceKindName = _iBasicDeviceKindService.Find((int)item.DeviceKindId)?.devicekind_name,
+                        ProjectName = _iBasicProjectService.Find((int)item.ProjectId)?.project_name,
+                        SchemeName = sch.SchemeName,
+                        SchemeId = sch.SchemeId,
+                    });
+               
+                }
+            
+            }
+            //所有新项目
+            List<string> projectNames = allDeviceList.Select(x => x.ProjectName).ToList();
+            foreach (var project in projectNames)
+            {
+                DeviceTestCardView deviceCard = new DeviceTestCardView();
+                deviceCard.txtName.Text = project;
+                deviceCard.txtProjectNo.Text = _iBasicProjectService.FindByProjectName(project)?.project_no;
+                deviceCard.txtPProjectLeader.Text = _iBasicProjectService.FindByProjectName(project)?.project_leader;
+                //赋值
+                ProjectePicList.Add(deviceCard);
+            }
+            //计算行数
+            if(projectNames.Count% 4==0)
+            {
+                RowsCount = projectNames.Count / 4;
+            }
+            else
+            {
+                RowsCount = projectNames.Count / 4 + 1;
+            }
+            if(RowsCount<2)
+            {
+                RowsCount = 2;
+            }
+
+
+
+        }
+        #region 命令绑定
+        public DelegateCommand OnLoadCommand { set; get; }
+        #endregion
+
+        #region 数据绑定
+        /// <summary>
+        /// 设备卡片
+        /// </summary>
+
+        private ObservableCollection<DeviceTestCardView> projectPicList=new ObservableCollection<DeviceTestCardView>();
+        public ObservableCollection<DeviceTestCardView> ProjectePicList
+        {
+            get { return projectPicList; }
+            set { projectPicList = value; RaisePropertyChanged(); }
+        }
+
+        private int rowsCount =2;
+        public int RowsCount
+        {
+            get { return rowsCount; }
+            set { rowsCount = value; RaisePropertyChanged(); }
+        }
+        #endregion
+    }
+}

+ 57 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/DeviceTestCardView.xaml

@@ -0,0 +1,57 @@
+<UserControl x:Class="PLCTool.Views.BusinessManageView.DeviceTestCardView"
+             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.BusinessManageView"
+             
+             Height="240" Width="280">
+    <Grid>
+        <Grid >
+            <Grid.InputBindings>
+                <MouseBinding MouseAction="LeftDoubleClick" Command="{Binding DoubleClickCommand}" CommandParameter="{Binding ElementName=txtName}">
+                </MouseBinding>
+            </Grid.InputBindings>
+            <Grid.RowDefinitions>
+                <RowDefinition Height="0.6*"/>
+                <RowDefinition/>
+            </Grid.RowDefinitions>
+            <Border BorderBrush="#CBCBCB" Grid.Row="1" BorderThickness="1"/>
+            <Grid Grid.Row="0" Background="#409EFF" >
+                <TextBlock  x:Name="txtName" Text="{Binding ProjectName}" Foreground="White" FontSize="30" HorizontalAlignment="Center" VerticalAlignment="Center"/>
+            </Grid>
+            
+            <Grid Grid.Row="1">
+                <Grid.ColumnDefinitions>
+                    <ColumnDefinition Width="2*"/>
+                    <ColumnDefinition Width="3*"/>
+                </Grid.ColumnDefinitions>
+                <Grid.RowDefinitions>
+                    <RowDefinition/>
+                    <RowDefinition/>
+                    <RowDefinition/>
+                    <RowDefinition/>
+                </Grid.RowDefinitions>
+                <Grid.Resources>
+                    <Style TargetType="Label">
+                        <Setter Property="FontSize" Value="20"/>
+                        <Setter Property="Width" Value="auto"/>
+                        <Setter Property="HorizontalAlignment" Value="Right"/>
+                        <Setter Property="VerticalAlignment" Value="Center"/>
+                        <Setter Property="Margin" Value="10 0 0 0"/>
+                    </Style>
+                </Grid.Resources>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}"  Grid.Row="0" Text="项目代号:" TextAlignment="Right"/>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" Grid.Row="1" Text="负责人:" TextAlignment="Right"/>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" Grid.Row="2" Text="设备数量:" TextAlignment="Right"/>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" Grid.Row="3" Text="待测设备数量:" TextAlignment="Right"/>
+
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" x:Name="txtProjectNo"  Grid.Row="0" Grid.Column="1" />
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" x:Name="txtPProjectLeader" Grid.Row="1" Grid.Column="1"  HorizontalAlignment="Left"/>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" x:Name="txtDeviceCount" Grid.Row="2" Grid.Column="1" HorizontalAlignment="Left"/>
+                <TextBlock Margin="0,10,0,0" Style="{StaticResource NormalTextBlockStyle}" x:Name="txtNoTestCount" Grid.Row="3" Grid.Column="1"  HorizontalAlignment="Left"/>
+            </Grid>
+            
+        </Grid>
+    </Grid>
+</UserControl>

+ 28 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/DeviceTestCardView.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.BusinessManageView
+{
+    /// <summary>
+    /// DeviceTestCardView.xaml 的交互逻辑
+    /// </summary>
+    public partial class DeviceTestCardView : UserControl
+    {
+        public DeviceTestCardView()
+        {
+            InitializeComponent();
+        }
+    }
+}

+ 109 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/ProjectTestView.xaml

@@ -0,0 +1,109 @@
+<UserControl x:Class="PLCTool.Views.BusinessManageView.ProjectTestView"
+             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.BusinessManageView"
+              xmlns:b="http://schemas.microsoft.com/xaml/behaviors"
+              xmlns:hc="https://handyorg.github.io/handycontrol"
+             xmlns:myControl="clr-namespace:PLCTool.Controls"
+             mc:Ignorable="d" 
+             d:DesignHeight="450" d:DesignWidth="800">
+    <Grid>
+        <b:Interaction.Triggers>
+            <b:EventTrigger EventName="Loaded">
+                <b:InvokeCommandAction Command="{Binding OnLoadCommand}"/>
+            </b:EventTrigger>
+        </b:Interaction.Triggers>
+      
+            <Grid.RowDefinitions>
+                <RowDefinition Height="60"/>
+                <RowDefinition Height="60"/>
+                <RowDefinition/>
+            </Grid.RowDefinitions>
+      
+       
+        <StackPanel  Grid.Row="0" Orientation="Horizontal">
+                <StackPanel Orientation="Horizontal">
+                    <TextBlock Text="项目代号:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                    <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"  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">
+                <TextBlock Text="创建时间:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                <hc:DateTimePicker ShowClearButton="True" Style="{StaticResource DateTimePickerExtend}" Height="25" Width="160"  Text="{Binding StartTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
+            </StackPanel>
+            <StackPanel Orientation="Horizontal">
+                <TextBlock Text="至:"  Style="{StaticResource NormalTextBlockStyle}" Margin="10,0,5,0"/>
+                <hc:DateTimePicker ShowClearButton="True" Style="{StaticResource DateTimePickerExtend}" Height="25" Width="160"  Text="{Binding EndTime, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"/>
+            </StackPanel>
+            
+
+        </StackPanel>
+        <Border Grid.Row="1"  BorderBrush="#CBCBCB" BorderThickness="0,1" />
+        <StackPanel Grid.Row="1" Orientation="Horizontal" HorizontalAlignment="Right" >
+
+            <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}" />
+        </StackPanel>
+        <ScrollViewer Grid.Row="2">
+            <ListBox  x:Name="listboxPic"  SnapsToDevicePixels="True" Grid.IsSharedSizeScope="True" ScrollViewer.VerticalScrollBarVisibility="Disabled" ItemsSource="{Binding ProjectePicList}"   >
+
+                <ListBox.ItemsPanel>
+                    <ItemsPanelTemplate>
+                        <UniformGrid  x:Name="gridPic" Columns="3" Rows="{Binding RowsCount}"  HorizontalAlignment="Stretch" VerticalAlignment="Stretch" />
+                    </ItemsPanelTemplate>
+                </ListBox.ItemsPanel>
+                <ListBox.Template>
+                    <ControlTemplate>
+                        <ItemsPresenter></ItemsPresenter>
+                    </ControlTemplate>
+                </ListBox.Template>
+
+            </ListBox>
+        </ScrollViewer>
+     
+        <!--<ScrollViewer Grid.Row="2">
+            <ListBox x:Name="listboxPic" ItemsSource="{Binding ProjectePicList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible"
+           VerticalAlignment="Center" BorderThickness="0">
+                <ListBox.ItemsPanel>
+                    <ItemsPanelTemplate>
+                        <myControl:MyWrapPanel IsItemsHost="True"/>
+                    </ItemsPanelTemplate>
+                </ListBox.ItemsPanel>
+                <ListBox.Template>
+                    <ControlTemplate>
+                        <ItemsPresenter></ItemsPresenter>
+                    </ControlTemplate>
+                </ListBox.Template>
+               
+            </ListBox>
+        </ScrollViewer>-->
+        <!--<ScrollViewer Grid.Row="2">
+            <ListBox x:Name="listboxPic" ItemsSource="{Binding ProjectePicList}" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Visible"
+    VerticalAlignment="Center" BorderThickness="0">
+                <ListBox.ItemsPanel>
+                    <ItemsPanelTemplate>
+                        
+                            <WrapPanel Orientation="Horizontal" Margin="10" IsItemsHost="True" ScrollViewer.CanContentScroll="True"/>
+                       
+                    </ItemsPanelTemplate>
+                </ListBox.ItemsPanel>
+                <ListBox.Template>
+                    <ControlTemplate>
+                        <ItemsPresenter></ItemsPresenter>
+                    </ControlTemplate>
+                </ListBox.Template>
+
+            </ListBox>
+        </ScrollViewer>-->
+    </Grid>
+</UserControl>

+ 28 - 0
BlankApp1/BlankApp1/Views/BusinessManageView/ProjectTestView.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.BusinessManageView
+{
+    /// <summary>
+    /// ProjectTestView.xaml 的交互逻辑
+    /// </summary>
+    public partial class ProjectTestView : UserControl
+    {
+        public ProjectTestView()
+        {
+            InitializeComponent();
+        }
+    }
+}