Esempio n. 1
0
        /// <summary>
        /// 円グラフ表示用データを取得
        /// </summary>
        /// <returns>円グラフ表示用データを取得</returns>
        private List <StatisticsData> GetStatisticsDataList()
        {
            Configuration config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
            int           userId = int.Parse(config.AppSettings.Settings["UserId"].Value);
            // ベースDBからデータ取得処理
            List <HouseholdABookBase.HouseholdABook> dataList = FindHouseholdABookList();

            if (dataList == null || dataList.Count <= 0)
            {
                return(new List <StatisticsData>());
            }

            AppConst.StatisticsInfo statisticsInfo = FindStatisticsInfo(dataList, userId);
            if (statisticsInfo == null)
            {
                return(new List <StatisticsData>());
            }

            //グラフ表示用データを作成or更新
            List <StatisticsData> statisticsDataList = StatisticsData.UpsertDataList(statisticsInfo);

            if (statisticsDataList == null || statisticsDataList.Count <= 0)
            {
                return(new List <StatisticsData>());
            }

            return(statisticsDataList);
        }
Esempio n. 2
0
        /// <summary>
        /// 日付の指定によって統計情報取得
        /// </summary>
        /// <returns>統計確認情報</returns>
        private AppConst.StatisticsInfo FindStatisticsInfo(List <HouseholdABookBase.HouseholdABook> bookList, int userId)
        {
            AppConst.StatisticsInfo statisticsInfo = new AppConst.StatisticsInfo();
            statisticsInfo.UserId = userId;

            if (!DTPickerBreakdown.Visible && !DTPickerBreakdown02.Visible)
            {
                return(null);
            }
            else if (DTPickerBreakdown.Visible && !DTPickerBreakdown02.Visible)
            {
                statisticsInfo.BookList = bookList;
                //月間
                if (CbPeriod.SelectedIndex == (int)PeriodType.Monthly)
                {
                    statisticsInfo.StartDate = new DateTime(DTPickerBreakdown.Value.Year, DTPickerBreakdown.Value.Month, 1);
                    if (statisticsInfo.StartDate.Month >= 12)
                    {
                        statisticsInfo.EndDate = new DateTime(DTPickerBreakdown.Value.AddYears(1).Year, DTPickerBreakdown.Value.AddMonths(1).Month, 1);
                    }
                    else
                    {
                        statisticsInfo.EndDate = new DateTime(DTPickerBreakdown.Value.Year, DTPickerBreakdown.Value.AddMonths(1).Month, 1);
                    }
                }
                //年間
                else if (CbPeriod.SelectedIndex == (int)PeriodType.Year)
                {
                    statisticsInfo.StartDate = new DateTime(DTPickerBreakdown.Value.Year, 1, 1);
                    statisticsInfo.EndDate   = new DateTime(DTPickerBreakdown.Value.AddYears(1).Year, 1, 1);
                }

                if (bookList.Count <= 0)
                {
                    statisticsInfo.Id = AppConst.INCOME_VALUE;
                }
                else
                {
                    statisticsInfo.Id = bookList[0].idStr == AppConst.INCOME ? AppConst.INCOME_VALUE : AppConst.SPENDING_VALUE;
                }
            }
            //期間指定
            else if (DTPickerBreakdown.Visible && DTPickerBreakdown02.Visible)
            {
                statisticsInfo.BookList  = bookList;
                statisticsInfo.StartDate = DateTime.Parse(DTPickerBreakdown.Value.ToShortDateString());
                statisticsInfo.EndDate   = DateTime.Parse(DTPickerBreakdown02.Value.ToShortDateString());
                if (bookList.Count <= 0)
                {
                    statisticsInfo.Id = AppConst.INCOME_VALUE;
                }
                else
                {
                    statisticsInfo.Id = bookList[0].idStr == AppConst.INCOME ? AppConst.INCOME_VALUE : AppConst.SPENDING_VALUE;
                }
            }

            return(statisticsInfo);
        }
        /// <summary>
        /// 円グラフのデータ作成 or 更新
        /// </summary>
        /// <param name="statisticsInfo">統計確認情報</param>
        /// <returns>統計確認データ</returns>
        public static List <StatisticsData> UpsertDataList(AppConst.StatisticsInfo statisticsInfo)
        {
            try
            {
                int id = statisticsInfo.Id;
                List <HouseholdABookBase.HouseholdABook> householdABookList = statisticsInfo.BookList;
                DateTime start  = statisticsInfo.StartDate;
                DateTime end    = statisticsInfo.EndDate;
                int      userId = statisticsInfo.UserId;

                List <StatisticsData> dataList = SelectStatisticsDataList(id, start, end, userId);
                if (dataList != null && dataList.Count > 0)
                {
                    if (!UpdateStatisticsData(householdABookList, start, end, userId))
                    {
                        return(null);
                    }
                }
                else
                {
                    if (!InsertStatisticsData(householdABookList, start, end, userId))
                    {
                        return(null);
                    }
                }

                dataList = SelectStatisticsDataList(id, start, end, userId);

                return(dataList);
            }
            catch (Exception e)
            {
                string s = e.Message;
                OriginMBox.MBoxErrorOK(AppConst.STATISTICS_MESSAGE2);
                return(null);
            }
        }