first commit

This commit is contained in:
2026-03-20 08:52:16 +09:00
commit 8c0b02233e
41 changed files with 6021 additions and 0 deletions

View File

@@ -0,0 +1,152 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using System.Windows.Forms;
using Keps.WinForms.Models;
using Keps.WinForms.Services;
namespace Keps.WinForms.Forms
{
public sealed partial class DataInputForm : Form
{
private readonly string _appBasePath = Application.StartupPath;
private ExcelImportService _excelImportService;
public DataInputForm()
{
InitializeComponent();
}
public DataInputForm(ExcelImportService excelImportService)
: this()
{
SetServices(excelImportService);
}
public void SetServices(ExcelImportService excelImportService)
{
_excelImportService = excelImportService;
}
private void DataInputForm_Load(object sender, EventArgs e)
{
if (_excelImportService == null)
{
_lblMain.Text = "서비스 미연결";
_lblDetail.Text = "MainMdiForm.InitializeRuntime 호출 후 사용하세요.";
return;
}
List<string> elections = _excelImportService.LoadElectionYears();
_cmbElection.Items.Clear();
foreach (string election in elections)
{
_cmbElection.Items.Add(election);
}
if (_cmbElection.Items.Count > 0)
{
_cmbElection.SelectedIndex = 0;
}
}
private void BtnFolder_Click(object sender, EventArgs e)
{
// 초기 디렉터리는 _txtFolder의 값(폴더이거나 파일이면 그 폴더) 또는 _appBasePath
string initialDir = _appBasePath;
if (!string.IsNullOrWhiteSpace(_txtFolder.Text))
{
try
{
if (Directory.Exists(_txtFolder.Text))
{
initialDir = _txtFolder.Text;
}
else
{
var dir = Path.GetDirectoryName(_txtFolder.Text);
if (!string.IsNullOrWhiteSpace(dir) && Directory.Exists(dir))
initialDir = dir;
}
}
catch
{
initialDir = _appBasePath;
}
}
// FolderBrowserDialog는 SelectedPath로 초기 경로를 설정
_folderDialog.SelectedPath = initialDir;
if (_folderDialog.ShowDialog(this) == DialogResult.OK)
{
_txtFolder.Text = _folderDialog.SelectedPath;
}
}
private async void BtnImportReal_Click(object sender, EventArgs e)
{
if (_excelImportService == null)
{
MessageBox.Show(this, "ExcelImportService가 초기화되지 않았습니다.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (_cmbElection.SelectedItem == null)
{
MessageBox.Show(this, "선거년월을 선택하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
if (string.IsNullOrWhiteSpace(_txtFolder.Text) || !Directory.Exists(_txtFolder.Text))
{
MessageBox.Show(this, "엑셀 폴더를 선택하세요.", "확인", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
string folderPath = _txtFolder.Text;
string electionName = _cmbElection.SelectedItem.ToString();
ToggleState(false);
_progress.Value = 0;
_lblMain.Text = "엑셀자료 입력 시작 - 최종 투표구 추출용";
Progress<ImportProgress> progress = new Progress<ImportProgress>(p =>
{
_progress.Value = Math.Max(0, Math.Min(100, p.Percent));
_lblDetail.Text = p.Message;
});
try
{
await Task.Run(() =>
{
_excelImportService.Import(folderPath, electionName, ImportMode.Real, progress);
});
_lblMain.Text = "완료";
MessageBox.Show(this, "엑셀 기초자료 DB 적재와 군집 재구성이 완료되었습니다.", "완료", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception ex)
{
_lblMain.Text = "실패";
MessageBox.Show(this, ex.Message, "오류", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
ToggleState(true);
}
}
private void ToggleState(bool enabled)
{
_cmbElection.Enabled = enabled;
_btnFolder.Enabled = enabled;
_btnImportReal.Enabled = enabled;
}
}
}