검색결과 수량부분이 자세히 표시됨

오류 메세지 표현 방식 변경
This commit is contained in:
SeungHo Yang
2025-07-09 22:52:54 +09:00
parent 8b63566684
commit 12d6c2dbfb
5 changed files with 227 additions and 129 deletions

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// 모든 값을 지정하거나 아래와 같이 '*'를 사용하여 빌드 번호 및 수정 번호를
// 기본값으로 할 수 있습니다.
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.186")]
[assembly: AssemblyFileVersion("1.0.0.186")]
[assembly: AssemblyVersion("1.0.187.1")]
[assembly: AssemblyFileVersion("1.0.187.1")]

View File

@@ -375,10 +375,20 @@ namespace BokBonCheck
await WaitForPageChange(new WebDriverWait(_driver, TimeSpan.FromSeconds(15)));
// 검색 결과 수 추출
var resultCount = ExtractBookCount(_driver);
var resultCount = ExtractBookCount(_driver, searchTerm, out string ermsg);
if (resultCount == -1)
{
result.BookCount = 0;
result.IsSuccess = false;
result.ErrorMessage = ermsg;
}
else
{
result.BookCount = resultCount;
result.IsSuccess = true;
result.ErrorMessage = ermsg;
}
result.BookCount = resultCount;
result.IsSuccess = true;
}
catch (Exception ex)
{
@@ -386,36 +396,71 @@ namespace BokBonCheck
result.ErrorMessage = ex.Message;
result.BookCount = 0;
}
return result;
}
private int ExtractBookCount(IWebDriver driver)
private int ExtractBookCount(IWebDriver driver, string searchTerm, out string errmessage)
{
errmessage = string.Empty;
try
{
// div.search-result 내부의 span에서 '전체 N' 텍스트 추출
var resultDiv = driver.FindElement(By.CssSelector("div.search-result"));
var bodytext = resultDiv.Text;
if (bodytext.Contains("검색결과가 없습니다"))
{
errmessage = "검색결과없음";
return 0;
}
var searchkey = resultDiv.FindElement(By.XPath("//*[@id=\"sub\"]/section[3]/div/div/div/div/div[2]/div[1]/p/b"));
var searchtitle = searchkey.Text;
if (searchTerm.Contains(searchtitle) == false)
{
errmessage = $"검색어불일치({searchtitle}/{searchTerm})";
return -1;
}
var span = resultDiv.FindElement(By.XPath(".//span[contains(text(),'전체')]"));
string text = span.Text; // 예: "전체 5 "
var match = System.Text.RegularExpressions.Regex.Match(text, @"전체\s*(\d+)");
if (match.Success)
{
return int.Parse(match.Groups[1].Value);
if(int.TryParse(match.Groups[1].Value,out int vqty)==false)
{
errmessage = $"수량값오류({match.Groups[1].Value})";
return -1;
}
else
{
searchTerm = string.Empty;
return vqty;
}
}
return 0;
else
{
errmessage = "수량항목없음";
return -1;
}
}
catch
catch (Exception ex)
{
return 0;
errmessage = ex.Message;
return -1;
}
}
// 페이지 변경을 감지하는 메서드
public async Task WaitForPageChange(WebDriverWait wait)
{
try
{
await Task.Delay(500);
// 방법 4: 페이지 로딩 상태 확인
wait.Until(d =>
{
@@ -426,10 +471,9 @@ namespace BokBonCheck
// 방법 5: 특정 텍스트가 페이지에 나타날 때까지 대기
wait.Until(d =>
{
var elm = d.FindElement(By.TagName("body"));
if (elm == null) return false;
var pageText = elm.Text;
return pageText.Contains("전체") || pageText.Contains("건") || pageText.Contains("검색결과");
var pageText = d.FindElement(By.ClassName("search-result")).Text;
if (pageText.Contains("검색결과가 없습니다")) return true;
return pageText.Contains("에 대하여") && pageText.Contains("검색되었습니다");
});
}

View File

@@ -85,6 +85,10 @@ namespace UniMarc.마크
cc.tb_SearchTarget.Text = lib_name;
cc.SearcherNo = searcher;
cc.groupBox1.Enabled = int.TryParse(searcher, out int vno) && vno > 0;
cc.chkRetryErrData.Enabled = cc.groupBox1.Enabled;
if (lib_name.Contains("Kolasys.net"))
{
Check_Copy_Login ccl = new Check_Copy_Login(this);

View File

@@ -30,6 +30,11 @@
{
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle();
this.panel1 = new System.Windows.Forms.Panel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radTargetErr = new System.Windows.Forms.RadioButton();
this.radTargetEmpty = new System.Windows.Forms.RadioButton();
this.radTargetErrEmpty = new System.Windows.Forms.RadioButton();
this.radTargetAll = new System.Windows.Forms.RadioButton();
this.rb_isNumber = new System.Windows.Forms.RadioButton();
this.rb_isHave = new System.Windows.Forms.RadioButton();
this.btn_SearchList = new System.Windows.Forms.Button();
@@ -45,6 +50,10 @@
this.lbl_PW = new System.Windows.Forms.Label();
this.lbl_ID = new System.Windows.Forms.Label();
this.dataGridView1 = new System.Windows.Forms.DataGridView();
this.book_name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.book_comp = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dvc_remark = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.btn_ApplyFilter = new System.Windows.Forms.Button();
this.panel3 = new System.Windows.Forms.Panel();
this.panel6 = new System.Windows.Forms.Panel();
@@ -57,17 +66,10 @@
this.btn_OpenMemo = new System.Windows.Forms.Button();
this.chk_spChar = new System.Windows.Forms.CheckBox();
this.panel5 = new System.Windows.Forms.Panel();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radTargetAll = new System.Windows.Forms.RadioButton();
this.radTargetErrEmpty = new System.Windows.Forms.RadioButton();
this.radTargetEmpty = new System.Windows.Forms.RadioButton();
this.radTargetErr = new System.Windows.Forms.RadioButton();
this.book_name = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.book_comp = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.Count = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.dvc_remark = new System.Windows.Forms.DataGridViewTextBoxColumn();
this.webBrowser1 = new System.Windows.Forms.WebBrowser();
this.chkRetryErrData = new System.Windows.Forms.CheckBox();
this.panel1.SuspendLayout();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.SearchCount)).BeginInit();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
@@ -76,12 +78,12 @@
this.statusStrip1.SuspendLayout();
this.panel4.SuspendLayout();
this.panel5.SuspendLayout();
this.groupBox1.SuspendLayout();
this.SuspendLayout();
//
// panel1
//
this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.panel1.Controls.Add(this.chkRetryErrData);
this.panel1.Controls.Add(this.groupBox1);
this.panel1.Controls.Add(this.rb_isNumber);
this.panel1.Controls.Add(this.rb_isHave);
@@ -91,9 +93,64 @@
this.panel1.Dock = System.Windows.Forms.DockStyle.Top;
this.panel1.Location = new System.Drawing.Point(0, 34);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(629, 83);
this.panel1.Size = new System.Drawing.Size(629, 106);
this.panel1.TabIndex = 0;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radTargetErr);
this.groupBox1.Controls.Add(this.radTargetEmpty);
this.groupBox1.Controls.Add(this.radTargetErrEmpty);
this.groupBox1.Controls.Add(this.radTargetAll);
this.groupBox1.Location = new System.Drawing.Point(318, 34);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(304, 39);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "검색대상";
//
// radTargetErr
//
this.radTargetErr.AutoSize = true;
this.radTargetErr.Location = new System.Drawing.Point(197, 16);
this.radTargetErr.Name = "radTargetErr";
this.radTargetErr.Size = new System.Drawing.Size(47, 16);
this.radTargetErr.TabIndex = 9;
this.radTargetErr.Text = "오류";
this.radTargetErr.UseVisualStyleBackColor = true;
//
// radTargetEmpty
//
this.radTargetEmpty.AutoSize = true;
this.radTargetEmpty.Location = new System.Drawing.Point(144, 16);
this.radTargetEmpty.Name = "radTargetEmpty";
this.radTargetEmpty.Size = new System.Drawing.Size(47, 16);
this.radTargetEmpty.TabIndex = 8;
this.radTargetEmpty.Text = "없음";
this.radTargetEmpty.UseVisualStyleBackColor = true;
//
// radTargetErrEmpty
//
this.radTargetErrEmpty.AutoSize = true;
this.radTargetErrEmpty.Location = new System.Drawing.Point(61, 17);
this.radTargetErrEmpty.Name = "radTargetErrEmpty";
this.radTargetErrEmpty.Size = new System.Drawing.Size(77, 16);
this.radTargetErrEmpty.TabIndex = 7;
this.radTargetErrEmpty.Text = "오류+없음";
this.radTargetErrEmpty.UseVisualStyleBackColor = true;
//
// radTargetAll
//
this.radTargetAll.AutoSize = true;
this.radTargetAll.Checked = true;
this.radTargetAll.Location = new System.Drawing.Point(8, 16);
this.radTargetAll.Name = "radTargetAll";
this.radTargetAll.Size = new System.Drawing.Size(47, 16);
this.radTargetAll.TabIndex = 6;
this.radTargetAll.TabStop = true;
this.radTargetAll.Text = "전체";
this.radTargetAll.UseVisualStyleBackColor = true;
//
// rb_isNumber
//
this.rb_isNumber.AutoSize = true;
@@ -121,7 +178,7 @@
//
this.btn_SearchList.Location = new System.Drawing.Point(4, 4);
this.btn_SearchList.Name = "btn_SearchList";
this.btn_SearchList.Size = new System.Drawing.Size(305, 69);
this.btn_SearchList.Size = new System.Drawing.Size(305, 93);
this.btn_SearchList.TabIndex = 3;
this.btn_SearchList.Text = "목록 검색";
this.btn_SearchList.UseVisualStyleBackColor = true;
@@ -267,11 +324,38 @@
this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1";
this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.Size = new System.Drawing.Size(629, 565);
this.dataGridView1.Size = new System.Drawing.Size(629, 542);
this.dataGridView1.TabIndex = 1;
this.dataGridView1.RowPostPaint += new System.Windows.Forms.DataGridViewRowPostPaintEventHandler(this.dataGridView1_RowPostPaint);
this.dataGridView1.KeyDown += new System.Windows.Forms.KeyEventHandler(this.dataGridView1_KeyDown);
//
// book_name
//
this.book_name.HeaderText = "도서명(총서명)";
this.book_name.Name = "book_name";
this.book_name.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.book_name.Width = 300;
//
// book_comp
//
this.book_comp.HeaderText = "출판사";
this.book_comp.Name = "book_comp";
this.book_comp.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.book_comp.Width = 120;
//
// Count
//
this.Count.HeaderText = "검색 수";
this.Count.Name = "Count";
this.Count.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Count.Width = 50;
//
// dvc_remark
//
this.dvc_remark.HeaderText = "비고";
this.dvc_remark.Name = "dvc_remark";
this.dvc_remark.Width = 110;
//
// btn_ApplyFilter
//
this.btn_ApplyFilter.Location = new System.Drawing.Point(317, 4);
@@ -299,16 +383,16 @@
this.panel6.Controls.Add(this.dataGridView1);
this.panel6.Controls.Add(this.statusStrip1);
this.panel6.Dock = System.Windows.Forms.DockStyle.Fill;
this.panel6.Location = new System.Drawing.Point(0, 151);
this.panel6.Location = new System.Drawing.Point(0, 174);
this.panel6.Name = "panel6";
this.panel6.Size = new System.Drawing.Size(629, 587);
this.panel6.Size = new System.Drawing.Size(629, 564);
this.panel6.TabIndex = 3;
//
// statusStrip1
//
this.statusStrip1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.lblStatus});
this.statusStrip1.Location = new System.Drawing.Point(0, 565);
this.statusStrip1.Location = new System.Drawing.Point(0, 542);
this.statusStrip1.Name = "statusStrip1";
this.statusStrip1.Size = new System.Drawing.Size(629, 22);
this.statusStrip1.TabIndex = 2;
@@ -330,7 +414,7 @@
this.panel4.Controls.Add(this.btn_ApplyFilter);
this.panel4.Controls.Add(this.chk_spChar);
this.panel4.Dock = System.Windows.Forms.DockStyle.Top;
this.panel4.Location = new System.Drawing.Point(0, 117);
this.panel4.Location = new System.Drawing.Point(0, 140);
this.panel4.Name = "panel4";
this.panel4.Size = new System.Drawing.Size(629, 34);
this.panel4.TabIndex = 2;
@@ -394,87 +478,6 @@
this.panel5.Size = new System.Drawing.Size(662, 738);
this.panel5.TabIndex = 4;
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radTargetErr);
this.groupBox1.Controls.Add(this.radTargetEmpty);
this.groupBox1.Controls.Add(this.radTargetErrEmpty);
this.groupBox1.Controls.Add(this.radTargetAll);
this.groupBox1.Location = new System.Drawing.Point(318, 34);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(305, 39);
this.groupBox1.TabIndex = 6;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "검색대상";
//
// radTargetAll
//
this.radTargetAll.AutoSize = true;
this.radTargetAll.Checked = true;
this.radTargetAll.Location = new System.Drawing.Point(8, 16);
this.radTargetAll.Name = "radTargetAll";
this.radTargetAll.Size = new System.Drawing.Size(47, 16);
this.radTargetAll.TabIndex = 6;
this.radTargetAll.Text = "전체";
this.radTargetAll.UseVisualStyleBackColor = true;
//
// radTargetErrEmpty
//
this.radTargetErrEmpty.AutoSize = true;
this.radTargetErrEmpty.Location = new System.Drawing.Point(61, 17);
this.radTargetErrEmpty.Name = "radTargetErrEmpty";
this.radTargetErrEmpty.Size = new System.Drawing.Size(77, 16);
this.radTargetErrEmpty.TabIndex = 7;
this.radTargetErrEmpty.Text = "오류+없음";
this.radTargetErrEmpty.UseVisualStyleBackColor = true;
//
// radTargetEmpty
//
this.radTargetEmpty.AutoSize = true;
this.radTargetEmpty.Location = new System.Drawing.Point(144, 16);
this.radTargetEmpty.Name = "radTargetEmpty";
this.radTargetEmpty.Size = new System.Drawing.Size(47, 16);
this.radTargetEmpty.TabIndex = 8;
this.radTargetEmpty.Text = "없음";
this.radTargetEmpty.UseVisualStyleBackColor = true;
//
// radTargetErr
//
this.radTargetErr.AutoSize = true;
this.radTargetErr.Location = new System.Drawing.Point(197, 16);
this.radTargetErr.Name = "radTargetErr";
this.radTargetErr.Size = new System.Drawing.Size(47, 16);
this.radTargetErr.TabIndex = 9;
this.radTargetErr.Text = "오류";
this.radTargetErr.UseVisualStyleBackColor = true;
//
// book_name
//
this.book_name.HeaderText = "도서명(총서명)";
this.book_name.Name = "book_name";
this.book_name.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.book_name.Width = 300;
//
// book_comp
//
this.book_comp.HeaderText = "출판사";
this.book_comp.Name = "book_comp";
this.book_comp.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.book_comp.Width = 120;
//
// Count
//
this.Count.HeaderText = "검색 수";
this.Count.Name = "Count";
this.Count.SortMode = System.Windows.Forms.DataGridViewColumnSortMode.NotSortable;
this.Count.Width = 50;
//
// dvc_remark
//
this.dvc_remark.HeaderText = "비고";
this.dvc_remark.Name = "dvc_remark";
this.dvc_remark.Width = 110;
//
// webBrowser1
//
this.webBrowser1.Dock = System.Windows.Forms.DockStyle.Fill;
@@ -485,6 +488,18 @@
this.webBrowser1.Size = new System.Drawing.Size(662, 738);
this.webBrowser1.TabIndex = 2;
//
// chkRetryErrData
//
this.chkRetryErrData.AutoSize = true;
this.chkRetryErrData.Checked = true;
this.chkRetryErrData.CheckState = System.Windows.Forms.CheckState.Checked;
this.chkRetryErrData.Location = new System.Drawing.Point(319, 81);
this.chkRetryErrData.Name = "chkRetryErrData";
this.chkRetryErrData.Size = new System.Drawing.Size(188, 16);
this.chkRetryErrData.TabIndex = 7;
this.chkRetryErrData.Text = "검색 후 오류 데이터 추가 검색";
this.chkRetryErrData.UseVisualStyleBackColor = true;
//
// Check_copy
//
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
@@ -498,6 +513,8 @@
this.Load += new System.EventHandler(this.Check_copy_Load);
this.panel1.ResumeLayout(false);
this.panel1.PerformLayout();
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.SearchCount)).EndInit();
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
@@ -510,8 +527,6 @@
this.panel4.ResumeLayout(false);
this.panel4.PerformLayout();
this.panel5.ResumeLayout(false);
this.groupBox1.ResumeLayout(false);
this.groupBox1.PerformLayout();
this.ResumeLayout(false);
}
@@ -547,7 +562,6 @@
private System.Windows.Forms.WebBrowser webBrowser1;
private System.Windows.Forms.StatusStrip statusStrip1;
private System.Windows.Forms.ToolStripLabel lblStatus;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radTargetAll;
private System.Windows.Forms.RadioButton radTargetErr;
private System.Windows.Forms.RadioButton radTargetEmpty;
@@ -556,5 +570,7 @@
private System.Windows.Forms.DataGridViewTextBoxColumn book_comp;
private System.Windows.Forms.DataGridViewTextBoxColumn Count;
private System.Windows.Forms.DataGridViewTextBoxColumn dvc_remark;
public System.Windows.Forms.CheckBox chkRetryErrData;
public System.Windows.Forms.GroupBox groupBox1;
}
}

