private void InsertContentControl(int number, string content, float X, float Y, float W, float H, StyleInfo styleInfo, PageText pt)
        {
            int sCountTo, sCountFrom;

            sCountFrom = (int)(X / spaceWidth);
            sCountTo   = (int)((X + W) / spaceWidth);
            int rCount = (int)((Y + H) / rowHeight);
            //if (styleInfo.FontWeight == FontWeightEnum.Bold)
            //{
            //    content = content.Insert(0, BoldOn);
            //    content = content.Insert(content.Length, BoldOff);
            //}
            //if (styleInfo.FontSize > 11f)
            //{
            //    content = content.Insert(0, Expanded);
            //    content = content.Insert(content.Length, ExpandedNormal);
            //}
            DMPControl control = new DMPControl();

            control.Number        = number;
            control.LineNumber    = rCount;
            control.FromIndex     = sCountFrom;
            control.ToIndex       = sCountTo;
            control.ContentLength = content.Length;
            control.VerticalAlign = styleInfo.VerticalAlign;
            control.TextAlign     = styleInfo.TextAlign;
            control.String        = content;
            control.CanGrow       = pt.CanGrow;
            control.SI            = styleInfo;
            control.TopBorder     = styleInfo.BStyleTop == BorderStyleEnum.Solid || styleInfo.BStyleTop == BorderStyleEnum.Dotted;
            control.BottomBorder  = styleInfo.BStyleBottom == BorderStyleEnum.Solid || styleInfo.BStyleBottom == BorderStyleEnum.Dotted;
            ContentControls.Add(control);
        }
Example #2
0
        public void TestMethod1()
        {
            List <string> contentL = new List <string>();

            contentL.Add("04:26:12: [Verföhnt] hat sich eingeloggt.");
            contentL.Add("08:13:15: [Filysha] hat sich eingeloggt.");
            contentL.Add("04:26:12: [16. Level 65][Shaslol@Zaviel]: tentakelrapeforlife");
            contentL.Add("04:26:12: [Gilde][Shaslol@Zaviel]: tentakelrapeforlife");
            contentL.Add("07:20:34: [10. Level 50-59@Typhiria][@Typhiria]: Das Zonenereignis [Instabil: Glutinsel] in [Glutinsel] hat auf Typhiria begonnen!");
            contentL.Add("04:26:12: [16. Level 65][Sheide@Zaviel]: we all have our secrets :D");
            contentL.Add("04:26:16: [16. Level 65][Wedancegj@Gelidra]: w8t one sec zaviel are u he or she :D");
            contentL.Add("04:26:19: [Artoine@Typhiria] flüstert: ich hab programmieren als haupt- und nebenfach in" +
                         "der schule aber da macht man nicht so schnell progress :D auf ner uni gehts schon tausendmal schneller vorwärts");
            contentL.Add("04:26:20: [4. Stufe 1-29][Raphaely]: Also ein paar k platin ansammeln und auktionshaus preiskontrolle veranstalten...");
            contentL.Add("15:39:07: [Bobito] hat beim Bedarfs-Wurf 44 gewürfelt für: [Dicker Goldgürtel]");
            contentL.Add("15:39:07: [Bobito] hat mit einem Bedarfs-Wurf von 44 Folgendes gewonnen: [Dicker Goldgürtel]");
            contentL.Add("15:39:07: [Bobito] hat Folgendes erbeutet: [Dicker Goldgürtel]");
            contentL.Add("15:39:15: [Bobito] hat beim Bedarfs-Wurf 3 gewürfelt für: [Güldener Zermalmer]");
            contentL.Add("15:39:15: [Bobito] hat mit einem Bedarfs-Wurf von 3 Folgendes gewonnen: [Güldener Zermalmer]");

            MacroManager.Initialize();
            LineEvaluator   lEval = new LineEvaluator();
            ContentControls dw    = new ContentControls("chattest");

            dw.add("global", new DataGrid());

            lEval.registerCustomMask("lfm", Brushes.Orange);

            foreach (var item in contentL)
            {
                Line line = lEval.createLine(item);
                dw.write(line);
            }
        }
Example #3
0
        private static Word.ContentControl GetFooterContentControl(Word.Document doc, string name)
        {
            Word.ContentControl contentControl = null;
            try
            {
                foreach (Microsoft.Office.Interop.Word.Section wordSection in doc.Sections)
                {
                    foreach (Microsoft.Office.Interop.Word.HeaderFooter wordFooter in wordSection.Footers)
                    {
                        Microsoft.Office.Interop.Word.Range docRange = wordFooter.Range;

                        ContentControls footerControls = docRange.ContentControls;

                        if (footerControls != null)
                        {
                            foreach (Microsoft.Office.Interop.Word.ContentControl control in footerControls)
                            {
                                if (control.Tag.ToUpper().Equals(name.ToUpper()))
                                {
                                    contentControl = control;
                                    break;
                                }
                                if (Marshal.IsComObject(control))
                                {
                                    Marshal.ReleaseComObject(control);
                                }
                            }
                        }
                        if (Marshal.IsComObject(docRange))
                        {
                            Marshal.ReleaseComObject(docRange);
                        }
                        if (Marshal.IsComObject(footerControls))
                        {
                            Marshal.ReleaseComObject(footerControls);
                        }

                        if (Marshal.IsComObject(wordFooter))
                        {
                            Marshal.ReleaseComObject(wordFooter);
                        }
                    }

                    if (Marshal.IsComObject(wordSection))
                    {
                        Marshal.ReleaseComObject(wordSection);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Error, "GetFooterContentControl", ex);
            }
            return(contentControl);
        }
Example #4
0
        public void Init()
        {
            if (BusinessObjects.Instance.RibbonTabPageManager.RibbonTabPageSettings.Any(tabPageConfig =>
                                                                                        tabPageConfig.Id.StartsWith(ContentIdentifiers.Browser, StringComparison.OrdinalIgnoreCase)))
            {
                Task.Run(() =>
                {
                    var threadRunner = new ThreadRunner();
                    var webView      = threadRunner.CreateWebView();
                    webView.Destroy();
                });
            }

            foreach (var tabPageConfig in BusinessObjects.Instance.RibbonTabPageManager.RibbonTabPageSettings)
            {
                if (tabPageConfig.Id.StartsWith(ContentIdentifiers.Browser, StringComparison.OrdinalIgnoreCase))
                {
                    var browserControl = CreateBrowser(tabPageConfig.Id);
                    if (browserControl == null)
                    {
                        continue;
                    }

                    browserControl.TabPage.Text    = tabPageConfig.Name;
                    browserControl.TabPage.Visible = true;
                    ContentControls.Add(browserControl);
                }
                else
                {
                    var contentEditControl = CreateContentEditor(tabPageConfig.Id);
                    if (contentEditControl == null)
                    {
                        continue;
                    }
                    contentEditControl.TabPage.Text    = tabPageConfig.Name;
                    contentEditControl.TabPage.Visible = true;
                    ContentControls.Add(contentEditControl);
                }
            }
            ContentControls.ForEach(c => c.InitMetaData());
            ContentEditManager <MediaScheduleChangeInfo> .Init(this);

            BusinessObjects.Instance.ScheduleManager.ScheduleOpened +=
                ContentEditManager <MediaScheduleChangeInfo> .OnScheduleOpened;
            BusinessObjects.Instance.ThemeManager.ThemesChanged +=
                ContentEditManager <MediaScheduleChangeInfo> .OnThemeChanged;
            ContentEditManager <MediaScheduleChangeInfo> .ScheduleSaving +=
                (o, e) => BusinessObjects.Instance.ScheduleManager.ActiveSchedule.Save();
            ContentEditManager <MediaScheduleChangeInfo> .ScheduleSavingAs +=
                (o, e) => BusinessObjects.Instance.ScheduleManager.SaveScheduleAs(e.Name);
            ContentEditManager <MediaScheduleChangeInfo> .ScheduleSavingTemplate += OnSaveTemplate;
            _tabStateManager.Init();
        }
Example #5
0
        //12/03/2017 - unlock controls to insert signatures
        public static void UnlockFooterSignatures(Word.Document doc)
        {
            try
            {
                foreach (Microsoft.Office.Interop.Word.Section wordSection in doc.Sections)
                {
                    foreach (Microsoft.Office.Interop.Word.HeaderFooter wordFooter in wordSection.Footers)
                    {
                        Microsoft.Office.Interop.Word.Range docRange = wordFooter.Range;

                        ContentControls footerControls = docRange.ContentControls;

                        if (footerControls != null)
                        {
                            foreach (Microsoft.Office.Interop.Word.ContentControl control in footerControls)
                            {
                                if (control.Tag.ToUpper().Contains(SIGNATURE_FIELD))
                                {
                                    control.LockContents       = false;
                                    control.LockContentControl = false;
                                }
                            }
                        }

                        if (Marshal.IsComObject(docRange))
                        {
                            Marshal.ReleaseComObject(docRange);
                        }
                        if (Marshal.IsComObject(footerControls))
                        {
                            Marshal.ReleaseComObject(footerControls);
                        }

                        if (Marshal.IsComObject(wordFooter))
                        {
                            Marshal.ReleaseComObject(wordFooter);
                        }
                    }

                    if (Marshal.IsComObject(wordSection))
                    {
                        Marshal.ReleaseComObject(wordSection);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Error, "GetFooterSignatureCtrls", ex);
            }
        }
Example #6
0
        private void button1_Click(object sender, EventArgs e)
        {
            string pathWord = "C:\\Users\\mishka\\Desktop\\UpWork\\wordTOXml\\wordTOXml\\bin\\Debug\\newword\\Before.docx";
            string savePath = "C:\\Users\\mishka\\Desktop\\UpWork\\wordTOXml\\wordTOXml\\bin\\Debug\\newword\\After.docx";

            Microsoft.Office.Interop.Word.Application appWord = new Microsoft.Office.Interop.Word.Application();
            Microsoft.Office.Interop.Word.Document    doc     = appWord.Documents.Open(pathWord);

            for (int i = 1; i <= doc.Shapes.Count; i++)
            {
                Shape objShape = doc.Shapes[i];

                if (objShape.Type == Microsoft.Office.Core.MsoShapeType.msoTextBox)
                {
                    ContentControls objContentControls = objShape.TextFrame.TextRange.ContentControls;

                    foreach (ContentControl objContentControl in objContentControls)
                    {
                        objShape.TextFrame.MarginTop    = 0;
                        objShape.TextFrame.MarginBottom = 0;
                        objShape.TextFrame.MarginLeft   = 0;
                        objShape.TextFrame.MarginRight  = 0;
                        objShape.TextFrame.AutoSize     = 0;

                        Microsoft.Office.Interop.Word.Table objTable = doc.Tables.Add(objShape.TextFrame.TextRange, 1, 2, WdDefaultTableBehavior.wdWord9TableBehavior, WdAutoFitBehavior.wdAutoFitContent);

                        objTable.TopPadding    = 0;
                        objTable.BottomPadding = 0;
                        objTable.LeftPadding   = 0;
                        objTable.RightPadding  = 0;

                        objTable.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;
                        objTable.Rows.SetHeight(objShape.Height, WdRowHeightRule.wdRowHeightExactly);
                        objTable.PreferredWidthType = WdPreferredWidthType.wdPreferredWidthPercent;
                        objTable.PreferredWidth     = 100;

                        objTable.Cell(1, 1).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
                        objTable.Cell(1, 1).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalTop;

                        objTable.Cell(1, 2).Range.ParagraphFormat.Alignment = WdParagraphAlignment.wdAlignParagraphRight;
                        objTable.Cell(1, 2).VerticalAlignment = WdCellVerticalAlignment.wdCellAlignVerticalBottom;
                    }
                }
            }

            doc.SaveAs2(savePath, Microsoft.Office.Interop.Word.WdExportFormat.wdExportFormatXPS);

            doc.Close();
            appWord.Quit(false);
        }
        public void InsertLineContent(int number, float X, float Y, float W, float H, StyleInfo styleInfo)
        {
            int sCountTo, sCountFrom;

            sCountFrom = (int)(X / spaceWidth);
            sCountTo   = (int)((X + W) / spaceWidth);
            int        rCount  = (int)((Y + H) / rowHeight);
            int        i       = rCount;
            DMPControl control = new DMPControl();

            control.Number        = number;
            control.LineNumber    = rCount;
            control.FromIndex     = sCountFrom;
            control.ToIndex       = sCountTo;
            control.VerticalAlign = styleInfo.VerticalAlign;
            control.TextAlign     = styleInfo.TextAlign;
            control.InsertLine(sCountFrom, sCountTo);
            control.CanGrow      = false;
            control.SI           = styleInfo;
            control.TopBorder    = styleInfo.BStyleTop == BorderStyleEnum.Solid || styleInfo.BStyleTop == BorderStyleEnum.Dotted;
            control.BottomBorder = styleInfo.BStyleBottom == BorderStyleEnum.Solid || styleInfo.BStyleBottom == BorderStyleEnum.Dotted;
            ContentControls.Add(control);
        }
        private void generateRemainingRiskPages(byte[] headerTemplateLocation, byte[] templateLocation, WordInterface wordInterface, Document wordDocument, DataView riskDataRows, DataRow projectInfoRow)
        {
            lock (this.threadLock)
            {
                int currentRisk = 0;
                try
                {
                    //Open template documents.
                    String tempHeaderTemplateFile = Path.GetTempFileName();
                    String tempTemplateFile       = Path.GetTempFileName();
                    File.WriteAllBytes(tempHeaderTemplateFile, headerTemplateLocation);
                    File.WriteAllBytes(tempTemplateFile, templateLocation);
                    Document remainingRiskHeaderTemplate = wordInterface.app.Documents.Open(tempHeaderTemplateFile);
                    Document remainingRiskTemplate       = wordInterface.app.Documents.Open(tempTemplateFile);

                    foreach (DataRowView riskDataRow in riskDataRows)
                    {
                        //Set generating process
                        backgroundWorker1.ReportProgress(
                            33 + (Int32)((float)currentRisk / (float)riskDataRows.Count * 33),
                            (object)string.Format("Generating page {0} of {1}.", currentRisk + 1, riskDataRows.Count)
                            );
                        currentRisk++;

                        //Get the risk data id and set some variables.
                        int     riskDataID           = (Int32)riskDataRow["RiskDataID"];
                        Color[] riskEstimationColors = { ARA_Colors.ARA_Green, ARA_Colors.ARA_Orange, ARA_Colors.ARA_Red };

                        //Get some more info about the risk.
                        DataRow riskData = this.tbl_Risk_DataTableAdapter.GetData().FindByRiskDataID(riskDataID);

                        DataView riskEstimationBeforeView     = new DataView(this.get_RiskEstimation_In_RiskData_BeforeTableAdapter.GetData(riskDataID));
                        DataView riskEstimationAfterView      = new DataView(this.get_RiskEstimation_In_RiskData_AfterTableAdapter.GetData(riskDataID));
                        DataView appliedRiskReductionMeasures = new DataView(this.get_RiskReduction_In_RiskDataTableAdapter.GetData(riskDataID));
                        DataView minimalAdditionMeasures      = new DataView(this.get_MinimalAddition_In_RiskDataTableAdapter.GetData(riskDataID));

                        //Set some value's before copying document.
                        remainingRiskTemplate.Activate();
                        foreach (DataRow exposedPersonRow in this.get_ExposedPersons_In_RiskDataTableAdapter.GetData(riskDataID).Rows)
                        {
                            ContentControls personCheckbox = remainingRiskTemplate.SelectContentControlsByTitle(exposedPersonRow["PersonDescription"].ToString());
                            if (personCheckbox.Count > 0)
                            {
                                personCheckbox[(object)1].Checked = exposedPersonRow["InProject"].ToString() == "1";
                            }
                        }

                        //Copy template.
                        if (currentRisk % 2 == 1)
                        {
                            wordInterface.copyDocumentToOtherDocument(remainingRiskHeaderTemplate, wordDocument, false);
                            wordInterface.copyDocumentToOtherDocument(remainingRiskTemplate, wordDocument, false);
                        }
                        else
                        {
                            wordInterface.copyDocumentToOtherDocument(remainingRiskTemplate, wordDocument, true);
                        }
                        wordDocument.Activate();

                        //Sets the risk hazard specifications.
                        generateHazardIndentification(wordInterface, wordDocument, (Int32)riskData["DangerID"], (Int32)riskData["DangerSourceID"]);

                        //Search and replace headerinfo.
                        wordInterface.searchAndReplace(wordDocument, "<CustomerName>", projectInfoRow["Customer"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<MachineInfo>", string.Format("{0}/{1}", projectInfoRow["MachineNumber"].ToString(), projectInfoRow["OrderNumber"].ToString()));
                        wordInterface.searchAndReplace(wordDocument, "<RiskID>", riskDataRow["RiskID"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<BriefActionDescription>", riskDataRow["HazardSituation"].ToString(), ARA_Colors.ARA_Red);

                        //Search and replace riskdata.
                        wordInterface.searchAndReplace(wordDocument, "<RiskGroup>", string.Format("{0} - {1}", riskDataRow["GroupName"].ToString(), riskDataRow["TypeName"].ToString()));
                        wordInterface.searchAndReplace(wordDocument, "<ActionEvent>", riskData["HazardEvent"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskReductionInfo>", riskData["RiskReductionInfo"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<MinimalAdditionInfo>", riskData["MinimalAdditionInfo"].ToString());

                        //Set the riskestimation fields.
                        ARA_EditRiskRiskEstimation temp = new ARA_EditRiskRiskEstimation();
                        temp.setControlData(riskEstimationBeforeView);

                        //Set risk class fields.
                        riskEstimationBeforeView.RowFilter = "InProject = '1'";
                        if (riskEstimationBeforeView.Count != 4)
                        {
                            throw new Exception("Cant generate report, because risk " + riskDataID.ToString() + " isn't correctly filled in.");
                        }
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassValueB>", temp.calculateRiskEstimationClass().ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassDescriptionB>", ARA_Globals.RiskClassDescription[temp.calculateRiskEstimationClass()], riskEstimationColors[temp.calculateRiskEstimationClass()]);

                        temp.setControlData(riskEstimationAfterView);
                        riskEstimationAfterView.RowFilter = "InProject = '1'";
                        if (riskEstimationAfterView.Count != 4)
                        {
                            throw new Exception("Cant generate report, because risk " + riskDataID.ToString() + " isn't correctly filled in.");
                        }
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassValueA>", temp.calculateRiskEstimationClass().ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassDescriptionA>", ARA_Globals.RiskClassDescription[temp.calculateRiskEstimationClass()], riskEstimationColors[temp.calculateRiskEstimationClass()]);

                        //Find minimal addition options table and fill it.
                        Microsoft.Office.Interop.Word.Table minimalAdditionMeasuresTable = wordInterface.findTableWithTitle(wordDocument, "MinimalAdditionMeasures");
                        minimalAdditionMeasures.RowFilter = "InProject = '1'";
                        wordInterface.fillTableWithRiskReducingMeasures(wordDocument, minimalAdditionMeasuresTable, minimalAdditionMeasures, "MeasureSubGroup", "InProject");
                        minimalAdditionMeasuresTable.Title = "";

                        //Clear some memory.
                        temp.Dispose();
                        temp = null;

                        //Do we need to cancel execution?
                        if (backgroundWorker1.CancellationPending)
                        {
                            break;
                        }
                    }

                    //Remove template from memory.
                    if (remainingRiskTemplate != null)
                    {
                        ((_Document)remainingRiskTemplate).Close(ref paramFalse, ref missing,
                                                                 ref missing);
                        File.Delete(tempTemplateFile);
                        remainingRiskTemplate = null;
                    }
                    //Remove headerTemplate from memory.
                    if (remainingRiskHeaderTemplate != null)
                    {
                        ((_Document)remainingRiskHeaderTemplate).Close(ref paramFalse, ref missing,
                                                                       ref missing);
                        File.Delete(tempHeaderTemplateFile);
                        remainingRiskHeaderTemplate = null;
                    }
                }
                catch (Exception ex)
                {
                }
            }
        }
        public static List <Microsoft.Office.Interop.Word.ContentControl> GetContentControl(ContentControls contentControls)
        {
            var ccList = new List <Microsoft.Office.Interop.Word.ContentControl>();

            try
            {
                foreach (Microsoft.Office.Interop.Word.ContentControl cc in contentControls)
                {
                    ccList.Add(cc);
                }
            }
            catch (COMException)
            {
            }

            return(ccList);
        }
Example #10
0
        internal override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Free managed
                if (_sections != null && !_sections.IsDisposed)
                {
                    _sections.Dispose();
                    _sections = null;
                }

                if (_bookmarks != null && !_bookmarks.IsDisposed)
                {
                    _bookmarks.Dispose();
                    _bookmarks = null;
                }

                if (_contentControls != null && !_contentControls.IsDisposed)
                {
                    _contentControls.Dispose();
                    _contentControls = null;
                }
            }

            base.Dispose(true);
        }
        private void generateRiskPages(byte[] templateLocation, WordInterface wordInterface, Document wordDocument, DataView riskDataRows, DataRow projectInfoRow)
        {
            lock (this.threadLock)
            {
                int currentRisk = 0;
                try
                {
                    //Open template document.
                    String tempTemplateFile = Path.GetTempFileName();
                    File.WriteAllBytes(tempTemplateFile, templateLocation);
                    Document riskTemplate = wordInterface.app.Documents.Open(tempTemplateFile);

                    foreach (DataRowView riskDataRow in riskDataRows)
                    {
                        //Set generating process
                        backgroundWorker1.ReportProgress(
                            33 + (Int32)((float)currentRisk / (float)riskDataRows.Count * 33),
                            (object)string.Format("Generating page {0} of {1}.", currentRisk + 1, riskDataRows.Count)
                            );
                        currentRisk++;

                        //Get the risk data id and set some variables.
                        int     riskDataID           = riskDataRow["ProjectRiskDataID"] != DBNull.Value ? (Int32)riskDataRow["ProjectRiskDataID"] : (Int32)riskDataRow["DefaultRiskDataID"];
                        Color[] riskEstimationColors = { ARA_Colors.ARA_Green, ARA_Colors.ARA_Orange, ARA_Colors.ARA_Red };

                        //Get some more info about the risk.
                        DataRow riskData  = this.tbl_Risk_DataTableAdapter.GetData().FindByRiskDataID(riskDataID);
                        DataRow authorRow = this.tbl_UserTableAdapter.GetData().FindByUserID((Int32)projectInfoRow["UserID"]);

                        DataView riskEstimationBeforeView     = new DataView(this.get_RiskEstimation_In_RiskData_BeforeTableAdapter.GetData(riskDataID));
                        DataView riskEstimationAfterView      = new DataView(this.get_RiskEstimation_In_RiskData_AfterTableAdapter.GetData(riskDataID));
                        DataView appliedRiskReductionMeasures = new DataView(this.get_RiskReduction_In_RiskDataTableAdapter.GetData(riskDataID));
                        DataView minimalAdditionMeasures      = new DataView(this.get_MinimalAddition_In_RiskDataTableAdapter.GetData(riskDataID));

                        //Add fileID row to the riskDataRow procedure.
                        //Get the blob data and convert it to byte[].
                        //And call the wordInterface function to add image watermark to a specific page.
                        //Disable default watermark generation.
                        //if(riskDataRow["fileID"] != DBNull.Value)
                        //{
                        //    DataRow blobDataView = this.tbl_BLOB_StorageTableAdapter.GetData().FindByFileID((Int32)riskDataRow["fileID"]);
                        //}

                        //Set some value's before copying document.
                        riskTemplate.Activate();
                        foreach (DataRow exposedPersonRow in this.get_ExposedPersons_In_RiskDataTableAdapter.GetData(riskDataID).Rows)
                        {
                            ContentControls personCheckbox = riskTemplate.SelectContentControlsByTitle(exposedPersonRow["PersonDescription"].ToString());
                            if (personCheckbox.Count > 0)
                            {
                                personCheckbox[(object)1].Checked = exposedPersonRow["InProject"].ToString() == "1";
                            }
                        }

                        //Copy template.
                        wordInterface.copyDocumentToOtherDocument(riskTemplate, wordDocument, true);
                        wordDocument.Activate();

                        //Sets the risk hazard specifications.
                        generateHazardIndentification(wordInterface, wordDocument, (Int32)riskData["DangerID"], (Int32)riskData["DangerSourceID"]);

                        //Search and replace headerinfo.
                        wordInterface.searchAndReplace(wordDocument, "<CustomerName>", projectInfoRow["Customer"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<MachineInfo>", string.Format("{0}/{1}", projectInfoRow["MachineNumber"].ToString(), projectInfoRow["OrderNumber"].ToString()));
                        wordInterface.searchAndReplace(wordDocument, "<RiskID>", riskDataRow["RiskID"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<BriefActionDescription>", riskDataRow["HazardSituation"].ToString(), ARA_Colors.ARA_Red);

                        //Search and replace riskdata.
                        wordInterface.searchAndReplace(wordDocument, "<RiskGroup>", string.Format("{0} - {1}", riskDataRow["GroupName"].ToString(), riskDataRow["TypeName"].ToString()));
                        wordInterface.searchAndReplace(wordDocument, "<ActionEvent>", riskData["HazardEvent"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskReductionInfo>", riskData["RiskReductionInfo"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<MinimalAdditionInfo>", riskData["MinimalAdditionInfo"].ToString());

                        //Set the riskestimation fields.
                        ARA_EditRiskRiskEstimation temp = new ARA_EditRiskRiskEstimation();
                        temp.setControlData(riskEstimationBeforeView);

                        riskEstimationBeforeView.RowFilter = "InProject = '1'";
                        if (riskEstimationBeforeView.Count != 4)
                        {
                            throw new Exception("Cant generate report, because risk " + riskDataRow["RiskID"].ToString() + " isn't correctly filled in.");
                        }
                        wordInterface.searchAndReplace(wordDocument, "<SEDescriptionB>", riskEstimationBeforeView[0]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<FRDescriptionB>", riskEstimationBeforeView[1]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<PRDescriptionB>", riskEstimationBeforeView[2]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<AVDescriptionB>", riskEstimationBeforeView[3]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<SEWeightB>", riskEstimationBeforeView[0]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<FRWeightB>", riskEstimationBeforeView[1]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<PRWeightB>", riskEstimationBeforeView[2]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<AVWeightB>", riskEstimationBeforeView[3]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassValueB>", temp.calculateRiskEstimationClass().ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassDescriptionB>", ARA_Globals.RiskClassDescription[temp.calculateRiskEstimationClass()], riskEstimationColors[temp.calculateRiskEstimationClass()]);

                        temp.setControlData(riskEstimationAfterView);
                        riskEstimationAfterView.RowFilter = "InProject = '1'";
                        if (riskEstimationAfterView.Count != 4)
                        {
                            throw new Exception("Cant generate report, because risk " + riskDataRow["RiskID"].ToString() + " isn't correctly filled in.");
                        }
                        wordInterface.searchAndReplace(wordDocument, "<SEDescriptionA>", riskEstimationAfterView[0]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<FRDescriptionA>", riskEstimationAfterView[1]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<PRDescriptionA>", riskEstimationAfterView[2]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<AVDescriptionA>", riskEstimationAfterView[3]["ItemDescription"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<SEWeightA>", riskEstimationAfterView[0]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<FRWeightA>", riskEstimationAfterView[1]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<PRWeightA>", riskEstimationAfterView[2]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<AVWeightA>", riskEstimationAfterView[3]["ItemWeight"].ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassValueA>", temp.calculateRiskEstimationClass().ToString());
                        wordInterface.searchAndReplace(wordDocument, "<RiskClassDescriptionA>", ARA_Globals.RiskClassDescription[temp.calculateRiskEstimationClass()], riskEstimationColors[temp.calculateRiskEstimationClass()]);

                        //Find table and do stuff with it.
                        Microsoft.Office.Interop.Word.Table appliedRiskReductionMeasuresTable = wordInterface.findTableWithTitle(wordDocument, "AppliedRiskReductionMeasures");
                        appliedRiskReductionMeasures.RowFilter = "InProject = '1'";
                        wordInterface.fillTableWithRiskReducingMeasures(wordDocument, appliedRiskReductionMeasuresTable, appliedRiskReductionMeasures, "MeasureSubGroup", "InProject");
                        appliedRiskReductionMeasuresTable.Title = "";

                        Microsoft.Office.Interop.Word.Table minimalAdditionMeasuresTable = wordInterface.findTableWithTitle(wordDocument, "MinimalAdditionMeasures");
                        minimalAdditionMeasures.RowFilter = "InProject = '1'";
                        wordInterface.fillTableWithRiskReducingMeasures(wordDocument, minimalAdditionMeasuresTable, minimalAdditionMeasures, "MeasureSubGroup", "InProject");
                        minimalAdditionMeasuresTable.Title = "";

                        //Set author en reviewer names.
                        wordInterface.searchAndReplace(wordDocument, "<AuthorName>", authorRow["UserName"].ToString(), new Color(), true);
                        //Did someone review this risk?
                        if (riskDataRow["ReviewedByUser"] != DBNull.Value)
                        {
                            DataRow reviewerRow = this.tbl_UserTableAdapter.GetData().FindByUserID((Int32)riskDataRow["ReviewedByUser"]);
                            wordInterface.searchAndReplace(wordDocument, "<ReviewerName>", reviewerRow["UserName"].ToString(), new Color(), true);
                        }
                        else
                        {
                            wordInterface.searchAndReplace(wordDocument, "<ReviewerName>", "NOT REVIEWED", new Color(), true);
                        }

                        //Clear some memory.
                        temp.Dispose();
                        temp = null;

                        //Do we need to cancel execution?
                        if (backgroundWorker1.CancellationPending)
                        {
                            break;
                        }
                    }

                    //Remove template from memory.
                    if (riskTemplate != null)
                    {
                        ((_Document)riskTemplate).Close(ref paramFalse, ref missing,
                                                        ref missing);
                        File.Delete(tempTemplateFile);
                        riskTemplate = null;
                    }
                }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ARA_Constants.messageBoxSomethingWrongWhileGenerating + ex.Message, ARA_Constants.messageBoxSomethingWrongWhileGeneratingHeader, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                }
            }
        }
Example #12
0
        private static List <SignatureInfo> GetHeaderSignatureCtrls(Word.Document doc)
        {
            List <SignatureInfo> signaturesHeader = new List <SignatureInfo>();

            try
            {
                foreach (Microsoft.Office.Interop.Word.Section wordSection in doc.Sections)
                {
                    foreach (Microsoft.Office.Interop.Word.HeaderFooter wordHeader in wordSection.Headers)
                    {
                        Microsoft.Office.Interop.Word.Range docRange = wordHeader.Range;
                        ContentControls headerControls = docRange.ContentControls;

                        if (headerControls != null)
                        {
                            int counter = 1;
                            foreach (Microsoft.Office.Interop.Word.ContentControl control in headerControls)
                            {
                                //MessageBox.Show("headerControls:" + control.Tag);
                                if (control.Tag.ToUpper().Contains(SIGNATURE_FIELD))
                                {
                                    //12/03/2017 - Do not allow typing in this field from inside the document
                                    //control.LockContents = false;
                                    //control.LockContentControl = false;

                                    //Tag will include section and name in the format:
                                    //B:Signature1
                                    //F1:Signature2
                                    //F2:Signature2
                                    string[]      parts         = control.Tag.ToUpper().Split(':');
                                    SignatureInfo signatureInfo = new SignatureInfo
                                    {
                                        Title                    = control.Title,
                                        Tag                      = parts.Length > 1 ? parts[1] : control.Tag,
                                        SignatureControl         = control,
                                        SignatureControlPosition = parts.Length > 1 ? parts[0] : "Header"
                                    };
                                    counter++;
                                    signaturesHeader.Add(signatureInfo);
                                }
                            }
                        }

                        if (Marshal.IsComObject(docRange))
                        {
                            Marshal.ReleaseComObject(docRange);
                        }
                        if (Marshal.IsComObject(headerControls))
                        {
                            Marshal.ReleaseComObject(headerControls);
                        }

                        if (Marshal.IsComObject(wordHeader))
                        {
                            Marshal.ReleaseComObject(wordHeader);
                        }
                    }

                    if (Marshal.IsComObject(wordSection))
                    {
                        Marshal.ReleaseComObject(wordSection);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Error, "GetHeaderSignatureCtrls", ex);
            }
            return(signaturesHeader);
        }
Example #13
0
        private static List <Word.ContentControl> GetHeaderCtrls(Word.Document doc, string tag, bool contains = true)
        {
            List <Microsoft.Office.Interop.Word.ContentControl> headerCtrls = new List <Microsoft.Office.Interop.Word.ContentControl>();

            try
            {
                foreach (Microsoft.Office.Interop.Word.Section wordSection in doc.Sections)
                {
                    foreach (Microsoft.Office.Interop.Word.HeaderFooter wordHeader in wordSection.Headers)
                    {
                        Microsoft.Office.Interop.Word.Range docRange = wordHeader.Range;

                        ContentControls headerControls = docRange.ContentControls;

                        if (headerControls != null)
                        {
                            foreach (Microsoft.Office.Interop.Word.ContentControl control in headerControls)
                            {
                                if (contains)
                                {
                                    if (control.Tag.ToUpper().Contains(tag.ToUpper()))
                                    {
                                        headerCtrls.Add(control);
                                    }
                                }
                                else
                                {
                                    if (control.Tag.ToUpper().Equals(tag.ToUpper()))
                                    {
                                        headerCtrls.Add(control);
                                    }
                                }
                            }
                        }

                        if (Marshal.IsComObject(docRange))
                        {
                            Marshal.ReleaseComObject(docRange);
                        }
                        if (Marshal.IsComObject(headerControls))
                        {
                            Marshal.ReleaseComObject(headerControls);
                        }
                        if (Marshal.IsComObject(wordHeader))
                        {
                            Marshal.ReleaseComObject(wordHeader);
                        }
                    }

                    if (Marshal.IsComObject(wordSection))
                    {
                        Marshal.ReleaseComObject(wordSection);
                    }
                }
            }
            catch (Exception ex)
            {
                logger.LogException(LogLevel.Error, "GetHeaderCtrls", ex);
            }
            return(headerCtrls);
        }
Example #14
0
        internal override void Dispose(bool disposing)
        {
            if (disposing)
            {
                // Free managed
                if (_contentControls != null && !_contentControls.IsDisposed)
                {
                    _contentControls.Dispose();
                    _contentControls = null;
                }

                if (_fields != null && !_fields.IsDisposed)
                {
                    _fields.Dispose();
                    _fields = null;
                }

                if (_inlineShapes != null && !_inlineShapes.IsDisposed)
                {
                    _inlineShapes.Dispose();
                    _inlineShapes = null;
                }
            }

            base.Dispose(true);
        }
Example #15
0
        private void InitialiseControls()
        {
            HtmlGenericControl divBlock = new HtmlGenericControl("Div");

            divBlock.ID = "DivCarga";
            divBlock.Style.Add(HtmlTextWriterStyle.Display, "none");
            this.Controls.Add(divBlock);


            HtmlGenericControl divCuerpo = new HtmlGenericControl("Div");

            divCuerpo.ID = "DivCuerpo";
            divCuerpo.Style.Add(HtmlTextWriterStyle.Display, "none");
            divCuerpo.Style.Add(HtmlTextWriterStyle.Position, "absolute");
            divCuerpo.Style.Add(HtmlTextWriterStyle.Top, "30%");
            divCuerpo.Style.Add(HtmlTextWriterStyle.Left, " 25%");

            if (ZIndex == null)
            {
                divCuerpo.Style.Add(HtmlTextWriterStyle.ZIndex, "100199999");
            }
            else
            {
                divCuerpo.Style.Add(HtmlTextWriterStyle.ZIndex, ZIndex);
            }

            divCuerpo.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Transparent");
            divCuerpo.Style.Add(HtmlTextWriterStyle.VerticalAlign, " middle");
            divCuerpo.Style.Add(HtmlTextWriterStyle.TextAlign, " center");
            divCuerpo.Style.Add(HtmlTextWriterStyle.Height, "100%");



            this.Controls.Add(divCuerpo);


            HtmlTable     tbl   = new HtmlTable();
            HtmlTableRow  row   = new HtmlTableRow();
            HtmlTableCell cell  = new HtmlTableCell();
            HtmlTableCell cell1 = new HtmlTableCell();
            HtmlTableCell cell2 = new HtmlTableCell();

            tbl.CellPadding = 0;
            tbl.CellSpacing = 0;
            tbl.Attributes.Add("border", "0");
            tbl.Style.Add(HtmlTextWriterStyle.BackgroundColor, "Transparent");

            string ImagenWindowColor = "ServerWindowMarzzan";

            switch (WindowColor)
            {
            case _WindowColor.Rojo:
                ImagenWindowColor = "LoginConosud";
                break;

            case _WindowColor.Azul:
                ImagenWindowColor = "ServerWindowMarzzan";
                break;

            case _WindowColor.Gray:
                ImagenWindowColor = "LoginKisoco";
                break;

            default:
                break;
            }


            #region Header windows


            cell.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r1_c1.png"));
            cell.Style.Add(HtmlTextWriterStyle.Width, "27px");
            cell.Style.Add(HtmlTextWriterStyle.Height, "44px");
            cell.Style.Add("background-color", "Transparent");
            cell.Style.Add("background-repeat", " no-repeat");
            cell.Style.Add("background-position", "top");
            cell.InnerHtml = "<div style='width: 100%; background-color: " + BackGroundColor + "; position:relative;left:15px;top:17px;z-index:-1'></div>";


            cell1.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r1_c3.png"));
            cell1.Style.Add(HtmlTextWriterStyle.Height, "35px");
            cell1.Style.Add("background-color", "Transparent");
            cell1.Style.Add("background-repeat", "repeat-x");
            cell1.Style.Add("background-position", "top");
            cell1.Style.Add(HtmlTextWriterStyle.TextAlign, "left");
            cell1.InnerHtml = "<div style='width: 100%;height:15px;background-color: " + BackGroundColor + "; position:relative;top:35px;z-index:-1'></div>";



            Label lblTitulo = new Label();
            lblTitulo.ID = "lblTituloControlWindow";
            lblTitulo.Style.Add(HtmlTextWriterStyle.Color, ForeColorTitle);
            lblTitulo.Style.Add(HtmlTextWriterStyle.FontSize, "16px");
            lblTitulo.Style.Add(HtmlTextWriterStyle.FontFamily, "'" + FontNameTitle + "'");
            lblTitulo.Style.Add(HtmlTextWriterStyle.FontWeight, "bold");
            lblTitulo.Style.Add(HtmlTextWriterStyle.TextAlign, "left");
            lblTitulo.Style.Add(HtmlTextWriterStyle.Top, "-12px");
            lblTitulo.Style.Add(HtmlTextWriterStyle.Left, "-10px");
            lblTitulo.Style.Add(HtmlTextWriterStyle.Position, "relative");
            lblTitulo.Style.Add("text-transform", "capitalize");
            cell1.ID = "CelllblTitulo";
            cell1.Controls.Add(lblTitulo);



            cell2.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r1_c5.png"));
            cell2.Style.Add(HtmlTextWriterStyle.Width, "22px");
            cell2.Style.Add(HtmlTextWriterStyle.Height, "35px");
            cell2.Style.Add("background-color", "Transparent");
            cell2.Style.Add("background-repeat", "no-repeat");
            cell2.Style.Add("background-position", "top");
            cell2.Attributes.Add("align", "left");
            cell2.InnerHtml = "<div style='width: 100%; background-color: " + BackGroundColor + "; position:relative;left:-10px;top:25px;z-index:-1'></div>";


            ImageButton imgClose = new ImageButton();
            imgClose.ID       = "imgCloseControlWindow";
            imgClose.ImageUrl = Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow.Cancelar.gif");
            imgClose.Style.Add(HtmlTextWriterStyle.Top, "-14px");
            imgClose.Style.Add(HtmlTextWriterStyle.Left, "-5px");
            imgClose.Style.Add(HtmlTextWriterStyle.Position, "relative");
            imgClose.CausesValidation = false;
            imgClose.OnClientClick    = "return false;";
            cell2.Controls.Add(imgClose);


            row.Cells.Add(cell);
            row.Cells.Add(cell1);
            row.Cells.Add(cell2);
            tbl.Rows.Add(row);
            #endregion


            #region Center windows

            row  = new HtmlTableRow();
            cell = new HtmlTableCell();
            HtmlTableCell cellContent = new HtmlTableCell();
            cell2 = new HtmlTableCell();

            cell.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r3_c1.png"));
            cell.Style.Add(HtmlTextWriterStyle.Width, "22px");
            cell.Style.Add("background-color", "Transparent");
            cell.Style.Add("background-repeat", "repeat-y");
            cell.Style.Add("background-position", "left top");

            HtmlGenericControl divLeft = new HtmlGenericControl("Div");
            divLeft.ID = "DivLeft";
            //divLeft.Style.Value = "height:100%;width: 100%;background-color: red; position:relative;left:10px;z-index:-1";
            divLeft.Style.Value = "height:100%;width: 100%;background-color: " + BackGroundColor + "; position:relative;left:10px;z-index:-1";
            cell.Controls.Add(divLeft);



            cellContent.Style.Add("background-color", BackGroundColor);
            cellContent.Attributes.Add("align", "left");
            cellContent.Style.Add(HtmlTextWriterStyle.FontSize, "12px");
            cellContent.Style.Add(HtmlTextWriterStyle.FontFamily, "Tahoma");
            cellContent.Style.Add(HtmlTextWriterStyle.Color, "black");
            cellContent.Style.Add(HtmlTextWriterStyle.MarginTop, "-20px");
            cellContent.Style.Add(HtmlTextWriterStyle.MarginLeft, "-20px");



            cell2.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r3_c5.png"));
            cell2.Style.Add("background-color", "Transparent");
            cell2.Style.Add("background-repeat", "repeat-y");
            cell2.Style.Add("background-position", "top");

            HtmlGenericControl divRight = new HtmlGenericControl("Div");
            divRight.ID = "DivRight";
            //divRight.Style.Value = "height:100%;width: 100%;background-color: red; position:relative;right:10px;z-index:-1";
            divRight.Style.Value = "height:100%;width: 100%;background-color: " + BackGroundColor + "; position:relative;right:10px;z-index:-1";
            cell2.Controls.Add(divRight);


            row.Cells.Add(cell);
            row.Cells.Add(cellContent);
            row.Cells.Add(cell2);
            tbl.Rows.Add(row);
            #endregion


            #region Footer windows

            row   = new HtmlTableRow();
            cell  = new HtmlTableCell();
            cell1 = new HtmlTableCell();
            cell2 = new HtmlTableCell();


            cell.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r5_c1.png"));
            cell.Style.Add(HtmlTextWriterStyle.Height, "37px");
            cell.Style.Add("background-color", "Transparent");
            cell.Style.Add("background-repeat", " no-repeat");
            cell.Style.Add("background-position", "left top");
            cell.InnerHtml = @"<div style='width: 100%; background-color: " + BackGroundColor + "; position:relative;left:10px;top:-15px;z-index:-1'></div>";


            cell1.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r5_c3.png"));
            cell1.Style.Add("background-color", "Transparent");
            cell1.Style.Add("background-repeat", "repeat-x");
            cell1.Style.Add("background-position", "top");
            cell1.InnerHtml = @"<div style='width: 100%;height:100%;background-color: " + BackGroundColor + "; position:relative;top:-15px;z-index:-1'></div>";


            cell2.Style.Add(HtmlTextWriterStyle.BackgroundImage, Page.ClientScript.GetWebResourceUrl(this.GetType(), "ControlsAjaxNotti.ImagenesWindow." + ImagenWindowColor + "_r5_c5.png"));
            cell2.Style.Add("background-color", "Transparent");
            cell2.Style.Add("background-repeat", "no-repeat");
            cell2.Style.Add("background-position", "top");
            cell2.InnerHtml = @"<div style='width: 100%; background-color: " + BackGroundColor + "; position:relative;top:-15px;right:15px;z-index:-1'></div>";


            row.Cells.Add(cell);
            row.Cells.Add(cell1);
            row.Cells.Add(cell2);
            tbl.Rows.Add(row);
            #endregion


            divCuerpo.Controls.Add(tbl);


            ContentControls.InstantiateIn(cellContent);
        }
 private ContentControl GetContentControl(ContentControls controls, string title)
 {
     return controls.Cast<ContentControl>().FirstOrDefault(control => control.Title == title);
 }