Esempio n. 1
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);
        }
Esempio n. 2
0
        /// <summary>
        /// Export Reactions for client delivery
        /// </summary>
        /// <param name="RefIDsList"></param>
        /// <param name="shipmentYear"></param>
        /// <param name="outputPath"></param>
        /// <param name="mdlStartNo"></param>
        /// <param name="deliveryDtls"></param>
        /// <param name="delivSovCats"></param>
        /// <returns></returns>
        public static bool ExportReactionsForClientDelivery(List <int> RefIDsList, string shipmentYear, string outputPath, int mdlStartNo, out Delivery deliveryDtls, out List <DeliverySolvCats> delivSovCatsList)
        {
            bool     blStatus    = false;
            Delivery objDelivery = null;
            List <DeliverySolvCats> lstDeliverySovCats = null;

            try
            {
                int           mdlNo            = mdlStartNo;//70000000;
                List <string> lstUniqSolvInchi = new List <string>();

                //Define Delivery class
                objDelivery = new Delivery();
                objDelivery.DeliveryDate     = DateTime.Now;
                objDelivery.MDLStartNo       = mdlStartNo;
                objDelivery.DeliveryRefCount = RefIDsList.Count;

                List <int> lstDelRefs        = new List <int>();
                List <int> lstDelRefMDLStNo  = new List <int>();
                List <int> lstDelRefMDLEndNo = new List <int>();
                int        deliveredRxnCnt   = 0;

                lstDeliverySovCats = new List <DeliverySolvCats>();

                foreach (int shipRefID in RefIDsList)
                {
                    DataSet   dsRxns      = ReactionCurationDB.GetReactionsForExportOnDocID(shipRefID);
                    DataTable dtRxnRefs   = null;
                    DataTable dtCrossRefs = null;

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

                    if (dsRxns != null)
                    {
                        if (dsRxns.Tables.Count == 8)
                        {
                            DataTable dtDocMaster = dsRxns.Tables[0];
                            DataTable dtReactions = dsRxns.Tables[1];
                            //Manual Export
                            //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];

                            // FullArticleInfo articleInfo =  GetArticleInfoFromTable(dtDocMaster);

                            FullArticleInfo articleInfo = GetFullArticleDetailsOnShipmentRefID(Convert.ToInt32(dtDocMaster.Rows[0]["SHIPMENT_REF_ID"].ToString()));

                            string shipementRefName        = dtDocMaster.Rows[0]["REFERENCE_NAME"].ToString();
                            List <ReactionInfo> lstRxnInfo = new List <ReactionInfo>();
                            int reactionID = 0;

                            //Add Reference Name and MDL Start No
                            lstDelRefs.Add(shipRefID);
                            lstDelRefMDLStNo.Add(mdlNo);

                            //Unique ID for reaction (serial number); format: RXCInnnnnnnn;n=numerical range for backfiles is 70000001...89999999.
                            //Feedback on 28th Oct 2014
                            //General: Please assign MDLnumbers according to the year, i.e. issues from 1981 should have MDLnumbers RXCI81nnnnnn, to avoid duplicates

                            foreach (DataRow drow in dtReactions.Rows)
                            {
                                reactionID = Convert.ToInt32(drow["REACTION_ID"]);

                                ReactionInfo rxnInfo = new ReactionInfo();
                                rxnInfo.ShipmentRefID  = shipRefID;
                                rxnInfo.ReactionID     = reactionID;
                                rxnInfo.SysNo          = dtDocMaster.Rows[0]["SYS_NO"].ToString();
                                rxnInfo.SysText        = dtDocMaster.Rows[0]["SYS_TEXT"].ToString();
                                rxnInfo.RxnMDLNo       = "RXCI" + shipmentYear + mdlNo.ToString("000000");//RXCI81nnnnnn
                                rxnInfo.ReactionScheme = drow["REACTION_SCHEME"];
                                rxnInfo.ReactionSNo    = Convert.ToInt32(drow["REACTION_SNO"]);
                                rxnInfo.RxnComments    = drow["RXN_COMMENTS"].ToString();
                                rxnInfo.RxnRef         = GetRxnRefInfoFromTableOnReactionID(dtRxnRefs, reactionID);
                                rxnInfo.RxnCrossRef    = GetCrossRefInfoFromTableOnReactionID(dtCrossRefs, reactionID);
                                rxnInfo.RxnProducts    = GetProductsFromTableOnReactionID(dtProducts, reactionID);
                                rxnInfo.RxnSteps       = GetStepsInfoFromTableOnReactionID(dtRxnSteps, dtParticipants, dtConditions, reactionID);

                                //Add to list
                                lstRxnInfo.Add(rxnInfo);

                                //increment MDL Numer
                                mdlNo++;

                                //Count delivery Rxns
                                deliveredRxnCnt++;
                            }

                            //Add Reference MDL End No
                            lstDelRefMDLEndNo.Add(mdlNo);

                            if (lstRxnInfo != null)
                            {
                                DeliverySolvCats refSovCats = new DeliverySolvCats();
                                if (ReactionExport.ExportToRDFile(lstRxnInfo, articleInfo, shipementRefName, outputPath, ref lstUniqSolvInchi, ref refSovCats))
                                {
                                    blStatus = true;

                                    if (refSovCats.RefNewSolvents != null)
                                    {
                                        refSovCats.ShipmentRefID = shipRefID;

                                        //Add Refs and SolvCats to List
                                        lstDeliverySovCats.Add(refSovCats);
                                    }
                                }
                            }
                        }
                    }
                }

                //Delivery references and Mdl Nos
                objDelivery.DeliveryRefsList  = lstDelRefs;
                objDelivery.RefMdlStartNoList = lstDelRefMDLStNo;
                objDelivery.RefMdlEndNoList   = lstDelRefMDLEndNo;
                objDelivery.DeliveryRxnCount  = deliveredRxnCnt;
                objDelivery.MDLEndNo          = (mdlStartNo + deliveredRxnCnt) - 1;
            }
            catch (Exception ex)
            {
                ErrorHandling.WriteErrorLog(ex.ToString());
            }
            deliveryDtls     = objDelivery;
            delivSovCatsList = lstDeliverySovCats;
            return(blStatus);
        }