chenzx
2025-01-20 f914946689e613f1dfeb4dfe91f5797764245332
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using CommonHelper;
using Dapper;
using GasolineBlend.Entity;
using Google.Protobuf.WellKnownTypes;
using Microsoft.Office.Interop.Excel;
using MySql.Data.MySqlClient;
using static System.Net.Mime.MediaTypeNames;
 
namespace GasolineBlend.DAL
{
    public class AnnualPolicyDAL : BaseMySQLDAL
    {
        public List<AnnualPolicyPage> GetAnnualPolicyList(int Year, int Month, string Title, string Region, string Category, int PageNum, int PageSize)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var sql = $"SELECT * FROM annualpolicy WHERE startdate >= '{Year}-{Month}-01' AND startdate <= '{Year}-{Month}-31'  ";
                if (!string.IsNullOrEmpty(Title))
                {
                    sql += $" and title like '%{Title.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(Region))
                {
                    sql += $" and region like '%{Region.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(Category))
                {
                    sql += $" and category like '%{Category.Trim()}%' ";
                }
                int offset = (PageNum - 1) * PageSize;
                sql += $" ORDER BY startdate ASC  LIMIT {PageSize} OFFSET {offset}";
 
                return connection.Query<AnnualPolicyPage>(sql).ToList();
            }
        }
      
        public int GetAnnualPolicyCount(int Year, int Month, string Title, string Region, string Category)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var sql = $"SELECT  COUNT(*) FROM annualpolicy WHERE startdate >= '{Year}-{Month}-01' AND startdate <= '{Year}-{Month}-31'  ";
                if (!string.IsNullOrEmpty(Title))
                {
                    sql += $" and title like '%{Title.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(Region))
                {
                    sql += $" and region like '%{Region.Trim()}%' ";
                }
                if (!string.IsNullOrEmpty(Category))
                {
                    sql += $" and category like '%{Category.Trim()}%' ";
                }
                sql += $"  ORDER BY startdate ASC ";
                int Count = connection.Query<int>(sql).FirstOrDefault();
                return Count;
            }
        }
 
        public List<AnnualPolicyPage> GetAnnualPolicySumList(int Year, string City)
        {
            using (IDbConnection connection = new MySqlConnection(connectionString))
            {
                var sql = $"SELECT DATE_FORMAT(startdate, '%Y-%m') AS month,COUNT(*) AS monthcount FROM annualpolicy WHERE startdate >= '{Year}-01-01' AND startdate < '{Year+1}-01-01' ";
 
                if (!string.IsNullOrEmpty(City))
                {
                    sql += $" and region = '{City.Trim()}' ";
                }
                sql += $"  GROUP BY DATE_FORMAT(startdate, '%Y-%m') ORDER BY month ";
                return connection.Query<AnnualPolicyPage>(sql).ToList();
            }
        }
 
    }
}