protected void btnDownload_Click(object sender, EventArgs e) { int downloadID = int.Parse(((System.Web.UI.WebControls.WebControl)(sender)).Attributes["qid"]); string type = ((System.Web.UI.WebControls.WebControl)(sender)).Attributes["istype"].ToString(); string filePath = string.Empty; if (type == "distributor") { if (downloadID > 0) { PriceListDownloadsBO objDownload = new PriceListDownloadsBO(); objDownload.ID = downloadID; objDownload.GetObject(); filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objDownload.FileName); } } if (type == "label") { if (downloadID > 0) { LabelPriceListDownloadsBO objLabelDownload = new LabelPriceListDownloadsBO(); objLabelDownload.ID = downloadID; objLabelDownload.GetObject(); filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objLabelDownload.FileName); } } if (!string.IsNullOrEmpty(filePath)) { while (true) { if (File.Exists(filePath)) { string[] attachFilePath = { filePath }; try { FileInfo fileInfo = new FileInfo(filePath); string outputName = System.Text.RegularExpressions.Regex.Replace(fileInfo.Name, @"\W+", "_"); outputName = System.Text.RegularExpressions.Regex.Replace(outputName, "_xlsx", ".xlsx"); Response.ClearContent(); Response.ClearHeaders(); Response.AddHeader("Content-Type", "application/vnd.ms-excel"); Response.AddHeader("Content-Disposition", string.Format("attachment; filename = {0}", outputName)); Response.AddHeader("Content-Length", (fileInfo.Length).ToString("F0")); Response.TransmitFile(filePath); Response.Flush(); Response.Close(); Response.BufferOutput = true; //Response.End(); } catch (Exception ex) { // Log the error IndicoLogging.log.Error("Fail to download excel file.", ex); } } break; } } }
private void PopulateDataGrid() { // Populate Items string searchText = this.txtSearch.Text.ToLower().Trim(); List <ReturnDownloadPriceListViewBO> lstReturnDownloadPriceList = new List <ReturnDownloadPriceListViewBO>(); if (!string.IsNullOrEmpty(searchText) && searchText != "search") { lstReturnDownloadPriceList = PriceListDownloadsBO.ReturnDownloadPriceList(0).Where(o => o.Name.ToLower().Trim() == searchText || o.PriceTerm.ToLower().Trim() == searchText || o.FileName.ToLower().Trim() == searchText).ToList(); } else { lstReturnDownloadPriceList = PriceListDownloadsBO.ReturnDownloadPriceList(0).OrderByDescending(o => o.CreatedDate).ToList(); } if (int.Parse(this.ddlType.SelectedValue) == 1) { lstReturnDownloadPriceList = PriceListDownloadsBO.ReturnDownloadPriceList(1).OrderByDescending(o => o.CreatedDate).ToList(); } if (int.Parse(this.ddlType.SelectedValue) == 2) { lstReturnDownloadPriceList = PriceListDownloadsBO.ReturnDownloadPriceList(2).OrderByDescending(o => o.CreatedDate).ToList(); } if (lstReturnDownloadPriceList.Count > 0) { this.dvEmptyContent.Visible = false; this.dvDataContent.Visible = true; this.dgPriceLists.AllowPaging = (lstReturnDownloadPriceList.Count > this.dgPriceLists.PageSize); this.dgPriceLists.DataSource = lstReturnDownloadPriceList; this.dgPriceLists.DataBind(); } else if ((searchText != string.Empty && searchText != "search") || int.Parse(this.ddlType.SelectedItem.Value) != 0) { //this.lblSerchKey.Text = searchText + ((searchText != string.Empty) ? " - " : string.Empty) + "Filter by " + this.ddlSortByGarmentSpec.SelectedItem.Text; this.dvDataContent.Visible = true; this.dgPriceLists.Visible = false; //(lstReturnDownloadPriceList.Count > 0); this.dvNoSearchResult.Visible = true; this.dgPriceLists.Visible = true; } else { this.dvDataContent.Visible = true; this.dgPriceLists.Visible = false; //(lstReturnDownloadPriceList.Count > 0); this.dvemptyresult.Visible = true; } if (onProgressCount > 2) { this.btnDownload.Visible = false; } }
protected void btnDelete_Click(object sender, EventArgs e) { int id = int.Parse(hdnSelectedID.Value); string type = this.hdnType.Value; if (type == "distributor") { PriceListDownloadsBO objPriceListDownload = new PriceListDownloadsBO(this.ObjContext); objPriceListDownload.ID = id; objPriceListDownload.GetObject(); string filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objPriceListDownload.FileName); if (File.Exists(filePath)) { File.Delete(filePath); try { using (TransactionScope ts = new TransactionScope()) { objPriceListDownload.Delete(); ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while deleting distrinutor price list", ex); } } } if (type == "label") { LabelPriceListDownloadsBO objLabelPriceListDownload = new LabelPriceListDownloadsBO(this.ObjContext); objLabelPriceListDownload.ID = id; objLabelPriceListDownload.GetObject(); string filePath = String.Format("{0}{1}", (IndicoConfiguration.AppConfiguration.PathToDataFolder + @"\PriceLists\"), objLabelPriceListDownload.FileName); if (File.Exists(filePath)) { File.Delete(filePath); try { using (TransactionScope ts = new TransactionScope()) { objLabelPriceListDownload.Delete(); ObjContext.SaveChanges(); ts.Complete(); } } catch (Exception ex) { IndicoLogging.log.Error("Error occured while deleting label price list", ex); } } } this.PopulateControls(); }