/// <summary> /// Handles the Command event of the btnDownload control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param> protected void btnDownload_Command(object sender, CommandEventArgs e) { if (String.Compare(e.CommandName, "Download", true) == 0) { // get the file GridServerTemplateContainer container = this.Parent as GridServerTemplateContainer; if (container != null) { object obj = container.DataItem[FilePathArgument]; if (obj != null) { string filePath = obj.ToString(); if (File.Exists(filePath)) { // shouldn't call methods like response.Write or TransmitFile here since the current control may be inside an UpdatePanel string redirectString = "~/Apps/Core/ImportExport/FileDownload.aspx?file=" + Server.UrlEncode(filePath); Response.Redirect(redirectString); // download the file //System.Web.HttpResponse response = System.Web.HttpContext.Current.Response; //response.AddHeader("content-disposition", string.Format("attachment; filename={0}", Path.GetFileName(filePath))); //response.ContentType = "application/octet-stream"; //response.TransmitFile(filePath); //response.Flush(); } } } } }
/// <summary> /// Handles the Load event of the Page control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected void Page_Load(object sender, EventArgs e) { if (String.IsNullOrEmpty(FileSizeArgument) || String.IsNullOrEmpty(FileSizeArgument)) { return; } GridServerTemplateContainer container = this.Parent as GridServerTemplateContainer; if (container != null) { object fileSize = container.DataItem[FileSizeArgument]; if (fileSize != null) { long size = 0; if (long.TryParse(fileSize.ToString(), out size)) { SizeText.Text = CommerceHelper.ByteSizeToStr(size); } } } }
/// <summary> /// Handles the Command event of the btnDelete control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="System.Web.UI.WebControls.CommandEventArgs"/> instance containing the event data.</param> protected void btnDelete_Command(object sender, CommandEventArgs e) { if (String.Compare(e.CommandName, "Delete", true) == 0) { // get the file GridServerTemplateContainer container = this.Parent as GridServerTemplateContainer; if (container != null) { object obj = container.DataItem[FilePathArgument]; if (obj != null) { string filePath = obj.ToString(); if (File.Exists(filePath)) { // delete file try { File.Delete(filePath); } catch (Exception ex) { // TODO: handle exception here // Dummy call on ex to suppress warning ex.ToString(); } } } } } // rebind control that contains parent grid UserControl parentControl = this.Parent.Parent.Parent as UserControl; if (parentControl != null) { parentControl.DataBind(); } }
private void dgJobsToBookIn_ItemContentCreated(object sender, GridItemContentCreatedEventArgs e) { try { int jobId = Convert.ToInt32(((HtmlInputHidden)e.Content.FindControl("hidJobId")).Value); if (jobId > 0) { DataView dvJobRow = new DataView(m_dsJobsData.Tables[0]); dvJobRow.RowFilter = "JobId = " + jobId.ToString(); eJobState jobState = (eJobState)Enum.Parse(typeof(eJobState), ((string)dvJobRow.Table.Rows[0]["JobState"]).Replace(" ", ""), true); HtmlInputHidden hidJobState = (HtmlInputHidden)e.Content.FindControl("hidJobState"); HtmlInputHidden hidJobType = (HtmlInputHidden)e.Content.FindControl("hidJobType"); if (hidJobState != null && hidJobType != null) { eJobType jobType = (eJobType)Enum.Parse(typeof(eJobType), ((string)dvJobRow.Table.Rows[0]["JobType"]).Replace(" ", ""), true); GridServerTemplateContainer container = (GridServerTemplateContainer)e.Content; if (jobState == eJobState.Booked || jobState == eJobState.Planned || jobState == eJobState.InProgress) { Facade.IJob facJob = new Facade.Job(); ((HtmlImage)e.Content.FindControl("imgRequiresCallIn")).Visible = facJob.RequiresCallIn(jobId); } else { ((HtmlImage)e.Content.FindControl("imgRequiresCallIn")).Visible = false; } HtmlImage imgHasRequests = (HtmlImage)e.Content.FindControl("imgHasRequests"); if (((int)dvJobRow[0]["Requests"]) == 0) { imgHasRequests.Visible = false; } else { imgHasRequests.Visible = true; imgHasRequests.Attributes.Add("onClick", "javascript:ShowPlannerRequests('" + jobId.ToString() + "');"); } HtmlAnchor lnkEditJob = (HtmlAnchor)e.Content.FindControl("lnkEditJob"); switch (jobType) { case eJobType.Normal: lnkEditJob.HRef = "javascript:openResizableDialogWithScrollbars('../job/wizard/wizard.aspx?jobId=" + jobId.ToString() + "', '623', '508');"; break; case eJobType.PalletReturn: lnkEditJob.HRef = "../job/addupdatepalletreturnjob.aspx?jobId=" + jobId.ToString(); break; case eJobType.Return: lnkEditJob.HRef = "../job/addupdategoodsreturnjob.aspx?jobId=" + jobId.ToString(); break; default: lnkEditJob.Visible = false; break; } } Table tblCollections = (Table)e.Content.FindControl("tblCollections"); if (tblCollections != null) { tblCollections.BackColor = Utilities.GetJobStateColour(jobState); DataView dvCollections = new DataView(m_dsJobsData.Tables[1]); foreach (DataRow collection in dvCollections.Table.Rows) { if ((int)collection["JobId"] == jobId) { // This is a collection for the current job ArrayList rows = CreateTableRows(collection); foreach (TableRow row in rows) { tblCollections.Rows.Add(row); } } } } Table tblDeliveries = (Table)e.Content.FindControl("tblDeliveries"); if (tblDeliveries != null) { tblDeliveries.BackColor = Utilities.GetJobStateColour(jobState); DataView dvDeliveries = new DataView(m_dsJobsData.Tables[2]); foreach (DataRow delivery in dvDeliveries.Table.Rows) { if ((int)delivery["JobId"] == jobId) { // This is a delivery for the current job ArrayList rows = CreateTableRows(delivery); foreach (TableRow row in rows) { tblDeliveries.Rows.Add(row); } } } } } } catch (Exception exc) { string error = exc.Message; } }