Files
Unimarc/ISBN_Check_test/Form1_Sub.cs
SeungHo Yang d13f0e942a * unimarc
a. 팩스전송 완료.
 b. 마크목록 폼 작성중
  1. 엑셀반출 기능 추가중 사용 작업중
  2. 마크편집 폼 수정 중 (마크 반출 test프로젝트 진행완료, 본 프로젝트에 적용중. / 저장기능활성화 작업완료)
   2-1. 기존의 칸채우기에서 예상되지 못한 버그가 발생하여 칸채우기 숨김.
   2-2. 008태크 재배치 => TextBox에 적용완료. 변경사항 메모장으로 넘기는 작업 진행해야함.
   2-3. 현재 TODO : 저장기능

TODOLIST
1. 팩스로 전송될 엑셀파일 밑작업마무리 (입력될 파라미터만 적용하면 실사용가능)
2. 알라딘API로 ISBN조회 프로젝트 새로 작업할 것 => 대부분의 작업 완료. 자동 업데이트쪽만 알아보면 될것같음.
2021-03-24 18:32:21 +09:00

188 lines
7.9 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;
using System.Windows.Forms;
using System.Xml;
namespace ISBN_Check_test
{
class Aladin_API
{
/// <summary>
/// https://blog.aladin.co.kr/openapi 참고
/// </summary>
/// <param name="Query"></param>
/// <param name="QueryType"></param>
/// <param name="Param"></param>
/// <returns></returns>
public string Find(string Query, string QueryType, string[] Param)
{
string result = string.Empty;
// 쿼리 생성
string key = "ttbgloriabook1512001";
string site = "http://www.aladin.co.kr/ttb/api/ItemSearch.aspx";
string query = string.Format("{0}?query={1}&TTBKey={2}&output=xml&querytype={3}&MaxResults={4}",
site, Query, key, "Title", 30.ToString());
// 쿼리를 입력인자로 WebRequest 개채 생성
WebRequest request = WebRequest.Create(query);
// WebRequest개체의 헤더에 인증키 포함시키기.
// request.Headers.Add("Authorization", header);
// WebResponse개체를 통해 서비스 요청.
WebResponse response = request.GetResponse();
// 결과문자열 확인
Stream stream = response.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
String xml = reader.ReadToEnd();
stream.Close();
// xml형식을 json형식으로 변환
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);
var json = JsonConvert.SerializeXmlNode(doc);
// json형식 분석을 위해 JavaScriptSerializer 개체 생성
JavaScriptSerializer js = new JavaScriptSerializer();
// 런타임에 개체를 확인하여 사용할수 있는 dynamic을 이용해 역직렬화
dynamic dob = js.Deserialize<dynamic>(json);
// "object"내에 있는것을 얻어오기 위해 다시 dynamic변수에 참조
dynamic docs = "";
try
{
docs = dob["object"]["item"];
}
catch
{
return "";
}
int length = 0;
int ID_length = Param.Length;
// 검색 결과가 1개 이하일 경우, 오류가 발생하여 try/catch문 사용.
try
{
// docs는 요소 컬렉션으로 object로 변환.
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++)
{
if (length == 1)
{
tmp_data.Add(docs[Param[b]]);
}
else
{
tmp_data.Add(docs[a][Param[b]]);
}
result += tmp_data[b] + "|";
}
result += "\n";
}
return result;
}
}
class Skill_Grid
{
/// <summary>
/// 그리드 앞 머리말에 넘버를 표시
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
public void Print_Grid_Num(Object sender, DataGridViewRowPostPaintEventArgs e)
{
// RowPostPaint 이벤트 핸들러
// 행헤더 열영역에 행번호를 위해 장방형으로 처리
Rectangle rect = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
((DataGridView)sender).RowHeadersWidth - 4,
e.RowBounds.Height);
// 위에서 생성된 장방형내에 행번호를 보여주고 폰트색상 및 배경을 설정
TextRenderer.DrawText(e.Graphics,
(e.RowIndex + 1).ToString(),
((DataGridView)sender).RowHeadersDefaultCellStyle.Font,
rect,
((DataGridView)sender).RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
/// <summary>
/// DataGirdView의 활성화된 셀값을 삭제하는 코드 (단, KeyDown에 넣어야함!!!!)
/// 사전에 if(e.KeyCode == Keys.Delete)안에 들어가야함.
/// </summary>
/// <param name="sender">KeyDown의 object "sender"</param>
/// <param name="e">KeyDown의 KeyEventArgs "e"</param>
public void DataGrid_to_Delete(object sender, KeyEventArgs e)
{
int rowIndex = ((DataGridView)sender).CurrentCell.RowIndex;
int columnIndex = ((DataGridView)sender).CurrentCell.ColumnIndex;
((DataGridView)sender).Rows[rowIndex].Cells[columnIndex].Value = "";
}
/// <summary>
/// 엑셀에서 복사한 데이터를 DataGirdView에 붙여넣어주는 코드 (단, KeyDown에 넣어야함!!!!)
/// 사전에 if ((e.Shift && e.KeyCode == Keys.Insert) || (e.Control && e.KeyCode == Keys.V))안에 들어가야함.
/// </summary>
/// <param name="sender">KeyDown의 object "sender"</param>
/// <param name="e">KeyDown의 KeyEventArgs "e"</param>
public void Excel_to_DataGridView(object sender, KeyEventArgs e)
{
//if user clicked Shift+Ins or Ctrl+V (paste from clipboard)
if ((e.Shift && e.KeyCode == Keys.Insert) || (e.Control && e.KeyCode == Keys.V))
{
char[] rowSplitter = { '\r', '\n' };
char[] columnSplitter = { '\t' };
//get the text from clipboard
IDataObject dataInClipboard = Clipboard.GetDataObject();
string stringInClipboard = (string)dataInClipboard.GetData(DataFormats.Text);
//split it into lines
string[] rowsInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries);
//get the row and column of selected cell in dataGridView1
int r = ((DataGridView)sender).SelectedCells[0].RowIndex;
int c = ((DataGridView)sender).SelectedCells[0].ColumnIndex;
//add rows into dataGridView1 to fit clipboard lines
if (((DataGridView)sender).Rows.Count < (r + rowsInClipboard.Length))
{
((DataGridView)sender).Rows.Add(r + rowsInClipboard.Length - ((DataGridView)sender).Rows.Count);
}
// loop through the lines, split them into cells and place the values in the corresponding cell.
for (int iRow = 0; iRow < rowsInClipboard.Length; iRow++)
{
//split row into cell values
string[] valuesInRow = rowsInClipboard[iRow].Split(columnSplitter);
//cycle through cell values
for (int iCol = 0; iCol < valuesInRow.Length; iCol++)
{
//assign cell value, only if it within columns of the dataGridView1
if (((DataGridView)sender).ColumnCount - 1 >= c + iCol)
{
((DataGridView)sender).Rows[r + iRow].Cells[c + iCol].Value = valuesInRow[iCol];
}
}
}
}
}
}
}