Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:

C#
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.
Posted
Updated 24-Nov-14 4:38am
v4
Comments
syed shanu 24-Nov-14 19:14pm    
I think you need to select the distinct and use group by in select query to avoid the duplicate values
Member 11162082 24-Nov-14 22:19pm    
Hi! Distinct in this case doesn't help and if I use group by, it only shows one record/payment per ID, and I need them all. I think I'll try a different approach since this might be a little too difficult to accomplish.

Thanks for answering anyway!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900