Beispiel #1
0
 public static void B2FPDFToZip(string[] ids, MemoryStream mem)
 {
     if (ids != null && ids.Length > 0)
     {
         using (ZipFile f = ZipFile.Create(mem))
         {
             f.BeginUpdate();
             foreach (string id in ids)
             {
                 int entityId = 0;
                 if (int.TryParse(id, out entityId) && entityId > 0)
                 {
                     MemoryStream mstream = new MemoryStream();
                     B2FPDFDownLoad pdf = new B2FPDFDownLoad();
                     string fileName;
                     if (pdf.WriterPDF(ref mstream, entityId, out fileName))
                     {
                         f.Add(new MemoryDataSource(mstream.GetBuffer()), fileName + ".pdf");
                     }
                 }
             }
             f.CommitUpdate();
         }
     }
 }
Beispiel #2
0
        //public ActionResult SaveExcel(DataSet ds)
        //{
        //   // DataSet ds = ExcelHelper.ReadExcel(@"D:\Files\SGP\Technical_Costing_template.xlsx");
        //    DataTable mainTable = ds.Tables["Primary"];
        //    List<FieldCategory> categories = FieldCategory.GetCategorys(FieldCategory.Category_TYPE_B2F);
        //    foreach (DataRow dr in mainTable.Rows)
        //    {
        //        int dataId = 0;
        //        string relationValue = "";
        //        Dictionary<string, DataRow[]> dicSubData = new Dictionary<string, DataRow[]>();
        //        foreach (FieldCategory fc in categories)
        //        {
        //            fc.ClearFieldsData();
        //        }
        //        if (mainTable.Columns.Contains("RFQ Number"))
        //        {
        //            relationValue = Convert.ToString(dr["RFQ Number"]);
        //        }
        //        for (int i = 0; i < ds.Tables.Count; i++)
        //        {
        //            string tableName = ds.Tables[i].TableName;
        //            if (String.Compare(tableName, "DataSource", true) != 0 && String.Compare(tableName, "Primary", true) != 0)
        //            {
        //                DataTable dt = ds.Tables[i];
        //                DataRow[] subDrs = null;
        //                if (!String.IsNullOrEmpty(relationValue))
        //                {
        //                    subDrs = dt.Select(String.Format("[RFQ Number]='{0}'", relationValue));
        //                }
        //                else
        //                {
        //                    subDrs = dt.Select("1=1");
        //                }
        //                if (subDrs != null && subDrs.Length > 0)
        //                {
        //                    dicSubData.Add(tableName, subDrs);
        //                }
        //            }
        //        }
        //        B2FQuotationDetail dm = new B2FQuotationDetail(categories, dr, dicSubData);
        //        if (!String.IsNullOrEmpty(relationValue))
        //        {
        //            string sSql = "SELECT ID FROM SGP_RFQ WHERE ExtNumber = @ExtNumber";
        //            dataId = DbHelperSQL.GetSingle<int>(sSql, new SqlParameter("@ExtNumber", dr["RFQ Number"]));
        //        }
        //        if (dataId > 0)
        //        {
        //            dm.Update(dataId);
        //        }
        //        else
        //        {
        //            dataId = dm.Add();
        //        }
        //    }
        //    return View();
        //}
        public FileResult DownloadPDF()
        {
            string KeyValues = Request.QueryString["RFQID"];
            string fileName = "";
            string tempFile = System.Web.HttpContext.Current.Server.MapPath("~/temp/" + Guid.NewGuid() + ".tmp");
            MemoryStream mem = new MemoryStream();
            if (!String.IsNullOrEmpty(KeyValues))
            {
                KeyValues = KeyValues.TrimEnd(',');
                string[] ids = KeyValues.Split(',');
                if (ids.Length == 1)
                {
                    int id = Int32.Parse(ids[0]);
                    B2FPDFDownLoad pdf = new B2FPDFDownLoad();

                    if (pdf.WriterPDF(ref mem, id, out fileName))
                    {

                        if (fileName == "")
                        {
                            fileName = "multek_" + DateTime.Now.ToString("mmssffff") + ".pdf";
                        }
                        else
                        {
                            fileName += ".pdf";
                        }
                        using (var fileStream = FileHelper.CreateFile(tempFile))
                        {
                            fileStream.Write(mem.GetBuffer(), 0, mem.GetBuffer().Length);
                        }
                    }
                }
                else
                {
                    ZipHelper.B2FPDFToZip(ids, mem);
                    fileName = "PDF_Packages_" + DateTime.Now.ToString("mmss") + ".zip";
                    using (var fileStream = FileHelper.CreateFile(tempFile))
                    {
                        mem.WriteTo(fileStream);
                    }
                }
            }

            return File(tempFile, "application/octet-stream", fileName);
        }