diff --git a/unimarc/unimarc/마크/Marc.cs b/unimarc/unimarc/마크/Marc.cs index e6ae66a..3724c1d 100644 --- a/unimarc/unimarc/마크/Marc.cs +++ b/unimarc/unimarc/마크/Marc.cs @@ -1569,7 +1569,7 @@ namespace ExcelTest return; } - UniMarc.Marc_FillBlank fb = new UniMarc.Marc_FillBlank(this); + UniMarc.Marc_FillBlank fb = new UniMarc.Marc_FillBlank(); for (int a = 0; a < List_Book.Rows.Count; a++) { if (List_Book.Rows[a].DefaultCellStyle.ForeColor == Color.Red) @@ -1588,7 +1588,40 @@ namespace ExcelTest } } fb.ISBN = ISBN; - fb.Show(); + if (fb.ShowDialog() == DialogResult.OK) + { + String_Text st = new String_Text(); + if (fb.BulkMarcResults.Count > 0) + { + foreach (var kvp in fb.BulkMarcResults) + { + int targetListIdx = kvp.Key; + foreach (DataGridViewRow r in List_Book.Rows) + { + // In legacy Marc.cs, finding row by index logic might be similar? + // Marc_FillBlank used 'idx' from 'List_idx' column in legacy logic too? + // Legacy code: int idx = Convert.ToInt32(dataGridView1.Rows[a].Cells["List_idx"].Value.ToString()); + // And then: this.marc.List_Book.Rows[idx].Cells["db_marc"].Value = ... + // Wait, legacy used `Rows[idx]`. This implies `idx` IS the row index in List_Book? + // Let's assume it matches if we use the same index logic. + // In my refactor, I passed 'a' as first element of GridData if 'List_idx' col missing? + // In Marc.cs line 1579: `a.ToString()` is passed as first element. + // So `idx` in `BulkMarcResults` IS `a` (the row index). + // So we can directly access `List_Book.Rows[targetListIdx]`. + + if (targetListIdx >= 0 && targetListIdx < List_Book.Rows.Count) + { + List_Book.Rows[targetListIdx].Cells["db_marc"].Value = kvp.Value; + List_Book.Rows[targetListIdx].DefaultCellStyle.ForeColor = Color.Blue; + } + } + } + } + else if (!string.IsNullOrEmpty(fb.SingleMarcResult)) + { + richTextBox1.Text = fb.SingleMarcResult; + } + } } private void tabControl1_SelectedIndexChanged(object sender, EventArgs e) diff --git a/unimarc/unimarc/마크/Marc2.cs b/unimarc/unimarc/마크/Marc2.cs index 60d5d4d..45c1562 100644 --- a/unimarc/unimarc/마크/Marc2.cs +++ b/unimarc/unimarc/마크/Marc2.cs @@ -355,7 +355,7 @@ namespace ExcelTest if (row_idx == -1 || col_idx == -1) { return; } SaveRowIdx = row_idx; - mOldMarc = List_Book.Rows[row_idx].Cells["db_marc"].Value.ToString(); + mOldMarc = List_Book.Rows[row_idx].Cells["db_marc"].Value?.ToString() ?? string.Empty; string isbn = List_Book.Rows[row_idx].Cells["ISBN13"].Value.ToString(); if (isbn != "") { @@ -692,7 +692,7 @@ namespace ExcelTest return; } - var fb = new UniMarc.Marc_FillBlank(this); + var fb = new UniMarc.Marc_FillBlank(); for (int a = 0; a < List_Book.Rows.Count; a++) { if (List_Book.Rows[a].DefaultCellStyle.ForeColor == Color.Red) @@ -711,7 +711,41 @@ namespace ExcelTest } } fb.ISBN = ISBN; - fb.Show(); + if (fb.ShowDialog() == DialogResult.OK) + { + String_Text st = new String_Text(); + if (fb.BulkMarcResults.Count > 0) + { + foreach(var kvp in fb.BulkMarcResults) + { + // Use list_idx to find row? Or assume key matches? + // Marc_FillBlank used 'idx' from 'List_idx' column. + // We need to iterate List_Book to find matching List_idx or if key is row index? + // In Marc_FillBlank, I stored 'idx' which was from 'List_idx'. + // Key = List_idx. + int targetListIdx = kvp.Key; + // Find row with this list_idx + foreach(DataGridViewRow r in List_Book.Rows) + { + if(r.Cells["List_idx"].Value != null && Convert.ToInt32(r.Cells["List_idx"].Value) == targetListIdx) + { + r.Cells["db_marc"].Value = kvp.Value; + // Update color etc? + r.DefaultCellStyle.ForeColor = Color.Blue; + // Need to update 'item' too if bound + var item = r.DataBoundItem as MarcBookItem; + if(item != null) item.ForeColor = Color.Blue; + break; + } + } + } + } + else if (!string.IsNullOrEmpty(fb.SingleMarcResult)) + { + // Update current Editor + marcEditorControl1.SetMarcString(fb.SingleMarcResult); + } + } } diff --git a/unimarc/unimarc/마크/Marc_FillBlank.cs b/unimarc/unimarc/마크/Marc_FillBlank.cs index 8f676e2..185c4b4 100644 --- a/unimarc/unimarc/마크/Marc_FillBlank.cs +++ b/unimarc/unimarc/마크/Marc_FillBlank.cs @@ -16,20 +16,14 @@ namespace UniMarc public partial class Marc_FillBlank : Form { public string ISBN; + public string SingleMarcResult { get; private set; } + public Dictionary BulkMarcResults { get; private set; } = new Dictionary(); bool isAll; bool isBreak; - ExcelTest.Marc marc; - Marc2 mae; - public Marc_FillBlank(Marc2 _mae) - { - InitializeComponent(); - mae = _mae; - } - public Marc_FillBlank(ExcelTest.Marc _marc) + public Marc_FillBlank() { InitializeComponent(); - marc = _marc; } private void Marc_FillBlank_Load(object sender, EventArgs e) @@ -252,14 +246,10 @@ namespace UniMarc } SearchResultMarc(); string Text = richTextBox1.Text; - if (marc != null) - { - marc.richTextBox1.Text = MakeMarc(Text); - } - else if (mae != null) - { - mae.marcEditorControl1.SetMarcString(MakeMarc(Text)); - } + + this.SingleMarcResult = MakeMarc(Text); + this.DialogResult = DialogResult.OK; + this.Close(); } private void btn_AllMove_Click(object sender, EventArgs e) @@ -268,6 +258,8 @@ namespace UniMarc progressBar1.Maximum = dataGridView1.Rows.Count; isAll = true; + BulkMarcResults.Clear(); + for (int a = 0; a < dataGridView1.Rows.Count; a++) { for (int b = 0; b < dataGridView1.RowCount; b++) @@ -276,7 +268,14 @@ namespace UniMarc } isBreak = false; dataGridView1.Rows[a].DefaultCellStyle.BackColor = Color.Yellow; - int idx = Convert.ToInt32(dataGridView1.Rows[a].Cells["List_idx"].Value.ToString()); + // Assuming List_idx is stored as a cell value? Or should we trust the 'a' index? + // The original code used "List_idx" cell. + int idx = -1; + if (dataGridView1.Rows[a].Cells["List_idx"].Value != null) + idx = Convert.ToInt32(dataGridView1.Rows[a].Cells["List_idx"].Value.ToString()); + else + idx = Convert.ToInt32(dataGridView1.Rows[a].Cells[0].Value.ToString()); // Fallback to column 0 if List_idx not guaranteed + string isbn = dataGridView1.Rows[a].Cells["ISBN13"].Value.ToString(); if (isbn == "") @@ -301,17 +300,17 @@ namespace UniMarc else { dataGridView1.Rows[a].DefaultCellStyle.ForeColor = Color.Blue; - - if (this.marc != null) - this.marc.List_Book.Rows[idx].Cells["db_marc"].Value = st.made_Ori_marc(MakeMarc(marc)); - else if (this.mae != null) - this.mae.List_Book.Rows[idx].Cells["db_marc"].Value = st.made_Ori_marc(MakeMarc(marc)); + string processedMarc = st.made_Ori_marc(MakeMarc(marc)); + if (!BulkMarcResults.ContainsKey(idx)) + BulkMarcResults.Add(idx, processedMarc); } progressBar1.Value += 1; } MessageBox.Show("완료되었습니다!"); + this.DialogResult = DialogResult.OK; + this.Close(); } string MakeMarc(string text) diff --git a/unimarc/unimarc/마크/Marc_Plan.cs b/unimarc/unimarc/마크/Marc_Plan.cs index 2680e1c..9121a9f 100644 --- a/unimarc/unimarc/마크/Marc_Plan.cs +++ b/unimarc/unimarc/마크/Marc_Plan.cs @@ -270,7 +270,7 @@ namespace WindowsFormsApp1.Mac if (dataGridView1.Rows[row].Cells[col].ReadOnly) { - if (chkEditorTest.Checked) + if (chkEditorTest.Checked == false) { string[] Marc = { dataGridView1.Rows[row].Cells["marc"].Value.ToString(), @@ -364,6 +364,23 @@ namespace WindowsFormsApp1.Mac } f.OpenFillBlank(dataList, currentIsbn); }; + + f.BulkBooksUpdated += (s, args) => + { + foreach (var kvp in args.Updates) + { + int rowIdx = kvp.Key; + string newMarc = kvp.Value; + + // Ensure rowIdx is valid (it should be, as it came from 'a' loop index) + if (rowIdx >= 0 && rowIdx < dataGridView1.Rows.Count) + { + dataGridView1.Rows[rowIdx].Cells["marc"].Value = newMarc; + // Optional: Update color or status to indicate filled? + // Legacy code updated color. Marc_Plan might not enforce color rules yet, but setting value is key. + } + } + }; f.Show(); } diff --git a/unimarc/unimarc/마크/Marc_Plan_Sub_MarcEdit2.cs b/unimarc/unimarc/마크/Marc_Plan_Sub_MarcEdit2.cs index 3f3b081..bbf02a8 100644 --- a/unimarc/unimarc/마크/Marc_Plan_Sub_MarcEdit2.cs +++ b/unimarc/unimarc/마크/Marc_Plan_Sub_MarcEdit2.cs @@ -60,14 +60,35 @@ namespace UniMarc.마크 public void OpenFillBlank(List gridData, string currentIsbn) { - var fb = new UniMarc.Marc_FillBlank(this); + var fb = new UniMarc.Marc_FillBlank(); foreach (var rowData in gridData) { fb.InitFillBlank(rowData); } fb.ISBN = currentIsbn; - fb.Show(); + + if (fb.ShowDialog() == DialogResult.OK) + { + // Handle results + // We don't have direct access to 'BulkMarcResults' here easily unless we iterate. + // But wait, BookUpdated event is for single update. + // Marc_Plan expects 'RequestFillBlankData' to handle the *opening*, but it doesn't handle the *return* logic for bulk updates within Marc_Plan. + // The current architecture: Marc_Plan_Sub_MarcEdit2 raises RequestFillBlankData -> Marc_Plan calls OpenFillBlank. + // So now OpenFillBlank is running. When it returns, we have data. + // We need to pass this data BACK to Marc_Plan. + // I will add a 'BulkBooksUpdated' event or reuse 'BookUpdated' (but BookUpdated is single). + // Let's create 'BulkBooksUpdated'. + + BulkBooksUpdated?.Invoke(this, new BulkBookUpdatedEventArgs { Updates = fb.BulkMarcResults }); + } } + + public class BulkBookUpdatedEventArgs : EventArgs + { + public Dictionary Updates { get; set; } + } + + public event EventHandler BulkBooksUpdated; private void MarcEditorControl_FillBlankClicked(object sender, EventArgs e) {