private void btnLuu_Click(object sender, EventArgs e)
        {
            obj.MaSach     = txtMaSach.Text;
            obj.TenSach    = txtTenSach.Text;
            obj.TenTG      = txtTenTG.Text;
            obj.GiaMua     = txtGiaMua.Text;
            obj.GiaBan     = txtDonGia.Text;
            obj.SoLuongKho = int.Parse(txtSoLuong.Text);
            obj.Mota       = txtMota.Text;
            obj.MaNXB      = cbNXB.EditValue.ToString();
            obj.MaTheLoai  = cbTheLoai.EditValue.ToString();

            if (IsInsert == true)
            {
                bus.Insert(obj);
                XtraMessageBox.Show("Thêm thành công");
                if (LamMoi != null)
                {
                    LamMoi(sender, e);
                }
                this.Close();
            }
            else
            {
                bus.Update(obj);
                XtraMessageBox.Show("Sửa thành công");
                if (LamMoi != null)
                {
                    LamMoi(sender, e);
                }
                this.Close();
            }
        }
Example #2
0
        private void ThemMoi()
        {
            Sach sach_moi = new Sach();

            sach_moi.TenSach    = this.textBox_tenSach.Text;
            sach_moi.TacGia     = this.textBox_tacGia.Text;
            sach_moi.TheLoai    = this.textBox_theLoai.Text;
            sach_moi.TomTat     = this.textBox_tomTat.Text;
            sach_moi.SoLuong    = int.Parse(this.textBox_soLuong.Text);
            sach_moi.NamXuatBan = int.Parse(this.textBox_namXuatBan.Text);
            switch (sach_moi.isValid())
            {
            case 0:
                if (SachBUS.Insert(sach_moi))
                {
                    foreach (Control i in this.Controls)
                    {
                        if (i is TextBox || i is MaskedTextBox || i is ComboBox)
                        {
                            i.Text = "";
                        }
                    }
                    if (MessageBox.Show("Đã thêm thành công") == DialogResult.OK)
                    {
                        this.DialogResult = DialogResult.OK;
                        this.Close();
                    }
                }
                else
                {
                    MessageBox.Show("Thất bại");
                    this.DialogResult = DialogResult.No;
                }
                break;

            case 1:
                MessageBox.Show("VUI LÒNG NHẬP TÊN SÁCH");
                break;

            case 2:
                MessageBox.Show("VUI LÒNG NHẬP TÊN TÁC GIẢ");
                break;

            case 3:
                MessageBox.Show("SỐ LƯỢNG PHẢI LỚN HƠN 0");
                break;

            case 4:
                MessageBox.Show("VUI LÒNG NHẬP THỂ LOẠI");
                break;

            case 5:
                MessageBox.Show("VUI LÒNG NHẬP TÓM TẮT");
                break;
            }
        }
Example #3
0
        private void btnThemSach_Click(object sender, EventArgs e)
        {
            try
            {
                if (tbxTenSach.Text == "")
                {
                    MessageBox.Show("Phải nhập tựa sách");
                    return;
                }
                if (cmbNgonNgu.Text == "")
                {
                    MessageBox.Show("Phải chọn ngôn ngữ");
                    return;
                }
                if (cmbTenTG.Text == "")
                {
                    MessageBox.Show("Phải chọn tác giả");
                    return;
                }
                if (comboBox4.Text == "")
                {
                    MessageBox.Show("Phải chọn nhà xuất bản");
                    return;
                }
                if (cmbLoaiSach.Text == "")
                {
                    MessageBox.Show("Phải chọn loại sách");
                    return;
                }
                if (textBox2.Text == "")
                {
                    MessageBox.Show("Phải nhập số trang");
                    return;
                }
                DialogResult result = MessageBox.Show("Bạn có chắc là muốn thực hiện tác vụ này không",
                                                      "Question",
                                                      MessageBoxButtons.YesNo,
                                                      MessageBoxIcon.Question,
                                                      MessageBoxDefaultButton.Button1);
                if (result == DialogResult.Yes)
                {
                    DateTime date;
                    int      matg;
                    int      manxb;
                    int      maloai;
                    int      mann;
                    matg   = (cmbTenTG.SelectedItem as TacGiaDTO).MaTG;
                    manxb  = (comboBox4.SelectedItem as NhaXuatBanDTO).MaNXB;
                    maloai = (cmbLoaiSach.SelectedItem as TheLoaiDTO).MaLoai;
                    mann   = (cmbNgonNgu.SelectedItem as NgonNguDTO).MaNgonNgu;

                    date = DateTime.Now.Date;
                    string  temp = Convert.ToString(date.Month) + "/" + Convert.ToString(date.Day) + "/" + Convert.ToString(date.Year);
                    SachDTO sach = new SachDTO();
                    sach.TenSach   = tbxTenSach.Text;
                    sach.MaTacGia  = matg;
                    sach.MaTheLoai = maloai;
                    sach.MaNXB     = manxb;
                    sach.MaNgonNgu = mann;
                    sach.TrangThai = 0;
                    sach.NgayNhap  = Convert.ToDateTime(temp);
                    sach.SoTrang   = int.Parse(textBox2.Text);
                    SachBUS sb = new SachBUS();
                    sb.Insert(sach);
                    MessageBox.Show("Thêm thành công");
                    tbxTenSach.Text  = "";
                    textBox2.Text    = "";
                    cmbNgonNgu.Text  = "";
                    cmbLoaiSach.Text = "";
                    cmbTenTG.Text    = "";
                    comboBox4.Text   = "";
                }
                else
                {
                    return;
                }
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }