Exemplo n.º 1
0
        private void btnThanhToan_Click(object sender, EventArgs e)
        {
            bool   kiemtra;
            string err = "";

            try
            {
                bool fHoaDon;
                fHoaDon = hoaDon.ThemHoaDonNhap(ref err, int.Parse(txtMaHD.Text),
                                                int.Parse(cbNhanVien.SelectedValue.ToString()), int.Parse(cbMaNoiCungCap.SelectedValue.ToString()),
                                                DateTime.Parse(dtNgayLap.Text), DateTime.Parse(dtNgayNhan.Text),
                                                decimal.Parse(txtTongTien.Text));
                if (fHoaDon == true)
                {
                    try
                    {
                        for (int i = 0; i < LvChiTiet.Items.Count; i++)
                        {
                            if (chiTiet.ThemChiTietHoaDonNhap(ref err, MangMaHoaDon[i], MangMaSanPham[i], MangSoLuong[i], MangGiaNhap[i]))
                            {
                                kiemtra = true;
                            }
                            else
                            {
                                kiemtra = false;
                                hoaDon.XoaHoaDonNhap(ref err, int.Parse(txtMaHD.Text));
                                MessageBox.Show(err, "Lỗi", MessageBoxButtons.OK, MessageBoxIcon.Error);

                                return;
                            }
                        }
                    }
                    catch
                    {
                        MessageBox.Show("Lỗi Khi Thêm Chi Tiết Hoá Đơn!!:");
                    }
                    DialogResult traLoi;
                    traLoi = MessageBox.Show("Đã Thêm Hoá Đơn Thành Công! Hãy Tạo Hoá Đơn Mới", "Thông Báo",
                                             MessageBoxButtons.OK, MessageBoxIcon.Question);
                    if (traLoi == DialogResult.OK)
                    {
                        for (int i = 0; i < LvChiTiet.Items.Count; i++)
                        {
                            MangMaHoaDon[i]  = 0;
                            MangMaSanPham[i] = 0;
                            MangGiaNhap[i]   = 0;
                        }
                        LvChiTiet.Items.Clear();
                        TaoHoaDonMoi();
                        LoadSanPham();
                    }
                    else
                    {
                        MessageBox.Show("Error: '" + err + "'", "Thông Báo",
                                        MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    }
                }
            }

            catch
            {
                MessageBox.Show("Hãy Điền Đầy Đủ Thông Tin Trên Hoá Đơn", "Thông Báo",
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }