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();
|
}
|
}
|
|
}
|
}
|