View File

@@ -305,11 +305,25 @@ namespace WindowsFormsApp1.Mac
return;
}
var intSearchCnt = 0;
this._isSearching = true;
btn_Start.Enabled = false;
btn_Stop.Enabled = false;
searcher.StartDriver();
byte searchopt = 0; //전체검색
if (radTargetEmpty.Checked) searchopt = 1;
else if (radTargetErr.Checked) searchopt = 2;
else if (radTargetErrEmpty.Checked) searchopt = 3;
bool retry = false;
var cnt_totalcnt = 0;
int cnt_skip = 0;
int cnt_ok = 0;
int cnt_ng = 0;
int cnt_er = 0;
RetrySearch:
foreach (DataGridViewRow drow in this.dataGridView1.Rows)
{
if (this._isSearching == false)
@@ -323,6 +337,7 @@ namespace WindowsFormsApp1.Mac
var bookName = drow.Cells["book_name"].Value?.ToString() ?? string.Empty;
if (bookName.isEmpty())
{
cnt_skip += 1;
drow.Cells["dvc_remark"].Value = "No Title";
drow.DefaultCellStyle.BackColor = Color.HotPink;
drow.DefaultCellStyle.ForeColor = Color.Blue;
@@ -334,49 +349,68 @@ namespace WindowsFormsApp1.Mac
if (radTargetErr.Checked) //오류데이터만 처리
{
if (cntValue.StartsWith("err") == false)
if ( cntValue.Equals("-1")==false)
continue;
}
else if (radTargetEmpty.Checked) //빈데이터만 처리
{
if (int.TryParse(cntValue,out int cntvalue) && cntvalue > 0)
if (int.TryParse(cntValue, out int cntvalue) && cntvalue > 0)
continue;
}
else if (radTargetErrEmpty.Checked) //오류+빈데이터처리
{
if (cntValue.StartsWith("err") == false && int.TryParse(cntValue, out int cntvalue) && cntvalue > 0)
if (cntValue.Equals("-1") == false && int.TryParse(cntValue, out int cntvalue) && cntvalue > 0)
continue;
}
intSearchCnt += 1;
var rlt = await searcher.SearchAsync(bookName);
cnt_totalcnt += 1;
var rlt = await searcher.SearchAsync(bookName);
if (rlt.IsSuccess)
{
drow.Cells["dvc_remark"].Value = rlt.ErrorMessage;
drow.Cells["Count"].Value = $"{rlt.BookCount}";
if (rlt.BookCount == 0)
{
drow.Cells["dvc_remark"].Value = "No Data";
cnt_ng += 1;
drow.DefaultCellStyle.BackColor = Color.LightGray;
drow.DefaultCellStyle.ForeColor = Color.Red;
}
else
{
drow.Cells["dvc_remark"].Value = "";
cnt_ok += 1;
drow.DefaultCellStyle.BackColor = Color.Yellow;
drow.DefaultCellStyle.ForeColor = Color.Blue;
}
}
else
{
drow.Cells["dvc_remark"].Value = "Error";
cnt_er += 1;
drow.Cells["dvc_remark"].Value = $"Error|{rlt.ErrorMessage}";
drow.DefaultCellStyle.BackColor = Color.HotPink;
drow.DefaultCellStyle.ForeColor = Color.Blue;
}
}
searcher.StopDriver();
UTIL.MsgI($"검색 완료({intSearchCnt})건");
if (retry == false && chkRetryErrData.Checked)
{
retry = true;
radTargetErr.Checked = true;
goto RetrySearch;
}
else
{
searcher.StopDriver();
UTIL.MsgI($"검색 완료\n전체:{cnt_totalcnt}건/오류:{cnt_er}/성공:{cnt_ok}/없음:{cnt_ng}");
//재시도한경우라면 원복해준다
if(retry)
{
if (searchopt == 1) radTargetEmpty.Checked = true;
else if (searchopt == 2) radTargetErr.Checked = true;
else if (searchopt == 3) radTargetErrEmpty.Checked = true;
else radTargetAll.Checked = true;
}
}
}
catch (Exception ex)
{