Esempio n. 1
0
        /// <summary>
        /// 月始めから月終わりまでの週ごとの収入と支出データ取得
        /// </summary>
        /// <param name="start">月初め</param>
        /// <param name="end">月終わり</param>
        /// <returns>週ごとの収入と支出データ</returns>
        public static List <WeekDataList> SelectDisplayList(DateTime start, DateTime end, int userId)
        {
            List <WeekDataList> dataLists = new List <WeekDataList>();

            using (NpgSqlDBManager dBManager = new NpgSqlDBManager())
            {
                try
                {
                    //収入
                    string sql = "select * from public.\"WeekDataList\" where \"Id\" = 0"
                                 + " and \"FirstDate\" >= '" + start.ToString() + "'"
                                 + " and \"LastDate\" < '" + end.ToString() + "'"
                                 + " and \"userId\" = " + userId;

                    DataSet   dataSet = dBManager.GetDataSet(sql);
                    DataTable table   = dataSet.Tables[0];
                    if (table.Rows.Count < 1)
                    {
                        return(null);
                    }
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        WeekDataList weekData = new WeekDataList();
                        weekData.InitDataRow(table.Rows[i]);

                        dataLists.Add(weekData);
                    }

                    //支出
                    sql = "select * from public.\"WeekDataList\" where \"Id\" = 1"
                          + " and \"FirstDate\" >= '" + start.ToString() + "'"
                          + " and \"LastDate\" < '" + end.ToString() + "'"
                          + " and \"userId\" = " + userId;
                    dataSet = dBManager.GetDataSet(sql);
                    table   = dataSet.Tables[0];
                    if (table.Rows.Count < 1)
                    {
                        return(null);
                    }
                    for (int i = 0; i < table.Rows.Count; i++)
                    {
                        WeekDataList weekData = new WeekDataList();
                        weekData.InitDataRow(table.Rows[i]);

                        dataLists.Add(weekData);
                    }
                }
                catch
                {
                    dBManager.RollBack();
                    dBManager.Close();
                    OriginMBox.MBoxErrorOK(AppConst.WEEKDATA_MESSAGE);
                    return(null);
                }
            }
            return(dataLists);
        }
Esempio n. 2
0
        /// <summary>
        /// 週ごとの表示用データ作成
        /// </summary>
        /// <param name="dataLists">週ごとの収入と支出データ</param>
        /// <returns>表示用文字列データ作成</returns>
        public static List <string[]> GetDisplayDataList(List <WeekDataList> dataLists)
        {
            List <string[]> vs = new List <string[]>();

            try
            {
                if (dataLists == null)
                {
                    return(null);
                }
                //表示用データ作成
                List <WeekDataList> incomeDataList   = dataLists.Where(data => data.Id == 0).ToList();
                List <WeekDataList> spendingDataList = dataLists.Where(data => data.Id == 1).ToList();

                for (int i = 0; i < incomeDataList.Count; i++)
                {
                    WeekDataList weekData = incomeDataList[i];

                    WeekDataList spendingData = spendingDataList.
                                                Where(data => data.FirstDate == weekData.FirstDate &&
                                                      data.LastDate == weekData.LastDate).First();

                    string[] dataListStr =
                    {
                        weekData.FirstDate.ToString("yyyy/MM/dd") + "~" + weekData.LastDate.ToString("yyyy/MM/dd"),
                        weekData.WeekData.ToString(),
                        spendingData.WeekData.ToString()
                    };

                    vs.Add(dataListStr);
                }
            }
            catch
            {
                //string s = e.Message;
                OriginMBox.MBoxErrorOK(AppConst.WEEKDATA_MESSAGE);
                return(null);
            }
            return(vs);
        }
Esempio n. 3
0
        /// <summary>
        /// ベースデータから週ごとのデータ作成
        /// </summary>
        /// <param name="dataLists">ベースデータ</param>
        /// <param name="dateTimeLists">週の始まりと終わりのデータリスト</param>
        /// <returns></returns>
        public static List <WeekDataList> CreateWeekDataList(List <int[]> dataLists, List <DateTime[]> dateTimeLists, int userId)
        {
            List <WeekDataList> weekDataLists = new List <WeekDataList>();

            try
            {
                if (dataLists == null)
                {
                    return(null);
                }
                if (dateTimeLists == null)
                {
                    return(null);
                }

                int count = 0;
                foreach (var dateTimes in dateTimeLists)
                {
                    count = 0;
                    int income   = 0;
                    int spending = 0;
                    int startDay = dateTimes[0].Day;
                    int endDay   = dateTimes[1].Day;

                    //収入
                    for (int i = 0; i < dataLists[count].Length; i++)
                    {
                        if (i >= startDay && endDay >= i)
                        {
                            income += dataLists[count][i];
                        }
                    }

                    WeekDataList weekData = new WeekDataList
                    {
                        Id        = AppConst.INCOME_VALUE,
                        WeekData  = income,
                        FirstDate = dateTimes[0],
                        LastDate  = dateTimes[1],
                        UserId    = userId
                    };
                    weekDataLists.Add(weekData);

                    count++;
                    //支出
                    for (int i = 0; i < dataLists[count].Length; i++)
                    {
                        if (i >= startDay && endDay >= i)
                        {
                            spending += dataLists[count][i];
                        }
                    }

                    weekData = new WeekDataList
                    {
                        Id        = AppConst.SPENDING_VALUE,
                        WeekData  = spending,
                        FirstDate = dateTimes[0],
                        LastDate  = dateTimes[1],
                        UserId    = userId
                    };
                    weekDataLists.Add(weekData);
                }
            }
            catch
            {
                OriginMBox.MBoxErrorOK(AppConst.CALENDER_MESSAGE2);
                return(null);
            }
            return(weekDataLists);
        }