알라딘데이터추출시 버퍼꼬이는 증상 수정

This commit is contained in:
2025-09-02 23:08:49 +09:00
parent 0cc71611d0
commit 8f74fb5557
8 changed files with 133 additions and 86 deletions

3
ISBN_Check/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"dotnet.preferCSharpExtension": true
}

3
ISBN_Check/Main/.vscode/settings.json vendored Normal file
View File

@@ -0,0 +1,3 @@
{
"dotnet.preferCSharpExtension": true
}

View File

@@ -29,9 +29,9 @@ namespace ISBN_Check_test
/// </summary> /// </summary>
private void InitializeComponent() private void InitializeComponent()
{ {
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle4 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle7 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle6 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle9 = new System.Windows.Forms.DataGridViewCellStyle();
System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle5 = new System.Windows.Forms.DataGridViewCellStyle(); System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle8 = new System.Windows.Forms.DataGridViewCellStyle();
this.cb_filter = new System.Windows.Forms.ComboBox(); this.cb_filter = new System.Windows.Forms.ComboBox();
this.button1 = new System.Windows.Forms.Button(); this.button1 = new System.Windows.Forms.Button();
this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.dataGridView1 = new System.Windows.Forms.DataGridView();
@@ -58,6 +58,7 @@ namespace ISBN_Check_test
this.panel1 = new System.Windows.Forms.Panel(); this.panel1 = new System.Windows.Forms.Panel();
this.panel2 = new System.Windows.Forms.Panel(); this.panel2 = new System.Windows.Forms.Panel();
this.panel3 = new System.Windows.Forms.Panel(); this.panel3 = new System.Windows.Forms.Panel();
this.button3 = new System.Windows.Forms.Button();
((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit();
this.panel1.SuspendLayout(); this.panel1.SuspendLayout();
this.panel2.SuspendLayout(); this.panel2.SuspendLayout();
@@ -76,7 +77,7 @@ namespace ISBN_Check_test
// //
// button1 // button1
// //
this.button1.Location = new System.Drawing.Point(416, 10); this.button1.Location = new System.Drawing.Point(388, 9);
this.button1.Name = "button1"; this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23); this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 2; this.button1.TabIndex = 2;
@@ -86,14 +87,14 @@ namespace ISBN_Check_test
// //
// dataGridView1 // dataGridView1
// //
dataGridViewCellStyle4.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle7.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle4.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle7.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle4.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); dataGridViewCellStyle7.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
dataGridViewCellStyle4.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle7.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle4.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle7.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle4.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle7.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle4.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle7.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle4; this.dataGridView1.ColumnHeadersDefaultCellStyle = dataGridViewCellStyle7;
this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { this.dataGridView1.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] {
this.book_name, this.book_name,
this.author, this.author,
@@ -110,14 +111,14 @@ namespace ISBN_Check_test
this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnF2; this.dataGridView1.EditMode = System.Windows.Forms.DataGridViewEditMode.EditOnF2;
this.dataGridView1.Location = new System.Drawing.Point(0, 0); this.dataGridView1.Location = new System.Drawing.Point(0, 0);
this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Name = "dataGridView1";
dataGridViewCellStyle6.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle9.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
dataGridViewCellStyle6.BackColor = System.Drawing.SystemColors.Control; dataGridViewCellStyle9.BackColor = System.Drawing.SystemColors.Control;
dataGridViewCellStyle6.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129))); dataGridViewCellStyle9.Font = new System.Drawing.Font("굴림", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(129)));
dataGridViewCellStyle6.ForeColor = System.Drawing.SystemColors.WindowText; dataGridViewCellStyle9.ForeColor = System.Drawing.SystemColors.WindowText;
dataGridViewCellStyle6.SelectionBackColor = System.Drawing.SystemColors.Highlight; dataGridViewCellStyle9.SelectionBackColor = System.Drawing.SystemColors.Highlight;
dataGridViewCellStyle6.SelectionForeColor = System.Drawing.SystemColors.HighlightText; dataGridViewCellStyle9.SelectionForeColor = System.Drawing.SystemColors.HighlightText;
dataGridViewCellStyle6.WrapMode = System.Windows.Forms.DataGridViewTriState.True; dataGridViewCellStyle9.WrapMode = System.Windows.Forms.DataGridViewTriState.True;
this.dataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle6; this.dataGridView1.RowHeadersDefaultCellStyle = dataGridViewCellStyle9;
this.dataGridView1.RowTemplate.Height = 23; this.dataGridView1.RowTemplate.Height = 23;
this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect; this.dataGridView1.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.CellSelect;
this.dataGridView1.Size = new System.Drawing.Size(1001, 471); this.dataGridView1.Size = new System.Drawing.Size(1001, 471);
@@ -186,8 +187,8 @@ namespace ISBN_Check_test
// //
// count // count
// //
dataGridViewCellStyle5.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter; dataGridViewCellStyle8.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleCenter;
this.count.DefaultCellStyle = dataGridViewCellStyle5; this.count.DefaultCellStyle = dataGridViewCellStyle8;
this.count.HeaderText = "검색갯수"; this.count.HeaderText = "검색갯수";
this.count.Name = "count"; this.count.Name = "count";
this.count.Width = 80; this.count.Width = 80;
@@ -239,7 +240,7 @@ namespace ISBN_Check_test
// //
// button2 // button2
// //
this.button2.Location = new System.Drawing.Point(503, 10); this.button2.Location = new System.Drawing.Point(467, 9);
this.button2.Name = "button2"; this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(75, 23); this.button2.Size = new System.Drawing.Size(75, 23);
this.button2.TabIndex = 2; this.button2.TabIndex = 2;
@@ -267,7 +268,7 @@ namespace ISBN_Check_test
// //
// btn_Yes24 // btn_Yes24
// //
this.btn_Yes24.Location = new System.Drawing.Point(590, 10); this.btn_Yes24.Location = new System.Drawing.Point(625, 9);
this.btn_Yes24.Name = "btn_Yes24"; this.btn_Yes24.Name = "btn_Yes24";
this.btn_Yes24.Size = new System.Drawing.Size(75, 23); this.btn_Yes24.Size = new System.Drawing.Size(75, 23);
this.btn_Yes24.TabIndex = 8; this.btn_Yes24.TabIndex = 8;
@@ -277,6 +278,7 @@ namespace ISBN_Check_test
// //
// panel1 // panel1
// //
this.panel1.Controls.Add(this.button3);
this.panel1.Controls.Add(this.cb_api); this.panel1.Controls.Add(this.cb_api);
this.panel1.Controls.Add(this.btn_Yes24); this.panel1.Controls.Add(this.btn_Yes24);
this.panel1.Controls.Add(this.cb_filter); this.panel1.Controls.Add(this.cb_filter);
@@ -311,6 +313,16 @@ namespace ISBN_Check_test
this.panel3.Size = new System.Drawing.Size(1001, 471); this.panel3.Size = new System.Drawing.Size(1001, 471);
this.panel3.TabIndex = 11; this.panel3.TabIndex = 11;
// //
// button3
//
this.button3.Location = new System.Drawing.Point(546, 9);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(75, 23);
this.button3.TabIndex = 9;
this.button3.Text = "리셋(전체)";
this.button3.UseVisualStyleBackColor = true;
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Form1 // Form1
// //
this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F); this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 12F);
@@ -360,6 +372,7 @@ namespace ISBN_Check_test
private System.Windows.Forms.Panel panel1; private System.Windows.Forms.Panel panel1;
private System.Windows.Forms.Panel panel2; private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Panel panel3; private System.Windows.Forms.Panel panel3;
private System.Windows.Forms.Button button3;
} }
} }

