コード例 #1
0
        private void btnThem_Click(object sender, EventArgs e)
        {
            try
            {
                if (txtMaPN.Text != "" && dtNgayNhap.IsEmpty != true)
                {
                    phieuNhapDTO.MaPN     = Convert.ToInt32(txtMaPN.Text);
                    phieuNhapDTO.NgayNhap = Convert.ToDateTime(dtNgayNhap.Value);

                    if (!(pnBLL.CheckID(phieuNhapDTO.MaPN)))
                    {
                        int check = pnBLL.InsertPN(phieuNhapDTO);

                        if (check == 1)
                        {
                            dgvPN.DataSource = pnBLL.getAllPN();
                            dgvPN.Show();
                        }
                        else
                        {
                            MessageBox.Show("Thêm không thành công");
                        }
                    }
                    else
                    {
                        MessageBox.Show("Mã phiếu nhập " + phieuNhapDTO.MaPN + " đã tồn tại.", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
                else
                {
                    MessageBox.Show("Các trường không được để trống !");
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Thêm bị lỗi ! " + ex.Message.ToString(), "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }