示例#1
0
        private void GenerateLoiDoc()
        {
            GeneratorController gc = new GeneratorController();

            DataTable dt = gc.LOI_generateDocument_getdata();

            Console.WriteLine("Total LOI Generated: " + dt.Rows.Count.ToString());

            foreach (DataRow dr in dt.Rows)
            {
                string LoiDocPath   = Path.Combine(Environment.CurrentDirectory, "Template");
                string Templatefile = ConfigurationManager.AppSettings["Templatefile"];
                string FullTemplate = Path.Combine(LoiDocPath, Templatefile);

                string DirectoryResultPath = Path.Combine(ConfigurationManager.AppSettings["DirectoryResultPath"], dr["LOI_Code"].ToString());
                if (!Directory.Exists(DirectoryResultPath))
                {
                    Directory.CreateDirectory(DirectoryResultPath);
                }

                string filenameSavedOri = string.Concat("LOIDoc_", dr["LOI_Code"].ToString());
                string resultfile       = Path.Combine(DirectoryResultPath, filenameSavedOri + "_final.pdf");
                string resultfilehtml   = Path.Combine(DirectoryResultPath, filenameSavedOri + ".htm");

                string ResultPathUrl = string.Concat(ConfigurationManager.AppSettings["ResultPathUrl"], dr["LOI_Code"].ToString(), "/", filenameSavedOri, ".pdf");

                string TextTemplate = ReadApprovalTemplate(FullTemplate);

                StringBuilder sb = new StringBuilder();
                sb.Append(TextTemplate);
                sb.Replace("[nokia_logo]", "<img src='https://eboqh3i.nsnebast.com/Images/nokia-logo.png' height='36px' width='100px'/>");
                sb.Replace("[ttd]", "<img src='data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOAAAADhCAMAAADmr0l2AAAAh1BMVEX///8AAAD7+/v4+PjBwcHU1NTQ0NDa2trw8PDd3d3p6ek5OTnl5eWfn5/X19dfX19kZGTHx8csLCy5ubmzs7NQUFCYmJiKioqCgoJzc3NISEhtbW2FhYUyMjKoqKgkJCQMCwtBQUEXFxekpKRKSkouLi57e3tXV1dycnIlJSUeHR6TkpJhYGAMfutBAAAG7klEQVR4nO2c2XqqMBCAHUAEBISC4Iqilqqc93++MwlY0aqgyCLf/FdEA82YyWwJ7fUIgiAIgiAIgiAIgiAIgiAIgiAIgiAIgi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FiX7kmQnOX5+rPYYv+ueXoa3viXXQgqdQ/hkrO7raMej0QIv7RIEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRAEQRBt4j8W3UZID7d+zwAAAABJRU5ErkJggg==' height='36px' width='100px'/>");
                sb.Replace("[subcon_name]", dr["Subcone_Name"].ToString());
                sb.Replace("[subcon_address]", dr["SCon_Addr"].ToString());
                sb.Replace("[subcon_address_city]", "");
                sb.Replace("[subcon_phone]", dr["SCon_Phone"].ToString());
                sb.Replace("[subcon_fax]", dr["SCon_Fax"].ToString());
                sb.Replace("[loi_reference]", dr["LOI_Reference"].ToString());
                sb.Replace("[loi_approved]", "Jakarta, " + Convert.ToDateTime(dr["MU_Approve_Date"]).ToString("dd MMMM yyyy"));
                string cpo = dr["CPO"].ToString();
                sb.Replace("[cpo]", cpo.Remove(cpo.Length - 1));
                sb.Replace("[epm_id]", dr["EPM_Vendor_ID"].ToString());
                sb.Replace("[po_no]", cpo.Remove(cpo.Length - 1));
                string sow = dr["ScopeOfWork"].ToString();
                sb.Replace("[sow_detail]", sow.Remove(sow.Length - 1));
                sb.Replace("[Approver_cpm]", dr["CPM_Approver_Id"].ToString());
                sb.Replace("[Approver_cpm_date]", Convert.ToDateTime(dr["CPM_Approve_Date"]).ToString("dd MMMM yyyy HH:mm:ss"));
                sb.Replace("[Approver_pbm]", dr["PBM_Approver_Id"].ToString());
                sb.Replace("[Approver_pbm_date]", Convert.ToDateTime(dr["PBM_Approve_Date"]).ToString("dd MMMM yyyy HH:mm:ss"));
                sb.Replace("[Approver_cdm]", dr["CDM_Approver_Id"].ToString());
                sb.Replace("[Approver_cdm_date]", Convert.ToDateTime(dr["CDM_Approve_Date"]).ToString("dd MMMM yyyy HH:mm:ss"));
                sb.Replace("[Approver_mb]", dr["MB_Approver_Id"].ToString());
                sb.Replace("[Approver_mb_date]", Convert.ToDateTime(dr["MB_Approve_Date"]).ToString("dd MMMM yyyy HH:mm:ss"));
                sb.Replace("[Approver_mu]", dr["MU_Approver_Id"].ToString());
                sb.Replace("[Approver_mu_date]", Convert.ToDateTime(dr["MU_Approve_Date"]).ToString("dd MMMM yyyy HH:mm:ss"));
                sb.Replace("[CTName]", dr["ProjectName"].ToString());
                Console.WriteLine("Preparing to generate document and Merge");
                try
                {
                    HtmlTextWriter sw = new HtmlTextWriter(new StreamWriter(resultfilehtml, false, UnicodeEncoding.UTF8));
                    sw.BeginRender();
                    sw.WriteLine(sb.ToString());
                    sw.Close();
                    sw.Dispose();
                    string result           = GeneralConfig.ConvertAnyFormatToPDFHtmlNew(resultfilehtml, DirectoryResultPath, filenameSavedOri);
                    int    RequestId        = Convert.ToInt32(dr["RequestId"]);
                    string LoiDetailPdfPath = GenerateDetailLoiDoc(gc, RequestId, dr["LOI_Code"].ToString(), DirectoryResultPath);
                    Console.WriteLine("Merge in Progress");
                    using (FileStream stream = new FileStream(resultfile, FileMode.Create))
                    {
                        Document pdfDoc = new Document(PageSize.A4);
                        PdfCopy  pdf    = new PdfCopy(pdfDoc, stream);
                        pdfDoc.Open();
                        pdf.AddDocument(new PdfReader(result));
                        pdf.AddDocument(new PdfReader(LoiDetailPdfPath));

                        if (pdfDoc != null)
                        {
                            pdfDoc.Close();
                        }
                    }
                    Console.WriteLine("Merge Completed");
                    Console.WriteLine("Record Result of Merge");
                    gc.LOI_Update_Document_GeneratedLink(ResultPathUrl, RequestId);
                    Console.WriteLine("Record Result of Merge Completed");
                }

                catch (Exception ex)
                {
                    Console.WriteLine("Merge error: " + ex.Message.ToString());
                    EBOQ_Lib_New.DAL.DAL_AppLog.ErrLogInsert("Program.cs:GenerateLoiDoc", ex.Message, "NON-SP");
                    Console.Read();
                }
            }
        }