Skip to content

Commit

Permalink
Merge pull request #37 from StevenKight/feature/rent-furniture
Browse files Browse the repository at this point in the history
Feature/rent furniture
  • Loading branch information
Cwill124 committed Oct 30, 2023
2 parents af57cce + c299eed commit ebec1f0
Show file tree
Hide file tree
Showing 22 changed files with 2,103 additions and 586 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,19 @@ public class FurnitureDAL
{
public static IList<Furniture> GetFurniture()
{
var furnitureList = new List<Furniture>();

using var connection = new MySqlConnection(Connection.ConnectionString);

var result = connection.Query<Furniture>(QueryStrings.GetFurniture);

foreach (var furniture in result) furnitureList.Add(furniture);
return furnitureList;
return result.ToList();
}

public static IList<Furniture> GetFurnitureById(int id)
{
var list = new List<Furniture>();

using var connection = new MySqlConnection(Connection.ConnectionString);

var result = connection.Query<Furniture>(QueryStrings.GetFurnitureById,new {id = id});

foreach (var furniture in result)
{
list.Add(furniture);
}
return list;
return result.ToList();
}

public static IList<Furniture> GetFurnitureByCategory(string category)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static class QueryStrings

#region Customer

public const string GetCustomerById = "select * from customer where member_id=@Id";

public const string GetCustomers = "select * from customer";

public const string CreateCustomer =
Expand Down Expand Up @@ -103,4 +105,37 @@ public static class QueryStrings
"insert into furniture(category_name,style_name,`name`,`description`,rental_rate,fine_rate,quantity) values(@Category,@Style,@Name,@Description,@Rental_rate,@Fine_rate,@Quantity)";

#endregion

#region Rental

public const string GetRentalById = "select * from `rental` where rental_id=@Id";

public const string GetRentalItems = "select * from `rental_item` where rental_id=@Id";

public const string GetRentalTotal = "SELECT SUM(`furniture`.rental_rate * `rental_item`.quantity) " +
"FROM `rental_item`, `furniture` " +
"WHERE `rental_item`.furniture_id=`furniture`.furniture_id " +
"AND `rental_item`.rental_id = @Id " +
"GROUP BY `rental_item`.rental_id";

public static string GetRentalId = "SELECT rental_id " +
"FROM `rental` " +
"WHERE member_id = @Member_id " +
"AND employee_num = @Employee_num " +
"AND `start_date` = @Start_date";

public static string CreateRental = "INSERT INTO `rental`(member_id, employee_num, `start_date`, due_date)" +
"VALUES (@Member_id, @Employee_num, @Start_date, @Due_date);";

public static string CreateRentalItem = "INSERT INTO `rental_item`(rental_id, furniture_id, quantity)" +
"VALUES (" +
"(SELECT rental_id " +
"FROM `rental` " +
"WHERE member_id = @Member_id " +
"AND employee_num = @Employee_num " +
"AND `start_date` = @Start_date " +
"AND due_date = @Due_date), " +
"@Furniture_id, @Quantity);";

#endregion
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
using Dapper;
using MySql.Data.MySqlClient;
using RentMeFurnitureRentalSystem.model;
using RentMeFurnitureRentalSystem.Model;

namespace RentMeFurnitureRentalSystem.DAL;

public class RentalDAL
{

public static RentalItem GetRentalById(int id)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var results = connection.Query<RentalItem>(QueryStrings.GetRentalById, new { Id = id });

return results.ElementAt(0);
}

public static List<RentalItem> GetRentalItems(int rentalId)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var results = connection.Query<RentalItem>(QueryStrings.GetRentalItems, new { Id = rentalId });

return results.ToList();
}

public static decimal GetRentalTotal(int rentalId)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var results = connection.QuerySingle<decimal>(QueryStrings.GetRentalTotal, new { Id = rentalId });

return results;
}

public static int GetRentalId(RentalItem rental)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var result = connection.Query<int>(QueryStrings.GetRentalId, rental);

try
{
return result.ElementAt(0);
}
catch
{
return -1;
}
}

public static bool CreateRental(RentalItem rental)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var affected = connection.Execute(QueryStrings.CreateRental, rental);

return affected > 0;
}

public static bool CreateRentalItem(RentalItem rentalItem)
{
using var connection = new MySqlConnection(Connection.ConnectionString);
connection.Open();

var affected = connection.Execute(QueryStrings.CreateRentalItem, rentalItem);

return affected > 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public class Customer
{
#region Properties

public string Fullname => this.Fname + " " + this.Lname;

public int Member_id { get; set; }
public string Fname { get; set; }
public string Lname { get; set; }
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Customer" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>RentMeFurnitureRentalSystem.Model.Customer, RentMeFurnitureRentalSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Employee" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>RentMeFurnitureRentalSystem.model.Employee, RentMeFurnitureRentalSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
This file is automatically generated by Visual Studio. It is
used to store generic object data source configuration information.
Renaming the file extension or editing the content of this file may
cause the file to be unrecognizable by the program.
-->
<GenericObjectDataSource DisplayName="Furniture" Version="1.0" xmlns="urn:schemas-microsoft-com:xml-msdatasource">
<TypeInfo>RentMeFurnitureRentalSystem.model.Furniture, RentMeFurnitureRentalSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null</TypeInfo>
</GenericObjectDataSource>
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,10 @@
<PackageReference Include="MySql.Data" Version="8.1.0" />
</ItemGroup>

<ItemGroup>
<Compile Update="view\RentalReceiptForm.cs">
<SubType>Form</SubType>
</Compile>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ public class Employee
{
#region Properties

public string Fullname => this.Fname + " " + this.Lname;
public int Employee_num { get; set; }
public string Username { get; set; }
public string Password { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,18 @@ public class Furniture
public int Quantity { get; set; }

#endregion

public override bool Equals(object? obj)
{
if (obj == null)
{
return false;
}
if (obj.GetType() != typeof(Furniture))
{
return false;
}

return this.Furniture_id == ((Furniture)obj).Furniture_id;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace RentMeFurnitureRentalSystem.model
{
public class RentalItem
{
public int Member_id { get; set; }
public int Employee_num { get; set; }
public DateTime Start_date { get; set; }
public DateTime Due_date { get; set; }
public int Furniture_id { get; set; }
public int Quantity { get; set; }
}
}
Loading

0 comments on commit ebec1f0

Please sign in to comment.