using System;
using System.Collections.Generic;
using Library;
using System.Linq;
using MySystem.MainModels;

namespace MySystem
{
    public class QrCodeTradeStat
    {
        public readonly static QrCodeTradeStat Instance = new QrCodeTradeStat();
        public QrCodeTradeStat()
        { }


        public decimal Amount(string SnNo)
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo);
            if (check)
            {
                amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo).Sum(m => m.TradeAmount);
            }
            db.Dispose();
            return amt;
        }

        public decimal Amount(string SnNo, string DateOrMonth)
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.TradeDate == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.TradeMonth == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            db.Dispose();
            return amt;
        }

        public int Count(string SnNo, string DateOrMonth)
        {
            int amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.TradeDate == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.TradeMonth == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            db.Dispose();
            return amt;
        }


        public decimal Amount(string SnNo, string DateOrMonth, int PayMode)
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeDate == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeMonth == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            db.Dispose();
            return amt;
        }

        public int Count(string SnNo, string DateOrMonth, int PayMode)
        {
            int amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeDate == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.TradeMonth == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            db.Dispose();
            return amt;
        }


        public decimal Amount(string SnNo, string DateOrMonth, int PayMode, int IsAct)
        {
            decimal amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeDate == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeMonth == DateOrMonth).Sum(m => m.TradeAmount);
                }
            }
            db.Dispose();
            return amt;
        }

        public int Count(string SnNo, string DateOrMonth, int PayMode, int IsAct)
        {
            int amt = 0;
            WebCMSEntities db = new WebCMSEntities();
            if(DateOrMonth.Length == 8)
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeDate == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeDate == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            else
            {
                bool check = db.QrCodeAmountSummay.Any(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeMonth == DateOrMonth);
                if (check)
                {
                    amt = db.QrCodeAmountSummay.Where(m => m.SnNo == SnNo && m.PayMode == PayMode && m.IsAct == IsAct && m.TradeMonth == DateOrMonth).Sum(m => m.TradeCount);
                }
            }
            db.Dispose();
            return amt;
        }

    }
}
