protected override void WndProc(ref Message m) { try { switch (m.Msg) { case WM_COPYDATA: DBUtils.DBBook dBBook = new DBUtils.DBBook(); dBBook.bookDataGridViewConnect(dataGridView1); sendInsertSuccessMessage(); //COPYDATASTRUCT cds = (COPYDATASTRUCT)m.GetLParam(typeof(COPYDATASTRUCT)); //byte[] buff = System.Text.Encoding.Default.GetBytes(cds.lpData); //COPYDATASTRUCT cs = new COPYDATASTRUCT(); //cs.dwData = new IntPtr(0); //cs.cbData = buff.Length; //cs.lpData = cds.lpData; // 다시 보낼 Form2의 windows 헨들을 가져 온다. //IntPtr hwnd = FindWindow(null, "Form2"); //SendMessage(hwnd, WM_COPYDATA, IntPtr.Zero, ref cs); break; default: base.WndProc(ref m); break; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void borrow(DataGridView bookDataGridView, DataGridView userDataGridView, int userId, string userName, int bookId, string bookName, string bookIsbn) { checkTooManyBorrowed(userId); if(tooManyBorrowed == 1) { MessageBox.Show("한번에 3권이상은 대여불가입니다."); return; } checkBorrowed(bookId); if(isBorrowed == 1) { MessageBox.Show("이미 대여중인 도서는 대여가 불가능합니다."); return; } connection = new MySqlConnection("server=localhost;user id=root;password=root1234;persistsecurityinfo=True;port=3306;database=lib;SslMode=none"); string borrowBookQuery = "UPDATE books SET userId = @userId, userName = @userName, isBorrowed = 1, borrowedAt = @borrowedAt, returnedAt = @returnedAt WHERE id = @bookId"; MySqlCommand bookCmd = new MySqlCommand(borrowBookQuery, connection); bookCmd.Parameters.AddWithValue("@userId", userId); bookCmd.Parameters.AddWithValue("@userName", userName); bookCmd.Parameters.AddWithValue("@borrowedAt", DateTime.Now); bookCmd.Parameters.AddWithValue("@returnedAt", DateTime.Now.AddDays(7)); bookCmd.Parameters.AddWithValue("@bookId", bookId); string borrowUserQuery = "UPDATE users SET borrowedNumber = borrowedNumber + 1 WHERE id = @userId"; MySqlCommand userCmd = new MySqlCommand(borrowUserQuery, connection); userCmd.Parameters.AddWithValue("@userId", userId); string borrowHistoryQuery = "INSERT INTO history (userId, userName, borrowedAt, bookName, bookIsbn) VALUES (@userId, @userName, @borrowedAt, @bookname, @bookIsbn)"; MySqlCommand historyCmd = new MySqlCommand(borrowHistoryQuery, connection); historyCmd.Parameters.AddWithValue("@userId", userId); historyCmd.Parameters.AddWithValue("@userName", userName); historyCmd.Parameters.AddWithValue("@borrowedAt", DateTime.Now); historyCmd.Parameters.AddWithValue("@bookName", bookName); historyCmd.Parameters.AddWithValue("@bookIsbn", bookIsbn); try { connection.Open(); bookCmd.ExecuteNonQuery(); userCmd.ExecuteNonQuery(); historyCmd.ExecuteNonQuery(); DBBook dBBook = new DBBook(); DBUser dBUser = new DBUser(); dBBook.bookDataGridViewConnect(bookDataGridView); dBUser.userDataGridViewConnect(userDataGridView); } catch(Exception exception) { MessageBox.Show("책을 대여하는데 실패."); } finally { if(connection != null) { connection.Close(); } } }
public void returnBook(DataGridView bookDataGridView, DataGridView userDataGridView, int bookId, int userId, string bookIsbn) { checkBorrowed(bookId); if (isBorrowed == 0) { MessageBox.Show("대여중이지 않은 도서는 반납할수 없습니다."); return; } connection = new MySqlConnection("server=localhost;user id=root;password=root1234;persistsecurityinfo=True;port=3306;database=lib;SslMode=none"); string bookReturnQuery = "UPDATE books SET userId = null, userName = null, isBorrowed = 0, borrowedAt = null, returnedAt = null WHERE id = @bookId"; MySqlCommand bookCmd = new MySqlCommand(bookReturnQuery, connection); bookCmd.Parameters.AddWithValue("@bookId", bookId); string userReturnQuery = "UPDATE users SET borrowedNumber = borrowedNumber - 1 WHERE id = @userId"; MySqlCommand userCmd = new MySqlCommand(userReturnQuery, connection); userCmd.Parameters.AddWithValue("@userId", userId); string historyReturnQuery = "UPDATE history SET returnedAt = @returnedAt WHERE userId = @userId AND bookIsbn = @bookIsbn"; MySqlCommand historyCmd = new MySqlCommand(historyReturnQuery, connection); historyCmd.Parameters.AddWithValue("@returnedAt", DateTime.Now); historyCmd.Parameters.AddWithValue("@userId", userId); historyCmd.Parameters.AddWithValue("@bookIsbn", bookIsbn); try { connection.Open(); bookCmd.ExecuteNonQuery(); userCmd.ExecuteNonQuery(); historyCmd.ExecuteNonQuery(); DBBook dBBook = new DBBook(); DBUser dBUser = new DBUser(); dBBook.bookDataGridViewConnect(bookDataGridView); dBUser.userDataGridViewConnect(userDataGridView); } catch (Exception exception) { MessageBox.Show("반납하는데 실패."); } finally { if (connection != null) { connection.Close(); } } }
public Form1() { InitializeComponent(); Text = "도서관 관리"; DBUtils.DBUser dBUser = new DBUtils.DBUser(); DBUtils.DBBook dBBook = new DBUtils.DBBook(); // 라벨 설정 //label5.Text = DataManager.Books.Count.ToString(); label5.Text = dBBook.getBookCount().ToString(); label6.Text = dBUser.getUserCount().ToString(); label7.Text = DataManager.Books.Where((x) => x.isBorrowed).Count().ToString(); label8.Text = DataManager.Books.Where((x) => { return(x.isBorrowed && x.BorrowedAt.AddDays(7) > DateTime.Now); }).Count().ToString(); // 데이터 그리드 설정 //dataGridView1.DataSource = DataManager.Books; dBBook.bookDataGridViewConnect(dataGridView1); dataGridView1.ReadOnly = true; //dataGridView2.DataSource = DataManager.Users; dBUser.userDataGridViewConnect(dataGridView2); dataGridView2.ReadOnly = true; dataGridView1.CurrentCellChanged += DataGridView1_CurrentCellChanged; dataGridView2.CurrentCellChanged += DataGridView2_CurrentCellChanged; // 버튼 이벤트 설정 //button1.Click += Button1_Click; button1.Click += borrowButtonClick; //button2.Click += Button2_Click; button2.Click += returnBook; // 대여 및 반납기록 클릭 이벤트 대여및반납기록ToolStripMenuItem.Click += ShowHistoryForm; }
public Form2() { InitializeComponent(); Text = "도서 관리"; DBUtils.DBBook dBBook = new DBUtils.DBBook(); // 데이터 그리드 설정 //dataGridView1.DataSource = DataManager.Books; dBBook.bookDataGridViewConnect(dataGridView1); dataGridView1.ReadOnly = true; dataGridView1.CurrentCellChanged += DataGridView1_CurrentCellChanged; dataGridView1.CellDoubleClick += cellDoubleClick; // 버튼 설정 button1.Click += insertNewBook; //button1.Click += messageTesting; //button1.Click += (sender, e) => //{ //// 추가 버튼 //try // { // if (DataManager.Books.Exists((x) => x.Isbn == textBox1.Text)) // { // MessageBox.Show("이미 존재하는 도서입니다"); // } // else // { // Book book = new Book() // { // Isbn = textBox1.Text, // Name = textBox2.Text, // Publisher = textBox3.Text, // Page = int.Parse(textBox4.Text) // }; // DataManager.Books.Add(book); // dataGridView1.DataSource = null; // dataGridView1.DataSource = DataManager.Books; // DataManager.Save(); // } // } // catch (Exception exception) // { // } //}; button2.Click += updateButtonClick; // += (sender, e) => //{ // //BookUpdateForm updateForm = new BookUpdateForm(); // //updateForm.ShowDialog(); // // 수정 버튼 // //try // //{ // // Book book = DataManager.Books.Single((x) => x.Isbn == textBox1.Text); // // book.Name = textBox2.Text; // // book.Publisher = textBox3.Text; // // book.Page = int.Parse(textBox4.Text); // // dataGridView1.DataSource = null; // // dataGridView1.DataSource = DataManager.Books; // // DataManager.Save(); // //} // //catch (Exception exception) // //{ // // MessageBox.Show("존재하지 않는 도서입니다"); // //} //}; button3.Click += removeSelectedBook; //button3.Click += (sender, e) => //{ // // 수정 버튼 // try // { // Book book = DataManager.Books.Single((x) => x.Isbn == textBox1.Text); // DataManager.Books.Remove(book); // dataGridView1.DataSource = null; // dataGridView1.DataSource = DataManager.Books; // DataManager.Save(); // } // catch (Exception exception) // { // MessageBox.Show("존재하지 않는 도서입니다"); // } //}; searchButton.Click += getSearchedBooks; searchCategoryCombo.Items.Add("isbn"); searchCategoryCombo.Items.Add("책 이름"); searchCategoryCombo.Items.Add("출판사"); searchCategoryCombo.SelectedIndex = 0; searchAllButton.Click += searchAll; getDelayedButton.Click += getDelayedButtonClick; }
private void searchAll(object sender, EventArgs e) { DBUtils.DBBook dBBook = new DBUtils.DBBook(); dBBook.bookDataGridViewConnect(dataGridView1); }