110 lines
3.8 KiB
C#
110 lines
3.8 KiB
C#
|
|
using DOAN.Model.MES.product;
|
|||
|
|
using DOAN.Model.MES.product.Dto;
|
|||
|
|
using Mapster;
|
|||
|
|
using Microsoft.Extensions.Configuration;
|
|||
|
|
using printsoftware.infrastructure.DAON_Attribute;
|
|||
|
|
using SqlSugar;
|
|||
|
|
using System.Configuration;
|
|||
|
|
using System.Data;
|
|||
|
|
using System.Reflection;
|
|||
|
|
|
|||
|
|
namespace printsoftware
|
|||
|
|
{
|
|||
|
|
public partial class Form1 : Form
|
|||
|
|
{
|
|||
|
|
private SqlSugarClient Context;
|
|||
|
|
public Form1()
|
|||
|
|
{
|
|||
|
|
InitializeComponent();
|
|||
|
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
var builder = new ConfigurationBuilder()
|
|||
|
|
.SetBasePath(Directory.GetCurrentDirectory())
|
|||
|
|
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true);
|
|||
|
|
|
|||
|
|
var _configuration = builder.Build();
|
|||
|
|
|
|||
|
|
|
|||
|
|
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
Context = new SqlSugarClient(new ConnectionConfig()
|
|||
|
|
{
|
|||
|
|
ConnectionString = _configuration.GetSection("ConnectionStrings:Conn").Value, // <20>滻Ϊ<E6BBBB><CEAA><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>
|
|||
|
|
DbType = (SqlSugar.DbType)int.Parse(_configuration.GetSection("ConnectionStrings:DbType").Value), // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ݿ<EFBFBD><DDBF><EFBFBD><EFBFBD>ͽ<EFBFBD><CDBD>и<EFBFBD><D0B8><EFBFBD>
|
|||
|
|
IsAutoCloseConnection = bool.Parse(_configuration.GetSection("ConnectionStrings:IsAutoCloseConnection").Value),
|
|||
|
|
InitKeyType = InitKeyType.Attribute // <20><>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ж<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>ѯ<EFBFBD><D1AF>ť <20><>ѯָ<D1AF><D6B8><EFBFBD><EFBFBD><EFBFBD>ڹ<EFBFBD><DAB9><EFBFBD>
|
|||
|
|
/// </summary>
|
|||
|
|
/// <param name="sender"></param>
|
|||
|
|
/// <param name="e"></param>
|
|||
|
|
private void button2_Click(object sender, EventArgs e)
|
|||
|
|
{
|
|||
|
|
DateTime startTime = this.dateTimePicker1.Value;
|
|||
|
|
DateTime endTime = this.dateTimePicker2.Value;
|
|||
|
|
string workorder = this.textBox1.Text;
|
|||
|
|
string workshop = this.textBox2.Text;
|
|||
|
|
string group = this.textBox3.Text;
|
|||
|
|
string route = this.textBox4.Text;
|
|||
|
|
List<ProWorkorderDto> data = Context.Queryable<ProWorkorder>()
|
|||
|
|
.Where(it => it.WorkorderDate >= startTime && it.WorkorderDate <= endTime)
|
|||
|
|
.WhereIF(!string.IsNullOrEmpty(workorder),it=>it.Workorder==workorder)
|
|||
|
|
.WhereIF(!string.IsNullOrEmpty(workshop),it=>it.WorkshopCode == workshop)
|
|||
|
|
.WhereIF(!string.IsNullOrEmpty(group),it=>it.GroupCode== group)
|
|||
|
|
.WhereIF(!string.IsNullOrEmpty(route),it=>it.RouteCode== route)
|
|||
|
|
.ToList().Adapt<List<ProWorkorderDto>>();
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
var dataTable = ToDataTable(data);
|
|||
|
|
|
|||
|
|
// <20><EFBFBD> DataGridView
|
|||
|
|
dataGridView1.DataSource = dataTable;
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
|
|||
|
|
private DataTable ToDataTable<T>(List<T> items)
|
|||
|
|
{
|
|||
|
|
DataTable dataTable = new DataTable(typeof(T).Name);
|
|||
|
|
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD>й<EFBFBD><D0B9><EFBFBD>ʵ<EFBFBD><CAB5><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
PropertyInfo[] Props = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance);
|
|||
|
|
|
|||
|
|
foreach (PropertyInfo prop in Props)
|
|||
|
|
{
|
|||
|
|
// <20><><EFBFBD><EFBFBD> SugarColumn <20><><EFBFBD><EFBFBD>
|
|||
|
|
var DOANColumnAttr = prop.GetCustomAttribute<DOAN_Column>();
|
|||
|
|
string columnName = DOANColumnAttr != null && !string.IsNullOrEmpty(DOANColumnAttr.ColumnName)
|
|||
|
|
? DOANColumnAttr.ColumnName
|
|||
|
|
: prop.Name;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD> DataColumns ʹ<>ô<EFBFBD><C3B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
dataTable.Columns.Add(columnName, Nullable.GetUnderlyingType(prop.PropertyType) ?? prop.PropertyType);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
foreach (T item in items)
|
|||
|
|
{
|
|||
|
|
var values = new object[Props.Length];
|
|||
|
|
for (int i = 0; i < Props.Length; i++)
|
|||
|
|
{
|
|||
|
|
// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>ֵ
|
|||
|
|
values[i] = Props[i].GetValue(item, null);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
dataTable.Rows.Add(values);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
return dataTable;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
}
|