public static void themHD(string MHD, string MKH, DateTime ngayTT, int tien, List <ChiTietHoaDonDTO> arrHD) { OleDbConnection link = null; try { link = KetNoi(); string chuoiLenh = "insert into HoaDon(MaHoaDon,MaKH,NgayThanhToan,ThanhTien) values (@MHD,@MKH,@NTT,@tien)"; OleDbCommand lenh = new OleDbCommand(chuoiLenh, link); OleDbParameter thamso = new OleDbParameter("@MHD", OleDbType.LongVarChar); thamso.Value = MHD; lenh.Parameters.Add(thamso); thamso = new OleDbParameter("@MKH", OleDbType.LongVarChar); thamso.Value = MKH; lenh.Parameters.Add(thamso); thamso = new OleDbParameter("@NTT", OleDbType.Date); thamso.Value = ngayTT; lenh.Parameters.Add(thamso); thamso = new OleDbParameter("@tien", OleDbType.Integer); thamso.Value = tien; lenh.Parameters.Add(thamso); lenh.ExecuteNonQuery(); OleDbDataAdapter Adapter = new OleDbDataAdapter(); Adapter.InsertCommand = lenh; for (int i = 0; i < arrHD.Count; i++) { HoaDonDAO.themCTPT(MHD, arrHD[i].Phieuthue.MaPhieuThue, arrHD[i].SoNgayThue, arrHD[i].TienThue, arrHD[i].TongCong); } } catch { } finally { if (link != null && link.State == System.Data.ConnectionState.Open) { link.Close(); } } }
public static List <HoaDonDTO> layDSHoaDon() { OleDbConnection link = null; List <HoaDonDTO> dsHoaDon = new List <HoaDonDTO>(); try { link = KetNoi(); string chuoiLenh = "select * from HoaDon "; OleDbCommand lenh = new OleDbCommand(chuoiLenh, link); OleDbDataReader Doc = lenh.ExecuteReader(); while (Doc.Read()) { HoaDonDTO hd = new HoaDonDTO(); hd.MaHD = Doc.GetString(0); hd.MaKH = Doc.GetString(1); hd.NgayTT = Doc.GetDateTime(2); hd.Thanhtien = Doc.GetInt32(3); List <ChiTietHoaDonDTO> cthd = new List <ChiTietHoaDonDTO>(); cthd = HoaDonDAO.layCTHD(hd.MaHD); hd.DsCTHD = cthd; dsHoaDon.Add(hd); } } catch (Exception ex) { dsHoaDon = new List <HoaDonDTO>(); } finally { if (link != null && link.State == System.Data.ConnectionState.Open) { link.Close(); } } return(dsHoaDon); }