コード例 #1
0
        override public void showIncomePieChart(Anaytics view, Building apartment)
        {
            int receivedCount = 0, receivedSum = 0, totalSum = 0;
            string receivedQuery = "SELECT COUNT(*), SUM(" + Util.Tables.TABLE_INCOMING_TRANSACTIONS.KEY_AMOUNT + ") FROM FLATS_PAID WHERE " + Util.Tables.TABLE_INCOMING_TRANSACTIONS.KEY_APARTMENT_ID + " = '" + apartment.getID() + "' AND " + Util.Tables.TABLE_INCOMING_TRANSACTIONS.KEY_MONTH + " = '" + DBproject.miscFunctions.ToMonthName(DateTime.Now) + "' AND " + Util.Tables.TABLE_INCOMING_TRANSACTIONS.KEY_YEAR + " = " + DateTime.Now.Year;
            string totalQuery = "SELECT SUM(" + Util.Tables.TABLE_FLATS.KEY_MONTHLYFEE + ") FROM " + Util.Tables.TABLE_FLATS.TBL_FLATS + " WHERE " + Util.Tables.TABLE_EXPENSES.KEY_APARTMENT_ID + " = '" + apartment.getID() + "'";


            connection.Open();
            using (SqlCommand command = new SqlCommand(receivedQuery, connection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        try
                        {

                            receivedCount = (int)reader[0];
                            receivedSum = (int)reader[1];
                        }

                        catch
                        {

                        }
                    }
                }
            }
            connection.Close();

            connection.Open();
            using (SqlCommand command = new SqlCommand(totalQuery, connection))
            {
                using (SqlDataReader reader = command.ExecuteReader())
                {
                    while (reader.Read())
                    {
                        try
                        {
                            totalSum = (int)reader[0];
                            
                        }

                        catch
                        {

                        }
                    }
                }
            }
            connection.Close();
            view.showIncomeGraph(receivedCount, receivedSum, totalSum);


        }