Files
Unimarc/unimarc/unimarc/마크/Marc_mkList.cs
2026-02-23 23:11:54 +09:00

413 lines
16 KiB
C#

using AR;
using Org.BouncyCastle.Pkcs;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace UniMarc
{
public partial class Marc_mkList : Form
{
Marc marc;
CD_LP cp;
Helper_DB db = new Helper_DB();
public Marc_mkList(Marc _marc)
{
InitializeComponent();
marc = _marc;
}
public Marc_mkList(CD_LP _cp)
{
InitializeComponent();
cp = _cp;
}
private void Marc_mkList_Load(object sender, EventArgs e)
{
db.DBcon();
#region panel1 set
rb_basicNum.Checked = true;
rb_autoNum.Enabled = false;
string[] type = { "정리" };
cb_listType.Items.AddRange(type);
cb_listType.SelectedIndex = 0;
#endregion
#region panel2 set // 분류기호
AuthorSymbol.Symbol symbol = new AuthorSymbol.Symbol();
// 저자기호
string[] First = symbol.authorBook;
cb_FirstAuthor.Items.AddRange(First);
cb_FirstAuthor.SelectedIndex = 0;
string[] authorType = symbol.authorType;
cb_authorTypeK.Items.AddRange(authorType);
cb_authorTypeK.SelectedIndex = 0;
cb_authorTypeE.Items.AddRange(authorType);
cb_authorTypeE.SelectedIndex = 0;
string[] Book = symbol.authorBook;
cb_FirstBook.Items.AddRange(Book);
cb_FirstBook.SelectedIndex = 0;
// 분류기호
string[] divType = { "KDC", "DDC" };
cb_divType.Items.AddRange(divType);
cb_divType.SelectedIndex = 0;
//4인이상저장
string[] author_four = { "출판사+서명", "서명+출판사" };
cmb_author_four.Items.AddRange(author_four);
cb_divType.SelectedIndex = 0;
#endregion
if (marc != null)
{
//customer idx 값이 있다면 그것을 사용한다.
if (int.TryParse(marc.lbCustIDX.Text, out int custidx) == true && custidx > 0)
{
//string mCompidx = PUB.user.CompanyIdx;
var dt = Helper_DB.GetDT("Client", "c_sangho,c_author_first,c_author_typeK,c_author_typeE,c_author_firstbook,c_author_divtype,c_author_divnum,c_author_four,c_pijunja,c_author_four_use", $"campanyidx = {PUB.user.CompanyIdx} AND idx = {custidx}");
if (dt != null && dt.Rows.Count > 0)
{
var row = dt.Rows[0];
// 저자기호 첫글자 설정 (c_author_first)
if (!string.IsNullOrEmpty(row["c_author_first"].ToString()))
{
int idx = cb_FirstAuthor.FindStringExact(row["c_author_first"].ToString());
if (idx >= 0) cb_FirstAuthor.SelectedIndex = idx;
}
// 저자기호 타입 설정 (c_author_typeK 또는 c_author_typeE)
if (!string.IsNullOrEmpty(row["c_author_typeK"].ToString()))
{
int idx = cb_authorTypeK.FindStringExact(row["c_author_typeK"].ToString());
if (idx >= 0) cb_authorTypeK.SelectedIndex = idx;
}
// 저자기호 타입 설정 (c_author_typeE 또는 c_author_typeE)
if (!string.IsNullOrEmpty(row["c_author_typeE"].ToString()))
{
int idx = cb_authorTypeE.FindStringExact(row["c_author_typeE"].ToString());
if (idx >= 0) cb_authorTypeE.SelectedIndex = idx;
}
// 도서기호 첫글자 설정 (c_author_firstbook)
if (!string.IsNullOrEmpty(row["c_author_firstbook"].ToString()))
{
int idx = cb_FirstBook.FindStringExact(row["c_author_firstbook"].ToString());
if (idx >= 0) cb_FirstBook.SelectedIndex = idx;
}
// 분류기호 타입 설정 (c_author_divtype)
if (!string.IsNullOrEmpty(row["c_author_divtype"].ToString()))
{
int idx = cb_divType.FindStringExact(row["c_author_divtype"].ToString());
if (idx >= 0) cb_divType.SelectedIndex = idx;
}
// 분류기호 자릿수 설정 (c_author_divnum)
if (!string.IsNullOrEmpty(row["c_author_divnum"].ToString()))
{
int idx = cb_divNum.FindStringExact(row["c_author_divnum"].ToString());
if (idx >= 0) cb_divNum.SelectedIndex = idx;
}
// 4인이상 저장(c_author_four)
if (!string.IsNullOrEmpty(row["c_author_four"].ToString()))
{
int idx = cmb_author_four.FindStringExact(row["c_author_four"].ToString());
if (idx >= 0) cmb_author_four.SelectedIndex = idx;
}
// 피전자적용
if (!string.IsNullOrEmpty(row["c_pijunja"].ToString()))
{
string chkvalue = row["c_pijunja"].ToString().Trim();
chkPijunja.Checked = (chkvalue == "1" || chkvalue.ToUpper() == "Y" || chkvalue.ToUpper() == "TRUE");
}
else
{
chkPijunja.Checked = false;
}
// 4인이상저자(사용여부)
if (!string.IsNullOrEmpty(row["c_author_four_use"].ToString()))
{
string chkvalue = row["c_author_four_use"].ToString().Trim();
chk_CompSymbol.Checked = (chkvalue == "1" || chkvalue.ToUpper() == "Y" || chkvalue.ToUpper() == "TRUE");
}
else
{
chk_CompSymbol.Checked = false;
}
}
}
}
}
private void cb_divType_SelectedIndexChanged(object sender, EventArgs e)
{
cb_divNum.Items.Clear();
if (((ComboBox)sender).SelectedIndex == 0)
{
string[] divNum = { "4", "5", "6" };
cb_divNum.Items.AddRange(divNum);
}
else
{
string[] divNum = { "21", "22", "23" };
cb_divNum.Items.AddRange(divNum);
}
cb_divNum.SelectedIndex = 0;
}
private void btn_mkList_Click(object sender, EventArgs e)
{
if (tb_listName.Text == "")
{
UTIL.MsgE("목록명을 입력해주세요!");
return;
}
if (tb_outnum.Text == "")
{
UTIL.MsgE("차수가 비어있습니다.");
return;
}
if (marc != null)
ExportOld();
}
void ExportOld()
{
String_Text st = new String_Text();
var marccnt2 = marc?.List_Book.RowCount ?? 0;
if (marccnt2 < 1)
{
UTIL.MsgE("마크데이터 목록이 존재하지 않습니다");
return;
}
string listName = tb_listName.Text;
string Time = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
string outnum = tb_outnum.Text + "차";
string user = PUB.user.UserName;// Properties.Settings.Default.User;
bool isAuthor = false;
bool isBook = false;
if (cb_FirstAuthor.SelectedIndex == 0)
isAuthor = true;
if (cb_FirstBook.SelectedIndex == 0)
isBook = true;
bool[] isType = { isAuthor, isBook };
// 시방서 목록 DB에 들어갈 것들.
string[] insert_list_col = {
"compidx", "work_list", "date", "state", "gu",
"first_Author", "symbol_Author","symbol_AuthorE", "book_Author", "divType", "divNum",
"etc", "user"
};
string[] insert_list_data = {
PUB.user.CompanyIdx, listName, Time, "진행", cb_listType.Text,
cb_FirstAuthor.Text, cb_authorTypeK.Text, cb_authorTypeE.Text, cb_FirstBook.Text, cb_divType.Text, cb_divNum.Text,
rtb_etc.Text, user
};
string cmdByList = db.DB_INSERT("Specs_List", insert_list_col, insert_list_data);
// 시방서 마크 DB에 들어갈 것들.
string[] insert_marc_col = {
"compidx", "work_list", "date", "ISBN", "book_name",
"s_book_name1", "s_book_num1", "author", "book_comp", "pubdate",
"price", "tag008", "class_symbol", "author_symbol", "marc",
"imageURL", "count", "num", "out_num", "midx",
"editDate", "user"
};
string[] insert_marc_data = {
PUB.user.CompanyIdx, listName, Time, "", "",
"", "", "", "", "",
"", "", "", "", "",
"", "", "", "", "",
Time, user
}; // 마크에서 추출 ( 3 ~ 12 )
int[] row = checkGridRow();
int num = 0;
progressBar1.Maximum = row.Length + 1;
string cmdByMarc = string.Format("INSERT INTO {0} {1} value", "Specs_Marc", db.DB_INSERT_SUB("", insert_marc_col));
bool CountSplit = chk_countSplit.Checked;
int listCount = 1;
int addCount = 1;
// 필터링하여 DB에 집어넣는 작업
for (int a = 0; a < row.Length; a++)
{
if (Convert.ToString(marc.List_Book.Rows[row[a]].Cells["db_marc"].Value) == "")
continue;
num += 1;
int.TryParse(Convert.ToString(marc.List_Book.Rows[row[a]].Cells["count"].Value), out listCount);
// ISBN, book_name, s_book_name1, s_book_num1, author, book_comp, pubdate, price, tag008, class_symbol
string[] Search = { "020a", "245a", "440a", "440v", "245d", "260b", "260c", "950b", "008", "056a" };
insert_marc_data[14] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["db_marc"].Value);
insert_marc_data[15] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["url"].Value);
insert_marc_data[16] = addCount.ToString();
if (rb_basicNum.Checked)
insert_marc_data[17] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["num"].Value);
else
insert_marc_data[17] = num.ToString();
insert_marc_data[18] = outnum;
insert_marc_data[19] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["marc_idx"].Value);
insert_marc_data[20] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["SaveDate"].Value);
insert_marc_data[21] = Convert.ToString(marc.List_Book.Rows[row[a]].Cells["user"].Value);
string[] Marc = st.Take_Tag(insert_marc_data[14], Search);
string[] Author = { "", Marc[1] }; // 저자, 도서명
// 100, 110, 111태그중 한개라도 있으면 저자로 인식.
string[] Author_Search = { "100a", "110a", "111a", "245d" };
string[] Author_res = st.Take_Tag(insert_marc_data[14], Author_Search);
if (Author_res[0].Length > 1) Author[0] = Author_res[0];
if (Author_res[1].Length > 1) Author[0] = Author_res[1];
if (Author_res[2].Length > 1) Author[0] = Author_res[2];
if (chk_CompSymbol.Checked)
if (Author_res[3].IndexOf("[외]") > -1)
Author[0] = Marc[5];
string tmp_ViewMarc = st.ConvertMarcType(insert_marc_data[14], out string errmessage);
// 마크에서 추출한 데이터 DB에 적용하기 위한 반복문
for (int b = 0; b < Marc.Length; b++)
{
insert_marc_data[b + 3] = Marc[b];
// 분류기호 설정값적용대로 가져오기.
if (b == 9)
{
string class_symbol = st.TakeTag_ConditionContent(tmp_ViewMarc, "056a", "056" + cb_divNum.Text);
if (class_symbol != "")
insert_marc_data[b + 3] = class_symbol;
}
}
// 22.10.24 740태그 삭제
tmp_ViewMarc = st.RemoveTagNumber(tmp_ViewMarc, "740");
// 마크 분류기호 설정값대로 적용
tmp_ViewMarc = st.RemoveTagNumber(tmp_ViewMarc, "056");
tmp_ViewMarc = st.AddTagInMarc(string.Format("056\t \t▼a{0}▼2{1}▲", insert_marc_data[12], cb_divNum.Text), tmp_ViewMarc);
insert_marc_data[14] = st.made_Ori_marc(tmp_ViewMarc);
if (Author[0].Length < 1)
{
UTIL.MsgE("저장할 목록명이 비어있습니다." + row[a] + "번째의 저자를 확인해주세요. \n (100a, 110a, 111a 중 1개 필수)");
return;
}
Author[0] = Regex.Replace(Author[0], @"[^a-zA-Z0-9가-힣_]", "", RegexOptions.Singleline);
Author[1] = st.RemoveWordInBracket(Author[1]);
Author[1] = Regex.Replace(Author[1], @"[^a-zA-Z0-9가-힣_]", "", RegexOptions.Singleline);
AuthorSymbol.Symbol sb = new AuthorSymbol.Symbol();
string authorTypeK = cb_authorTypeK.SelectedItem.ToString();
string authorTypeE = cb_authorTypeE.SelectedItem.ToString();
string res_Author = "";
if (chk_CompSymbol.Checked == false || cmb_author_four.Text == "출판사+서명")
res_Author = sb.SymbolAuthor(Author[0], Author[1], authorTypeK, authorTypeE, isType);
else //서명+출판사는 뒤집어서 입력한다 251110
res_Author = sb.SymbolAuthor(Author[1], Author[0], authorTypeK, authorTypeE, isType);
insert_marc_data[13] = res_Author;
cmdByMarc += db.DB_INSERT_SUB("value", insert_marc_data) + ",";
if (CountSplit && listCount > addCount)
{
a--;
addCount++;
continue;
}
else
{
addCount = 1;
progressBar1.PerformStep();
}
}
cmdByMarc = cmdByMarc.TrimEnd(',');
cmdByMarc += ";";
Helper_DB.ExcuteNonQuery(cmdByList);
Helper_DB.ExcuteNonQuery(cmdByMarc);
progressBar1.PerformStep();
if (progressBar1.Value == progressBar1.Maximum)
{
label2.Text = $"완료되었습니다!({row.Length}건)";
}
}
#region mkList_Sub
int[] checkGridRow()
{
List<int> GridRow = new List<int>();
if (marc != null)
{
for (int a = 0; a < marc.List_Book.Rows.Count; a++)
{
bool isSuccess = true;
if (marc.Check_BackColor(a) == false && marc.Check_List_V(a))
isSuccess = false;
if (isSuccess)
GridRow.Add(a);
}
}
int[] Result = GridRow.ToArray();
return Result;
}
#endregion
private void btn_Close_Click(object sender, EventArgs e)
{
this.Close();
}
private void chk_CompSymbol_CheckedChanged(object sender, EventArgs e)
{
cmb_author_four.Enabled = chk_CompSymbol.Checked;
}
}
}