260511_01_ENH: 테스트 파일 실제로 돌려가며 오류 내용 수정

This commit is contained in:
2026-05-11 16:24:45 +09:00
parent b501332f06
commit c652d4ad43
7 changed files with 104 additions and 57 deletions

View File

@@ -8,13 +8,13 @@ namespace Keps.WinForms.Forms
private System.Windows.Forms.Label _lblElection;
private System.Windows.Forms.Label _lblFolder;
private System.Windows.Forms.ComboBox _cmbElection;
private System.Windows.Forms.TextBox _txtFolder;
private System.Windows.Forms.TextBox _txtFile;
private System.Windows.Forms.Button _btnFolder;
private System.Windows.Forms.Button _btnImportReal;
private System.Windows.Forms.ProgressBar _progress;
private System.Windows.Forms.Label _lblMain;
private System.Windows.Forms.Label _lblDetail;
private System.Windows.Forms.FolderBrowserDialog _folderDialog;
private System.Windows.Forms.OpenFileDialog _fileDialog;
protected override void Dispose(bool disposing)
{
@@ -35,14 +35,14 @@ namespace Keps.WinForms.Forms
this._lblElection = new System.Windows.Forms.Label();
this._cmbElection = new System.Windows.Forms.ComboBox();
this._lblFolder = new System.Windows.Forms.Label();
this._txtFolder = new System.Windows.Forms.TextBox();
this._txtFile = new System.Windows.Forms.TextBox();
this._btnFolder = new System.Windows.Forms.Button();
this._progress = new System.Windows.Forms.ProgressBar();
this._lblMain = new System.Windows.Forms.Label();
this._lblDetail = new System.Windows.Forms.Label();
this._buttonPanel = new System.Windows.Forms.FlowLayoutPanel();
this._btnImportReal = new System.Windows.Forms.Button();
this._folderDialog = new System.Windows.Forms.FolderBrowserDialog();
this._fileDialog = new System.Windows.Forms.OpenFileDialog();
this._layout.SuspendLayout();
this._buttonPanel.SuspendLayout();
this.SuspendLayout();
@@ -56,7 +56,7 @@ namespace Keps.WinForms.Forms
this._layout.Controls.Add(this._lblElection, 0, 0);
this._layout.Controls.Add(this._cmbElection, 1, 0);
this._layout.Controls.Add(this._lblFolder, 0, 1);
this._layout.Controls.Add(this._txtFolder, 1, 1);
this._layout.Controls.Add(this._txtFile, 1, 1);
this._layout.Controls.Add(this._btnFolder, 2, 1);
this._layout.Controls.Add(this._progress, 0, 2);
this._layout.Controls.Add(this._lblMain, 0, 3);
@@ -102,16 +102,16 @@ namespace Keps.WinForms.Forms
this._lblFolder.Name = "_lblFolder";
this._lblFolder.Size = new System.Drawing.Size(57, 12);
this._lblFolder.TabIndex = 2;
this._lblFolder.Text = "엑셀 폴더";
this._lblFolder.Text = "엑셀 파일";
//
// _txtFolder
// _txtFile
//
this._txtFolder.Dock = System.Windows.Forms.DockStyle.Fill;
this._txtFolder.Location = new System.Drawing.Point(135, 41);
this._txtFolder.Name = "_txtFolder";
this._txtFolder.ReadOnly = true;
this._txtFolder.Size = new System.Drawing.Size(670, 21);
this._txtFolder.TabIndex = 3;
this._txtFile.Dock = System.Windows.Forms.DockStyle.Fill;
this._txtFile.Location = new System.Drawing.Point(135, 41);
this._txtFile.Name = "_txtFile";
this._txtFile.ReadOnly = true;
this._txtFile.Size = new System.Drawing.Size(670, 21);
this._txtFile.TabIndex = 3;
//
// _btnFolder
//
@@ -120,10 +120,15 @@ namespace Keps.WinForms.Forms
this._btnFolder.Name = "_btnFolder";
this._btnFolder.Size = new System.Drawing.Size(100, 25);
this._btnFolder.TabIndex = 4;
this._btnFolder.Text = "폴더 선택";
this._btnFolder.Text = "파일 선택";
this._btnFolder.UseVisualStyleBackColor = true;
this._btnFolder.Click += new System.EventHandler(this.BtnFolder_Click);
//
// _fileDialog
//
this._fileDialog.Filter = "Excel 파일 (*.xlsx;*.xlsm)|*.xlsx;*.xlsm|모든 파일 (*.*)|*.*";
this._fileDialog.Title = "엑셀 파일 선택";
//
// _progress
//
this._layout.SetColumnSpan(this._progress, 3);

View File

@@ -55,20 +55,20 @@ namespace Keps.WinForms.Forms
private void BtnFolder_Click(object sender, EventArgs e)
{
// 초기 디렉터리는 _txtFolder의 값(폴더이거나 파일이면 그 폴더) 또는 _appBasePath
// 초기 디렉터리는 _txtFile의 값(폴더이거나 파일이면 그 폴더) 또는 _appBasePath
string initialDir = _appBasePath;
if (!string.IsNullOrWhiteSpace(_txtFolder.Text))
if (!string.IsNullOrWhiteSpace(_txtFile.Text))
{
try
{
if (Directory.Exists(_txtFolder.Text))
if (Directory.Exists(_txtFile.Text))
{
initialDir = _txtFolder.Text;
initialDir = _txtFile.Text;
}
else
{
var dir = Path.GetDirectoryName(_txtFolder.Text);
var dir = Path.GetDirectoryName(_txtFile.Text);
if (!string.IsNullOrWhiteSpace(dir) && Directory.Exists(dir))
initialDir = dir;
}
@@ -79,12 +79,12 @@ namespace Keps.WinForms.Forms
}
}
// FolderBrowserDialog는 SelectedPath로 초기 경로를 설정
_folderDialog.SelectedPath = initialDir;
_fileDialog.InitialDirectory = initialDir;
_fileDialog.FileName = string.Empty;
if (_folderDialog.ShowDialog(this) == DialogResult.OK)
if (_fileDialog.ShowDialog(this) == DialogResult.OK)
{
_txtFolder.Text = _folderDialog.SelectedPath;
_txtFile.Text = _fileDialog.FileName;
}
}
@@ -102,13 +102,13 @@ namespace Keps.WinForms.Forms
return;
}
if (string.IsNullOrWhiteSpace(_txtFolder.Text) || !Directory.Exists(_txtFolder.Text))
if (string.IsNullOrWhiteSpace(_txtFile.Text) || !File.Exists(_txtFile.Text))
{
MessageBox.Show(this, "엑셀 폴더를 선택하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
MessageBox.Show(this, "엑셀 파일을 선택하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string folderPath = _txtFolder.Text;
string filePath = _txtFile.Text;
string electionName = _cmbElection.SelectedItem.ToString();
ToggleState(false);
@@ -125,7 +125,7 @@ namespace Keps.WinForms.Forms
{
await Task.Run(() =>
{
_excelImportService.Import(folderPath, electionName, ImportMode.Real, progress);
_excelImportService.Import(filePath, electionName, ImportMode.Real, progress);
});
_lblMain.Text = "완료";

View File

@@ -117,7 +117,7 @@
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="_folderDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<metadata name="_fileDialog.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
</root>

View File

@@ -82,7 +82,8 @@ namespace Keps.WinForms.Forms
_numTotalSamples.Minimum = 1;
_numTotalSamples.Maximum = 5000;
_numTotalSamples.Value = 123;
_numTotalSamples.Value = 1;
_numTotalSamples.Text = string.Empty;
_numOffsetValue.Minimum = 0;
_numOffsetValue.Maximum = 100;
_preparedContext = null;
@@ -181,10 +182,11 @@ namespace Keps.WinForms.Forms
string election = _cmbElection.SelectedItem.ToString();
string area = _cmbArea.SelectedItem.ToString();
int clusterMax = Convert.ToInt32(_cmbClusterMax.SelectedItem);
int totalSamples = GetTotalSamples();
RealScenarioContext context = _samplingService.LoadRealScenario(election, area, clusterMax);
_preparedContext = context;
_autoRows = new BindingList<ClusterSummaryRow>(_samplingService.AllocateAutoSampleCounts(context.AutoRows, Convert.ToInt32(_numTotalSamples.Value)));
_autoRows = new BindingList<ClusterSummaryRow>(_samplingService.AllocateAutoSampleCounts(context.AutoRows, totalSamples));
_manualRows = new BindingList<ClusterSummaryRow>(context.ManualRows.Select(CloneRow).ToList());
for (int i = 0; i < _manualRows.Count && i < _autoRows.Count; i++)
{
@@ -265,7 +267,13 @@ namespace Keps.WinForms.Forms
if (_rdoAuto.Checked)
{
_autoRows = new BindingList<ClusterSummaryRow>(_samplingService.AllocateAutoSampleCounts(_preparedContext.AutoRows, Convert.ToInt32(_numTotalSamples.Value)));
int totalSamples;
if (!TryGetTotalSamples(out totalSamples))
{
return;
}
_autoRows = new BindingList<ClusterSummaryRow>(_samplingService.AllocateAutoSampleCounts(_preparedContext.AutoRows, totalSamples));
if (_manualRows == null || _manualRows.Count != _autoRows.Count)
{
@@ -391,9 +399,37 @@ namespace Keps.WinForms.Forms
MessageBox.Show(this, "군집수를 선택하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;
}
if (!TryGetTotalSamples(out _))
{
MessageBox.Show(this, "총 표본 수를 입력하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
_numTotalSamples.Focus();
return false;
}
return true;
}
private int GetTotalSamples()
{
int totalSamples;
if (!TryGetTotalSamples(out totalSamples))
{
throw new InvalidOperationException("총 표본 수를 입력하세요.");
}
return totalSamples;
}
private bool TryGetTotalSamples(out int totalSamples)
{
totalSamples = 0;
if (string.IsNullOrWhiteSpace(_numTotalSamples.Text))
{
return false;
}
totalSamples = Convert.ToInt32(_numTotalSamples.Value);
return totalSamples >= _numTotalSamples.Minimum && totalSamples <= _numTotalSamples.Maximum;
}
private List<ClusterSummaryRow> GetWorkingRows()
{
return (_rdoAuto.Checked ? _autoRows : _manualRows).Select(CloneRow).ToList();