2014-11-15 12:09:12 +08:00
|
|
|
|
using GalaSoft.MvvmLight;
|
|
|
|
|
using NTwain;
|
2014-05-20 08:48:21 +08:00
|
|
|
|
using NTwain.Data;
|
2014-11-15 12:09:12 +08:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Windows.Data;
|
2014-04-08 19:36:28 +08:00
|
|
|
|
|
|
|
|
|
namespace Tester.WPF
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Wraps a data source as view model.
|
|
|
|
|
/// </summary>
|
2014-11-15 12:09:12 +08:00
|
|
|
|
class DSVM : ViewModelBase
|
2014-04-08 19:36:28 +08:00
|
|
|
|
{
|
2014-09-15 19:24:13 +08:00
|
|
|
|
public DataSource DS { get; set; }
|
2014-04-08 19:36:28 +08:00
|
|
|
|
|
2014-05-20 08:48:21 +08:00
|
|
|
|
public string Name { get { return DS.Name; } }
|
2014-04-08 19:36:28 +08:00
|
|
|
|
public string Version { get { return DS.Version.Info; } }
|
2014-09-18 08:15:05 +08:00
|
|
|
|
public string Protocol { get { return DS.ProtocolVersion.ToString(); } }
|
2014-11-15 12:09:12 +08:00
|
|
|
|
|
|
|
|
|
ICollectionView _capView;
|
|
|
|
|
public DSVM()
|
|
|
|
|
{
|
|
|
|
|
Caps = new ObservableCollection<CapVM>();
|
|
|
|
|
_capView = CollectionViewSource.GetDefaultView(Caps);
|
|
|
|
|
_capView.SortDescriptions.Add(new System.ComponentModel.SortDescription("Name", System.ComponentModel.ListSortDirection.Ascending));
|
|
|
|
|
_capView.Filter = FilterCapRoutine;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private bool FilterCapRoutine(object obj)
|
|
|
|
|
{
|
|
|
|
|
if (!string.IsNullOrWhiteSpace(CapFilter))
|
|
|
|
|
{
|
|
|
|
|
var vm = obj as CapVM;
|
|
|
|
|
if (vm != null)
|
|
|
|
|
{
|
|
|
|
|
return vm.Name.IndexOf(CapFilter, System.StringComparison.OrdinalIgnoreCase) > -1;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Open()
|
|
|
|
|
{
|
|
|
|
|
Caps.Clear();
|
|
|
|
|
var rc = DS.Open();
|
|
|
|
|
//rc = DGControl.Status.Get(dsId, ref stat);
|
|
|
|
|
if (rc == ReturnCode.Success)
|
|
|
|
|
{
|
|
|
|
|
foreach (var c in DS.SupportedCaps.Select(o => new CapVM(DS, o)))
|
|
|
|
|
{
|
|
|
|
|
Caps.Add(c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string _capFilter;
|
|
|
|
|
|
|
|
|
|
public string CapFilter
|
|
|
|
|
{
|
|
|
|
|
get { return _capFilter; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_capFilter = value;
|
|
|
|
|
_capView.Refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public ObservableCollection<CapVM> Caps { get; private set; }
|
2014-04-08 19:36:28 +08:00
|
|
|
|
}
|
|
|
|
|
}
|