155 lines
4.7 KiB
C#
155 lines
4.7 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using System.ComponentModel;
|
||
|
|
using System.Drawing;
|
||
|
|
using System.Linq;
|
||
|
|
using System.Windows.Forms;
|
||
|
|
using DCIT.Core.Models;
|
||
|
|
|
||
|
|
namespace DCIT.App.Forms
|
||
|
|
{
|
||
|
|
public sealed class AutoExtractPreviewForm : Form
|
||
|
|
{
|
||
|
|
private readonly BindingList<ExtractionCandidate> _items;
|
||
|
|
private readonly DataGridView _grid;
|
||
|
|
|
||
|
|
public AutoExtractPreviewForm(IList<ExtractionCandidate> candidates)
|
||
|
|
{
|
||
|
|
Text = "自动提取预览";
|
||
|
|
StartPosition = FormStartPosition.CenterParent;
|
||
|
|
MinimumSize = new Size(980, 540);
|
||
|
|
Width = 1200;
|
||
|
|
Height = 720;
|
||
|
|
|
||
|
|
_items = new BindingList<ExtractionCandidate>(candidates.ToList());
|
||
|
|
_grid = new DataGridView
|
||
|
|
{
|
||
|
|
Dock = DockStyle.Fill,
|
||
|
|
AllowUserToAddRows = false,
|
||
|
|
AllowUserToDeleteRows = false,
|
||
|
|
AutoGenerateColumns = false,
|
||
|
|
MultiSelect = true,
|
||
|
|
SelectionMode = DataGridViewSelectionMode.FullRowSelect,
|
||
|
|
DataSource = _items,
|
||
|
|
};
|
||
|
|
|
||
|
|
_grid.Columns.Add(new DataGridViewCheckBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.Append),
|
||
|
|
HeaderText = "追加",
|
||
|
|
Width = 60,
|
||
|
|
});
|
||
|
|
_grid.Columns.Add(new DataGridViewTextBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.CategoryDisplay),
|
||
|
|
HeaderText = "提取类型",
|
||
|
|
Width = 180,
|
||
|
|
ReadOnly = true,
|
||
|
|
});
|
||
|
|
_grid.Columns.Add(new DataGridViewTextBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.OriginalText),
|
||
|
|
HeaderText = "原文本",
|
||
|
|
Width = 260,
|
||
|
|
ReadOnly = true,
|
||
|
|
});
|
||
|
|
_grid.Columns.Add(new DataGridViewTextBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.StatisticDisplay),
|
||
|
|
HeaderText = "统计值",
|
||
|
|
Width = 180,
|
||
|
|
ReadOnly = true,
|
||
|
|
});
|
||
|
|
_grid.Columns.Add(new DataGridViewTextBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.FirstDocumentPath),
|
||
|
|
HeaderText = "首次出现文档",
|
||
|
|
Width = 360,
|
||
|
|
ReadOnly = true,
|
||
|
|
});
|
||
|
|
_grid.Columns.Add(new DataGridViewTextBoxColumn
|
||
|
|
{
|
||
|
|
DataPropertyName = nameof(ExtractionCandidate.FirstOccurrenceOrder),
|
||
|
|
HeaderText = "首次出现顺序",
|
||
|
|
Width = 120,
|
||
|
|
ReadOnly = true,
|
||
|
|
});
|
||
|
|
|
||
|
|
var buttonPanel = new FlowLayoutPanel
|
||
|
|
{
|
||
|
|
Dock = DockStyle.Bottom,
|
||
|
|
Height = 44,
|
||
|
|
Padding = new Padding(8),
|
||
|
|
FlowDirection = FlowDirection.RightToLeft,
|
||
|
|
};
|
||
|
|
|
||
|
|
var confirmButton = new Button
|
||
|
|
{
|
||
|
|
Text = "追加选中项",
|
||
|
|
AutoSize = true,
|
||
|
|
};
|
||
|
|
confirmButton.Click += ConfirmButton_Click;
|
||
|
|
|
||
|
|
var cancelButton = new Button
|
||
|
|
{
|
||
|
|
Text = "取消",
|
||
|
|
AutoSize = true,
|
||
|
|
};
|
||
|
|
cancelButton.Click += delegate
|
||
|
|
{
|
||
|
|
DialogResult = DialogResult.Cancel;
|
||
|
|
Close();
|
||
|
|
};
|
||
|
|
|
||
|
|
var selectAllButton = new Button
|
||
|
|
{
|
||
|
|
Text = "全选",
|
||
|
|
AutoSize = true,
|
||
|
|
};
|
||
|
|
selectAllButton.Click += delegate
|
||
|
|
{
|
||
|
|
foreach (var item in _items)
|
||
|
|
{
|
||
|
|
item.Append = true;
|
||
|
|
}
|
||
|
|
|
||
|
|
_grid.Refresh();
|
||
|
|
};
|
||
|
|
|
||
|
|
var clearButton = new Button
|
||
|
|
{
|
||
|
|
Text = "全不选",
|
||
|
|
AutoSize = true,
|
||
|
|
};
|
||
|
|
clearButton.Click += delegate
|
||
|
|
{
|
||
|
|
foreach (var item in _items)
|
||
|
|
{
|
||
|
|
item.Append = false;
|
||
|
|
}
|
||
|
|
|
||
|
|
_grid.Refresh();
|
||
|
|
};
|
||
|
|
|
||
|
|
buttonPanel.Controls.Add(confirmButton);
|
||
|
|
buttonPanel.Controls.Add(cancelButton);
|
||
|
|
buttonPanel.Controls.Add(clearButton);
|
||
|
|
buttonPanel.Controls.Add(selectAllButton);
|
||
|
|
|
||
|
|
Controls.Add(_grid);
|
||
|
|
Controls.Add(buttonPanel);
|
||
|
|
}
|
||
|
|
|
||
|
|
public IList<ExtractionCandidate> SelectedCandidates
|
||
|
|
{
|
||
|
|
get { return _items.Where(item => item.Append).ToList(); }
|
||
|
|
}
|
||
|
|
|
||
|
|
private void ConfirmButton_Click(object sender, EventArgs e)
|
||
|
|
{
|
||
|
|
DialogResult = DialogResult.OK;
|
||
|
|
Close();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|