84 lines
2.1 KiB
C#
84 lines
2.1 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using Thermo.Active.Model.DatabaseModels;
|
|
using static Thermo.Active.Config.ServerConfig;
|
|
|
|
namespace Thermo.Active.Database.Controllers
|
|
{
|
|
public class HistorySheetsController : IDisposable
|
|
{
|
|
private DatabaseContext dbCtx;
|
|
|
|
public HistorySheetsController()
|
|
{
|
|
// Initialize database context
|
|
dbCtx = new DatabaseContext();
|
|
}
|
|
|
|
public void Dispose()
|
|
{
|
|
dbCtx.Dispose();
|
|
}
|
|
|
|
public HistorySheetModel Create(string recipe, short piece, float value1, float value2, float value3, ushort typeval)
|
|
{
|
|
HistorySheetModel mod = new HistorySheetModel()
|
|
{
|
|
DtEvent = DateTime.Now,
|
|
RecipeName = recipe,
|
|
NumDone = piece,
|
|
FirstVal = value1,
|
|
SecondVal = value2,
|
|
ThirdVal = value3,
|
|
TypeVal = typeval
|
|
};
|
|
|
|
// Add to database
|
|
dbCtx.HistorySheet.Add(mod);
|
|
// Commit changes
|
|
dbCtx.SaveChanges();
|
|
|
|
return mod;
|
|
}
|
|
|
|
|
|
public void Clean()
|
|
{
|
|
if (this.count() >= ServerStartupConfig.MaxSheetHistoryRows)
|
|
{
|
|
dbCtx.Database.ExecuteSqlCommand("DELETE FROM historysheets LIMIT {0}", ServerStartupConfig.SheetHistoryToDelete);
|
|
}
|
|
|
|
}
|
|
|
|
public List<HistorySheetModel> GetData(int start, int number)
|
|
{
|
|
// Get page numbers
|
|
return dbCtx
|
|
.HistorySheet
|
|
.OrderByDescending(x => x.DtEvent).Skip(start).Take(number).ToList();
|
|
}
|
|
|
|
public List<HistorySheetModel> GetData()
|
|
{
|
|
// Get page numbers
|
|
return dbCtx
|
|
.HistorySheet
|
|
.OrderByDescending(x => x.DtEvent).ToList();
|
|
}
|
|
public int count()
|
|
{
|
|
// Get page numbers
|
|
return dbCtx
|
|
.HistorySheet.Count();
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|