using AppData; using System; using System.IO; using System.Web; using System.Web.UI; using System.Linq; namespace NKC_WF.WebUserControls { public partial class cmp_BatchStatsList : BaseUserControl { #region Private Properties private string fullPath { get { string dirPath = HttpContext.Current.Server.MapPath("~/temp/"); return $"{dirPath}\\{FileName}"; } } #endregion Private Properties #region Protected Properties protected bool fileExist { get { return File.Exists(fullPath); } } protected int ShowLast { get { int answ = 100; int.TryParse(txtNumShow.Text, out answ); return answ; } set { txtNumShow.Text = $"{value}"; } } #endregion Protected Properties #region Public Properties public string FileName { get { return hfFileName.Value; } set { hfFileName.Value = value; } } #endregion Public Properties #region Private Methods private void clearFile() { if (fileExist) { File.Delete(fullPath); } } private void Cmp_numRow_eh_doRefresh(object sender, EventArgs e) { // recupero num righe ed aggiorno... grView.PageSize = cmp_numRow.numRow; grView.DataBind(); } private void updateGraph() { cmp_BatchStatsPlot.PlotType = ddlType.SelectedValue; cmp_BatchStatsPlot.ShowLast = ShowLast; cmp_BatchStatsPlot.Legend = traduci($"rep_{ddlType.SelectedValue}"); } #endregion Private Methods #region Protected Methods protected void chkPlotGraph_CheckedChanged(object sender, EventArgs e) { doUpdate(); } protected void ddlPlaces_SelectedIndexChanged(object sender, EventArgs e) { } protected void ddlType_SelectedIndexChanged(object sender, EventArgs e) { doUpdate(); } protected void grView_PageIndexChanged(object sender, EventArgs e) { } protected void lbtExportCsv_Click(object sender, EventArgs e) { DataLayer DLMan = new DataLayer(); DS_App.BatchStatsDataTable currRecords = DLMan.taBStats.getLast(ShowLast); var rowList = currRecords .Select(x => new FileBatchStats() { FileCsv = x.Takt, Yeld = (double)x.AvgYeld, NumMaterials = x.NumMat, NumSheets = x.NumSheets, NumModels = x.NumModel, NumKit = x.NumKit, NumParts = x.NumParts, NumPainted = x.NumPainted }) .ToList(); utils.SaveToCsv(rowList, fullPath); hlDownload.NavigateUrl = $"~/temp/{FileName}"; lbtExportCsv.Visible = !fileExist; hlDownload.Visible = fileExist; } /// /// Caricamento pagina /// /// /// protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { cmp_numRow.numRow = 25; grView.PageSize = cmp_numRow.numRow; divGraph.Visible = false; divType.Visible = false; FileName = "BatchStats.csv"; clearFile(); lbtExportCsv.Visible = !fileExist; hlDownload.Visible = fileExist; } cmp_numRow.eh_doRefresh += Cmp_numRow_eh_doRefresh; } protected void txtNumShow_TextChanged(object sender, EventArgs e) { doUpdate(); } #endregion Protected Methods #region Public Methods public void doUpdate() { divGraph.Visible = chkPlotGraph.Checked; divType.Visible = chkPlotGraph.Checked; if (chkPlotGraph.Checked) { updateGraph(); } grView.DataBind(); lbtExportCsv.Visible = !fileExist; hlDownload.Visible = fileExist; } #endregion Public Methods } }