Hello! So I'm working on a rent management software. It's for a residential complex so the manager can register the payments made by the tenants, etc. To keep track of the month being paid, I store the year/month value in a field like this:
If it is November, 2014 -> MonthPaid = 201411 | December would be 201412
The payments are stored in a table (Payments) with a foreign key to the TenantID in another table (Rent), which also stores the number of apartament (AptID) of every tenant.
The issue is that I'm trying to display in a ListView the payments in the corresponding ListView Column (by month). If there are no payments in a specified month (ex. April 20144), then it should show a message, for now, "Deuda" in the respective ListView Column (Abril, in this example). This is what I have so far:
http://i.imgur.com/G4Pubkz.jpg
And this is the expected result:
http://i.imgur.com/80oU8cN.jpg
And this is the code I'm working with right now:
using (SQLiteConnection conn = new SQLiteConnection(cs.connstring))
{
using (SQLiteCommand cmd = new SQLiteCommand("select AptID,MonthPaid from Rent inner join Payments on Rent.TenantID = Payments.TenantID", conn))
{
conn.Open();
using (SQLiteDataReader dr = cmd.ExecuteReader())
{
while (dr.Read())
{
ListViewItem item = new ListViewItem(dr["AptID"].ToString());
if (dr["MonthPaid"].ToString() == "20141")
{
item.SubItems.Add(dr["MonthPaid"].ToString());
}
else
{
item.SubItems.Add("Deuda");
}
if (dr["MonthPaid"].ToString() == "20142")
{
item.SubItems.Add(dr["MonthPaid"].ToString());
}
else
{
item.SubItems.Add("Deuda");
}
if (dr["MonthPaid"].ToString() == "20143")
{
item.SubItems.Add(dr["MonthPaid"].ToString());
}
else
{
item.SubItems.Add("Deuda");
}
if (dr["MonthPaid"].ToString() == "20144")
{
item.SubItems.Add(dr["MonthPaid"].ToString());
}
else
{
item.SubItems.Add("Deuda");
}
lstMesesTodos.Items.Add(item);
}
}
}
}
Any idea of how I can accomplish this or a different approach? I just need to show the payments made by the tenants and I thought of doing something like that.
And I tried using a DataGridView, but I coulnd't show more than one record.