From 35792b0a7203dd52b6ff6fbf6c9daa3f657f1ec8 Mon Sep 17 00:00:00 2001 From: LGram16 Date: Thu, 19 Feb 2026 18:42:25 +0900 Subject: [PATCH] =?UTF-8?q?=EB=A7=88=ED=81=AC=EB=AA=A9=EB=A1=9D(new),=20?= =?UTF-8?q?=EC=A0=95=EB=A0=AC,=ED=95=84=ED=84=B0=20=EA=B8=B0=EB=8A=A5=20?= =?UTF-8?q?=EC=97=85=EB=8D=B0=EC=9D=B4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unimarc/unimarc/SortableBindingList.cs | 169 +++++++++++++++++++++++++ unimarc/unimarc/UniMarc.csproj | 1 + unimarc/unimarc/recover_v2.ps1 | 23 ---- unimarc/unimarc/마크/Marc2.cs | 55 ++++---- unimarc/unimarc/마크/Search_Infor2.cs | 2 +- 5 files changed, 195 insertions(+), 55 deletions(-) create mode 100644 unimarc/unimarc/SortableBindingList.cs delete mode 100644 unimarc/unimarc/recover_v2.ps1 diff --git a/unimarc/unimarc/SortableBindingList.cs b/unimarc/unimarc/SortableBindingList.cs new file mode 100644 index 0000000..7db6a57 --- /dev/null +++ b/unimarc/unimarc/SortableBindingList.cs @@ -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 : BindingList, IBindingListView + { + private bool _isSorted; + private ListSortDirection _sortDirection; + private PropertyDescriptor _sortProperty; + private string _filter; + private readonly List _originalItems = new List(); + + public SortableBindingList() : base() { } + public SortableBindingList(IList 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; + if (items != null) + { + PropertyComparer pc = new PropertyComparer(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 : IComparer + { + 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; + } + } + } +} diff --git a/unimarc/unimarc/UniMarc.csproj b/unimarc/unimarc/UniMarc.csproj index e51f2b1..54408c5 100644 --- a/unimarc/unimarc/UniMarc.csproj +++ b/unimarc/unimarc/UniMarc.csproj @@ -267,6 +267,7 @@ + Form diff --git a/unimarc/unimarc/recover_v2.ps1 b/unimarc/unimarc/recover_v2.ps1 deleted file mode 100644 index f702266..0000000 --- a/unimarc/unimarc/recover_v2.ps1 +++ /dev/null @@ -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) diff --git a/unimarc/unimarc/마크/Marc2.cs b/unimarc/unimarc/마크/Marc2.cs index 166d7ff..c96b70e 100644 --- a/unimarc/unimarc/마크/Marc2.cs +++ b/unimarc/unimarc/마크/Marc2.cs @@ -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 dataList = new BindingList(); + public SortableBindingList dataList = new SortableBindingList(); MacListItem pItem = null; protected override bool ProcessCmdKey(ref Message msg, Keys keyData) @@ -168,7 +168,7 @@ namespace UniMarc mLoadCompleted = false; - dataList = new BindingList(); + dataList = new SortableBindingList(); 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; - if (list != null) + if (combo == 0) { - List 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 /// [0] idx, [1] compidx, [2] user, [3] date, [4] grade, [5] tag008, [6] marc 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) + + var currentitem = this.bs1.Current as MarcBookItem; + 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); } diff --git a/unimarc/unimarc/마크/Search_Infor2.cs b/unimarc/unimarc/마크/Search_Infor2.cs index ebda068..6475f5a 100644 --- a/unimarc/unimarc/마크/Search_Infor2.cs +++ b/unimarc/unimarc/마크/Search_Infor2.cs @@ -15,7 +15,7 @@ namespace UniMarc { Main main; public string compidx; - BindingList searchList = new BindingList(); + SortableBindingList searchList = new SortableBindingList(); public Search_Infor2(Main _main) {