From 179ebcd14e1aa6a8eba25ca591d738e200d71ea9 Mon Sep 17 00:00:00 2001 From: "Samuele E. Locatelli" Date: Fri, 15 Sep 2017 11:28:24 +0200 Subject: [PATCH] Fix gestione FileUpload in Allegati --- ScheMe-PIC/Allegati.aspx | 19 +- ScheMe-PIC/App_Start/BundleConfig.cs | 4 +- ScheMe-PIC/Bootstrap.Master | 5 +- ScheMe-PIC/Bootstrap.Master.designer.cs | 9 + ScheMe-PIC/Prova.aspx | 6 + ScheMe-PIC/Prova.aspx.designer.cs | 27 ++- .../WebUserControls/mod_fileUpload.ascx | 149 +++++++------- .../WebUserControls/mod_fileUpload.ascx.cs | 189 +++++++++--------- .../mod_fileUpload.ascx.designer.cs | 94 ++++----- 9 files changed, 274 insertions(+), 228 deletions(-) diff --git a/ScheMe-PIC/Allegati.aspx b/ScheMe-PIC/Allegati.aspx index 89d3b62..9f16854 100644 --- a/ScheMe-PIC/Allegati.aspx +++ b/ScheMe-PIC/Allegati.aspx @@ -1,9 +1,22 @@ -<%@ Page Title="" Language="C#" MasterPageFile="~/JQMob.Master" AutoEventWireup="true" CodeBehind="Allegati.aspx.cs" Inherits="ScheMe.Allegati" %> +<%@ Page Title="" Language="C#" MasterPageFile="~/Bootstrap.Master" AutoEventWireup="true" CodeBehind="Allegati.aspx.cs" Inherits="ScheMe.Allegati" %> <%@ Register Src="WebUserControls/mod_fileUpload.ascx" TagName="mod_fileUpload" TagPrefix="uc1" %> - - + + + +
+
+
+
+ Allegati Paziente +
+
+
+
+ +
+
diff --git a/ScheMe-PIC/App_Start/BundleConfig.cs b/ScheMe-PIC/App_Start/BundleConfig.cs index 2441da6..3ca1dd7 100644 --- a/ScheMe-PIC/App_Start/BundleConfig.cs +++ b/ScheMe-PIC/App_Start/BundleConfig.cs @@ -42,10 +42,10 @@ namespace ScheMe "~/Scripts/jSteamware.js")); bundles.Add(new ScriptBundle("~/bundles/bootSwitch").Include( "~/Scripts/bootstrap-switch.min.js")); - + bundles.Add(new ScriptBundle("~/bundles/jquerymobile").Include( "~/Scripts/jquery.mobile-{version}.js")); - + //bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include( // "~/Scripts/jquery.unobtrusive*", // "~/Scripts/jquery.validate*")); diff --git a/ScheMe-PIC/Bootstrap.Master b/ScheMe-PIC/Bootstrap.Master index eb34e26..b506955 100644 --- a/ScheMe-PIC/Bootstrap.Master +++ b/ScheMe-PIC/Bootstrap.Master @@ -18,6 +18,7 @@ <%: Scripts.Render("~/bundles/jquery") %> <%: Scripts.Render("~/bundles/jqueryui") %> <%: Scripts.Render("~/bundles/bootSwitch") %> + <%--<%: Scripts.Render("~/bundles/bootstrap-file-input") %>--%> @@ -61,9 +62,11 @@ + + - + diff --git a/ScheMe-PIC/Bootstrap.Master.designer.cs b/ScheMe-PIC/Bootstrap.Master.designer.cs index 647c72c..97a7aeb 100644 --- a/ScheMe-PIC/Bootstrap.Master.designer.cs +++ b/ScheMe-PIC/Bootstrap.Master.designer.cs @@ -84,6 +84,15 @@ namespace ScheMe { /// protected global::System.Web.UI.WebControls.ContentPlaceHolder MainContent; + /// + /// Controllo NoAjaxContent. + /// + /// + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. + /// + protected global::System.Web.UI.WebControls.ContentPlaceHolder NoAjaxContent; + /// /// Controllo uppFooter. /// diff --git a/ScheMe-PIC/Prova.aspx b/ScheMe-PIC/Prova.aspx index 1ae74c6..bce2a88 100644 --- a/ScheMe-PIC/Prova.aspx +++ b/ScheMe-PIC/Prova.aspx @@ -1,5 +1,11 @@ <%@ Page Title="" Language="C#" MasterPageFile="~/Bootstrap.Master" AutoEventWireup="true" CodeBehind="Prova.aspx.cs" Inherits="ScheMe.Prova" %> + +<%@ Register Src="~/WebUserControls/mod_fileUpload.ascx" TagPrefix="uc1" TagName="mod_fileUpload" %> + + + + diff --git a/ScheMe-PIC/Prova.aspx.designer.cs b/ScheMe-PIC/Prova.aspx.designer.cs index b020c34..002b8cf 100644 --- a/ScheMe-PIC/Prova.aspx.designer.cs +++ b/ScheMe-PIC/Prova.aspx.designer.cs @@ -1,17 +1,24 @@ //------------------------------------------------------------------------------ -// +// // Codice generato da uno strumento. // // Le modifiche a questo file possono causare un comportamento non corretto e verranno perse se -// il codice viene rigenerato. -// +// il codice viene rigenerato. +// //------------------------------------------------------------------------------ -namespace ScheMe -{ - - - public partial class Prova - { - } +namespace ScheMe { + + + public partial class Prova { + + /// + /// Controllo mod_fileUpload. + /// + /// + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. + /// + protected global::ScheMe.WebUserControls.mod_fileUpload mod_fileUpload; + } } diff --git a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx index be6187c..9d7658a 100644 --- a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx +++ b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx @@ -1,80 +1,85 @@ <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="mod_fileUpload.ascx.cs" Inherits="ScheMe.WebUserControls.mod_fileUpload" %> -
- - -
-
-
- -
-
- -
+
+
+ +
+
+ +
+
+ +
+
+
+ +
+
+
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
- - -
-
- -
-
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + +
+
+ +
+
- - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + diff --git a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.cs b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.cs index 7266fa9..49d850b 100644 --- a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.cs +++ b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.cs @@ -14,99 +14,102 @@ using SteamWare; namespace ScheMe.WebUserControls { - public partial class mod_fileUpload : SteamWare.UserControl + public partial class mod_fileUpload : SteamWare.UserControl + { + protected void Page_Load(object sender, EventArgs e) { - protected void Page_Load(object sender, EventArgs e) - { - if (!IsPostBack) - { - fisVisFU(false); - grView.DataBind(); - } - divNewEdit.Visible = isWriteEnabled; - } - protected void Upload(object sender, EventArgs e) - { - string filename = Path.GetFileName(FileUpload1.PostedFile.FileName); - string contentType = FileUpload1.PostedFile.ContentType; - string gruppo = memLayer.ML.StringSessionObj("Gruppo"); - int idxPaziente = memLayer.ML.IntSessionObj("IdxPaziente"); - using (Stream fs = FileUpload1.PostedFile.InputStream) - { - using (BinaryReader br = new BinaryReader(fs)) - { - byte[] bytes = br.ReadBytes((Int32)fs.Length); - // controllo se sia caricamento o update... - if (grView.SelectedIndex != -1) - { - try - { - int orig_idxFile = Convert.ToInt32(grView.SelectedValue); - DtProxy.man.taFile.UpdateQuery(gruppo, idxPaziente, filename, contentType, bytes, orig_idxFile); - } - catch - { } - } - else - { - DtProxy.man.taFile.InsertQuery(gruppo, idxPaziente, filename, contentType, bytes); - } - } - } - Response.Redirect(Request.Url.AbsoluteUri); - } - - protected void DownloadFile(object sender, EventArgs e) - { - int idxFile = int.Parse((sender as LinkButton).CommandArgument); - byte[] bytes; - string fileName, contentType; - ScheMe_Data.DS_Utility.tblFilesRow fileRow = DtProxy.man.taFile.getByKey(idxFile)[0]; - bytes = fileRow.Data; - contentType = fileRow.ContentType; - fileName = fileRow.FileName; - Response.Clear(); - Response.Buffer = true; - Response.Charset = ""; - Response.Cache.SetCacheability(HttpCacheability.NoCache); - Response.ContentType = contentType; - Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); - Response.BinaryWrite(bytes); - Response.Flush(); - Response.End(); - } - - protected void grView_SelectedIndexChanged(object sender, EventArgs e) - { - // mostro controllo x edit... - fisVisFU(true); - btnUpload.Text = "Aggiorna File"; - } - - protected void btnAdd_Click(object sender, EventArgs e) - { - fisVisFU(true); - btnUpload.Text = "Carica Nuovo"; - } - /// - /// fix visibilità controllo file upload - /// - /// mostra controlli add=true oppure nasconde = false - private void fisVisFU(bool showAdd) - { - divFileUpl.Visible = showAdd; - btnAdd.Visible = !showAdd; - btnCancel.Visible = showAdd; - if (grView.SelectedIndex != -1 && !showAdd) - { - grView.SelectedIndex = -1; - } - } - - protected void btnCancel_Click(object sender, EventArgs e) - { - fisVisFU(false); - } - + if (!IsPostBack) + { + fisVisFU(false); + grView.DataBind(); + } + divNewEdit.Visible = isWriteEnabled || true; } + protected void Upload(object sender, EventArgs e) + { + if (FileUpload1.PostedFile != null) + { + string filename = Path.GetFileName(FileUpload1.PostedFile.FileName); + string contentType = FileUpload1.PostedFile.ContentType; + string gruppo = memLayer.ML.StringSessionObj("Gruppo"); + int idxPaziente = memLayer.ML.IntSessionObj("IdxPaziente"); + using (Stream fs = FileUpload1.PostedFile.InputStream) + { + using (BinaryReader br = new BinaryReader(fs)) + { + byte[] bytes = br.ReadBytes((Int32)fs.Length); + // controllo se sia caricamento o update... + if (grView.SelectedIndex != -1) + { + try + { + int orig_idxFile = Convert.ToInt32(grView.SelectedValue); + DtProxy.man.taFile.UpdateQuery(gruppo, idxPaziente, filename, contentType, bytes, orig_idxFile); + } + catch + { } + } + else + { + DtProxy.man.taFile.InsertQuery(gruppo, idxPaziente, filename, contentType, bytes); + } + } + } + } + Response.Redirect(Request.Url.AbsoluteUri); + } + + protected void DownloadFile(object sender, EventArgs e) + { + int idxFile = int.Parse((sender as LinkButton).CommandArgument); + byte[] bytes; + string fileName, contentType; + ScheMe_Data.DS_Utility.tblFilesRow fileRow = DtProxy.man.taFile.getByKey(idxFile)[0]; + bytes = fileRow.Data; + contentType = fileRow.ContentType; + fileName = fileRow.FileName; + Response.Clear(); + Response.Buffer = true; + Response.Charset = ""; + Response.Cache.SetCacheability(HttpCacheability.NoCache); + Response.ContentType = contentType; + Response.AppendHeader("Content-Disposition", "attachment; filename=" + fileName); + Response.BinaryWrite(bytes); + Response.Flush(); + Response.End(); + } + + protected void grView_SelectedIndexChanged(object sender, EventArgs e) + { + // mostro controllo x edit... + fisVisFU(true); + btnUpload.Text = "Aggiorna File"; + } + + protected void btnAdd_Click(object sender, EventArgs e) + { + fisVisFU(true); + btnUpload.Text = "Carica Nuovo"; + } + /// + /// fix visibilità controllo file upload + /// + /// mostra controlli add=true oppure nasconde = false + private void fisVisFU(bool showAdd) + { + divFileUpl.Visible = showAdd; + btnAdd.Visible = !showAdd; + btnCancel.Visible = showAdd; + if (grView.SelectedIndex != -1 && !showAdd) + { + grView.SelectedIndex = -1; + } + } + + protected void btnCancel_Click(object sender, EventArgs e) + { + fisVisFU(false); + } + + } } \ No newline at end of file diff --git a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.designer.cs b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.designer.cs index a9df4cd..2e68ba9 100644 --- a/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.designer.cs +++ b/ScheMe-PIC/WebUserControls/mod_fileUpload.ascx.designer.cs @@ -1,10 +1,10 @@ //------------------------------------------------------------------------------ -// -// This code was generated by a tool. +// +// Codice generato da uno strumento. // -// Changes to this file may cause incorrect behavior and will be lost if -// the code is regenerated. -// +// Le modifiche a questo file possono causare un comportamento non corretto e verranno perse se +// il codice viene rigenerato. +// //------------------------------------------------------------------------------ namespace ScheMe.WebUserControls { @@ -13,74 +13,74 @@ namespace ScheMe.WebUserControls { public partial class mod_fileUpload { /// - /// divNewEdit control. + /// Controllo divFileUpl. /// /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.HtmlControls.HtmlGenericControl divNewEdit; - - /// - /// btnAdd control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Button btnAdd; - - /// - /// btnCancel control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. - /// - protected global::System.Web.UI.WebControls.Button btnCancel; - - /// - /// divFileUpl control. - /// - /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. /// protected global::System.Web.UI.HtmlControls.HtmlGenericControl divFileUpl; /// - /// FileUpload1 control. + /// Controllo btnCancel. /// /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. + /// + protected global::System.Web.UI.WebControls.Button btnCancel; + + /// + /// Controllo FileUpload1. + /// + /// + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. /// protected global::System.Web.UI.WebControls.FileUpload FileUpload1; /// - /// btnUpload control. + /// Controllo btnUpload. /// /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. /// protected global::System.Web.UI.WebControls.Button btnUpload; /// - /// grView control. + /// Controllo divNewEdit. /// /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. + /// + protected global::System.Web.UI.HtmlControls.HtmlGenericControl divNewEdit; + + /// + /// Controllo btnAdd. + /// + /// + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. + /// + protected global::System.Web.UI.WebControls.Button btnAdd; + + /// + /// Controllo grView. + /// + /// + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. /// protected global::System.Web.UI.WebControls.GridView grView; /// - /// odsFile control. + /// Controllo odsFile. /// /// - /// Auto-generated field. - /// To modify move field declaration from designer file to code-behind file. + /// Campo generato automaticamente. + /// Per la modifica, spostare la dichiarazione di campo dal file di progettazione al file code-behind. /// protected global::System.Web.UI.WebControls.ObjectDataSource odsFile; }