public static CHITIETHOADON_DTO ThemChiTietHoaDon(BANG_CHITIETHOADON bcthd) { QuanLyShop = new QUANLYCUAHANGEntities(); bcthd = QuanLyShop.BANG_CHITIETHOADON.Add(bcthd); QuanLyShop.SaveChanges(); CHITIETHOADON_DTO cthdDTO = ConvertDTO(bcthd); return(cthdDTO); }
public static CHITIETHOADON_DTO ConvertDTO(BANG_CHITIETHOADON cthd) { CHITIETHOADON_DTO cthdDTO = new CHITIETHOADON_DTO(); cthdDTO.idhoadon = cthd.idhoadon; cthdDTO.idsanpham = cthd.idsanpham; cthdDTO.dongia = cthd.dongia; return(cthdDTO); }
/// <summary> /// Creates a new instance of the CHI_TIET_HOA_DON class and populates it with data from the specified SqlDataReader. /// </summary> private CHITIETHOADON_DTO MakeCHITIETHOADON_DTO(SqlDataReader dataReader) { CHITIETHOADON_DTO ChiTietHoaDon = new CHITIETHOADON_DTO(); ChiTietHoaDon.Ma = SqlClientUtility.GetInt32(dataReader, "MA", 0); ChiTietHoaDon.MaHoaDon = SqlClientUtility.GetInt32(dataReader, "MA_HOA_DON", 0); ChiTietHoaDon.MaXe = SqlClientUtility.GetInt32(dataReader, "MA_XE", 0); ChiTietHoaDon.MaMau = SqlClientUtility.GetString(dataReader, "MA_MAU", String.Empty); ChiTietHoaDon.SoLuong = SqlClientUtility.GetInt32(dataReader, "SO_LUONG", 0); ChiTietHoaDon.ThanhTien = SqlClientUtility.GetDecimal(dataReader, "THANH_TIEN", Decimal.Zero); return(ChiTietHoaDon); }
/// <summary> /// Selects all records from the CHI_TIET_HOA_DON table. /// </summary> public List <CHITIETHOADON_DTO> SelectAll() { using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(m_ConnectionString, CommandType.StoredProcedure, "PROC_ChiTietHoaDon_SelectAll")) { List <CHITIETHOADON_DTO> ChiTietHoaDonList = new List <CHITIETHOADON_DTO>(); while (dataReader.Read()) { CHITIETHOADON_DTO ChiTietHoaDon = MakeCHITIETHOADON_DTO(dataReader); ChiTietHoaDonList.Add(ChiTietHoaDon); } return(ChiTietHoaDonList); } }
/// <summary> /// Saves a record to the CHI_TIET_HOA_DON table. /// </summary> public void Insert(CHITIETHOADON_DTO ChiTietHoaDon) { ValidationUtility.ValidateArgument("ChiTietHoaDon", ChiTietHoaDon); SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MA_HOA_DON", ChiTietHoaDon.MaHoaDon), new SqlParameter("@MA_XE", ChiTietHoaDon.MaXe), new SqlParameter("@MA_MAU", ChiTietHoaDon.MaMau), new SqlParameter("@SO_LUONG", ChiTietHoaDon.SoLuong), new SqlParameter("@THANH_TIEN", ChiTietHoaDon.ThanhTien) }; ChiTietHoaDon.Ma = (int)SqlClientUtility.ExecuteScalar(m_ConnectionString, CommandType.StoredProcedure, "PROC_ChiTietHoaDon_Insert", parameters); }
private void ThemHoaDon() { if (grid_DanhSachXeMua.Rows.Count == 0) { MessageBox.Show("Chua có thông tin Xe mu?n mua", "Thi?u Thông Tin", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } HOADON_DTO HoaDon = new HOADON_DTO(); HoaDon.MaKhachHang = KhachHang.Ma; HoaDon.MaNhanVien = int.Parse(txt_ro_MaNhanVien.Text); HoaDon.NgayLap = DateTime.Today; if (combo_HinhThucThanToan.Text == "Thanh Toán 1 L?n") { HoaDon.SoLanTra = 0; HoaDon.KieuThanhToan = false; HoaDon.TienTraMoiDot = Decimal.Parse(txt_ro_TongTien.Text); } else { HoaDon.KieuThanhToan = true; HoaDon.SoLanTra = (int)updown_SoLanThanhToan.SelectedItem; HoaDon.TienTraMoiDot = Decimal.Parse(txt_ro_TongTien.Text) / Decimal.Parse(updown_SoLanThanhToan.Text); } HoaDon.TongTien = Decimal.Parse(txt_ro_TongTien.Text); new HOADON_BUS().Insert(HoaDon); CHITIETHOADON_BUS BUS_ChiTietHoaDon = new CHITIETHOADON_BUS(); foreach (DataGridViewRow Row in grid_DanhSachXeMua.Rows) { CHITIETHOADON_DTO ChiTietHoaDon = new CHITIETHOADON_DTO(); ChiTietHoaDon.MaMau = Row.Cells["MaMau"].Value.ToString(); ChiTietHoaDon.MaHoaDon = HoaDon.Ma; ChiTietHoaDon.MaXe = (int)Row.Cells["MaXe"].Value; ChiTietHoaDon.SoLuong = (int)Row.Cells["SoLuong"].Value; ChiTietHoaDon.ThanhTien = (Decimal)Row.Cells["ThanhTien"].Value; BUS_ChiTietHoaDon.Insert(ChiTietHoaDon); } MessageBox.Show("Ðã thêm Hoá Ðon", "Thông Báo", MessageBoxButtons.OK, MessageBoxIcon.Information); grid_DanhSachXeMua.Rows.Clear(); txt_ro_TongTienTruocThue.Text = "0"; txt_ro_TongTien.Text = "0"; txt_ro_Thue.Text = "0"; txt_ro_TienTraMoiDot.Text = "0"; }
/// <summary> /// Selects all records from the CHI_TIET_HOA_DON table by a foreign key. /// </summary> public List <CHITIETHOADON_DTO> SelectAllByMaXe(int MaXe) { SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("@MA_XE", MaXe) }; using (SqlDataReader dataReader = SqlClientUtility.ExecuteReader(m_ConnectionString, CommandType.StoredProcedure, "PROC_ChiTietHoaDonSelectAllByMaXe", parameters)) { List <CHITIETHOADON_DTO> ChiTietHoaDonList = new List <CHITIETHOADON_DTO>(); while (dataReader.Read()) { CHITIETHOADON_DTO ChiTietHoaDon = MakeCHITIETHOADON_DTO(dataReader); ChiTietHoaDonList.Add(ChiTietHoaDon); } return(ChiTietHoaDonList); } }
/// <summary> /// Updates a record in the CHI_TIET_HOA_DON table. /// </summary> public void Update(CHITIETHOADON_DTO ChiTietHoaDon) { ValidationUtility.ValidateArgument("ChiTietHoaDon", ChiTietHoaDon); new CHITIETHOADON_DAO().Update(ChiTietHoaDon); }