コード例 #1
0
ファイル: frmSanPham.cs プロジェクト: tranchiduong1/Testing
        private void btThem_Click(object sender, EventArgs e)
        {
            try
            {
                string MaSP, TenSP, MaLSP, SLTK, DGN, DGB;
                MaSP  = txtMaSP.Text;
                TenSP = txtTenSP.Text;
                MaLSP = cboMaLSP.SelectedValue.ToString();
                SLTK  = txtSLTonKho.Text;
                DGN   = txtDGNhap.Text;
                DGB   = txtDGBan.Text;

                SanPhamDTO sanpham = new SanPhamDTO(MaSP, TenSP, MaLSP, SLTK, DGN, DGB);

                if (string.IsNullOrEmpty(txtMaSP.Text))

                {
                    MessageBox.Show("Vui lòng nhập mã sản phẩm cần thêm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                int numOfRows = sanphamBUS.Add(sanpham);
                if (numOfRows > 0)
                {
                    MessageBox.Show("Thêm thành công", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    Reset();
                }
                GridSP.DataSource = sanphamBUS.GetSanPham();
            }
            catch
            {
                MessageBox.Show("Thêm thất bại, trùng mã sản phẩm", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
                Reset();
            }
        }
コード例 #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            string id, name, unit, unitprice;

            id        = txtMaSP.Text;
            name      = txtTenSP.Text;
            unit      = txtDvt.Text;
            unitprice = txtDonGia.Text;
            SanPham p = new SanPham(id, name, unit, unitprice);

            int NumberOfRows = SPBUS.Add(p);

            if (NumberOfRows > 0)
            {
                List <SanPham> list = SPBUS.LoadSanPham();
                dgvSanPham.DataSource = list;
                MessageBox.Show("Thêm " + NumberOfRows + " sản phẩm thành công");
            }
            else
            {
                MessageBox.Show("Thêm thất bại");
            }
        }