|
@@ -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();
|