示例#1
0
    protected void ButtonGenerateChart_Click(object sender, EventArgs e)
    {
        moneyReceived = new List<decimal>();
        tenantPaid = new Dictionary<string, decimal>();
        months = new List<long>();
        int beginYear = Convert.ToInt32(DropDownListBeginYear.SelectedValue);
        int beginMonth = QuickPM.Util.ConvertMonthToInt(DropDownListBeginMonth.SelectedValue);
        int endYear = Convert.ToInt32(DropDownListEndYear.SelectedValue);
        int endMonth = QuickPM.Util.ConvertMonthToInt(DropDownListEndMonth.SelectedValue);
        QuickPM.Period beginPeriod = new QuickPM.Period(beginYear, beginMonth);
        QuickPM.Period endPeriod = new QuickPM.Period(endYear, endMonth);
        if (endMonth == beginMonth && endYear == beginYear)
        {
            endPeriod = endPeriod.AddMonth();
        }
        int property;
        if (Request["PropertyId"] == null)
        {
            string selectedValue = this.PropertyList.SelectedValue;
            string[] tmp = selectedValue.Split(new char[] { ' ' });
            property = Convert.ToInt32(tmp[0]);
        }
        else
        {
            property = Convert.ToInt32(Request["PropertyId"]);
        }
        this.property = new QuickPM.Property(property);

        for (QuickPM.Period p = beginPeriod; p <= endPeriod; p = p.AddMonth())
        {
            months.Add((new DateTime(p.Year, p.Month, 1).Ticks) - (new DateTime(1970, 1, 1).Ticks));
            decimal received = 0;

            List<string> profileIds = new List<string>(QuickPM.Database.GetPropertyTenantIds(this.property.Id, p));
            foreach (string profileId in profileIds)
            {
                QuickPM.Tenant tenant = new QuickPM.Tenant(profileId);
                string shortName = tenant.GetShortName();
                List<QuickPM.Check> checks = QuickPM.Database.GetChecks(profileId, p);
                List<QuickPM.NSFCheck> nsfChecks = QuickPM.Database.GetNSFChecks(profileId, p);
                foreach (QuickPM.Check c in checks)
                {
                    received += c.Amount;
                    if (!tenantPaid.ContainsKey(shortName))
                    {
                        tenantPaid[shortName] = 0m;
                    }
                    tenantPaid[shortName] += c.Amount;
                }
                foreach (QuickPM.NSFCheck n in nsfChecks)
                {
                    received += n.Amount;
                    if (!tenantPaid.ContainsKey(shortName))
                    {
                        tenantPaid[shortName] = 0m;
                    }
                    tenantPaid[shortName] += n.Amount;
                }

            }
            moneyReceived.Add(received);
        }
        CreateTenantList();
    }