Esempio n. 1
0
        // them sach moi
        private void buttonSave_Click(object sender, EventArgs e)
        {
            if (textBoxBookTitle.Text == "" || comboBoxAuthor.Text == "" || comboBoxPublisher.Text == "" || comboBoxCategory.Text == "" || textBoxPrice.Text == "")
            {
                MessageBox.Show("Hãy nhập đầy đủ các thông tin !");
            }
            else if (int.TryParse(textBoxPrice.Text, out _) == false)
            {
                MessageBox.Show("Dữ liệu giá bán phải là số !");
                textBoxPrice.Text = "";
            }
            else
            {
                SachDao dao  = new SachDao();
                var     book = new Sach()
                {
                    TenSach = textBoxBookTitle.Text,
                    GiaBan  = int.Parse(textBoxPrice.Text),
                    //SoLuongTon = int.Parse(textBoxQuantity.Text),
                    SoLuongTon = 0,
                    MaNXB      = int.Parse(textBoxPublisherID.Text),
                    MaCD       = int.Parse(textBoxCategoryID.Text)
                };
                var res = dao.insertBook(book.TenSach, book.GiaBan, book.SoLuongTon, book.MaNXB, book.MaCD);

                textBoxBookID.Text = dao.getIdBookByName(book.TenSach).ToString();
                // return về cái BookID and AuthorID de tao ThamGia
                ThamGiaDao tgd  = new ThamGiaDao();
                var        ress = tgd.insertThamGia(int.Parse(textBoxBookID.Text), int.Parse(textBoxAuthorID.Text));


                if (res > 0 && ress > 0)
                {
                    MessageBox.Show("Thêm thành công !");
                    clearAll();
                }
                else
                {
                    MessageBox.Show("Chưa thêm được !");
                }
            }
        }