eDosWeb/safety/Bericht.aspx.cs

144 lines
5.2 KiB
C#
Raw Normal View History

2018-12-13 09:09:17 +01:00
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Telerik.Web.UI;
namespace safety
{
public partial class Bericht : System.Web.UI.Page
{
const int MaxTotalBytes = 1048576; // 1 MB
Int64 totalBytes;
protected void Page_Load(object sender, EventArgs e)
{
General.setTitle(Master, "Bericht");
}
public bool? IsRadAsyncValid
{
get
{
if (Session["IsRadAsyncValid"] == null)
{
Session["IsRadAsyncValid"] = true;
}
return Convert.ToBoolean(Session["IsRadAsyncValid"].ToString());
}
set
{
Session["IsRadAsyncValid"] = value;
}
}
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
IsRadAsyncValid = null;
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
if (e.Item is GridEditableItem && e.Item.IsInEditMode)
{
RadAsyncUpload upload = ((GridEditableItem)e.Item)["Upload"].FindControl("AsyncUpload1") as RadAsyncUpload;
TableCell cell = (TableCell)upload.Parent;
CustomValidator validator = new CustomValidator();
validator.ErrorMessage = "Please select file to be uploaded";
validator.ClientValidationFunction = "validateRadUpload";
validator.Display = ValidatorDisplay.Dynamic;
cell.Controls.Add(validator);
}
}
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e)
{
if (e.CommandName == RadGrid.EditCommandName)
{
RadScriptManager.RegisterStartupScript(Page, Page.GetType(), "SetEditMode", "isEditMode = true;", true);
}
else if (e.CommandName == "DownloadMyFile")
{
GridDataItem item = e.Item as GridDataItem;
int MessageID = (int) item.GetDataKeyValue("MessageID");
string lang = (string) item.GetDataKeyValue("lang");
//object im = item.GetDataKeyValue("Message");
//string strID = item.GetDataKeyValue("ID").ToString();
//string strName = item["Name"].Text;
//// Download File
//string path = Server.MapPath("~/images/" + e.CommandArgument);
//string attachment = "attachment; filename=" + e.CommandArgument;
//Response.Clear();
//Response.AddHeader("content-disposition", attachment);
//Response.ContentType = "image/jpeg";
//Response.WriteFile(path);
//Response.End();
System.Data.SqlClient.SqlConnection cn = new System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["BerichtConnectionString"].ConnectionString);
System.Data.SqlClient.SqlCommand cm = new System.Data.SqlClient.SqlCommand("getImage", cn);
cm.CommandType = System.Data.CommandType.StoredProcedure;
cm.Parameters.AddWithValue("@id", MessageID);
cm.Parameters.AddWithValue("@lang", lang);
cn.Open();
Response.Clear();
string attachment = "attachment; filename=image.jpg";
Response.AddHeader("content-disposition", attachment);
Response.ContentType = "image/jpeg";
try
{
System.Data.SqlClient.SqlDataReader r = cm.ExecuteReader(System.Data.CommandBehavior.CloseConnection | System.Data.CommandBehavior.SingleResult | System.Data.CommandBehavior.SingleRow);
if (r != null && r.Read())
{
Byte[] bytChunk = (byte[])r["Message"];
Response.ContentType = "image/jpeg";
Response.BinaryWrite(bytChunk);
}
else
Response.Redirect("images/no-photo.gif");
}
catch (System.Exception ex)
{
}
finally
{
cn.Close();
Response.End();
}
}
}
protected string TrimDescription(string description)
{
if (!string.IsNullOrEmpty(description) && description.Length > 200)
{
return string.Concat(description.Substring(0, 200), "...");
}
return description;
}
protected void AsyncUpload1_FileUploaded(object sender, FileUploadedEventArgs e)
{
if ((totalBytes < MaxTotalBytes) && (e.File.ContentLength < MaxTotalBytes))
{
e.IsValid = true;
totalBytes += e.File.ContentLength;
IsRadAsyncValid = true;
}
else
{
e.IsValid = false;
IsRadAsyncValid = false;
}
}
}
}