private void table_CellClick(object sender, DataGridViewCellEventArgs e) { try { bookUpdateAndDelete.Enabled = true; BookDTO bookDTO = bookDAO.selectBook(int.Parse(table.Rows[table.CurrentRow.Index].Cells[0].Value.ToString())); Bitmap sourceImage = new Bitmap((Environment.CurrentDirectory.ToString().Substring(0, Environment.CurrentDirectory.ToString().LastIndexOf("\\bin"))) + bookDTO.B_img.Replace("\\source\\repos\\bookPjt\\bookPjt", "")); sourceImage = UtilClass.imgResize(sourceImage, 337, 164); subBookImg.Image = sourceImage; txtTitle.Text = bookDTO.B_name; txtAuthor.Text = bookDTO.B_author; txtPublisher.Text = bookDTO.B_puBlisher; txtDate.Text = bookDTO.B_date; txtCategory.Text = bookDTO.B_category; txtStatus.Text = bookDTO.B_status; } catch (Exception a) { } }
private void button10_Click(object sender, EventArgs e) { try { int.Parse(bookStock.Text); } catch (Exception a) { MessageBox.Show("수량을 다시 입력해주세요."); bookStock.Focus(); return; } if (bookName.Text.Trim() == "") { MessageBox.Show("도서 명을 입력해주세요."); bookName.Focus(); } else if (Regex.IsMatch(bookName.Text, @"[^a-zA-Z0-9가-힣]")) { MessageBox.Show("도서 명에 특수문자가 포함되어 있습니다."); bookName.Focus(); } else if (bookAuthor.Text.Trim() == "") { MessageBox.Show("저자를 입력해주세요."); bookAuthor.Focus(); } else if (Regex.IsMatch(bookAuthor.Text, @"[^a-zA-Z0-9가-힣]")) { MessageBox.Show("저자에 특수문자가 포함되어 있습니다."); bookAuthor.Focus(); } else if (bookStock.Text.Trim() == "") { MessageBox.Show("수량을 입력해주세요."); bookStock.Focus(); } else if (publisher.Text.Trim() == "") { MessageBox.Show("출판사를 선택해주세요."); publisher.Focus(); } else if (category.Text.Trim() == "") { MessageBox.Show("카테고리를 선택해주세요."); category.Focus(); } else if (bookGuest.Text.Trim() == "") { MessageBox.Show("연령 제한을 선택해주세요."); bookGuest.Focus(); } else if (bookContent.Text.Trim() == "") { MessageBox.Show("줄거리를 입력해주세요."); bookContent.Focus(); } else if (Regex.IsMatch(bookContent.Text, @"[^a-zA-Z0-9가-힣]")) { MessageBox.Show("줄거리에 특수문자가 포함되어 있습니다."); bookContent.Focus(); } else if (bookImg.Text.Trim() == "") { MessageBox.Show("이미지를 선택해주세요."); btnAddImg.Focus(); } else if (bookImg.Text.Substring(bookImg.Text.Length - 3) != "jpg") { MessageBox.Show("이미지는 jpg 형식만 첨부 가능합니다."); btnAddImg.Focus(); } else { if (MessageBox.Show("정말 도서를 등록하시겠습니까?", "도서 등록", MessageBoxButtons.YesNo) == DialogResult.Yes) { string realPath = "\\\\source\\\\repos\\\\bookPjt\\\\bookPjt\\\\Resources\\\\BookImg"; string imgPath = bookImg.Text.ToString().Replace("\\", "\\\\"); string fileName = imgPath.Substring(imgPath.LastIndexOf("\\\\")); string copyPath = Environment.CurrentDirectory.ToString().Replace("\\bin\\Debug", "\\Resources\\BookImg") + fileName; try { BookDTO bookDTO = new BookDTO(replaceAll(bookName.Text), replaceAll(bookAuthor.Text), replaceAll(publisher.Text), replaceAll(category.Text), replaceAll(bookContent.Text), (realPath + fileName), int.Parse(bookStock.Text), replaceAll(bookGuest.Text)); bookDAO.insertBook(bookDTO); } catch (Exception a) { MessageBox.Show("도서 추가 중 문제가 발생했습니다."); } try { File.Copy(@imgPath, @copyPath); } catch (Exception a) { } finally { MessageBox.Show("도서 등록 완료"); clearText(); selectList(); TabControll.SelectedIndex = 0; } } } }
private void button10_Click(object sender, EventArgs e) { try { int.Parse(bookStock.Text); } catch (Exception a) { MessageBox.Show("수량을 다시 입력해주세요."); bookStock.Focus(); return; } if (bookName.Text == "") { MessageBox.Show("도서 명을 입력해주세요."); bookName.Focus(); } else if (bookAuthor.Text == "") { MessageBox.Show("저자를 입력해주세요."); bookAuthor.Focus(); } else if (bookStock.Text == "") { MessageBox.Show("수량을 입력해주세요."); bookStock.Focus(); } else if (publisher.Text == "") { MessageBox.Show("출판사를 선택해주세요."); publisher.Focus(); } else if (category.Text == "") { MessageBox.Show("카테고리를 선택해주세요."); category.Focus(); } else if (bookGuest.Text == "") { MessageBox.Show("연령 제한을 선택해주세요."); bookGuest.Focus(); } else if (bookContent.Text == "") { MessageBox.Show("줄거리를 입력해주세요."); bookContent.Focus(); } else if (bookImg.Text == "") { MessageBox.Show("이미지를 선택해주세요."); btnAddImg.Focus(); } else { string realPath = "\\\\source\\\\repos\\\\bookPjt\\\\bookPjt\\\\Resources\\\\BookImg"; string imgPath = bookImg.Text.ToString().Replace("\\", "\\\\"); string fileName = imgPath.Substring(imgPath.LastIndexOf("\\\\")); string copyPath = Environment.CurrentDirectory.ToString().Replace("\\bin\\Debug", "\\Resources\\BookImg") + fileName; try { BookDTO bookDTO = new BookDTO(bookName.Text, bookAuthor.Text, publisher.Text, category.Text, bookContent.Text, (realPath + fileName), int.Parse(bookStock.Text), bookGuest.Text); bookDAO.insertBook(bookDTO); } catch (Exception a) { MessageBox.Show("도서 추가 중 문제가 발생했습니다."); } try { File.Copy(@imgPath, @copyPath); } catch (Exception a) { } finally { MessageBox.Show("도서 등록 완료"); clearText(); BookDAO.dbStatus = 1; selectList(); TabControll.SelectedIndex = 0; } } }
public bool insertBook(BookDTO bookDTO) { MySqlConnection mySqlConnection = new MySqlConnection(dbInfo); mySqlConnection.Open(); MySqlTransaction trans = mySqlConnection.BeginTransaction(); string b_name = bookDTO.B_name; string b_author = bookDTO.B_author; string b_publisher = bookDTO.B_puBlisher; string b_category = bookDTO.B_category; string b_summery = bookDTO.B_summary; string b_img = bookDTO.B_img; int b_stock = bookDTO.B_stock; string b_guest = "0"; if (bookDTO.B_guest == "전체 이용") { b_guest = "0"; } else if (bookDTO.B_guest == "12세 이용") { b_guest = "12"; } else if (bookDTO.B_guest == "15세 이용") { b_guest = "15"; } else if (bookDTO.B_guest == "성인") { b_guest = "19"; } try { string sql = "insert into book values (NULL,'" + b_name + "'," + b_stock + ",'" + b_author + "','" + b_summery + "','" + b_img + "','" + b_guest + "',now())"; MySqlCommand mysqlCommand = new MySqlCommand(sql, mySqlConnection); mysqlCommand.ExecuteNonQuery(); int categoryNum = resultCategory(b_category); int publisherNum = resultPublisher(b_publisher); sql = "insert into category values (" + categoryNum + ",NULL)"; mysqlCommand = new MySqlCommand(sql, mySqlConnection); mysqlCommand.ExecuteNonQuery(); sql = "insert into publisher values (" + publisherNum + ",NULL)"; mysqlCommand = new MySqlCommand(sql, mySqlConnection); mysqlCommand.ExecuteNonQuery(); trans.Commit(); mySqlConnection.Close(); } catch (Exception e) { trans.Rollback(); MessageBox.Show(e.Message); } return(true); }