View File

@@ -159,11 +159,16 @@ namespace ISBN_Check_test
gridview.Rows[a ].DefaultCellStyle.BackColor = Color.Empty; gridview.Rows[a ].DefaultCellStyle.BackColor = Color.Empty;
// string aladin = api.Aladin(query, "ISBN13", param); // string aladin = api.Aladin(query, "ISBN13", param);
string aladin = api.Aladin(query, type, param); var aladin = api.Aladin(query, type, param);
insert_By_Aladin(aladin, a); insert_By_Aladin(aladin, a);
try try
{ {
richTextBox1.Text = aladin; var sb = new StringBuilder();
foreach(var item in aladin)
{
sb.AppendLine(string.Join("|", item));
}
richTextBox1.Text = sb.ToString();
} }
catch { } catch { }
} }
@@ -309,7 +314,7 @@ namespace ISBN_Check_test
{ {
progressBar1.PerformStep(); progressBar1.PerformStep();
} }
void insert_By_Aladin(string data, int row) void insert_By_Aladin(string[] insert, int row)
{ {
if (row >0) if (row >0)
{ {
@@ -317,9 +322,8 @@ namespace ISBN_Check_test
} }
dataGridView1.Rows[row ].Selected = true; dataGridView1.Rows[row ].Selected = true;
string[] insert = data.Split('|');
if (data == "") { return; } if (insert.Any() == false) { return; }
// pubDate형 보기편하게 DateTime형으로 재정리 // pubDate형 보기편하게 DateTime형으로 재정리
string newstring = ""; string newstring = "";
@@ -328,7 +332,7 @@ namespace ISBN_Check_test
newstring = String.Format("{0:yyyy/MM/dd}", newstring = String.Format("{0:yyyy/MM/dd}",
DateTime.Parse(insert[5].Remove(insert[5].IndexOf(" G")))); DateTime.Parse(insert[5].Remove(insert[5].IndexOf(" G"))));
} }
catch (Exception ex) { MessageBox.Show(data); } catch (Exception ex) { MessageBox.Show(string.Join("|",insert)); }
for (int a = 0; a < insert.Length; a++) for (int a = 0; a < insert.Length; a++)
{ {
@@ -641,7 +645,8 @@ namespace ISBN_Check_test
{ {
if (System.Diagnostics.Debugger.IsAttached) if (System.Diagnostics.Debugger.IsAttached)
{ {
string[] lst = { "9791193110584", string[] lst = { "9788965427520",
"9791193110584",
"9791168672260", "9791168672260",
"9788993858396", "9788993858396",
"9791171200351", "9791171200351",
@@ -658,5 +663,17 @@ namespace ISBN_Check_test
end_idx.Text = (this.dataGridView1.Rows.Count - 1).ToString(); end_idx.Text = (this.dataGridView1.Rows.Count - 1).ToString();
} }
} }
private void button3_Click(object sender, EventArgs e)
{
for (int a = 0; a < dataGridView1.Rows.Count - 1; a++)
{
//if (dataGridView1.Rows[a].DefaultCellStyle.BackColor != Color.Yellow)
{
dataGridView1.Rows[a].Cells["Column1"].Value = "";
dataGridView1.Rows[a].DefaultCellStyle.BackColor = Color.Empty;
}
}
}
} }
} }

