You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CaiQie/DB/Service/ReadBufLogService.cs

115 lines
3.3 KiB
C#

6 days ago
using Chloe;
using DB.Entity;
using System;
using System.Collections.Generic;
6 days ago
using System.Data;
6 days ago
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tool;
namespace DB.Service
{
public class ReadBufLogService
{
public PagedList<ReadBufLog> GetPagedList(int pageIndex, int pageSize, string category,DateTime beDateTime,DateTime endTime)
{
PagingResult<ReadBufLog> pagePagingResult;
using (var dbContext = DbFactory.GetContext)
{
pagePagingResult = dbContext.Query<ReadBufLog>()
6 days ago
.Where(x => x.CreateTime >= beDateTime)
.Where(x => x.CreateTime <= endTime)
6 days ago
.Where(x=>x.Category==category)
.OrderByDesc(x => x.ID)
.Paging(pageIndex, pageSize);
}
PagedList<ReadBufLog> paged =
new PagedList<ReadBufLog>(pagePagingResult.DataList,
pagePagingResult.Totals.ToInt(), pageIndex, pageSize);
return paged;
}
6 days ago
public DataTable GetDtaTable(string category, DateTime beDateTime, DateTime endTime)
{
string text = "";
switch (category)
{
case "A":
text = "收料1";
break;
case "B":
text = "收料2";
break;
case "C":
text = "废料";
break;
}
DataTable table = new DataTable();
table.Columns.Add("条码", typeof(string));
table.Columns.Add("类型", typeof(string));
table.Columns.Add("时间", typeof(string));
using (var dbContext = DbFactory.GetContext)
{
var List = dbContext.Query<ReadBufLog>()
.Where(x => x.CreateTime >= beDateTime)
.Where(x => x.CreateTime <= endTime)
.Where(x => x.Category == category)
.OrderByDesc(x => x.ID).ToList();
foreach (var str in List)
{
var dataRow = table.NewRow();
dataRow[0] = str.BarCode;
dataRow[1] = text;
dataRow[2] = str.CreateTime.ToFullString();
table.Rows.Add(dataRow);
}
}
return table;
}
6 days ago
public void Insert(string category, string barCode)
{
using (var dbContext = DbFactory.GetContext)
{
var entity= dbContext.Query<ReadBufLog>()
.Where(x => x.Category == category)
.Where(x => x.BarCode == barCode)
.OrderBy(x => x.ID)
.Select(x => x.BarCode).FirstOrDefault();
if (string.IsNullOrEmpty(entity))
{
ReadBufLog log = new ReadBufLog();
log.CreateTime=DateTime.Now;
log.ID = SnowflakeFactory.NewId;
log.Category = category;
log.BarCode = barCode;
dbContext.Insert(log);
}
}
}
}
}