private void bt_Ok_Click(object sender, EventArgs e) { if (tb_Desc.Text.Length == 0 || tb_Seq.Text.Length == 0) { MessageBox.Show("오류", "Modify", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { if (MessageBox.Show("수정하시겠습니까?", "Modify", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { string str_qu = "update userbricks set part_desc = @DESC, part_seq = @SEQ where part_name = '" + tb_Name.Text + "'"; OleDbCommand conm = new OleDbCommand(str_qu); conm.Parameters.AddWithValue("@DESC", tb_Desc.Text); conm.Parameters.AddWithValue("@SEQ", tb_Seq.Text.Replace("\r\n", "").Replace(" ", "")); connector.update_Data(conm); MessageBox.Show("수정됨"); this.Close(); } } }
// 기본 데이터 베이스 작성하기 private void BackgroundWorker2_DoWork(object sender, DoWorkEventArgs e) { try { downfile.Refresh(); try { this.Invoke(new MethodInvoker(delegate() { progressBar1.Style = ProgressBarStyle.Marquee; })); } catch (Exception ex) { Debug.WriteLine(ex.Message); } if (downfile.Exists) { string str_q = "select part_id from part;"; OleDbDataReader oddr = connector.select_Data(str_q); List <string> strl_Part_id = new List <string>(); while (oddr.Read()) { strl_Part_id.Add(oddr.GetInt32(0).ToString()); } FileStream fs = new FileStream(Path.Combine(Directory.GetCurrentDirectory(), downfile.Name), FileMode.Open, FileAccess.Read); StreamReader sr = new StreamReader(fs, Encoding.Default); string line; String[] str_Brickname; System.Text.RegularExpressions.Regex rx = new System.Text.RegularExpressions.Regex("\"" + @"[\w\W]*" + "\""); while ((line = sr.ReadLine()) != null) { if (line.StartsWith(">")) { str_Brickname = null; str_Brickname = line.Split(' '); // 만약 데이터베이스에 있다면 건너기 if (strl_Part_id.Contains(str_Brickname[2])) { // nothing; } // end if else { // 없다면 추가하기 string str_qu_insert_brick = "insert into part (part_id,part_name,part_short_desc,part_type) values (@ID, @NAME, @SDESC, @TYPE);"; OleDbCommand conm = new OleDbCommand(str_qu_insert_brick); conm.Parameters.AddWithValue("@ID", str_Brickname[2]); conm.Parameters.AddWithValue("@NAME", str_Brickname[0].Replace(">", "")); conm.Parameters.AddWithValue("@SD", rx.Match(line).ToString().Replace("\"", "")); conm.Parameters.AddWithValue("@TYPE", str_Brickname[3]); connector.update_Data(conm); } // end else } // end if } // end while } } catch (System.Exception ex) { Debug.WriteLine(ex.Message); } }