Exemple #1
0
        private void btnThem2_Click(object sender, EventArgs e)
        {
            try
            {
                string mahd = "";
                if (cboHoaDon.SelectedIndex != -1)
                {
                    mahd = cboHoaDon.SelectedValue.ToString();
                }
                string masp = "";
                if (cboMaSP.SelectedIndex != -1)
                {
                    masp = cboMaSP.SelectedValue.ToString();
                }
                decimal dongia = 0;
                if (txtDonGia.Text != string.Empty)
                {
                    dongia = Convert.ToDecimal(txtDonGia.Text);
                }
                int soluong = int.Parse(txtSoLuong.Text.ToString());

                decimal tongtien = 0;
                if (txtTongTien.Text != string.Empty)
                {
                    tongtien = decimal.Parse(txtTongTien.Text);
                }
                int soluong_tonkho = 0;
                if (txtSLHientai.Text != string.Empty)
                {
                    soluong_tonkho = int.Parse(txtSLHientai.Text);
                }
                // kt xem có bị bỏ trống không
                if (mahd != string.Empty && cboHoaDon.SelectedIndex != -1 && masp != string.Empty &&
                    cboMaSP.SelectedIndex != -1)
                {
                    DialogResult result;
                    result = MessageBox.Show("Bạn Có Muốn Thêm Vào Hóa Đơn " + mahd + "?",
                                             "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button2);
                    if (result == DialogResult.Yes)
                    {
                        // thêm chi tiết hóa đơn
                        if (hd_bll.KiemTraTrung_CTHD(mahd, masp) == true)
                        {
                            if (soluong > 0 && soluong <= soluong_tonkho)
                            {
                                hd_bll.ThemChiTiet_HoaDon(mahd, masp, soluong, dongia, tongtien);
                                MessageBox.Show("Thêm Thành Công Vào Hóa Dơn " + mahd, "Thông báo");
                                Clear_CTHD();
                                loadData_CTHD(mahd);
                                // update số lượng sản phẩm lại nè
                                int soluong_hientai = soluong_tonkho - soluong;
                                hd_bll.updateSanPham_saukhiThemCTD(masp, soluong_hientai);
                                // update lại tổng tiền của hóa đơn
                                txtTienCanThanhToan.Text = Convert.ToString(laydata_thanhtien());
                                Clear_CTHD();
                            }
                            else
                            {
                                MessageBox.Show("Sai Sô Lượng ", "Thông báo");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Hóa Đơn Đã Tồn Tại Sản Phẩm " + masp, "Thông báo");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Có Thông Tin Chưa Được Nhập", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {
                MessageBox.Show("Có Vấn Đề Trong Việc Thêm Vào Hóa Đơn", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }