마크목록(new), 정렬,필터 기능 업데이트
This commit is contained in:
169
unimarc/unimarc/SortableBindingList.cs
Normal file
169
unimarc/unimarc/SortableBindingList.cs
Normal file
@@ -0,0 +1,169 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UniMarc
|
||||
{
|
||||
public class SortableBindingList<T> : BindingList<T>, IBindingListView
|
||||
{
|
||||
private bool _isSorted;
|
||||
private ListSortDirection _sortDirection;
|
||||
private PropertyDescriptor _sortProperty;
|
||||
private string _filter;
|
||||
private readonly List<T> _originalItems = new List<T>();
|
||||
|
||||
public SortableBindingList() : base() { }
|
||||
public SortableBindingList(IList<T> list) : base(list)
|
||||
{
|
||||
foreach (var item in list)
|
||||
_originalItems.Add(item);
|
||||
}
|
||||
|
||||
protected override void OnListChanged(ListChangedEventArgs e)
|
||||
{
|
||||
if (e.ListChangedType == ListChangedType.ItemAdded)
|
||||
{
|
||||
_originalItems.Insert(e.NewIndex, this[e.NewIndex]);
|
||||
}
|
||||
else if (e.ListChangedType == ListChangedType.ItemDeleted)
|
||||
{
|
||||
// This is slightly tricky if filtered, but we assume basic usage for now
|
||||
// Ideally we'd track IDs
|
||||
}
|
||||
base.OnListChanged(e);
|
||||
}
|
||||
|
||||
#region Sorting
|
||||
protected override bool SupportsSortingCore => true;
|
||||
protected override bool IsSortedCore => _isSorted;
|
||||
protected override ListSortDirection SortDirectionCore => _sortDirection;
|
||||
protected override PropertyDescriptor SortPropertyCore => _sortProperty;
|
||||
|
||||
protected override void ApplySortCore(PropertyDescriptor prop, ListSortDirection direction)
|
||||
{
|
||||
var items = this.Items as List<T>;
|
||||
if (items != null)
|
||||
{
|
||||
PropertyComparer<T> pc = new PropertyComparer<T>(prop, direction);
|
||||
items.Sort(pc);
|
||||
_isSorted = true;
|
||||
_sortDirection = direction;
|
||||
_sortProperty = prop;
|
||||
}
|
||||
else
|
||||
{
|
||||
_isSorted = false;
|
||||
}
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
}
|
||||
|
||||
protected override void RemoveSortCore()
|
||||
{
|
||||
_isSorted = false;
|
||||
_sortProperty = null;
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region Filtering (IBindingListView)
|
||||
public string Filter
|
||||
{
|
||||
get => _filter;
|
||||
set
|
||||
{
|
||||
_filter = value;
|
||||
if (string.IsNullOrEmpty(_filter))
|
||||
RemoveFilter();
|
||||
else
|
||||
ApplyFilter(_filter);
|
||||
}
|
||||
}
|
||||
|
||||
public bool SupportsFiltering => true;
|
||||
|
||||
public void ApplyFilter(string filter)
|
||||
{
|
||||
_filter = filter;
|
||||
if (_originalItems.Count == 0 && this.Count > 0)
|
||||
{
|
||||
foreach (var item in this) _originalItems.Add(item);
|
||||
}
|
||||
|
||||
// Simple parser for "Property=Value" or "Property='Value'"
|
||||
var parts = filter.Split('=');
|
||||
if (parts.Length != 2) return;
|
||||
|
||||
string propName = parts[0].Trim();
|
||||
string valStr = parts[1].Trim().Trim('\'');
|
||||
|
||||
var prop = TypeDescriptor.GetProperties(typeof(T))[propName];
|
||||
if (prop == null) return;
|
||||
|
||||
this.RaiseListChangedEvents = false;
|
||||
this.Clear();
|
||||
foreach (var item in _originalItems)
|
||||
{
|
||||
var val = prop.GetValue(item);
|
||||
if (val != null && val.ToString().Equals(valStr, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
this.Add(item);
|
||||
}
|
||||
}
|
||||
this.RaiseListChangedEvents = true;
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
}
|
||||
|
||||
public void RemoveFilter()
|
||||
{
|
||||
_filter = null;
|
||||
if (_originalItems.Count > 0)
|
||||
{
|
||||
this.RaiseListChangedEvents = false;
|
||||
this.Clear();
|
||||
foreach (var item in _originalItems) this.Add(item);
|
||||
this.RaiseListChangedEvents = true;
|
||||
OnListChanged(new ListChangedEventArgs(ListChangedType.Reset, -1));
|
||||
}
|
||||
}
|
||||
|
||||
public ListSortDescriptionCollection SortDescriptions => null;
|
||||
public bool SupportsAdvancedSorting => false;
|
||||
public void ApplySort(ListSortDescriptionCollection sorts) => throw new NotSupportedException();
|
||||
#endregion
|
||||
|
||||
private class PropertyComparer<TItem> : IComparer<TItem>
|
||||
{
|
||||
private readonly PropertyDescriptor _prop;
|
||||
private readonly ListSortDirection _direction;
|
||||
|
||||
public PropertyComparer(PropertyDescriptor prop, ListSortDirection direction)
|
||||
{
|
||||
_prop = prop;
|
||||
_direction = direction;
|
||||
}
|
||||
|
||||
public int Compare(TItem x, TItem y)
|
||||
{
|
||||
object xVal = _prop.GetValue(x);
|
||||
object yVal = _prop.GetValue(y);
|
||||
|
||||
int result;
|
||||
|
||||
if (xVal == null && yVal == null) result = 0;
|
||||
else if (xVal == null) result = -1;
|
||||
else if (yVal == null) result = 1;
|
||||
else if (xVal is IComparable comparable)
|
||||
result = comparable.CompareTo(yVal);
|
||||
else if (xVal.Equals(yVal))
|
||||
result = 0;
|
||||
else
|
||||
result = xVal.ToString().CompareTo(yVal.ToString());
|
||||
|
||||
return _direction == ListSortDirection.Ascending ? result : -result;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -267,6 +267,7 @@
|
||||
<Compile Include="SearchModel\JunnamEduSearcher.cs" />
|
||||
<Compile Include="SearchModel\NamguLibrarySearcher.cs" />
|
||||
<Compile Include="SearchModel\SeleniumHelper.cs" />
|
||||
<Compile Include="SortableBindingList.cs" />
|
||||
<Compile Include="개발자용\fDevDB.cs">
|
||||
<SubType>Form</SubType>
|
||||
</Compile>
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
$path = "s:\Source\Gloria\Unimarc\unimarc\unimarc\Helper_LibraryDelaySettings.cs"
|
||||
$utf8 = [System.Text.Encoding]::GetEncoding(65001)
|
||||
$cp949 = [System.Text.Encoding]::GetEncoding(949)
|
||||
|
||||
# Read the CURRENT mangled file as UTF-8
|
||||
$mangledString = [System.IO.File]::ReadAllText($path, $utf8)
|
||||
|
||||
# Convert each character to its CP949 bytes
|
||||
# Note: This is tricky because some "characters" might be multiple bytes in CP949
|
||||
# but here each character in the string represents what CP949 read from the original UTF-8 bytes.
|
||||
$byteList = New-Object System.Collections.Generic.List[byte]
|
||||
foreach ($char in $mangledString.ToCharArray()) {
|
||||
$cBytes = $cp949.GetBytes($char)
|
||||
foreach ($b in $cBytes) {
|
||||
$byteList.Add($b)
|
||||
}
|
||||
}
|
||||
|
||||
# Now interpret these bytes as UTF-8 (the original encoding)
|
||||
$restored = $utf8.GetString($byteList.ToArray())
|
||||
|
||||
Write-Host "--- Attempted Restoration ---"
|
||||
Write-Host ($restored -split "`r`n" | select -First 10)
|
||||
@@ -39,7 +39,7 @@ namespace UniMarc
|
||||
Skill_Search_Text search_Text = new Skill_Search_Text();
|
||||
String_Text st = new String_Text();
|
||||
Mac_List ml;
|
||||
public BindingList<MarcBookItem> dataList = new BindingList<MarcBookItem>();
|
||||
public SortableBindingList<MarcBookItem> dataList = new SortableBindingList<MarcBookItem>();
|
||||
MacListItem pItem = null;
|
||||
|
||||
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
|
||||
@@ -168,7 +168,7 @@ namespace UniMarc
|
||||
|
||||
mLoadCompleted = false;
|
||||
|
||||
dataList = new BindingList<MarcBookItem>();
|
||||
dataList = new SortableBindingList<MarcBookItem>();
|
||||
for (int a = 0; a < db_data.Length - 1; a += 11)
|
||||
{
|
||||
MarcBookItem bitem = new MarcBookItem();
|
||||
@@ -457,24 +457,15 @@ namespace UniMarc
|
||||
|
||||
if (isSort)
|
||||
{
|
||||
var list = bs1.DataSource as BindingList<MarcBookItem>;
|
||||
if (list != null)
|
||||
if (combo == 0)
|
||||
{
|
||||
List<MarcBookItem> sorted;
|
||||
if (combo == 0)
|
||||
{
|
||||
sorted = list.OrderBy(x => x.Grade).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
sorted = list.OrderBy(x => x.ISBN13).ToList();
|
||||
}
|
||||
|
||||
list.RaiseListChangedEvents = false;
|
||||
list.Clear();
|
||||
foreach (var item in sorted) list.Add(item);
|
||||
list.RaiseListChangedEvents = true;
|
||||
list.ResetBindings();
|
||||
this.bs1.Sort = "Grade";
|
||||
//sorted = list.OrderBy(x => x.Grade).ToList();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.bs1.Sort = "ISBN13";
|
||||
//sorted = list.OrderBy(x => x.ISBN13).ToList();
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -483,11 +474,12 @@ namespace UniMarc
|
||||
if (combo == 0)
|
||||
{
|
||||
comboIdx = comboBox9.SelectedIndex;
|
||||
Search_Filter("grade", comboIdx);
|
||||
this.bs1.Filter = $"Grade={comboIdx}";
|
||||
//Search_Filter("grade", comboIdx);
|
||||
}
|
||||
else
|
||||
{ // 수정필요
|
||||
|
||||
UTIL.MsgE("이 기능은 구현되지 않았습니다");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -537,7 +529,7 @@ namespace UniMarc
|
||||
|
||||
var dr = this.bs1.Current as MarcBookItem;
|
||||
|
||||
var copySelect = new MarcCopySelect2(this,dr);
|
||||
var copySelect = new MarcCopySelect2(this, dr);
|
||||
copySelect.Init("isbn", dr.ISBN13);
|
||||
copySelect.Show();
|
||||
}
|
||||
@@ -549,19 +541,19 @@ namespace UniMarc
|
||||
/// <param name="GridData">[0] idx, [1] compidx, [2] user, [3] date, [4] grade, [5] tag008, [6] marc </param>
|
||||
public void SelectMarc_Sub(MarcBookItem row, string[] GridData)
|
||||
{
|
||||
row.MarcIdx = GridData[0];
|
||||
row.User= GridData[2];
|
||||
row.MarcIdx = GridData[0];
|
||||
row.User = GridData[2];
|
||||
row.SaveDate = GridData[4];
|
||||
row.Grade= GridData[3];
|
||||
row.Grade = GridData[3];
|
||||
// text008.Text = GridData[5];
|
||||
row.DbMarc= GridData[6];
|
||||
row.DbMarc = GridData[6];
|
||||
mOldMarc = GridData[6];
|
||||
|
||||
row.ForeColor = SetGradeColor(row.Grade);
|
||||
row.BackColor = Color.Yellow;
|
||||
|
||||
var currentitem = this.bs1.Current as MarcBookItem;
|
||||
if (currentitem != null && currentitem == row)
|
||||
if (currentitem != null && currentitem == row)
|
||||
{
|
||||
List_Book_SelectionChanged(null, null);
|
||||
}
|
||||
@@ -880,7 +872,8 @@ namespace UniMarc
|
||||
comboBox8.SelectedIndex = 0;
|
||||
comboBox9.SelectedIndex = 0;
|
||||
|
||||
this.bs1.Sort = "ListIdx desc";
|
||||
this.bs1.Filter = null;
|
||||
this.bs1.Sort = "ListIdx";
|
||||
//List_Book.Sort(list_idx, System.ComponentModel.ListSortDirection.Ascending);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ namespace UniMarc
|
||||
{
|
||||
Main main;
|
||||
public string compidx;
|
||||
BindingList<SearchInforItem> searchList = new BindingList<SearchInforItem>();
|
||||
SortableBindingList<SearchInforItem> searchList = new SortableBindingList<SearchInforItem>();
|
||||
|
||||
public Search_Infor2(Main _main)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user