Пример #1
0
        private void btnLuu_Click(object sender, EventArgs e)
        {
            if (txtTenSP.Text.Trim() == string.Empty)
            {
                txtTenSP.Focus();
                MessageBox.Show("bạn chưa nhập tên sản phẩm");
                return;
            }
            if (cboLoaiSP.SelectedValue.ToString() == null)
            {
                cboLoaiSP.Focus();
                MessageBox.Show("Bạn chưa chọn loại sản phẩm");
                return;
            }
            if (cboNCC.SelectedValue.ToString() == null)
            {
                cboNCC.Focus();
                MessageBox.Show("Bạn chưa chọn nhà cung cấp");
                return;
            }
            if (txtGiaNhap.Text.Trim() == string.Empty)
            {
                txtGiaNhap.Focus();
                MessageBox.Show("Bạn chưa nhập giá nhập của sản phẩm");
                return;
            }
            if (txtGiaBanLe.Text.Trim() == string.Empty)
            {
                txtGiaBanLe.Focus();
                MessageBox.Show("Bạn chưa nhập giá bán lẻ của sản phẩm");
                return;
            }
            if (txtGiaBanSi.Text.Trim() == string.Empty)
            {
                txtGiaBanSi.Focus();
                MessageBox.Show("Bạn chưa nhập giá bán sỉ của sản phẩm");
                return;
            }

            SAN_PHAM p = new SAN_PHAM();

            p.MASP     = txtMaSP.Text.Trim();
            p.TEN_SP   = txtTenSP.Text;
            p.MALOAI   = cboLoaiSP.SelectedValue.ToString().Trim();
            p.MANCC    = cboNCC.SelectedValue.ToString().Trim();
            p.MANSX    = cboNSX.SelectedValue.ToString().Trim();
            p.MAUSAC   = txtMauSac.Text;
            p.DVT      = txtDVT.Text;
            p.GIANHAP  = double.Parse(txtGiaNhap.Text.Trim());
            p.GIABANSI = double.Parse(txtGiaBanSi.Text.Trim());
            p.GIABANLE = double.Parse(txtGiaBanLe.Text.Trim());
            p.MOTASP   = txtGhiChu.Text;
            if (spdal.ThemSanPham(p))
            {
                dataGV_SanPham.DataSource = spdal.Load_DL();
                groupControl1.Enabled     = false;
                btnLuu.Enabled            = false;
                MessageBox.Show("Thêm thành công");
            }
            else
            {
                MessageBox.Show("Thêm thất bại");
            }
        }