Files
cms_thermo_active/Thermo.Active.Database/Controllers/HistorySheetsController.cs
T
2021-03-19 22:52:17 +01:00

83 lines
2.0 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)
{
HistorySheetModel mod = new HistorySheetModel()
{
DtEvent = DateTime.Now,
RecipeName = recipe,
NumDone = piece,
FirstVal = value1,
SecondVal = value2,
ThirdVal = value3
};
// 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();
}
}
}