示例#1
0
        private void ThemHoaDon()
        {
            DTO.HoaDon hoadon = new DTO.HoaDon()
            {
                Ma          = txtMaHD.Text,
                Khachhangma = txtMaKH.Text,
                Nhanvienma  = txtMaNV.Text,
                Ngaylap     = dtpNgayLap.Value,
                Tongtien    = decimal.Parse(labTongTien.Text.Split(' ')[2])
            };
            if (hoadon.Them() == 1)
            {
                for (int i = 0; i < dgvCTHD.Rows.Count; i++)
                {
                    DTO.ChiTietHoaDon chitiet = new DTO.ChiTietHoaDon()
                    {
                        Hoadonma  = hoadon.Ma,
                        Mathangma = dgvCTHD.Rows[i].Cells[0].Value.ToString(),
                        Soluong   = (double)dgvCTHD.Rows[i].Cells[3].Value,
                        Giaban    = (decimal)dgvCTHD.Rows[i].Cells[4].Value
                    };
                    chitiet.Them();
                    DTO.MatHang.Update_SoLuongMatHang(chitiet.Mathangma);
                }

                Clear_InputHoaDon();

                MessageBox.Show("Đã thêm", "", MessageBoxButtons.OK);
            }
        }