알라딘 API 응답 처리 구조화 및 URL 브라우저 열기 개선
- AladinBookData 클래스 추가하여 API 응답 데이터 구조화 - ToString() 메서드 오버라이드로 파이프 구분자 형식 출력 지원 - Aladin_struct() 메서드 추가: List<AladinBookData> 반환 - 기존 Aladin() 메서드는 호환성 유지를 위해 보존 - URL 링크 클릭 시 탐색기 대신 기본 웹 브라우저로 열리도록 수정 (UseShellExecute = true) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -11,6 +11,8 @@ using System.Threading;
|
||||
using System.Windows.Forms;
|
||||
using WindowsFormsApp1;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Diagnostics.Eventing.Reader;
|
||||
using Org.BouncyCastle.Pkcs;
|
||||
|
||||
namespace ISBN_Check_test
|
||||
{
|
||||
@@ -25,8 +27,15 @@ namespace ISBN_Check_test
|
||||
}
|
||||
private void Form1_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.Show();
|
||||
Application.DoEvents();
|
||||
string[] api_list = { "다음", "네이버", "알라딘" };
|
||||
cb_api.Items.AddRange(api_list);
|
||||
cb_api.SelectedIndex = 2;
|
||||
Application.DoEvents();
|
||||
cb_filter_SelectedIndexChanged(null, null);
|
||||
Application.DoEvents();
|
||||
|
||||
}
|
||||
private void button2_Click(object sender, EventArgs e)
|
||||
{
|
||||
@@ -45,8 +54,16 @@ namespace ISBN_Check_test
|
||||
if (cb_api.SelectedIndex == -1) { MessageBox.Show("조건이 선택되지 않았습니다."); return; }
|
||||
if (cb_filter.SelectedIndex == -1) { MessageBox.Show("조건이 선택되지 않았습니다."); return; }
|
||||
|
||||
this.dataGridView1.AutoResizeColumn(3);
|
||||
this.Refresh();
|
||||
|
||||
Stopwatch stopwatch = new Stopwatch();
|
||||
stopwatch.Start();
|
||||
if (int.TryParse(tbDelay.Text, out int delayms) == false)
|
||||
{
|
||||
MessageBox.Show("지연시간 입력 오류");
|
||||
return;
|
||||
}
|
||||
|
||||
var sistr = start_idx.Text.Trim();
|
||||
var eistr = end_idx.Text.Trim();
|
||||
@@ -69,7 +86,7 @@ namespace ISBN_Check_test
|
||||
|
||||
ei = ei - 1;
|
||||
si = si - 1;
|
||||
if(si < 0 || ei <0)
|
||||
if (si < 0 || ei < 0)
|
||||
{
|
||||
MessageBox.Show("시작,종료번호를 확인하세요");
|
||||
return;
|
||||
@@ -97,7 +114,7 @@ namespace ISBN_Check_test
|
||||
Naver_API(dataGridView1, si, ei);
|
||||
break;
|
||||
case 2:
|
||||
Aladin_API(dataGridView1, si, ei);
|
||||
Aladin_API(dataGridView1, si, ei, delayms);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -119,7 +136,7 @@ namespace ISBN_Check_test
|
||||
/// 알라딘 API
|
||||
/// </summary>
|
||||
/// <param name="gridview"></param>
|
||||
private void Aladin_API(DataGridView gridview, int start, int end)
|
||||
private void Aladin_API(DataGridView gridview, int start, int end, int delayms)
|
||||
{
|
||||
// 도서명 / 저자 / 출판사 / isbn / 정가
|
||||
// 발행일 / 도서분류 / 재고
|
||||
@@ -152,25 +169,32 @@ namespace ISBN_Check_test
|
||||
break;
|
||||
}
|
||||
// string query = dataGridView1.Rows[a].Cells["isbn"].Value?.ToString() ?? string.Empty;
|
||||
string query = Set_query(type, a ); //a=는줄번호이고 idx는 -1 해야함
|
||||
string query = Set_query(type, a); //a=는줄번호이고 idx는 -1 해야함
|
||||
if (gridview.Rows[a].DefaultCellStyle.BackColor == Color.Yellow)
|
||||
continue;
|
||||
else if (gridview.Rows[a ].DefaultCellStyle.BackColor == Color.LightGray)
|
||||
gridview.Rows[a ].DefaultCellStyle.BackColor = Color.Empty;
|
||||
else if (gridview.Rows[a].DefaultCellStyle.BackColor == Color.LightGray)
|
||||
gridview.Rows[a].DefaultCellStyle.BackColor = Color.Empty;
|
||||
|
||||
// string aladin = api.Aladin(query, "ISBN13", param);
|
||||
var aladin = api.Aladin(query, type, param);
|
||||
insert_By_Aladin(aladin, a);
|
||||
try
|
||||
{
|
||||
var sb = new StringBuilder();
|
||||
foreach(var item in aladin)
|
||||
{
|
||||
sb.AppendLine(string.Join("|", item));
|
||||
}
|
||||
richTextBox1.Text = sb.ToString();
|
||||
}
|
||||
catch { }
|
||||
//var aladin = api.Aladin(query, type, param);
|
||||
var aladin_struct = api.Aladin_struct(query, type, out string xmlString);
|
||||
insert_By_Aladin(aladin_struct, a, xmlString);
|
||||
if (aladin_struct.Any())
|
||||
richTextBox1.Text = aladin_struct.First().ToString();
|
||||
else
|
||||
richTextBox1.Text = "No Data";
|
||||
|
||||
System.Threading.Thread.Sleep(delayms);
|
||||
//try
|
||||
//{
|
||||
// var sb = new StringBuilder();
|
||||
// foreach (var item in aladin)
|
||||
// {
|
||||
// sb.AppendLine(string.Join("|", item));
|
||||
// }
|
||||
// richTextBox1.Text = aladin_struct.ToString();// sb.ToString();
|
||||
//}
|
||||
//catch { }
|
||||
}
|
||||
}
|
||||
string Set_query(string type, int idx)
|
||||
@@ -314,13 +338,60 @@ namespace ISBN_Check_test
|
||||
{
|
||||
progressBar1.PerformStep();
|
||||
}
|
||||
void insert_By_Aladin(string[] insert, int row)
|
||||
|
||||
void insert_By_Aladin(List<AladinBookData> insert, int row, string xmlString)
|
||||
{
|
||||
if (row >0)
|
||||
if (row > 0)
|
||||
{
|
||||
dataGridView1.Rows[row - 1].Selected = false;
|
||||
}
|
||||
dataGridView1.Rows[row ].Selected = true;
|
||||
dataGridView1.Rows[row].Selected = true;
|
||||
|
||||
//데이터가 없다면 처리하지 않는다.
|
||||
if (insert.Any() == false)
|
||||
{
|
||||
dataGridView1.Rows[row].Cells["count"].Value = "0";
|
||||
dataGridView1.Rows[row].Cells["dvc_remark"].Value = $"No Data\n{xmlString}";
|
||||
return;
|
||||
}
|
||||
|
||||
var item = insert.First();
|
||||
|
||||
// pubDate형 보기편하게 DateTime형으로 재정리
|
||||
string pubdate = item.PubDate;
|
||||
try
|
||||
{
|
||||
//pubdate = item.PubDate;
|
||||
pubdate = String.Format("{0:yyyy/MM/dd}",
|
||||
DateTime.Parse(pubdate.Remove(pubdate.IndexOf(" G"))));
|
||||
}
|
||||
catch (Exception ex) { MessageBox.Show(item.ToString()); }
|
||||
|
||||
//카테고리명 정리
|
||||
item.CategoryName = Aladin_CategorySort(item.CategoryName);
|
||||
//for (int a = 0; a < insert.Length; a++)
|
||||
//{
|
||||
// if (a % 8 == 6) { insert[a] = Aladin_CategorySort(insert[a]); }
|
||||
//}
|
||||
|
||||
dataGridView1.Rows[row].Cells["Column1"].Value += item.ToString();// string.Join("|", insert) + "|";
|
||||
if (item.Description.StartsWith("<")) item.Description = item.Description.Substring(item.Description.IndexOf(">")+1);
|
||||
dataGridView1.Rows[row].Cells["dvc_remark"].Value = item.Description;// $"{insert.Count}건";
|
||||
dataGridView1.Rows[row].Cells["dvc_link"].Value = $"{item.Link}";
|
||||
dataGridView1.Rows[row].Cells["count"].Value = $"{insert.Count}";
|
||||
dataGridView1.Rows[row].DefaultCellStyle.BackColor = Color.LightGray;
|
||||
if (cb_filter.SelectedItem.ToString() == "별치조사")
|
||||
input_api_aladin(item, row, pubdate);
|
||||
|
||||
input_api(item, row, pubdate);
|
||||
}
|
||||
void insert_By_Aladin(string[] insert, int row)
|
||||
{
|
||||
if (row > 0)
|
||||
{
|
||||
dataGridView1.Rows[row - 1].Selected = false;
|
||||
}
|
||||
dataGridView1.Rows[row].Selected = true;
|
||||
|
||||
|
||||
if (insert.Any() == false) { return; }
|
||||
@@ -332,7 +403,7 @@ namespace ISBN_Check_test
|
||||
newstring = String.Format("{0:yyyy/MM/dd}",
|
||||
DateTime.Parse(insert[5].Remove(insert[5].IndexOf(" G"))));
|
||||
}
|
||||
catch (Exception ex) { MessageBox.Show(string.Join("|",insert)); }
|
||||
catch (Exception ex) { MessageBox.Show(string.Join("|", insert)); }
|
||||
|
||||
for (int a = 0; a < insert.Length; a++)
|
||||
{
|
||||
@@ -357,6 +428,17 @@ namespace ISBN_Check_test
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
void input_api_aladin(AladinBookData data, int row, string date)
|
||||
{
|
||||
dataGridView1.Rows[row].Cells["book_name"].Value = data.Title;
|
||||
dataGridView1.Rows[row].Cells["author"].Value = data.Author;
|
||||
dataGridView1.Rows[row].Cells["book_comp"].Value = data.Publisher;
|
||||
dataGridView1.Rows[row].Cells["price2"].Value = data.PriceStandard;
|
||||
dataGridView1.Rows[row].Cells["pubDate"].Value = date;
|
||||
dataGridView1.Rows[row].Cells["category"].Value = data.CategoryName;
|
||||
}
|
||||
|
||||
void input_api_aladin(string[] data, int row, string date)
|
||||
{
|
||||
dataGridView1.Rows[row].Cells["book_name"].Value = data[0];
|
||||
@@ -368,7 +450,7 @@ namespace ISBN_Check_test
|
||||
}
|
||||
void insert_By_Naver(string value, int row)
|
||||
{
|
||||
if (row > 0) { dataGridView1.Rows[row -1].Selected = false; }
|
||||
if (row > 0) { dataGridView1.Rows[row - 1].Selected = false; }
|
||||
dataGridView1.Rows[row].Selected = true;
|
||||
|
||||
if (value == "") return;
|
||||
@@ -479,6 +561,46 @@ namespace ISBN_Check_test
|
||||
|
||||
input_api(grid, row, newstring);
|
||||
}
|
||||
|
||||
void input_api(AladinBookData value, int idx, string date)
|
||||
{
|
||||
|
||||
//string[] param = { "title", "authors", "publisher", "isbn", "price",
|
||||
// "datetime", "status" };
|
||||
//string[] param = { "title", "author", "publisher", "isbn13", "priceStandard",
|
||||
// "pubDate", "categoryName", "stockStatus", };
|
||||
|
||||
bool[] chk = { false, false, false };
|
||||
|
||||
string book_name = dataGridView1.Rows[idx].Cells["book_name"].Value?.ToString() ?? string.Empty;
|
||||
string author = dataGridView1.Rows[idx].Cells["author"].Value?.ToString() ?? string.Empty;
|
||||
string book_comp = dataGridView1.Rows[idx].Cells["book_comp"].Value?.ToString() ?? string.Empty;
|
||||
|
||||
if (value.Title == book_name) chk[0] = true;
|
||||
|
||||
if (value.Author.Contains(author) == true) chk[1] = true;
|
||||
else if (author.Contains(value.Author) == true) chk[1] = true;
|
||||
else if (value.Author == author) chk[1] = true;
|
||||
|
||||
if (value.Publisher.Contains(book_comp) == true) chk[2] = true;
|
||||
else if (book_comp.Contains(value.Publisher) == true) chk[2] = true;
|
||||
else if (value.Publisher == book_comp) chk[2] = true;
|
||||
|
||||
if (chk[0] == true && chk[1] == true && chk[2] == true)
|
||||
{
|
||||
|
||||
dataGridView1.Rows[idx].Cells["isbn"].Value = value.Isbn13;
|
||||
dataGridView1.Rows[idx].Cells["price2"].Value = value.PriceStandard;
|
||||
dataGridView1.Rows[idx].Cells["pubDate"].Value = date;
|
||||
//if (cb_api.SelectedIndex == 2)
|
||||
dataGridView1.Rows[idx].Cells["category"].Value = value.CategoryName;
|
||||
dataGridView1.Rows[idx].Cells["sold_out"].Value = value.StockStatus;
|
||||
dataGridView1.Rows[idx].DefaultCellStyle.BackColor = Color.Yellow;
|
||||
}
|
||||
count_res();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// API에서 가져온 데이터가 요구한 데이터와 일치하는지 알아보는 함수
|
||||
/// </summary>
|
||||
@@ -519,15 +641,15 @@ namespace ISBN_Check_test
|
||||
#region 검색갯수 계산
|
||||
private void count_res()
|
||||
{
|
||||
String_Text st = new String_Text();
|
||||
int count = dataGridView1.Rows.Count;
|
||||
for (int a = 0; a < count; a++)
|
||||
{
|
||||
string search_data = dataGridView1.Rows[a].Cells["Column1"].Value?.ToString() ?? string.Empty;
|
||||
int tmp_count = st.Char_count(search_data, '|');
|
||||
int lcount = tmp_count / 8;
|
||||
dataGridView1.Rows[a].Cells["count"].Value = lcount.ToString();
|
||||
}
|
||||
//String_Text st = new String_Text();
|
||||
//int count = dataGridView1.Rows.Count;
|
||||
//for (int a = 0; a < count; a++)
|
||||
//{
|
||||
// string search_data = dataGridView1.Rows[a].Cells["Column1"].Value?.ToString() ?? string.Empty;
|
||||
// int tmp_count = st.Char_count(search_data, '|');
|
||||
// int lcount = tmp_count / 8;
|
||||
// dataGridView1.Rows[a].Cells["count"].Value = lcount.ToString();
|
||||
//}
|
||||
}
|
||||
#endregion
|
||||
private void dataGridView1_KeyDown(object sender, KeyEventArgs e)
|
||||
@@ -574,12 +696,49 @@ namespace ISBN_Check_test
|
||||
}
|
||||
private void dataGridView1_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
|
||||
{
|
||||
if (dataGridView1.Rows[rowidx].Cells["Column1"].Value == null ||
|
||||
dataGridView1.Rows[rowidx].Cells["Column1"].Value.ToString() == "") { return; }
|
||||
Form2 f2 = new Form2(this);
|
||||
f2.row = rowidx;
|
||||
f2.Call_API = cb_api.Text;
|
||||
f2.Show();
|
||||
if (e.RowIndex < 0 || e.ColumnIndex < 0) return;
|
||||
var column = this.dataGridView1.Columns[e.ColumnIndex];
|
||||
|
||||
if (column.Name.Equals("dvc_remark"))
|
||||
{
|
||||
var value = this.dataGridView1.Rows[e.RowIndex].Cells[column.Name].Value?.ToString() ?? string.Empty;
|
||||
if(value.StartsWith("<"))
|
||||
{
|
||||
value = value.Substring(value.IndexOf(">") + 1);
|
||||
}
|
||||
else this.richTextBox1.Text = value;
|
||||
}
|
||||
else if (column.Name.Equals("Column"))
|
||||
{
|
||||
var value = this.dataGridView1.Rows[e.RowIndex].Cells[column.Name].Value?.ToString() ?? string.Empty;
|
||||
if (value == string.Empty) return;
|
||||
|
||||
Form2 f2 = new Form2(this);
|
||||
f2.row = rowidx;
|
||||
f2.Call_API = cb_api.Text;
|
||||
f2.Show();
|
||||
}
|
||||
else if (column.Name.Equals("dvc_link"))
|
||||
{
|
||||
var value = this.dataGridView1.Rows[e.RowIndex].Cells[column.Name].Value?.ToString() ?? string.Empty;
|
||||
if (value == string.Empty) return;
|
||||
try
|
||||
{
|
||||
var prc = new System.Diagnostics.Process();
|
||||
prc.StartInfo = new System.Diagnostics.ProcessStartInfo()
|
||||
{
|
||||
FileName = value,
|
||||
UseShellExecute = true
|
||||
};
|
||||
prc.Start();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
|
||||
@@ -606,6 +765,7 @@ namespace ISBN_Check_test
|
||||
{
|
||||
string[] aladin = { "도서명 + 저자", "도서명", "저자", "출판사", "별치조사" };
|
||||
cb_filter.Items.AddRange(aladin);
|
||||
cb_filter.SelectedIndex = cb_filter.Items.Count - 1;
|
||||
}
|
||||
Must_Col(cb_api.SelectedIndex);
|
||||
}
|
||||
@@ -675,5 +835,10 @@ namespace ISBN_Check_test
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void button4_Click(object sender, EventArgs e)
|
||||
{
|
||||
dataGridView1.Rows.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user