Browse Source

主页-扫描仪-高保真和逻辑

lvle 1 year ago
parent
commit
7d58ccf8ea

+ 1 - 0
PDF Office/PDF Master.csproj

@@ -2267,6 +2267,7 @@
     <Resource Include="Resources\PromotionIcon\Mac.png" />
     <Resource Include="Resources\Service\IAPBottom.png" />
     <Resource Include="Resources\Service\IAPTop.png" />
+    <Resource Include="Resources\HomeIcon\noScanner.png" />
     <Content Include="Resources\Service\Login.png">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>

BIN
PDF Office/Resources/HomeIcon/noScanner.png


+ 79 - 27
PDF Office/ViewModels/Dialog/HomePageToolsDialogs/CreateFromScannerDialogsViewModel.cs

@@ -44,8 +44,18 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
     public class CreateFromScannerDialogsViewModel : BindableBase, IDialogAware
     {
 
-
         public static ImageFile imageFile;
+
+        public string Title => "";
+        //图片路径
+        public string FilePath { get; private set; }
+        public event Action<IDialogResult> RequestClose;
+        public virtual void RaiseRequestClose(IDialogResult dialogResult)
+        {
+            RequestClose?.Invoke(dialogResult);
+        }
+
+        
         private List<ScannerItem> _scanners = new List<ScannerItem>();
         public List<ScannerItem> Scanners
         {
@@ -53,15 +63,44 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
             set => SetProperty(ref _scanners, value);
         }
 
-        public string Title => "";
+        public List<string> _ScanItems =new List<string>();
         //图片路径
-        public string FilePath { get; private set; }
-        public event Action<IDialogResult> RequestClose;
-        public virtual void RaiseRequestClose(IDialogResult dialogResult)
+        public List<string> Scanitems
         {
-            RequestClose?.Invoke(dialogResult);
+            get { return _ScanItems; }
+            set => SetProperty(ref _ScanItems, value);
+        }
+        private bool _IsEnable = true;
+        public bool IsEnable
+        {
+            get { return _IsEnable; }
+            set { SetProperty(ref _IsEnable, value);
+                
+            }
+        }
+
+        /// <summary>
+        ///  没有扫描仪显示图
+        /// </summary>
+        private Visibility _Gridvis=Visibility.Collapsed;
+        public Visibility Gridvis
+        {
+            get { return _Gridvis; }
+            set { SetProperty(ref _Gridvis, value);
+                if (Gridvis == Visibility.Visible)
+                {
+                    IsEnable = false;
+                }
+                else
+                {
+                    IsEnable = true;
+                }
+            }
         }
 
+
+
+
         #region 框架
         public bool CanCloseDialog()
         {
@@ -83,7 +122,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
 
      
 
-        //没有检测到扫描仪
+       
         private int _SeIndex=-1;
         public int SeIndex
         {
@@ -103,8 +142,37 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
         {
 
             ToScanCommand = new DelegateCommand(ToScan);
+            ScanAdd();
+         
+        }
+
+        public void ScanAdd()
+        {
+            DeviceManager deviceManager;
+            deviceManager = new DeviceManager();
+
+            for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
+            {
+
+                if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
+                {
+                    continue;
+                }
+                Scanitems.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
+            }
+            if (Scanitems.Count == 0)
+            {
+                Gridvis = Visibility.Visible;
+            }
+            else
+            {
+                SeIndex = 0;
+            }
+
         }
 
+
+
         public void ToScan()
         {
            
@@ -112,7 +180,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
             {
                 imageFile = Scan();
             }
-          
+            
 
         }
 
@@ -145,6 +213,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
                         items = dialog.ShowSelectItems(device, SingleSelect: true);
                         if (items != null)
                         {
+                            //image = (ImageFile)device.Items[1];
                             image = dialog.ShowTransfer(device.Items[1]);
                             ToImage(image);
                             break;
@@ -161,14 +230,7 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
             }
             catch (COMException ex)
             {
-                if (ex.ErrorCode == -2145320939)
-                {
-                    //throw new ScannerNotFoundException();
-                }
-                else
-                {
-                    //throw new ScannerException("COM Exception", ex);
-                }
+                 Gridvis = Visibility.Visible;
                 return null;
             }
         }
@@ -176,22 +238,12 @@ namespace PDF_Master.ViewModels.Dialog.HomePageToolsDialogs
 
         public void ToImage(ImageFile img)
         {
-            //System.Windows.Forms.SaveFileDialog mys = new System.Windows.Forms.SaveFileDialog();
-            //mys.FileName = "MergeDocuments";
-            //mys.Filter = "bmp文件|*.bmp";
-            ////mys.ShowDialog();
-            //string myFileN = mys.FileName.ToString();
-            //myFileN = "C\\";//要保存的文件路径
-            //string FileName = myFileN+ mys.FileName;
-            //FileName = (FileName.Remove(0, FileName.Length - 4).Contains(".bmp")) ? FileName : FileName + ".bmp";
-            //System.IO.Directory.CreateDirectory("C\\img.bmp");
+          
             if (img != null)
 
             {
-                //System.IO.Directory.CreateDirectory("C\\img.bmp");
                 string path = App.CachePath.ScanFilePath;
                 string FileName = path+ "\\"+ Guid.NewGuid().ToString() + ".bmp";
-                //File.Create(FileName);
                 img.SaveFile(FileName);
                 string keyy = "Imagepath";
                 DialogParameters keyValues = new DialogParameters();

+ 55 - 13
PDF Office/Views/Dialog/HomePageToolsDialogs/CreateFromScannerDialogs.xaml

@@ -5,12 +5,35 @@
     xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
     xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
     xmlns:prism="http://prismlibrary.com/"
-    Width="352"
-    Height="560"
+    Width="468"
+    Height="520"
     prism:Dialog.WindowStyle="{StaticResource DialogWindowStyle}"
     prism:ViewModelLocator.AutoWireViewModel="True"
     Background="White"
     mc:Ignorable="d">
+    <UserControl.Resources>
+        <Style x:Key="radioButtonStyle" TargetType="{x:Type ListBox}">
+            <Setter Property="ItemContainerStyle">
+                <Setter.Value>
+                    <Style TargetType="{x:Type ListBoxItem}">
+                        <Setter Property="Margin" Value="9,8,0,0" />
+                        <Setter Property="Template">
+
+                            <Setter.Value>
+                                <ControlTemplate TargetType="ListBoxItem">
+                                    <RadioButton Focusable="False" IsChecked="{Binding Path=IsSelected, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
+                                        <ContentPresenter />
+
+                                    </RadioButton>
+                                </ControlTemplate>
+                            </Setter.Value>
+                        </Setter>
+                    </Style>
+                </Setter.Value>
+            </Setter>
+        </Style>
+
+    </UserControl.Resources>
     <Grid Margin="16,0,16,0" Background="White">
 
         <Grid.RowDefinitions>
@@ -27,43 +50,62 @@
             FontStyle="Normal"
             FontWeight="SemiBold"
             Text="Create PDF from scanner" />
-        <Grid Grid.Row="1" Background="#F3F3F3">
+
+        <Grid Grid.Row="1" Background="#F7F8FA">
             <StackPanel>
                 <TextBlock
-                    Margin="8,0,0,0"
+                    Margin="8,8,0,0"
+                    VerticalAlignment="Center"
                     FontFamily="Segoe UI"
                     FontSize="14"
-                    LineHeight="22"
+                    Foreground="#616469"
+                    LineHeight="20"
                     Text="Scanners" />
                 <ListBox
                     Name="Listboxscan"
                     Height="Auto"
-                    Margin="10,0,0,0"
-                    SelectedIndex="{Binding SeIndex, Mode=TwoWay}" />
+                    Margin="0,10,0,0"
+                    Background="#F7F8FA"
+                    ItemsSource="{Binding Scanitems}"
+                    BorderThickness="0"
+                    SelectedIndex="{Binding SeIndex, Mode=TwoWay}"
+                    Style="{StaticResource radioButtonStyle}" />
             </StackPanel>
         </Grid>
+        <Grid Grid.Row="1" Visibility="{Binding Gridvis,Mode=TwoWay}" Background="#FFFFFF">
+            <Image
+                Width="128"
+                Height="128"
+                HorizontalAlignment="Center"
+                VerticalAlignment="Center"
+                Source="pack://application:,,,/PDF Master;component/Resources/HomeIcon/noScanner.png" 
+                Visibility="Visible"
+                />
+        </Grid>
         <Grid Grid.Row="2">
             <WrapPanel HorizontalAlignment="Right" VerticalAlignment="Center">
                 <Button
                     x:Name="But_Scan"
-                    Width="60"
+                    Width="80"
                     Height="32"
                     HorizontalAlignment="Center"
                     VerticalAlignment="Top"
                     Command="{Binding ToScanCommand}"
                     Content="Scan"
                     IsDefault="True"
+                    IsEnabled="{Binding IsEnable,Mode=TwoWay}"
                     Style="{StaticResource Btn.cta}" />
-              
+
                 <Button
-                    Width="60"
+                    Width="80"
                     Height="32"
-                    Margin="8,0,0,0"
+                    Margin="16,0,0,0"
                     HorizontalAlignment="Center"
                     VerticalAlignment="Top"
+                    Content="Cancel"
                     IsCancel="True"
-                    Style="{StaticResource btn.sec}" Content="Cancel" />
-               
+                    Style="{StaticResource btn.sec}" />
+
             </WrapPanel>
         </Grid>
     </Grid>

+ 0 - 36
PDF Office/Views/Dialog/HomePageToolsDialogs/CreateFromScannerDialogs.xaml.cs

@@ -29,46 +29,10 @@ namespace PDF_Master.Views.Dialog.HomePageToolsDialogs
         public CreateFromScannerDialogs()
         {
             InitializeComponent();
-            ListScanners();
 
-            Loaded += Focus_Loaded;
         }
 
-        public static ImageFile imageFile;
 
-        private void Focus_Loaded(object sender, RoutedEventArgs e)
-        {
-            //if (Listboxscan.Items.Count > 0)
-            //{
-            // Focus;
-            //}
-
-
-        }
-
-        private void ListScanners()
-        {
-           
-
-            DeviceManager deviceManager;
-            deviceManager = new DeviceManager();
-
-            for (int i = 1; i <= deviceManager.DeviceInfos.Count; i++)
-            {
-
-                if (deviceManager.DeviceInfos[i].Type != WiaDeviceType.ScannerDeviceType)
-                {
-                    continue;
-                }
-                Listboxscan.Items.Add(deviceManager.DeviceInfos[i].Properties["Name"].get_Value());
-            }
-            if(Listboxscan.Items.Count==0)
-            {
-                Listboxscan.Items.Add("NO Device");
-            }
-           
-        }
-