diff --git a/AppData/Objects.cs b/AppData/Objects.cs index 8369867..cebb98c 100644 --- a/AppData/Objects.cs +++ b/AppData/Objects.cs @@ -36,6 +36,21 @@ namespace AppData #endregion Public Properties } + // + // This is here so CodeMaid doesn't reorganize this document + // + + public class FileBatchStats + { + public string FileCsv { get; set; } = ""; + public double Yeld { get; set; } = 0; + public int NumMaterials { get; set; } = 0; + public int NumSheets { get; set; } = 0; + public int NumModels { get; set; } = 0; + public int NumKit { get; set; } = 0; + public int NumParts { get; set; } = 0; + public int NumPainted { get; set; } = 0; + } // // This is here so CodeMaid doesn't reorganize this document diff --git a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx index cc72949..f0197a9 100644 --- a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx +++ b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx @@ -15,6 +15,8 @@
+ Create CSV + Download CSV
@@ -84,5 +86,6 @@ +
\ No newline at end of file diff --git a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.cs b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.cs index 3352aab..031d1ad 100644 --- a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.cs @@ -1,12 +1,37 @@ -using System; +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 @@ -23,8 +48,32 @@ namespace NKC_WF.WebUserControls #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... @@ -61,6 +110,29 @@ namespace NKC_WF.WebUserControls { } + 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 /// @@ -70,10 +142,14 @@ namespace NKC_WF.WebUserControls { if (!Page.IsPostBack) { - cmp_numRow.numRow = 10; + 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; } @@ -96,6 +172,8 @@ namespace NKC_WF.WebUserControls updateGraph(); } grView.DataBind(); + lbtExportCsv.Visible = !fileExist; + hlDownload.Visible = fileExist; } #endregion Public Methods diff --git a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.designer.cs b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.designer.cs index 1345a60..f36fb14 100644 --- a/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.designer.cs +++ b/NKC_WF/WebUserControls/cmp_BatchStatsList.ascx.designer.cs @@ -32,6 +32,24 @@ namespace NKC_WF.WebUserControls /// protected global::NKC_WF.WebUserControls.cmp_BatchStatsPlot cmp_BatchStatsPlot; + /// + /// lbtExportCsv control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.LinkButton lbtExportCsv; + + /// + /// hlDownload control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HyperLink hlDownload; + /// /// divType control. /// @@ -103,5 +121,14 @@ namespace NKC_WF.WebUserControls /// To modify move field declaration from designer file to code-behind file. /// protected global::System.Web.UI.WebControls.ObjectDataSource ods; + + /// + /// hfFileName control. + /// + /// + /// Auto-generated field. + /// To modify move field declaration from designer file to code-behind file. + /// + protected global::System.Web.UI.WebControls.HiddenField hfFileName; } } diff --git a/NKC_WF/WebUserControls/cmp_DailyStatsList.ascx.cs b/NKC_WF/WebUserControls/cmp_DailyStatsList.ascx.cs index 635309a..3b3da1e 100644 --- a/NKC_WF/WebUserControls/cmp_DailyStatsList.ascx.cs +++ b/NKC_WF/WebUserControls/cmp_DailyStatsList.ascx.cs @@ -174,7 +174,7 @@ namespace NKC_WF.WebUserControls { if (!Page.IsPostBack) { - cmp_numRow.numRow = 10; + cmp_numRow.numRow = 25; grView.PageSize = cmp_numRow.numRow; divGraph.Visible = false; divType.Visible = false;