/// <summary> /// Initializes a DataAccessFacade for accessing a MS SQL database /// </summary> /// <param name="test">For integration tests, set test = true to use test database</param> public DataAccessFacade(bool test = false) { if (!test) { //take the database information from a textfile. connectionString = File.ReadAllText("C:\\ConnectString.txt"); } else { connectionString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=LTTEST;Integrated Security=True"; } //Creates a new instance of the mappers with the connection information paymentMapper = new PaymentMapper(connectionString); customerMapper = new CustomerMapper(connectionString); supplierMapper = new SupplierMapper(connectionString); bookingMapper = new BookingMapper(connectionString); paymentRuleMapper = new PaymentRuleMapper(connectionString); PartyMapper partyMapper = new PartyMapper(); partyMapper.CustomerMapper = customerMapper; partyMapper.SupplierMapper = supplierMapper; paymentMapper.PartyMapper = partyMapper; bookingMapper.CustomerMapper = customerMapper; bookingMapper.SupplierMapper = supplierMapper; paymentRuleMapper.CustomerMapper = customerMapper; paymentRuleMapper.SupplierMapper = supplierMapper; customerMapper.ReadAll(); supplierMapper.ReadAll(); }
protected override PaymentEntity entityFromReader(SqlDataReader reader) { //Reads the different columns from the database and set them to corresponding data type in the program. DateTime dueDate = (DateTime)reader["DueDate"]; decimal dueAmount = (decimal)reader["DueAmount"]; DateTime paidDate = (DateTime)reader["PaidDate"]; decimal paidAmount = (decimal)reader["PaidAmount"]; bool paid = (bool)reader["Paid"]; bool archived = (bool)reader["Archived"]; string attachments = (string)reader["Attachments"]; int payerId = (int)reader["Payer"]; int payeeId = (int)reader["Payee"]; string note = (string)reader["Note"]; PaymentType type = (PaymentType)Enum.Parse(typeof(PaymentType), reader["Type"].ToString()); string sale = (string)reader["Sale"]; int booking = (int)reader["Booking"]; string invoice = (string)reader["Invoice"]; int id = (int)reader["PaymentId"]; DateTime lastModified = (DateTime)reader["LastModified"]; bool deleted = (bool)reader["Deleted"]; APartyEntity payer = PartyMapper.Read(payerId); APartyEntity payee = PartyMapper.Read(payeeId); PaymentEntity paymentEntity = new PaymentEntity(dueDate, dueAmount, payer, payee, type, sale, booking); paymentEntity.PaidDate = paidDate; paymentEntity.PaidAmount = paidAmount; paymentEntity.Paid = paid; paymentEntity.Archived = archived; if (attachments != "") { foreach (string attachment in attachments.Split(';')) { paymentEntity.AddAttachment(attachment); } } paymentEntity.Note = note; paymentEntity.Invoice = invoice; paymentEntity.Id = id; paymentEntity.LastModified = lastModified; paymentEntity.Deleted = deleted; return(paymentEntity); }