Implemetato FILE upload/modifica/cancellazione...
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="mod_collaudi.ascx.cs" Inherits="CMS_SC.WebUserControls.mod_collaudi" %>
|
||||
<%@ Register Src="~/WebUserControls/mod_fileUpload.ascx" TagPrefix="uc1" TagName="mod_fileUpload" %>
|
||||
|
||||
|
||||
<asp:GridView ID="grView" runat="server" AutoGenerateColumns="False" DataKeyNames="IdxDossier,CodScheda,Vers,NumScheda,CodMisura,Fase" DataSourceID="ods" CssClass="table table-striped" AllowPaging="True" AllowSorting="True" OnRowCommand="grView_RowCommand" OnSelectedIndexChanged="grView_SelectedIndexChanged">
|
||||
<PagerStyle CssClass="active GridPager" />
|
||||
<PagerSettings Mode="NumericFirstLast" />
|
||||
@@ -20,7 +21,12 @@
|
||||
<asp:BoundField DataField="NomeMisura" HeaderText="Misura" SortExpression="NomeMisura" ReadOnly="true" />
|
||||
<asp:TemplateField HeaderText="Val. Misura" SortExpression="ValoreMis">
|
||||
<EditItemTemplate>
|
||||
<asp:TextBox ID="txtValoreMis" runat="server" Text='<%# Bind("ValoreMis") %>' />
|
||||
<div runat="server" id="divMisura" visible='<%# Eval("TipovalMisura").ToString()!="FILE" %>'>
|
||||
<asp:TextBox ID="txtValoreMis" runat="server" Text='<%# Bind("ValoreMis") %>' />
|
||||
</div>
|
||||
<div runat="server" id="divFile" visible='<%# Eval("TipovalMisura").ToString()=="FILE" %>'>
|
||||
<uc1:mod_fileUpload runat="server" ID="mod_fileUpload" filtKey='<%# Bind("ValoreMis") %>' enableMod="true" />
|
||||
</div>
|
||||
</EditItemTemplate>
|
||||
<ItemTemplate>
|
||||
<div runat="server" id="divMisura" visible='<%# Eval("TipovalMisura").ToString()!="FILE" %>'>
|
||||
|
||||
@@ -13,7 +13,6 @@ namespace CMS_SC.WebUserControls
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
/// <summary>
|
||||
/// dimensione pagina grid view
|
||||
|
||||
@@ -1,72 +1,84 @@
|
||||
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="mod_fileUpload.ascx.cs" Inherits="CMS_SC.WebUserControls.mod_fileUpload" %>
|
||||
|
||||
<div>
|
||||
<div id="divNewEdit" runat="server">
|
||||
<asp:Button ID="btnAdd" runat="server" Text="Nuovo Allegato" OnClick="btnAdd_Click" Enabled='<%# enableMod %>' />
|
||||
<asp:Button ID="btnCancel" runat="server" Text="Annulla" OnClick="btnCancel_Click" />
|
||||
</div>
|
||||
<asp:UpdatePanel ID="uppContainer" runat="server">
|
||||
<Triggers>
|
||||
<asp:PostBackTrigger ControlID="btnUpload" />
|
||||
</Triggers>
|
||||
<ContentTemplate>
|
||||
<div id="divFileUpl" runat="server" style="width: 100%;">
|
||||
<asp:FileUpload ID="FileUploadControl" runat="server" />
|
||||
</div>
|
||||
<div id="divNewEdit" class="row" runat="server">
|
||||
<div class="col-xs-6">
|
||||
<asp:Button ID="btnAdd" runat="server" Text="Nuovo Allegato" OnClick="btnAdd_Click" Enabled='<%# enableMod %>' Width="100%" />
|
||||
<asp:Button ID="btnCancel" runat="server" Text="Annulla" OnClick="btnCancel_Click" Width="100%" />
|
||||
</div>
|
||||
<div class="col-xs-6">
|
||||
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" data-theme="b" Width="100%" />
|
||||
</div>
|
||||
</div>
|
||||
<asp:GridView ID="grView" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="odsFile" DataKeyNames="idxFile" OnSelectedIndexChanged="grView_SelectedIndexChanged">
|
||||
<EditRowStyle BackColor="#2461BF" />
|
||||
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
|
||||
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
|
||||
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
|
||||
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" />
|
||||
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
|
||||
<SortedAscendingCellStyle BackColor="#F5F7FB" />
|
||||
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
|
||||
<SortedDescendingCellStyle BackColor="#E9EBEF" />
|
||||
<SortedDescendingHeaderStyle BackColor="#4870BE" />
|
||||
<AlternatingRowStyle BackColor="White" />
|
||||
<EmptyDataTemplate>
|
||||
<%: traduci("NoFileFound") %>
|
||||
</EmptyDataTemplate>
|
||||
<Columns>
|
||||
<asp:TemplateField ItemStyle-HorizontalAlign="right">
|
||||
<ItemTemplate>
|
||||
<div id="DivSel" runat="server" visible='<%# isWriteEnabled %>'>
|
||||
<asp:LinkButton ID="lnkSelect" runat="server" CausesValidation="False" CommandName="Select" Text="Select" CssClass="ui-btn ui-shadow ui-corner-all ui-icon-edit ui-btn-icon-notext ui-btn-inline" ToolTip="Modifica" Visible='<%# enableMod %>'><i class="fa fa-2x fa-edit"></i></asp:LinkButton>
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
<ItemStyle HorizontalAlign="Center"></ItemStyle>
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField HeaderText="File">
|
||||
<EditItemTemplate>
|
||||
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FileName") %>'></asp:TextBox>
|
||||
</EditItemTemplate>
|
||||
<ItemTemplate>
|
||||
<div>
|
||||
<asp:LinkButton ID="lnkDownload" runat="server" OnClick="DownloadFile"
|
||||
CommandArgument='<%# Eval("idxFile") %>'>
|
||||
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FileName") %>' />
|
||||
</asp:LinkButton>
|
||||
</div>
|
||||
<div>
|
||||
<asp:Label CssClass="flLeft" ID="lblDataMod" runat="server" Text='<%# Eval("DataMod","{0:yyyy-MM-dd HH:mm}") %>' Font-Size="0.7em" />
|
||||
<asp:Label CssClass="flRight" ID="lblSize" runat="server" Text='<%# Eval("Size","{0:N0} kb") %>' Font-Size="0.8em" />
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
<ItemStyle HorizontalAlign="Left" />
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField ItemStyle-HorizontalAlign="right">
|
||||
<ItemTemplate>
|
||||
<div id="DivDel" runat="server" visible='<%# isWriteEnabled %>'>
|
||||
<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" CssClass="ui-btn ui-shadow ui-corner-all ui-icon-delete ui-btn-icon-notext ui-btn-inline" ToolTip="Elimina" OnClientClick="return confirm('Sei sicuro di voler eliminare il file?')" Visible='<%# enableMod %>'><i class="fa fa-2x fa-trash"></i></asp:LinkButton>
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
<ItemStyle HorizontalAlign="Center"></ItemStyle>
|
||||
</asp:TemplateField>
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
<asp:HiddenField runat="server" ID="hfFiltKey" />
|
||||
<asp:HiddenField runat="server" ID="hfReadOnly" />
|
||||
<asp:ObjectDataSource ID="odsFile" runat="server" DeleteMethod="deleteQuery" OldValuesParameterFormatString="original_{0}" SelectMethod="getByFiltKey" TypeName="CMS_SC_Data.DS_UtilityTableAdapters.tblFilesTableAdapter">
|
||||
<SelectParameters>
|
||||
<asp:ControlParameter ControlID="hfFiltKey" PropertyName="Value" Type="String" Name="FiltKey" />
|
||||
</SelectParameters>
|
||||
<DeleteParameters>
|
||||
<asp:Parameter Name="Original_idxFile" Type="Int32" />
|
||||
</DeleteParameters>
|
||||
</asp:ObjectDataSource>
|
||||
|
||||
<div id="divFileUpl" runat="server">
|
||||
<div style="width: 100%;">
|
||||
<asp:FileUpload ID="FileUpload1" runat="server" />
|
||||
</div>
|
||||
<div style="width: 100%;">
|
||||
<asp:Button ID="btnUpload" runat="server" Text="Upload" OnClick="Upload" data-theme="b" />
|
||||
</div>
|
||||
</div>
|
||||
<asp:GridView ID="grView" runat="server" Width="100%" AutoGenerateColumns="False" DataSourceID="odsFile" DataKeyNames="idxFile" OnSelectedIndexChanged="grView_SelectedIndexChanged">
|
||||
<EditRowStyle BackColor="#2461BF" />
|
||||
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
|
||||
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
|
||||
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
|
||||
<RowStyle BackColor="#EFF3FB" HorizontalAlign="Left" />
|
||||
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
|
||||
<SortedAscendingCellStyle BackColor="#F5F7FB" />
|
||||
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
|
||||
<SortedDescendingCellStyle BackColor="#E9EBEF" />
|
||||
<SortedDescendingHeaderStyle BackColor="#4870BE" />
|
||||
<AlternatingRowStyle BackColor="White" />
|
||||
<EmptyDataTemplate>
|
||||
<%: traduci("NoFileFound") %>
|
||||
</EmptyDataTemplate>
|
||||
<Columns>
|
||||
<asp:TemplateField HeaderText="Documento">
|
||||
<EditItemTemplate>
|
||||
<asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("FileName") %>'></asp:TextBox>
|
||||
</EditItemTemplate>
|
||||
<ItemTemplate>
|
||||
<div>
|
||||
<asp:LinkButton ID="lnkDownload" runat="server" OnClick="DownloadFile"
|
||||
CommandArgument='<%# Eval("idxFile") %>'>
|
||||
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FileName") %>' />
|
||||
</asp:LinkButton>
|
||||
</div>
|
||||
<div>
|
||||
<asp:Label CssClass="flLeft" ID="lblDataMod" runat="server" Text='<%# Eval("DataMod","{0:yyyy-MM-dd HH:mm}") %>' Font-Size="0.7em" />
|
||||
<asp:Label CssClass="flRight" ID="lblSize" runat="server" Text='<%# Eval("Size","{0:N0} kb") %>' Font-Size="0.8em" />
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
<ItemStyle HorizontalAlign="Left" />
|
||||
</asp:TemplateField>
|
||||
<asp:TemplateField ItemStyle-HorizontalAlign="right">
|
||||
<ItemTemplate>
|
||||
<div id="Div1" runat="server" visible='<%# isWriteEnabled %>'>
|
||||
<asp:LinkButton ID="lnkSelect" runat="server" CausesValidation="False" CommandName="Select" Text="Select" CssClass="ui-btn ui-shadow ui-corner-all ui-icon-edit ui-btn-icon-notext ui-btn-inline" ToolTip="Modifica" Visible='<%# enableMod %>' />
|
||||
<asp:LinkButton ID="lnkDelete" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" CssClass="ui-btn ui-shadow ui-corner-all ui-icon-delete ui-btn-icon-notext ui-btn-inline" ToolTip="Elimina" OnClientClick="return confirm('Sei sicuro di voler eliminare il file?')" Visible='<%# enableMod %>' />
|
||||
</div>
|
||||
</ItemTemplate>
|
||||
<ItemStyle HorizontalAlign="Center"></ItemStyle>
|
||||
</asp:TemplateField>
|
||||
</Columns>
|
||||
</asp:GridView>
|
||||
<asp:HiddenField runat="server" ID="hfFiltKey" />
|
||||
<asp:HiddenField runat="server" ID="hfReadOnly" />
|
||||
<asp:ObjectDataSource ID="odsFile" runat="server" DeleteMethod="deleteQuery" OldValuesParameterFormatString="original_{0}" SelectMethod="getByFiltKey" TypeName="CMS_SC_Data.DS_UtilityTableAdapters.tblFilesTableAdapter">
|
||||
<SelectParameters>
|
||||
<asp:ControlParameter ControlID="hfFiltKey" PropertyName="Value" Type="string" Name="FiltKey" />
|
||||
</SelectParameters>
|
||||
<DeleteParameters>
|
||||
<asp:Parameter Name="Original_idxFile" Type="Int32" />
|
||||
</DeleteParameters>
|
||||
</asp:ObjectDataSource>
|
||||
</div>
|
||||
</ContentTemplate>
|
||||
</asp:UpdatePanel>
|
||||
|
||||
@@ -16,6 +16,21 @@ namespace CMS_SC.WebUserControls
|
||||
{
|
||||
public partial class mod_fileUpload : SteamWare.UserControl
|
||||
{
|
||||
/// <summary>
|
||||
/// selezione valore in DettScheda
|
||||
/// </summary>
|
||||
public event EventHandler eh_fileMod;
|
||||
/// <summary>
|
||||
/// sollevo evento selezione
|
||||
/// </summary>
|
||||
protected void raiseEvent()
|
||||
{
|
||||
// sollevo evento nuovo valore...
|
||||
if (eh_fileMod != null)
|
||||
{
|
||||
eh_fileMod(this, new EventArgs());
|
||||
}
|
||||
}
|
||||
/// <summary>
|
||||
/// abilita modifica/cancellazione allegati
|
||||
/// </summary>
|
||||
@@ -27,6 +42,7 @@ namespace CMS_SC.WebUserControls
|
||||
/// <param name="e"></param>
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.Page.Form.Enctype = "multipart/form-data";
|
||||
fisVisFU(enableMod);
|
||||
if (!IsPostBack)
|
||||
{
|
||||
@@ -34,7 +50,7 @@ namespace CMS_SC.WebUserControls
|
||||
grView.DataBind();
|
||||
}
|
||||
divNewEdit.Visible = isWriteEnabled && enableMod;
|
||||
btnAdd.DataBind();
|
||||
btnAdd.DataBind();
|
||||
}
|
||||
/// <summary>
|
||||
/// Chiave di filtraggio dati...
|
||||
@@ -50,54 +66,45 @@ namespace CMS_SC.WebUserControls
|
||||
hfFiltKey.Value = value;
|
||||
}
|
||||
}
|
||||
#if false
|
||||
/// <summary>
|
||||
/// determina se sia in modalità read only = non permette upload/cancellazioni/...
|
||||
/// </summary>
|
||||
public bool readOnly
|
||||
{
|
||||
get
|
||||
{
|
||||
return Convert.ToBoolean(hfReadOnly.Value);
|
||||
}
|
||||
set
|
||||
{
|
||||
hfReadOnly.Value = value.ToString();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
protected void Upload(object sender, EventArgs e)
|
||||
{
|
||||
string filename = Path.GetFileName(FileUpload1.PostedFile.FileName);
|
||||
string contentType = FileUpload1.PostedFile.ContentType;
|
||||
using (Stream fs = FileUpload1.PostedFile.InputStream)
|
||||
if (FileUploadControl.HasFile)
|
||||
{
|
||||
using (BinaryReader br = new BinaryReader(fs))
|
||||
string filename = Path.GetFileName(FileUploadControl.PostedFile.FileName);
|
||||
string contentType = FileUploadControl.PostedFile.ContentType;
|
||||
using (Stream fs = FileUploadControl.PostedFile.InputStream)
|
||||
{
|
||||
byte[] bytes = br.ReadBytes((Int32)fs.Length);
|
||||
// PROCEDO SOLO SE HO UN FILE!!!! ovvero bytes <> null
|
||||
if (bytes.Length > 0)
|
||||
using (BinaryReader br = new BinaryReader(fs))
|
||||
{
|
||||
// controllo se sia caricamento o update...
|
||||
if (grView.SelectedIndex != -1)
|
||||
byte[] bytes = br.ReadBytes((Int32)fs.Length);
|
||||
// PROCEDO SOLO SE HO UN FILE!!!! ovvero bytes <> null
|
||||
if (bytes.Length > 0)
|
||||
{
|
||||
try
|
||||
// controllo se sia caricamento o update...
|
||||
if (grView.SelectedIndex != -1)
|
||||
{
|
||||
int orig_idxFile = Convert.ToInt32(grView.SelectedValue);
|
||||
DtProxy.man.taFiles.updateQuery(filename, filtKey, contentType, bytes, orig_idxFile);
|
||||
try
|
||||
{
|
||||
int orig_idxFile = Convert.ToInt32(grView.SelectedValue);
|
||||
DtProxy.man.taFiles.updateQuery(filename, filtKey, contentType, bytes, orig_idxFile);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
DtProxy.man.taFiles.insertQuery(filename, filtKey, contentType, bytes);
|
||||
}
|
||||
catch
|
||||
{ }
|
||||
}
|
||||
else
|
||||
{
|
||||
DtProxy.man.taFiles.insertQuery(filename, filtKey, contentType, bytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
grView.DataBind();
|
||||
raiseEvent();
|
||||
#if false
|
||||
Response.Redirect(Request.Url.AbsoluteUri);
|
||||
#endif
|
||||
}
|
||||
Response.Redirect(Request.Url.AbsoluteUri);
|
||||
}
|
||||
|
||||
protected void DownloadFile(object sender, EventArgs e)
|
||||
|
||||
+27
-18
@@ -12,6 +12,33 @@ namespace CMS_SC.WebUserControls {
|
||||
|
||||
public partial class mod_fileUpload {
|
||||
|
||||
/// <summary>
|
||||
/// uppContainer control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.UpdatePanel uppContainer;
|
||||
|
||||
/// <summary>
|
||||
/// divFileUpl control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlGenericControl divFileUpl;
|
||||
|
||||
/// <summary>
|
||||
/// FileUploadControl control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.FileUpload FileUploadControl;
|
||||
|
||||
/// <summary>
|
||||
/// divNewEdit control.
|
||||
/// </summary>
|
||||
@@ -39,24 +66,6 @@ namespace CMS_SC.WebUserControls {
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.Button btnCancel;
|
||||
|
||||
/// <summary>
|
||||
/// divFileUpl control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.HtmlControls.HtmlGenericControl divFileUpl;
|
||||
|
||||
/// <summary>
|
||||
/// FileUpload1 control.
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Auto-generated field.
|
||||
/// To modify move field declaration from designer file to code-behind file.
|
||||
/// </remarks>
|
||||
protected global::System.Web.UI.WebControls.FileUpload FileUpload1;
|
||||
|
||||
/// <summary>
|
||||
/// btnUpload control.
|
||||
/// </summary>
|
||||
|
||||
Reference in New Issue
Block a user