2018-07-16 00:48:31 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
using System.Windows.Forms;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
using PKHeX.Core;
|
|
|
|
|
using PKHeX.WinForms.Properties;
|
2018-04-07 04:23:09 +00:00
|
|
|
|
using static PKHeX.Core.MessageStrings;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
|
|
|
|
namespace PKHeX.WinForms
|
|
|
|
|
{
|
|
|
|
|
public partial class SAV_FolderList : Form
|
|
|
|
|
{
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private readonly Action<SaveFile> OpenSaveFile;
|
2020-12-05 13:36:23 +00:00
|
|
|
|
private readonly List<INamedFolderPath> Paths;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private readonly SortableBindingList<SavePreview> Recent;
|
|
|
|
|
private readonly SortableBindingList<SavePreview> Backup;
|
2020-12-22 07:37:07 +00:00
|
|
|
|
private readonly List<Label> TempTranslationLabels = new();
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
public SAV_FolderList(Action<SaveFile> openSaveFile)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2018-07-16 00:48:31 +00:00
|
|
|
|
OpenSaveFile = openSaveFile;
|
2018-07-21 17:23:15 +00:00
|
|
|
|
|
|
|
|
|
var drives = Environment.GetLogicalDrives();
|
|
|
|
|
Paths = GetPathList(drives);
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
dgDataRecent.ContextMenuStrip = GetContextMenu(dgDataRecent);
|
|
|
|
|
dgDataBackup.ContextMenuStrip = GetContextMenu(dgDataBackup);
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var extra = Paths.Select(z => z.Path).Where(z => z != Main.BackupPath).Distinct();
|
|
|
|
|
var recent = SaveFinder.GetSaveFiles(drives, false, extra).ToList();
|
|
|
|
|
var loaded = Main.Settings.Startup.RecentlyLoaded
|
|
|
|
|
.Where(z => recent.All(x => x.Metadata.FilePath != z))
|
|
|
|
|
.Where(File.Exists).Select(SaveUtil.GetVariantSAV).Where(z => z is not null);
|
|
|
|
|
recent.AddRange(loaded!);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Recent = PopulateData(dgDataRecent, recent);
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var backup = SaveFinder.GetSaveFiles(drives, false, Main.BackupPath);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Backup = PopulateData(dgDataBackup, backup);
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
CB_FilterColumn.Items.Add(MsgAny);
|
|
|
|
|
var dgv = Recent.Count >= 1 ? dgDataRecent : dgDataBackup;
|
|
|
|
|
int count = dgv.ColumnCount;
|
|
|
|
|
for (int i = 0; i < count; i++)
|
2018-07-18 04:02:01 +00:00
|
|
|
|
{
|
|
|
|
|
var text = dgv.Columns[i].HeaderText;
|
|
|
|
|
CB_FilterColumn.Items.Add(text);
|
|
|
|
|
var tempLabel = new Label {Name = "DGV_" + text, Text = text, Visible = false};
|
|
|
|
|
Controls.Add(tempLabel);
|
|
|
|
|
TempTranslationLabels.Add(tempLabel);
|
|
|
|
|
}
|
2018-07-18 03:52:08 +00:00
|
|
|
|
CB_FilterColumn.SelectedIndex = 0;
|
|
|
|
|
|
2018-07-18 04:02:01 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, Main.CurrentLanguage);
|
|
|
|
|
|
|
|
|
|
// Update Translated headers
|
|
|
|
|
for (int i = 0; i < TempTranslationLabels.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
var text = TempTranslationLabels[i].Text;
|
2018-07-19 02:32:57 +00:00
|
|
|
|
if (i < dgDataRecent.ColumnCount)
|
|
|
|
|
dgDataRecent.Columns[i].HeaderText = text;
|
|
|
|
|
if (i < dgDataBackup.ColumnCount)
|
|
|
|
|
dgDataBackup.Columns[i].HeaderText = text;
|
2018-07-18 04:02:01 +00:00
|
|
|
|
CB_FilterColumn.Items[i+1] = text;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
// Preprogrammed folders
|
|
|
|
|
foreach (var loc in Paths)
|
|
|
|
|
AddButton(loc.DisplayText, loc.Path);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
|
|
|
|
|
dgDataRecent.DoubleBuffered(true);
|
|
|
|
|
dgDataBackup.DoubleBuffered(true);
|
|
|
|
|
|
|
|
|
|
CenterToParent();
|
2018-07-18 03:52:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
private static List<INamedFolderPath> GetPathList(IReadOnlyList<string> drives)
|
2018-07-18 03:52:08 +00:00
|
|
|
|
{
|
2020-12-05 13:36:23 +00:00
|
|
|
|
var locs = new List<INamedFolderPath>
|
2018-07-18 03:52:08 +00:00
|
|
|
|
{
|
|
|
|
|
new CustomFolderPath(Main.BackupPath, "PKHeX Backups")
|
|
|
|
|
};
|
|
|
|
|
locs.AddRange(GetUserPaths());
|
2018-07-21 17:23:15 +00:00
|
|
|
|
locs.AddRange(GetConsolePaths(drives));
|
|
|
|
|
locs.AddRange(GetSwitchPaths(drives));
|
2018-07-18 03:52:08 +00:00
|
|
|
|
return locs.GroupBy(z => z.Path).Select(z => z.First())
|
|
|
|
|
.OrderByDescending(z => Directory.Exists(z.Path)).ToList();
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
private const int ButtonHeight = 30;
|
|
|
|
|
private const int ButtonWidth = 130;
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void AddButton(string name, string path)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Button button = GetCustomButton(name);
|
|
|
|
|
button.Enabled = new DirectoryInfo(path).Exists;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
button.Click += (s, e) =>
|
|
|
|
|
{
|
2018-07-25 14:26:29 +00:00
|
|
|
|
if (!Directory.Exists(path))
|
2017-05-18 01:25:48 +00:00
|
|
|
|
{
|
2018-07-25 14:26:29 +00:00
|
|
|
|
WinFormsUtil.Alert(MsgFolderNotFound, path);
|
|
|
|
|
return;
|
2017-05-18 01:25:48 +00:00
|
|
|
|
}
|
2018-07-25 14:26:29 +00:00
|
|
|
|
Process.Start("explorer.exe", path);
|
|
|
|
|
Close();
|
2017-05-16 23:27:43 +00:00
|
|
|
|
};
|
|
|
|
|
FLP_Buttons.Controls.Add(button);
|
|
|
|
|
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var hover = new ToolTip {AutoPopDelay = 30_000};
|
|
|
|
|
button.MouseHover += (s, e) => hover.Show(path, button);
|
2018-07-22 21:27:48 +00:00
|
|
|
|
}
|
2017-05-16 23:27:43 +00:00
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
private static Button GetCustomButton(string name)
|
|
|
|
|
{
|
2020-12-22 07:37:07 +00:00
|
|
|
|
return new()
|
2018-07-22 21:27:48 +00:00
|
|
|
|
{
|
|
|
|
|
Size = new Size { Height = ButtonHeight, Width = ButtonWidth },
|
|
|
|
|
Text = name,
|
|
|
|
|
Name = $"B_{name}",
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static IEnumerable<CustomFolderPath> GetUserPaths()
|
|
|
|
|
{
|
2021-04-12 01:09:54 +00:00
|
|
|
|
var lines = Main.Settings.Backup.OtherBackupPaths;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return lines.Select(z => z.Split('\t'))
|
|
|
|
|
.Where(a => a.Length == 2)
|
2018-07-22 21:27:48 +00:00
|
|
|
|
.Select(x => new CustomFolderPath(x, true));
|
2017-05-17 04:44:02 +00:00
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> GetConsolePaths(IEnumerable<string> drives)
|
2017-05-17 04:44:02 +00:00
|
|
|
|
{
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var path3DS = SaveFinder.Get3DSLocation(drives);
|
2018-07-21 17:23:15 +00:00
|
|
|
|
if (path3DS == null)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
return Array.Empty<CustomFolderPath>();
|
2018-05-22 01:20:08 +00:00
|
|
|
|
var root = Path.GetPathRoot(path3DS);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (root == null)
|
|
|
|
|
return Array.Empty<CustomFolderPath>();
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var paths = SaveFinder.Get3DSBackupPaths(root);
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return paths.Select(z => new CustomFolderPath(z));
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-21 17:23:15 +00:00
|
|
|
|
private static IEnumerable<CustomFolderPath> GetSwitchPaths(IEnumerable<string> drives)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var pathNX = SaveFinder.GetSwitchLocation(drives);
|
2018-07-21 17:23:15 +00:00
|
|
|
|
if (pathNX == null)
|
2020-10-18 18:02:39 +00:00
|
|
|
|
return Array.Empty<CustomFolderPath>();
|
2018-05-22 01:20:08 +00:00
|
|
|
|
var root = Path.GetPathRoot(pathNX);
|
2020-10-18 18:02:39 +00:00
|
|
|
|
if (root == null)
|
|
|
|
|
return Array.Empty<CustomFolderPath>();
|
2020-04-14 17:59:16 +00:00
|
|
|
|
var paths = SaveFinder.GetSwitchBackupPaths(root);
|
2018-05-22 01:20:08 +00:00
|
|
|
|
return paths.Select(z => new CustomFolderPath(z));
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
private sealed class CustomFolderPath : INamedFolderPath
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
2020-12-05 13:36:23 +00:00
|
|
|
|
public string Path { get; }
|
|
|
|
|
public string DisplayText { get; }
|
|
|
|
|
public bool Custom { get; }
|
2018-05-22 01:20:08 +00:00
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(string z, bool custom = false)
|
2017-05-16 23:27:43 +00:00
|
|
|
|
{
|
2017-05-17 04:44:02 +00:00
|
|
|
|
var di = new DirectoryInfo(z);
|
|
|
|
|
var root = di.Root.Name;
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var folder = di.Parent?.Name ?? di.Name;
|
2017-05-17 04:44:02 +00:00
|
|
|
|
if (root == folder)
|
|
|
|
|
folder = di.Name;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
|
|
|
|
|
Path = z;
|
|
|
|
|
DisplayText = folder;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(IReadOnlyList<string> arr, bool custom = false)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
|
|
|
|
Path = arr[1];
|
|
|
|
|
DisplayText = arr[0];
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-22 21:27:48 +00:00
|
|
|
|
public CustomFolderPath(string path, string display, bool custom = false)
|
2018-05-22 01:20:08 +00:00
|
|
|
|
{
|
|
|
|
|
Path = path;
|
|
|
|
|
DisplayText = display;
|
2018-07-22 21:27:48 +00:00
|
|
|
|
Custom = custom;
|
2018-05-22 01:20:08 +00:00
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
public override string ToString() => $"{DisplayText}\t{Path}";
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private sealed class SaveList<T> : SortableBindingList<T> where T : class { }
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private ContextMenuStrip GetContextMenu(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var mnuOpen = new ToolStripMenuItem
|
|
|
|
|
{
|
|
|
|
|
Name = "mnuOpen",
|
|
|
|
|
Text = "Open",
|
|
|
|
|
Image = Resources.open,
|
|
|
|
|
};
|
|
|
|
|
mnuOpen.Click += (sender, e) => ClickOpenFile(dgv);
|
|
|
|
|
|
|
|
|
|
var mnuBrowseAt = new ToolStripMenuItem
|
|
|
|
|
{
|
|
|
|
|
Name = "mnuBrowseAt",
|
|
|
|
|
Text = "Browse...",
|
|
|
|
|
Image = Resources.folder,
|
|
|
|
|
};
|
|
|
|
|
mnuBrowseAt.Click += (sender, e) => ClickOpenFolder(dgv);
|
|
|
|
|
|
2020-12-22 07:37:07 +00:00
|
|
|
|
ContextMenuStrip mnu = new();
|
2018-07-16 00:48:31 +00:00
|
|
|
|
mnu.Items.Add(mnuOpen);
|
|
|
|
|
mnu.Items.Add(mnuBrowseAt);
|
|
|
|
|
return mnu;
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private void ClickOpenFile(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var sav = GetSaveFile(dgv);
|
2021-03-08 19:37:46 +00:00
|
|
|
|
if (sav == null || !File.Exists(sav.FilePath))
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenSaveFile(sav.Save);
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-16 00:48:31 +00:00
|
|
|
|
private void ClickOpenFolder(DataGridView dgv)
|
|
|
|
|
{
|
|
|
|
|
var sav = GetSaveFile(dgv);
|
2021-03-08 19:37:46 +00:00
|
|
|
|
if (sav == null || !File.Exists(sav.FilePath))
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
WinFormsUtil.Alert(MsgFileLoadFail);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-05 13:36:23 +00:00
|
|
|
|
var path = sav.Save.Metadata.FilePath;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Process.Start("explorer.exe", $"/select, \"{path}\"");
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2020-10-18 18:02:39 +00:00
|
|
|
|
private SavePreview? GetSaveFile(DataGridView dgData)
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
var c = dgData.SelectedCells;
|
|
|
|
|
if (c.Count != 1)
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
|
|
var item = c[0].RowIndex;
|
|
|
|
|
var parent = dgData == dgDataRecent ? Recent : Backup;
|
|
|
|
|
return parent[item];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void DataGridCellMouseDown(object sender, DataGridViewCellMouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (e.ColumnIndex == -1 || e.RowIndex == -1 || e.Button != MouseButtons.Right)
|
|
|
|
|
return;
|
2020-11-14 16:20:48 +00:00
|
|
|
|
var dgv = (DataGridView)sender;
|
|
|
|
|
var c = dgv[e.ColumnIndex, e.RowIndex];
|
|
|
|
|
dgv.ClearSelection();
|
|
|
|
|
dgv.CurrentCell = c;
|
2018-07-16 00:48:31 +00:00
|
|
|
|
c.Selected = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private SaveList<SavePreview> PopulateData(DataGridView dgData, IEnumerable<SaveFile> saves)
|
|
|
|
|
{
|
|
|
|
|
var list = new SaveList<SavePreview>();
|
|
|
|
|
|
|
|
|
|
var enumerator = saves.GetEnumerator();
|
|
|
|
|
while (enumerator.Current == null)
|
|
|
|
|
{
|
|
|
|
|
if (!enumerator.MoveNext())
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var first = enumerator.Current;
|
2020-12-05 13:36:23 +00:00
|
|
|
|
var sav1 = new SavePreview(first, Paths);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
LoadEntryInitial(dgData, list, sav1);
|
2018-07-28 03:41:49 +00:00
|
|
|
|
|
|
|
|
|
int ctr = 1; // refresh every 7 until 15+ are loaded
|
2018-07-16 00:48:31 +00:00
|
|
|
|
Task.Run(async () => // load the rest async
|
|
|
|
|
{
|
2018-07-16 22:31:23 +00:00
|
|
|
|
while (!dgData.IsHandleCreated)
|
|
|
|
|
await Task.Delay(15).ConfigureAwait(false);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
while (enumerator.MoveNext())
|
|
|
|
|
{
|
|
|
|
|
var next = enumerator.Current;
|
2020-12-05 13:36:23 +00:00
|
|
|
|
var sav = new SavePreview(next, Paths);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
dgData.Invoke(new Action(() => LoadEntry(dgData, list, sav)));
|
2018-07-28 03:41:49 +00:00
|
|
|
|
ctr++;
|
|
|
|
|
if (ctr < 15 && ctr % 7 == 0)
|
|
|
|
|
dgData.Invoke(new Action(() => Refresh(dgData)));
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
2018-07-28 03:41:49 +00:00
|
|
|
|
dgData.Invoke(new Action(() => Refresh(dgData)));
|
2018-07-16 00:48:31 +00:00
|
|
|
|
enumerator.Dispose();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return list;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-28 03:41:49 +00:00
|
|
|
|
private static void Refresh(DataGridView dgData)
|
|
|
|
|
{
|
|
|
|
|
dgData.SuspendLayout();
|
|
|
|
|
dgData.AutoResizeColumns();
|
2020-07-22 04:50:23 +00:00
|
|
|
|
dgData.ResumeLayout(true);
|
2018-07-28 03:41:49 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-23 22:58:48 +00:00
|
|
|
|
private static void LoadEntryInitial(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(sav);
|
|
|
|
|
dgData.DataSource = list;
|
|
|
|
|
dgData.AutoGenerateColumns = true;
|
|
|
|
|
for (int i = 0; i < dgData.Columns.Count; i++)
|
|
|
|
|
dgData.Columns[i].SortMode = DataGridViewColumnSortMode.Automatic;
|
|
|
|
|
dgData.AutoResizeColumns(); // Trigger Resizing
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
private void LoadEntry(DataGridView dgData, ICollection<SavePreview> list, SavePreview sav)
|
2018-07-16 00:48:31 +00:00
|
|
|
|
{
|
|
|
|
|
list.Add(sav);
|
2018-07-18 03:52:08 +00:00
|
|
|
|
int count = list.Count;
|
|
|
|
|
if (CB_FilterColumn.SelectedIndex != 0)
|
|
|
|
|
ToggleRowVisibility(dgData, CB_FilterColumn.SelectedIndex - 1, TB_FilterTextContains.Text, count - 1);
|
2018-07-16 00:48:31 +00:00
|
|
|
|
}
|
2018-07-18 03:52:08 +00:00
|
|
|
|
|
|
|
|
|
private void ChangeFilterIndex(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
TB_FilterTextContains.Enabled = CB_FilterColumn.SelectedIndex != 0;
|
|
|
|
|
SetRowFilter();
|
|
|
|
|
}
|
2018-07-22 21:27:48 +00:00
|
|
|
|
|
2018-07-18 03:52:08 +00:00
|
|
|
|
private void ChangeFilterText(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (CB_FilterColumn.SelectedIndex != 0)
|
|
|
|
|
SetRowFilter();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void SetRowFilter()
|
|
|
|
|
{
|
|
|
|
|
GetFilterText(dgDataRecent);
|
|
|
|
|
GetFilterText(dgDataBackup);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void GetFilterText(DataGridView dg)
|
|
|
|
|
{
|
2018-07-19 02:32:57 +00:00
|
|
|
|
if (dg.RowCount == 0)
|
|
|
|
|
return;
|
2018-07-18 03:52:08 +00:00
|
|
|
|
var cm = (CurrencyManager)BindingContext[dg.DataSource];
|
|
|
|
|
cm.SuspendBinding();
|
|
|
|
|
int column = CB_FilterColumn.SelectedIndex - 1;
|
|
|
|
|
var text = TB_FilterTextContains.Text;
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < dg.RowCount; i++)
|
|
|
|
|
ToggleRowVisibility(dg, column, text, i);
|
|
|
|
|
cm.ResumeBinding();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static void ToggleRowVisibility(DataGridView dg, int column, string text, int i)
|
|
|
|
|
{
|
|
|
|
|
var row = dg.Rows[i];
|
|
|
|
|
if (text.Length == 0 || column < 0)
|
|
|
|
|
{
|
|
|
|
|
row.Visible = true;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
var cell = row.Cells[column];
|
2020-10-18 18:02:39 +00:00
|
|
|
|
var value = cell.Value?.ToString();
|
|
|
|
|
if (value == null)
|
|
|
|
|
{
|
|
|
|
|
row.Visible = false;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2018-07-18 03:52:08 +00:00
|
|
|
|
row.Visible = value.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0; // case insensitive contains
|
|
|
|
|
}
|
2017-05-16 23:27:43 +00:00
|
|
|
|
}
|
|
|
|
|
}
|