diff --git a/Keps.WinForms/Forms/RealExtractionForm.cs b/Keps.WinForms/Forms/RealExtractionForm.cs index eaa06bc..86ec185 100644 --- a/Keps.WinForms/Forms/RealExtractionForm.cs +++ b/Keps.WinForms/Forms/RealExtractionForm.cs @@ -329,22 +329,20 @@ namespace Keps.WinForms.Forms if (targetRow != null) { int total = targetRow.PollingPlaceCount; - int sample = Math.Max(0, targetRow.SampleCount); - if (sample > 0) - { - int interval = total / sample; - int start = interval / 2; - int endPoint = start + (interval * (sample - 1)); - int x1 = total - endPoint; - int x2 = start - 1; - start = (int)Math.Round((x1 + x2) / 2m, 0, MidpointRounding.AwayFromZero); - maxRange = total - (interval * (sample - 1)) - start; + int sample = targetRow.SampleCount; + + int interval = total / sample; + int start = interval / 2; + int endPoint = start + (interval * (sample - 1)); + int x1 = total - endPoint; + int x2 = start - 1; + start = (int)Math.Round((x1 + x2) / 2m, 0, MidpointRounding.AwayFromZero); + maxRange = total - (interval * (sample - 1)) - start; - if (interval == 0) - { - maxRange = 0; - offsetEnabled = false; - } + if (interval == 0) + { + maxRange = 0; + offsetEnabled = false; } } diff --git a/Keps.WinForms/Services/LookupService.cs b/Keps.WinForms/Services/LookupService.cs index e36f55c..2220ff4 100644 --- a/Keps.WinForms/Services/LookupService.cs +++ b/Keps.WinForms/Services/LookupService.cs @@ -82,35 +82,21 @@ namespace Keps.WinForms.Services using (SqlConnection connection = _connectionFactory.Open()) using (SqlCommand command = new SqlCommand(LegacySqlCatalog.RealCandidateNames, connection)) { - int electionNo; - if (int.TryParse(electionName, out electionNo)) + command.Parameters.AddWithValue("@electionName", electionName); + + using (SqlDataReader reader = command.ExecuteReader()) { - command.Parameters.AddWithValue("@electionName", electionNo); - } - else - { - command.Parameters.AddWithValue("@electionName", electionName); - } - - try - { - using (SqlDataReader reader = command.ExecuteReader()) + while (reader.Read()) { - while (reader.Read()) + string candNo = Convert.ToString(reader["cand_no"]); + string candName = Convert.ToString(reader["cand_name"]); + result.Add(new CandidateOption { - string candNo = Convert.ToString(reader["cand_no"]); - string candName = Convert.ToString(reader["cand_name"]); - result.Add(new CandidateOption - { - Key = "cand_ratio_" + candNo, - DisplayName = candName + "(" + candNo + ")" - }); - } + Key = "cand_ratio_" + candNo, + DisplayName = candName + "(" + candNo + ")" + }); } } - catch - { - } } result.Add(new CandidateOption { Key = "투표인수", DisplayName = "투표인수" }); diff --git a/Keps.WinForms/Services/SamplingService.cs b/Keps.WinForms/Services/SamplingService.cs index 38e11f4..7f9ee26 100644 --- a/Keps.WinForms/Services/SamplingService.cs +++ b/Keps.WinForms/Services/SamplingService.cs @@ -179,7 +179,7 @@ namespace Keps.WinForms.Services string sortKey, string sortDisplayName, bool descending, - List allocationRows, + List workingRows, int signedOffset, string offsetDescription, bool isAutoAllocation) @@ -190,23 +190,23 @@ namespace Keps.WinForms.Services List populationRows = new List(); List extractedSourceRows = new List(); - foreach (ClusterSummaryRow allocation in allocationRows.OrderBy(x => x.ClusterNo)) + foreach (ClusterSummaryRow workingRow in workingRows.OrderBy(x => x.ClusterNo)) { - List clusterRows = allRows.Where(x => x.ClusterValue == allocation.ClusterNo).ToList(); + List clusterRows = allRows.Where(x => x.ClusterValue == workingRow.ClusterNo).ToList(); clusterRows = descending ? clusterRows.OrderByDescending(x => x.GetSortValue(sortKey)).ThenBy(x => x.EupMyeonDong).ThenBy(x => GetPollingPlaceSortValue(x.PollingPlaceNo)).ThenBy(x => x.PollingPlaceNo).ToList() : clusterRows.OrderBy(x => x.GetSortValue(sortKey)).ThenBy(x => x.EupMyeonDong).ThenBy(x => GetPollingPlaceSortValue(x.PollingPlaceNo)).ThenBy(x => x.PollingPlaceNo).ToList(); int interval; int startPosition; - List extractIds = SelectLegacyExtractIds(clusterRows.Count, allocation.SampleCount, signedOffset, out interval, out startPosition); + List extractIds = SelectLegacyExtractIds(clusterRows.Count, workingRow.SampleCount, signedOffset, out interval, out startPosition); HashSet selectedPositions = new HashSet(extractIds); for (int i = 0; i < clusterRows.Count; i++) { int originalOrder = i + 1; PollingPlaceRecord row = clusterRows[i]; - populationRows.Add(CreateExtractionRow(row, allocation.ClusterNo, originalOrder, originalOrder, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), selectedPositions.Contains(originalOrder), selectedPositions.Contains(originalOrder))); + populationRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, originalOrder, originalOrder, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), selectedPositions.Contains(originalOrder), selectedPositions.Contains(originalOrder))); } for (int i = 0; i < extractIds.Count; i++) @@ -219,7 +219,7 @@ namespace Keps.WinForms.Services PollingPlaceRecord row = clusterRows[extractId - 1]; extractedSourceRows.Add(row); - extractedRows.Add(CreateExtractionRow(row, allocation.ClusterNo, i + 1, extractId, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), true, true)); + extractedRows.Add(CreateExtractionRow(row, workingRow.ClusterNo, i + 1, extractId, interval, startPosition, offsetDescription, row.GetSortValue(sortKey), true, true)); } } @@ -235,9 +235,9 @@ namespace Keps.WinForms.Services ExtractedRows = extractedRows.OrderBy(x => x.ClusterNo).ThenBy(x => x.ClusterOrder).ToList(), PopulationRows = populationRows.OrderBy(x => x.ClusterNo).ThenBy(x => x.OriginalOrder).ToList(), AdjustmentRows = BuildAdjustmentRows(extractedRows), - VerificationRows = BuildVerificationRows(allRows, extractedSourceRows, allocationRows, candidateMeta), + VerificationRows = BuildVerificationRows(allRows, extractedSourceRows, workingRows, candidateMeta), ClusterMax = clusterMax, - TotalSampleCount = allocationRows.Sum(x => x.SampleCount), + TotalSampleCount = workingRows.Sum(x => x.SampleCount), IsAutoAllocation = isAutoAllocation, SortDisplayName = sortDisplayName, SortDescending = descending, @@ -308,15 +308,7 @@ namespace Keps.WinForms.Services using (SqlConnection connection = _connectionFactory.Open()) using (SqlCommand command = new SqlCommand(LegacySqlCatalog.RealCandidateNames, connection)) { - int electionNo; - if (int.TryParse(electionName, out electionNo)) - { - command.Parameters.AddWithValue("@electionName", electionNo); - } - else - { - command.Parameters.AddWithValue("@electionName", electionName); - } + command.Parameters.AddWithValue("@electionName", electionName); try {