260511_01_ENH: 테스트 파일 실제로 돌려가며 오류 내용 수정
This commit is contained in:
@@ -51,29 +51,29 @@ namespace Keps.WinForms.Services
|
||||
/// <summary>
|
||||
/// 지정한 폴더의 Excel 파일(.xlsx/.xlsm)을 읽어 실데이터를 DB에 적재합니다.
|
||||
/// </summary>
|
||||
/// <param name="folderPath">Excel 파일들이 위치한 폴더 경로.</param>
|
||||
/// <param name="filePath">읽어들일 Excel 파일 경로.</param>
|
||||
/// <param name="electionYear">적재 대상 선거 연월(예: "201804").</param>
|
||||
/// <param name="mode">적재 모드(현재 Real만 지원).</param>
|
||||
/// <param name="progress">진행 상황을 보고받을 프로그레스 리스너.</param>
|
||||
/// <exception cref="InvalidOperationException">폴더가 없거나 지원 확장자가 없을 때 발생.</exception>
|
||||
/// <exception cref="InvalidOperationException">파일이 없거나 지원 확장자가 아닐 때 발생.</exception>
|
||||
/// <exception cref="NotSupportedException">미지원 모드일 때 발생.</exception>
|
||||
public void Import(string folderPath, string electionYear, ImportMode mode, IProgress<ImportProgress> progress)
|
||||
public void Import(string filePath, string electionYear, ImportMode mode, IProgress<ImportProgress> progress)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(folderPath) || !Directory.Exists(folderPath))
|
||||
if (string.IsNullOrWhiteSpace(filePath) || !File.Exists(filePath))
|
||||
{
|
||||
throw new InvalidOperationException("유효한 폴더를 선택하세요.");
|
||||
throw new InvalidOperationException("유효한 Excel 파일을 선택하세요.");
|
||||
}
|
||||
|
||||
List<string> files = [.. Directory.GetFiles(folderPath, "*.xlsx")];
|
||||
|
||||
if (files.Count == 0)
|
||||
string extension = Path.GetExtension(filePath);
|
||||
if (string.Equals(extension, ".xls", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
if (Directory.GetFiles(folderPath, "*.xls").Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException("현재 버전은 EPPlus 4.5.3.3 기준으로 작성되어 .xlsx/.xlsm만 지원합니다. 기존 .xls 파일은 .xlsx로 변환 후 다시 시도하세요.");
|
||||
}
|
||||
throw new InvalidOperationException("현재 버전은 EPPlus 4.5.3.3 기준으로 작성되어 .xlsx/.xlsm만 지원합니다. 기존 .xls 파일은 .xlsx로 변환 후 다시 시도하세요.");
|
||||
}
|
||||
|
||||
throw new InvalidOperationException("선택한 폴더에 지원되는 Excel 파일(.xlsx/.xlsm)이 없습니다.");
|
||||
if (!string.Equals(extension, ".xlsx", StringComparison.OrdinalIgnoreCase)
|
||||
&& !string.Equals(extension, ".xlsm", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException("지원되는 Excel 파일(.xlsx/.xlsm)을 선택하세요.");
|
||||
}
|
||||
|
||||
progress.Report(new ImportProgress(5, "기존 데이터 정리"));
|
||||
@@ -88,14 +88,13 @@ namespace Keps.WinForms.Services
|
||||
throw new NotSupportedException("시뮬레이션 엑셀 적재는 지원하지 않습니다.");
|
||||
}
|
||||
|
||||
string firstFile = files[0];
|
||||
progress.Report(new ImportProgress(10, Path.GetFileName(firstFile) + " 열기"));
|
||||
progress.Report(new ImportProgress(10, Path.GetFileName(filePath) + " 열기"));
|
||||
|
||||
List<string> candidateNames = new List<string>();
|
||||
|
||||
using (ExcelEpplusReader reader = new ExcelEpplusReader())
|
||||
{
|
||||
reader.Open(firstFile);
|
||||
reader.Open(filePath);
|
||||
List<ExcelSheet> sheets = new List<ExcelSheet>(reader.ReadSheets());
|
||||
|
||||
for (int sheetIndex = 0; sheetIndex < sheets.Count; sheetIndex++)
|
||||
@@ -153,14 +152,20 @@ namespace Keps.WinForms.Services
|
||||
int totalColumn = sheet.FindHeaderColumn("계", 128);
|
||||
if (voteColumn <= 0 || totalColumn <= 0 || totalColumn <= voteColumn)
|
||||
{
|
||||
return;
|
||||
throw new InvalidOperationException(
|
||||
string.Format(
|
||||
"Excel 시트 '{0}'에서 필수 헤더를 찾을 수 없습니다. '투표수'와 '계' 헤더를 확인하세요.",
|
||||
sheet.Name));
|
||||
}
|
||||
|
||||
int candidateStartColumn = voteColumn + 1;
|
||||
int candidateEndColumn = totalColumn - 1;
|
||||
if (candidateEndColumn < candidateStartColumn)
|
||||
{
|
||||
return;
|
||||
throw new InvalidOperationException(
|
||||
string.Format(
|
||||
"Excel 시트 '{0}'에서 후보자 득표 컬럼을 찾을 수 없습니다. '투표수'와 '계' 사이에 후보자 컬럼이 있는지 확인하세요.",
|
||||
sheet.Name));
|
||||
}
|
||||
|
||||
if (candidateNames.Count == 0)
|
||||
@@ -207,10 +212,11 @@ namespace Keps.WinForms.Services
|
||||
candidateNo++;
|
||||
}
|
||||
|
||||
string buildingName = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 2)).Replace("'", "'");
|
||||
string address1 = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 3)).Replace("'", "'");
|
||||
string note = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 4));
|
||||
string duplicateFlag = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 5));
|
||||
string buildingName = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 3)).Replace("'", "'");
|
||||
string address1 = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 4)).Replace("'", "'");
|
||||
string note = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 5));
|
||||
string duplicateFlag = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 6));
|
||||
string areaDetail = LegacyValueHelper.CleanString(sheet.GetValue(row, totalColumn + 8));
|
||||
string candJson = JsonHelper.Serialize(cand);
|
||||
string candRatioJson = JsonHelper.Serialize(candRatio);
|
||||
|
||||
@@ -244,7 +250,7 @@ namespace Keps.WinForms.Services
|
||||
command.Parameters.Add(new SqlParameter("@candRatio", SqlDbType.VarChar, -1) { Value = candRatioJson ?? string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@totalCandidateVoteCount", SqlDbType.Int) { Value = totalCandidateVotes });
|
||||
command.Parameters.Add(new SqlParameter("@duplicateFlag", SqlDbType.VarChar, 50) { Value = duplicateFlag ?? string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@areaDetail", SqlDbType.VarChar, 50) { Value = string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@areaDetail", SqlDbType.VarChar, 50) { Value = areaDetail ?? string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@buildingName", SqlDbType.VarChar, 500) { Value = buildingName ?? string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@address1", SqlDbType.VarChar, 500) { Value = address1 ?? string.Empty });
|
||||
command.Parameters.Add(new SqlParameter("@note", SqlDbType.VarChar, 200) { Value = note ?? string.Empty });
|
||||
@@ -315,7 +321,7 @@ namespace Keps.WinForms.Services
|
||||
|
||||
for (int i = 0; i < candidateNames.Count; i++)
|
||||
{
|
||||
using (SqlCommand insertCommand = new SqlCommand("INSERT INTO cand_name(ele_ym, cand_no, cand_name) VALUES(@eleYm, @candNo, @candName)", connection))
|
||||
using (SqlCommand insertCommand = new SqlCommand("INSERT INTO cand_name(ele_ym, title, cand_no, cand_name, 당이름) VALUES(@eleYm, @eleYm, @candNo, @candName, @candName)", connection))
|
||||
{
|
||||
insertCommand.Parameters.AddWithValue("@eleYm", electionYear);
|
||||
insertCommand.Parameters.AddWithValue("@candNo", (i + 1).ToString());
|
||||
|
||||
Reference in New Issue
Block a user