View File

@@ -10,6 +10,7 @@ using System.Threading.Tasks;
using System.Web.Script.Serialization; using System.Web.Script.Serialization;
using System.Windows.Forms; using System.Windows.Forms;
using System.Xml; using System.Xml;
using System.Xml.Linq;
namespace ISBN_Check_test namespace ISBN_Check_test
{ {
@@ -22,7 +23,7 @@ namespace ISBN_Check_test
/// <param name="QueryType"></param> /// <param name="QueryType"></param>
/// <param name="Param"></param> /// <param name="Param"></param>
/// <returns></returns> /// <returns></returns>
public string Aladin(string Query, string QueryType, string[] Param) public string[] Aladin(string Query, string QueryType, string[] Param)
{ {
string result = string.Empty; string result = string.Empty;
// 쿼리 생성 // 쿼리 생성
@@ -49,57 +50,40 @@ namespace ISBN_Check_test
// xml형식을 json형식으로 변환 // xml형식을 json형식으로 변환
XmlDocument doc = new XmlDocument(); XmlDocument doc = new XmlDocument();
doc.LoadXml(xml); doc.LoadXml(xml);
var json = JsonConvert.SerializeXmlNode(doc);
// json형식 분석을 위해 JavaScriptSerializer 개체 생성 var xdoc = XDocument.Parse(xml);
JavaScriptSerializer js = new JavaScriptSerializer(); var xroot = xdoc.Root;
// 런타임에 개체를 확인하여 사용할수 있는 dynamic을 이용해 역직렬화 // XML에서 직접 totalResults와 item 추출 (XDocument 사용)
dynamic dob = js.Deserialize<dynamic>(json); XNamespace ns = "http://www.aladin.co.kr/ttb/apiguide.aspx";
// "object"내에 있는것을 얻어오기 위해 다시 dynamic변수에 참조 // totalResults 추출
dynamic docs = ""; string totalResults = xdoc.Descendants(ns + "totalResults").FirstOrDefault()?.Value ?? "0";
try
// item들 추출
var itemElements = xdoc.Descendants(ns + "item");
if (!itemElements.Any())
{ {
docs = dob["object"]["item"]; return new string[] { };
} }
catch
{ int length = itemElements.Count();
return "";
}
int length = 0;
int ID_length = Param.Length; int ID_length = Param.Length;
// 검색 결과가 1개 이하일 경우, 오류가 발생하여 try/catch문 사용. // XML item들을 순회하면서 필요한 데이터 추출 (XDocument 사용)
try List<string[]> retval = new List<string[]>();
foreach (var itemElement in itemElements)
{ {
// docs는 요소 컬렉션으로 object로 변환. string[] buffer = new string[ID_length];
object[] buf = docs;
length = buf.Length;
}
catch
{
object buf = docs;
length = 1;
}
for (int a = 0; a < length; a++)
{
List<string> tmp_data = new List<string>();
for (int b = 0; b < ID_length; b++) for (int b = 0; b < ID_length; b++)
{ {
if (length == 1) buffer[b] = itemElement.Element(ns + Param[b])?.Value ?? "";
{
tmp_data.Add(docs[Param[b]]);
} }
else //retval.Add(buffer);
{ return buffer;
tmp_data.Add(docs[a][Param[b]]);
} }
result += tmp_data[b] + "|"; return new string[] { };
}
result += "\n";
}
return result;
} }
/// <summary> /// <summary>
/// https://blog.aladin.co.kr/openapi 참고 /// https://blog.aladin.co.kr/openapi 참고
@@ -292,13 +276,15 @@ namespace ISBN_Check_test
List<object> tmp_data = new List<object>(); List<object> tmp_data = new List<object>();
for (int b = 0; b < ID_length; b++) for (int b = 0; b < ID_length; b++)
{ {
if (Param[b] == "authors") { if (Param[b] == "authors")
{
object[] tmp = docs[a][Param[b]]; object[] tmp = docs[a][Param[b]];
string tmp_str = string.Empty; string tmp_str = string.Empty;
for (int j = 0; j < tmp.Length; j++) for (int j = 0; j < tmp.Length; j++)
{ {
tmp_str += tmp[j]; tmp_str += tmp[j];
if (j < tmp.Length - 1) { if (j < tmp.Length - 1)
{
tmp_str += ", "; tmp_str += ", ";
} }
} }
@@ -306,7 +292,8 @@ namespace ISBN_Check_test
result += tmp_data[b] + "|"; result += tmp_data[b] + "|";
tmp_str = ""; tmp_str = "";
} }
else { else
{
tmp_data.Add(docs[a][Param[b]]); tmp_data.Add(docs[a][Param[b]]);
result += tmp_data[b] + "|"; result += tmp_data[b] + "|";
} }

View File

@@ -41,15 +41,15 @@ namespace ISBN_Check_test
else { tb_price.Text = ""; } else { tb_price.Text = ""; }
string data = f1GridView.Rows[row].Cells["Column1"].Value.ToString(); var data = (string[])f1GridView.Rows[row].Cells["Column1"].Value;
inputGrid(data); inputGrid(data);
} }
private void inputGrid(string data) private void inputGrid(string[] tmp)
{ {
dataGridView1.Rows.Clear(); dataGridView1.Rows.Clear();
// 도서명 / 저자 / 출판사 / isbn / 출간일 / 카테고리 / 품절여부 // 도서명 / 저자 / 출판사 / isbn / 출간일 / 카테고리 / 품절여부
string[] tmp = data.Split('|'); //string[] tmp = data.Split('|');
string[] grid = { "", "", "", "", "", "", "", "" }; string[] grid = { "", "", "", "", "", "", "", "" };
for (int a = 0; a < tmp.Length; a++) for (int a = 0; a < tmp.Length; a++)
@@ -186,8 +186,8 @@ namespace ISBN_Check_test
string type = "Title"; string type = "Title";
string query = tb_book_name.Text; string query = tb_book_name.Text;
string aladin = api.Aladin(query, type, param); var aladin = api.Aladin(query, type, param);
if (aladin == "") return; if (aladin.Any()==false) return;
inputGrid(aladin); inputGrid(aladin);
} }

24
ISBN_Check/Main/Main.sln Normal file
View File

@@ -0,0 +1,24 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ISBN_Check_test", "ISBN_Check_test.csproj", "{B1FE7D47-6EFF-E4AE-FF42-BADB7C89CEEE}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{B1FE7D47-6EFF-E4AE-FF42-BADB7C89CEEE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{B1FE7D47-6EFF-E4AE-FF42-BADB7C89CEEE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B1FE7D47-6EFF-E4AE-FF42-BADB7C89CEEE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B1FE7D47-6EFF-E4AE-FF42-BADB7C89CEEE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E8EB61EB-992B-4C29-AC57-A0B63137A787}
EndGlobalSection
EndGlobal

View File

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