Пример #1
0
        private void bt_them_Click(object sender, EventArgs e)
        {
            string ten = "";

            if (tb_ten.TextLength > 0)
            {
                ten = tb_ten.Text;
            }
            else
            {
                MessageBox.Show("Tên không được trống");
            }
            decimal gianhap = 0;
            decimal giaxuat = 0;

            try
            {
                gianhap = Convert.ToDecimal(tb_gianhap.Text.Trim());
                giaxuat = Convert.ToDecimal(tb_giaxuat.Text.Trim());
            }
            catch (Exception ex)
            {
                MessageBox.Show("giá phai nhập số");
            }
            string mota = "";

            if (tb_mota.TextLength > 0)
            {
                mota = tb_mota.Text.Trim();
            }
            int  id_danhmuc = Convert.ToInt16(cb_danhmuc.SelectedValue);
            int  id_nxb     = Convert.ToInt16(cb_nhaxb.SelectedValue);
            book b          = new book();

            b.id_danhmuc = id_danhmuc;
            b.id_nxb     = id_nxb;
            b.ten        = ten;
            b.mota       = mota;
            b.gianhap    = gianhap;
            b.giaxuat    = giaxuat;
            b.img        = img;
            bool kq = SachService.InsertBook(b);

            if (kq)
            {
                MessageBox.Show("Tạo thành công");
                loadSach();
            }
            else
            {
                MessageBox.Show("Tạo thất bại");
            }
        }