Esempio n. 1
0
        public string ConverterRtfToHtml(TextRange text)
        {
            string t = "";

            t = markupConverter.ConvertRtfToHtml(t);
            return(t);
        }
Esempio n. 2
0
        private void ConvertRtfInSTAThread(object rtf)
        {
            var threadData = rtf as ConvertRtfThreadData;

            try
            {
                threadData.HtmlText = markupConverter.ConvertRtfToHtml(threadData.RtfText);
            }
            catch (Exception ex)
            {
                threadData.HtmlText = "EXC: ConvertRtfInSTAThread; " + ex.Message + " \n" + threadData.RtfText;
            }
        }
Esempio n. 3
0
        public bool ExportReferenceDataToPdf(int shipmentRefID, string outFilePath)
        {
            bool blStatus = false;

            try
            {
                if (shipmentRefID > 0)
                {
                    DataTable dtRxnRefs   = null;
                    DataTable dtCrossRefs = null;

                    DataSet dsRxn_CrossRefs = ReactionCurationDB.GetRxnAndCrossReferencesOnShipmentRefID(shipmentRefID);
                    if (dsRxn_CrossRefs != null)
                    {
                        if (dsRxn_CrossRefs.Tables.Count == 2)
                        {
                            dtCrossRefs = dsRxn_CrossRefs.Tables[0];
                            dtRxnRefs   = dsRxn_CrossRefs.Tables[1];
                        }
                    }

                    DataSet dsRxns = ReactionCurationDB.GetReactionsForExportOnDocID(shipmentRefID);
                    if (dsRxns != null)
                    {
                        if (dsRxns.Tables.Count == 8)
                        {
                            DataTable dtDocMaster = dsRxns.Tables[0];
                            DataTable dtReactions = dsRxns.Tables[1];
                            //DataTable dtRxnRefs = dsRxns.Tables[2];
                            //DataTable dtCrossRefs = dsRxns.Tables[3];
                            DataTable dtRxnSteps     = dsRxns.Tables[4];
                            DataTable dtConditions   = dsRxns.Tables[5];
                            DataTable dtParticipants = dsRxns.Tables[6];
                            DataTable dtProducts     = dsRxns.Tables[7];

                            string rxnsRefNo   = dtDocMaster.Rows[0]["REFERENCE_NAME"].ToString();
                            string sysText     = dtDocMaster.Rows[0]["SYS_TEXT"].ToString();
                            string sysNo       = dtDocMaster.Rows[0]["SYS_NO"].ToString();
                            string outFileName = outFilePath;// Path.Combine(outFilePath, rxnsRefNo + ".pdf");

                            List <ReactionInfo> lstRxnInfo = new List <ReactionInfo>();
                            int reactionID = 0;
                            //Unique ID for reaction (serial number); format: RXCInnnnnnnn;n=numerical range for backfiles is 70000001...89999999.
                            int mdlNo = 70000000;
                            foreach (DataRow drow in dtReactions.Rows)
                            {
                                //increment MDL Numer
                                mdlNo++;

                                reactionID = Convert.ToInt32(drow["REACTION_ID"]);

                                ReactionInfo rxnInfo = new ReactionInfo();
                                rxnInfo.ShipmentRefID  = shipmentRefID;
                                rxnInfo.ReactionID     = reactionID;
                                rxnInfo.SysNo          = dtDocMaster.Rows[0]["SYS_NO"].ToString();
                                rxnInfo.SysText        = dtDocMaster.Rows[0]["SYS_TEXT"].ToString();
                                rxnInfo.RxnMDLNo       = "RXCI" + mdlNo;
                                rxnInfo.ReactionScheme = drow["REACTION_SCHEME"];
                                rxnInfo.ReactionSNo    = Convert.ToInt32(drow["REACTION_SNO"]);
                                rxnInfo.RxnRef         = GetRxnRefInfoFromTableOnReactionID(dtRxnRefs, reactionID);
                                rxnInfo.RxnCrossRef    = GetCrossRefInfoFromTableOnReactionID(dtCrossRefs, reactionID);

                                DataTable dtRxnStages      = GetStepsOnReactionID(dtRxnSteps, reactionID);
                                DataTable participantsData = GetParticipantsForProdFormation(dtParticipants, dtConditions, dtRxnStages);

                                rxnInfo.ParticipantsForPdf = participantsData;// GetReactionStepsInfoFromTableOnReactionID(dtRxnSteps, dtParticipants, dtConditions, reactionID);
                                //Add to list
                                lstRxnInfo.Add(rxnInfo);
                            }

                            if (lstRxnInfo != null)
                            {
                                if (dtReactions.Rows.Count > 0)
                                {
                                    using (iTextSharp.text.Document doc = new iTextSharp.text.Document())
                                    {
                                        iTextSharp.text.pdf.PdfWriter.GetInstance(doc, new System.IO.FileStream(outFileName, FileMode.Create));
                                        doc.Open();

                                        //Declare Reaction Participants tables
                                        #region MyRegion
                                        DataTable dtProdTbl     = null;
                                        DataTable dtReactantTbl = null;
                                        DataTable dtPartpntTbl  = null;
                                        DataTable dtCondsTbl    = null;
                                        DataTable dtStagesTbl   = null;
                                        #endregion

                                        iTextSharp.text.Image chemimg = null;
                                        iTextSharp.text.Font  georgia = FontFactory.GetFont("georgia", 10f);

                                        //Define variables
                                        #region MyRegion

                                        int intProdCnt  = 0;
                                        int intReactCnt = 0;

                                        string    strRxnHdr = "";
                                        PdfPTable PdfTable  = null;
                                        PdfPCell  rxnCell   = null;

                                        #endregion

                                        //Define font style
                                        #region MyRegion
                                        styles = new StyleSheet();
                                        styles.LoadTagStyle("th", "size", "8px");
                                        styles.LoadTagStyle("th", "face", "helvetica");
                                        styles.LoadTagStyle("span", "size", "7px");
                                        styles.LoadTagStyle("span", "face", "helvetica");
                                        styles.LoadTagStyle("td", "size", "7px");
                                        styles.LoadTagStyle("td", "face", "helvetica");
                                        #endregion

                                        PdfPTable pTRxnRef   = null;
                                        PdfPTable pTCrossRef = null;

                                        PdfPCell pcRxnRef   = null;
                                        PdfPCell pcCrossRef = null;

                                        //Add Pdf Header to document
                                        PdfPTable ptHeader = GetPdfHeaderTable(rxnsRefNo, sysNo);
                                        doc.Add(ptHeader);

                                        //Define Participants elements
                                        List <IElement> lstPartpnt = null;

                                        foreach (ReactionInfo rxnInfo in lstRxnInfo)
                                        {
                                            //Create instance of the pdf table and set the number of column in that table
                                            PdfTable = new PdfPTable(1);
                                            PdfTable.SpacingAfter        = 4f;
                                            PdfTable.HorizontalAlignment = 0;    //0=Left, 1=Centre, 2=Right
                                            PdfTable.TotalWidth          = 800f; // doc.PageSize.Width;
                                            PdfTable.WidthPercentage     = 100;

                                            //Add Reaction Header to Pdf Table
                                            strRxnHdr                   = "Reaction - " + rxnInfo.ReactionSNo.ToString();
                                            rxnCell                     = new PdfPCell(new Phrase(strRxnHdr, fontTinyItalic));
                                            rxnCell.Colspan             = intProdCnt + intReactCnt;
                                            rxnCell.HorizontalAlignment = PdfPCell.ALIGN_LEFT;// 0; //0=Left, 1=Centre, 2=Right
                                            rxnCell.VerticalAlignment   = PdfPCell.ALIGN_TOP;
                                            rxnCell.BackgroundColor     = bgcolRxnNo;
                                            PdfTable.AddCell(rxnCell);

                                            //Reaction Reference Info
                                            pTRxnRef = GetReactionReferecneTable(rxnInfo);
                                            if (pTRxnRef != null)
                                            {
                                                pcRxnRef        = new PdfPCell(pTRxnRef);
                                                pcRxnRef.Border = PdfPCell.NO_BORDER;
                                                //pcRxnRef.BackgroundColor = bgcolRctNumStage;
                                                PdfTable.AddCell(pcRxnRef);
                                            }

                                            //Cross Reference Info
                                            pTCrossRef = GetCrossReferecneTable(rxnInfo);
                                            if (pTCrossRef != null)
                                            {
                                                pcCrossRef        = new PdfPCell(pTCrossRef);
                                                pcCrossRef.Border = PdfPCell.NO_BORDER;
                                                //pcRxnRef.BackgroundColor = bgcolRctNumStage;
                                                PdfTable.AddCell(pcCrossRef);
                                            }

                                            if (rxnInfo.ReactionScheme != null)
                                            {
                                                System.Drawing.Image img = GetStructureImage(rxnInfo.ReactionScheme.ToString());
                                                chemimg = iTextSharp.text.Image.GetInstance(img as System.Drawing.Image, System.Drawing.Imaging.ImageFormat.Jpeg);
                                                if (chemimg != null)
                                                {
                                                    chemimg.ScaleToFit(450f, 150f);
                                                    //chemimg.ScaleAbsolute((float)600f, (float)250f);
                                                    chemimg.Alignment = iTextSharp.text.Image.TEXTWRAP | iTextSharp.text.Image.ALIGN_CENTER;

                                                    //pdfCell = new PdfPCell(chemimg, true);
                                                }
                                                else
                                                {
                                                    //pdfCell = new PdfPCell(new Phrase("Structure generation error", fontTinyItalic));
                                                }

                                                PdfTable.AddCell(chemimg);
                                            }

                                            //Product Yield, CS, DS and Other information

                                            //Get Participatns text from RichTextBox object
                                            string strRtf = GetPartpntsDataBindToRichTextBox(rxnInfo.ParticipantsForPdf);

                                            //Get Participants elements from RichTextBox Rtf and convert to HTML
                                            lstPartpnt = HTMLWorker.ParseToList(new StringReader(markupConverter.ConvertRtfToHtml(strRtf)), styles);

                                            //Add Participants string in a row cell to Pdf Table
                                            PdfPCell pcPartpnt = new PdfPCell();
                                            foreach (IElement iEle in lstPartpnt)
                                            {
                                                pcPartpnt.AddElement(iEle);
                                            }
                                            pcPartpnt.Colspan = 1;// intProdCnt + intReactCnt;
                                            //pcPartpnt.BackgroundColor =  bgcolRxnPartpnt;
                                            pcPartpnt.VerticalAlignment   = Element.ALIGN_TOP;
                                            pcPartpnt.HorizontalAlignment = 0;// Element.ALIGN_LEFT; //0=Left, 1=Centre, 2=Right
                                            PdfTable.AddCell(pcPartpnt);


                                            doc.Add(PdfTable);
                                        }

                                        doc.Close();
                                        blStatus = true;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ErrorHandling.WriteErrorLog(ex.ToString());
            }
            return(blStatus);
        }
 public void convertRtfToHtml(object sender, RoutedEventArgs e)
 {
     myTextBox3.Text = markupConverter.ConvertRtfToHtml(myTextBox3.Text);
     MessageBox.Show("Content Conversion Complete!");
 }