예제 #1
0
파일: History.cs 프로젝트: timka203/Ebaboba
        public DataTable GetTransactionsInfo(bool outcome, bool income, DateTime?dateBegin, DateTime?dateEnd, object type, object currency)
        {
            QueryLite query = new QueryLite(ConfigurationManager.ConnectionStrings["EbabobaConnectionString"].ConnectionString);

            query.Add($"select tt.Name 'Тип', concat((case h.IsIncome when 1 then '+' else '-' end), h.Sum) 'Cумма', c.Name 'Валюта', h.Date 'Дата' from History h " +
                      $"join Currency c on h.CurrencyId = c.CurrencyId " +
                      $"join TransactionType tt on tt.TransactionTypeId = h.TypeId ");
            var wheres = new Dictionary <string, string>();

            if (type != null)
            {
                wheres.Add("h.TypeId", type.ToString());
            }
            if (currency != null)
            {
                wheres.Add("h.Currencyid", currency.ToString());
            }
            if (dateEnd != null)
            {
                query.Add($" and '{dateEnd.ToString()}' > h.Date");
            }
            if (dateBegin != null)
            {
                query.Add($" and '{dateBegin.ToString()}' < h.Date");
            }
            if (outcome && income)
            {
                query.Add(" and h.IsIncome in (1, 0)");
            }
            else if (!outcome && income)
            {
                query.Add(" and h.IsIncome = 1");
            }
            else if (outcome && !income)
            {
                query.Add(" and h.IsIncome = 0");
            }

            query.AddWheres(wheres);
            var returnValue = query.ExecuteAndGet();

            query.Clear();
            return(returnValue);
        }