예제 #1
0
    public ActionResult SaveAndCopy(IncidentAction incidentAction, bool applyAction, long businessRiskId, int userId)
    {
        var res = ActionResult.NoAction;

        if (incidentAction.Id < 1)
        {
            res = incidentAction.Insert(userId);
        }
        else
        {
            res = incidentAction.Update(userId);
        }

        if (applyAction)
        {
            var risk = BusinessRisk.ById(incidentAction.CompanyId, businessRiskId);
            incidentAction.BusinessRiskId   = risk.Id;
            incidentAction.WhatHappenedOn   = risk.DateStart;
            incidentAction.Causes           = risk.Causes;
            incidentAction.ClosedBy         = null;
            incidentAction.ClosedExecutor   = null;
            incidentAction.ClosedExecutorOn = null;
            incidentAction.ClosedOn         = null;
            res = incidentAction.Insert(userId);
        }

        return(res);
    }
예제 #2
0
        public void MapFromDomainEntity_NullContent_ReturnNull()
        {
            //Act
            var response = BusinessRisk.MapFromDomainEntity(null);

            //Assert
            Assert.IsNull(response);
        }
예제 #3
0
        public ActionResult BusinessRiskActivate(int businessRiskId, int companyId, int userId)
        {
            var res = BusinessRisk.Activate(businessRiskId, string.Empty, companyId, userId);

            if (res.Success)
            {
                this.Session["Company"] = new Company(companyId);
            }

            return(res);
        }
예제 #4
0
        public ActionResult BusinessRiskInsert(BusinessRisk businessRisk, int companyId, int userId)
        {
            var res = businessRisk.Insert(userId);

            if (res.Success)
            {
                //// string differences = businessRisk.Differences(BusinessRisk.Empty);
                //// ActionResult logRes = ActivityLog.BusinessRisk(Convert.ToInt64(res.MessageError), userId, companyId, DepartmentLogActions.Create, differences);
                this.Session["Company"] = new Company(companyId);
            }

            return(res);
        }
예제 #5
0
        public static BusinessRiskDTO MapFromDatabaseEntity(BusinessRisk businessRisk)
        {
            if (businessRisk == null)
            {
                return(null);
            }

            return(new BusinessRiskDTO()
            {
                Id = businessRisk.Id,
                Value = businessRisk.Value,
                Position = businessRisk.Position
            });
        }
예제 #6
0
        public string GetFilter(int companyId, DateTime?from, DateTime?to, long rulesId, long processId, int type, int itemType)
        {
            var filter = new StringBuilder("{");

            filter.Append(Tools.JsonPair("companyId", companyId)).Append(",");
            filter.Append(Tools.JsonPair("from", from)).Append(",");
            filter.Append(Tools.JsonPair("to", to)).Append(",");
            filter.Append(Tools.JsonPair("rulesId", rulesId)).Append(",");
            filter.Append(Tools.JsonPair("processId", processId)).Append(",");
            filter.Append(Tools.JsonPair("itemType", itemType)).Append(",");
            filter.Append(Tools.JsonPair("type", type)).Append("}");
            this.Session["BusinessRiskFilter"] = filter.ToString();
            this.Session["OportunityFilter"]   = null;
            return(BusinessRisk.FilterList(companyId, from, to, rulesId, processId, type));
        }
예제 #7
0
        public void MapFromDomainEntity_ValidEntity_ReturnDTOEntity()
        {
            //Arrange
            var businessRisk = new BusinessRisk()
            {
                Id       = Guid.NewGuid(),
                Value    = "Security",
                Position = 0
            };
            var response = BusinessRiskDTO.MapFromDatabaseEntity(businessRisk);

            Assert.IsNotNull(response);
            Assert.AreEqual(businessRisk.Id, response.Id);
            Assert.AreEqual(businessRisk.Value, response.Value);
            Assert.AreEqual(businessRisk.Position, response.Position);
        }
        private static void SeedBusinessRisks(CapRedV2Context context)
        {
            if (context.BusinessRisks.Any())
            {
                return;
            }
            string[] businessRisks = { "Security", "Financial", "Compliance", "Operational" };

            for (int i = 0; i < businessRisks.Length; i++)
            {
                var businessRisk = new BusinessRisk {
                    Id = Guid.NewGuid(), Position = i, Value = businessRisks[i]
                };
                context.BusinessRisks.Add(businessRisk);
            }
        }
예제 #9
0
    private void RenderBusinessRiskTable()
    {
        var resJson = new StringBuilder("[");
        int total   = 0;

        if (this.RuleId > 0)
        {
            var res   = new StringBuilder();
            var risks = BusinessRisk.GetByRulesId(this.RuleId, this.company.Id);
            if (risks.Count > 0)
            {
                bool first = true;
                foreach (BusinessRisk risk in risks)
                {
                    long result = risk.FinalResult;
                    if (result == 0)
                    {
                        result = risk.StartResult;
                    }

                    string status = string.Empty;
                    string color  = "#000";

                    if (risk.Assumed || risk.FinalAction == 1)
                    {
                        status = this.Dictionary["Item_BusinessRisk_Status_Assumed"];
                        color  = "#ffb752";
                    }
                    else if (result == 0)
                    {
                        status = this.Dictionary["Item_BusinessRisk_Status_Unevaluated"];
                        color  = "#777777";
                    }
                    else
                    {
                        if (result < this.Rule.Limit)
                        {
                            status = this.dictionary["Item_BusinessRisk_Status_NotSignificant"];
                            color  = "#87b87f";
                        }
                        else
                        {
                            status = this.dictionary["Item_BusinessRisk_Status_Significant"];
                            color  = "#d15b47";
                        }
                    }

                    total++;
                    res.AppendFormat(
                        CultureInfo.GetCultureInfo("en-us"),
                        @"<tr><td style=""display:none;width:90px;"">{0}</td><td>{1}</td><td style=""width:120px;font-weight:bold;color:{4}"">{2}</td><td style=""Width:70px;"" align=""right"">{3}</td></tr>",
                        risk.LinkCode,
                        risk.LinkList,
                        status,
                        result == 0 ? string.Empty : result.ToString(),
                        color);

                    if (first)
                    {
                        first = false;
                    }
                    else
                    {
                        resJson.Append(",");
                    }

                    resJson.AppendFormat(
                        CultureInfo.InvariantCulture,
                        @"{{""Name"":""{0}"", ""Value"":{1}}}",
                        risk.Description,
                        risk.FinalResult != 0 ? risk.FinalResult : risk.StartResult);
                }
            }
            else
            {
                res.AppendFormat(
                    CultureInfo.InvariantCulture,
                    @"<td colspan=""4"" align=""center"" style=""background-color:#ddddff;color:#0000aa;""><table style=""border:none;""><tbody><tr><td rowspan=""2"" style=""border:none;""><i class=""icon-info-sign"" style=""font-size:48px;""></i></td><td style=""border:none;""><h4>{0}</h4></td></tr></tbody></table></td>",
                    this.dictionary["Item_Rules_Section_BusinessRisk_NoData"]
                    );
            }

            this.TableBusiness.Text = res.ToString();
            this.TotalData.Text     = total.ToString();
        }

        resJson.Append("]");
        this.BusinessRisksJson = resJson.ToString();
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        var borderSides = Rectangle.RIGHT_BORDER + Rectangle.LEFT_BORDER;
        var borderBL    = Rectangle.BOTTOM_BORDER + Rectangle.LEFT_BORDER;
        var borderBR    = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER;
        var borderTBL   = Rectangle.TOP_BORDER + Rectangle.BOTTOM_BORDER + Rectangle.LEFT_BORDER;
        var borderTBR   = Rectangle.TOP_BORDER + Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER;
        var alignRight  = Element.ALIGN_RIGHT;

        long businessRiskId = Convert.ToInt64(Request.QueryString["id"]);
        int  companyId      = Convert.ToInt32(Request.QueryString["companyId"]);
        var  company        = new Company(companyId);
        var  res            = ActionResult.NoAction;
        var  user           = HttpContext.Current.Session["User"] as ApplicationUser;
        var  dictionary     = HttpContext.Current.Session["Dictionary"] as Dictionary <string, string>;
        var  businessRisk   = BusinessRisk.ById(user.CompanyId, businessRiskId);

        string path = HttpContext.Current.Request.PhysicalApplicationPath;

        if (!path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase))
        {
            path = string.Format(CultureInfo.InvariantCulture, @"{0}\", path);
        }

        var    formatedDescription = ToolsPdf.NormalizeFileName(businessRisk.Description);
        var    alignLeft           = Element.ALIGN_LEFT;
        string fileName            = string.Format(
            CultureInfo.InvariantCulture,
            @"{0}_{1}_Data_{2:yyyyMMddhhmmss}.pdf",
            dictionary["Item_BusinessRisk"],
            formatedDescription,
            DateTime.Now);

        var pathFonts = HttpContext.Current.Request.PhysicalApplicationPath;

        if (!path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase))
        {
            pathFonts = string.Format(CultureInfo.InstalledUICulture, @"{0}\", pathFonts);
        }

        this.headerFont = BaseFont.CreateFont(string.Format(CultureInfo.InvariantCulture, @"{0}fonts\ARIAL.TTF", pathFonts), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        this.arial      = BaseFont.CreateFont(string.Format(CultureInfo.InvariantCulture, @"{0}fonts\ARIAL.TTF", pathFonts), BaseFont.IDENTITY_H, BaseFont.EMBEDDED);
        var descriptionFont = new Font(this.headerFont, 12, Font.BOLD, BaseColor.BLACK);
        var document        = new iTextSharp.text.Document(PageSize.A4, 40, 40, 65, 55);

        var writer           = PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\Temp\\" + fileName, FileMode.Create));
        var pageEventHandler = new TwoColumnHeaderFooter
        {
            CompanyLogo = string.Format(CultureInfo.InvariantCulture, @"{0}\images\logos\{1}.jpg", path, companyId),
            IssusLogo   = string.Format(CultureInfo.InvariantCulture, "{0}issus.png", path),
            Date        = string.Format(CultureInfo.InvariantCulture, "{0:dd/MM/yyyy}", DateTime.Now),
            CreatedBy   = string.Format(CultureInfo.InvariantCulture, "{0}", user.UserName),
            CompanyId   = businessRisk.CompanyId,
            CompanyName = company.Name,
            Title       = dictionary["Item_BusinessRisk"]
        };

        writer.PageEvent = pageEventHandler;
        document.Open();

        #region Dades bàsiques
        var table = new PdfPTable(4)
        {
            WidthPercentage     = 100,
            HorizontalAlignment = 0
        };

        table.SetWidths(new float[] { 30f, 50f, 30f, 50f });

        table.AddCell(new PdfPCell(new Phrase(businessRisk.Description, descriptionFont))
        {
            Colspan             = 4,
            Border              = Rectangle.NO_BORDER,
            PaddingTop          = 10f,
            PaddingBottom       = 10f,
            HorizontalAlignment = Element.ALIGN_CENTER
        });

        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_Tab_Basic"], 4));

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_DateStart"]));
        table.AddCell(TitleData(string.Format(CultureInfo.InvariantCulture, @"{0:dd/MM/yyyy}", businessRisk.DateStart)));

        table.AddCell(TitleLabel(dictionary["Item_Process"]));
        table.AddCell(TitleData(businessRisk.Process.Description));

        table.AddCell(TitleLabel(dictionary["Item_Rule"]));
        table.AddCell(TitleData(businessRisk.Rules.Description));

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_IPR"]));
        table.AddCell(TitleData(businessRisk.Rules.Limit.ToString()));

        string startProbabilityText = businessRisk.StartProbability.ToString();
        if (startProbabilityText == "0")
        {
            startProbabilityText = "-";
        }

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Probability"]));
        table.AddCell(TitleData(startProbabilityText));

        string startSeverityText = businessRisk.StartSeverity.ToString();
        if (startSeverityText == "0")
        {
            startSeverityText = "-";
        }

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Severity"]));
        table.AddCell(TitleData(startSeverityText));

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Status"]));
        table.AddCell(TitleData(dictionary["Item_BusinessRisk_Status_Assumed"]));

        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_LabelField_Description"]));
        table.AddCell(TextAreaCell(Environment.NewLine + businessRisk.ItemDescription, ToolsPdf.BorderAll, alignLeft, 4));

        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_LabelField_Causes"]));
        table.AddCell(TextAreaCell(Environment.NewLine + businessRisk.Causes, ToolsPdf.BorderAll, alignLeft, 4));

        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_LabelField_StartControl"]));
        table.AddCell(TextAreaCell(Environment.NewLine + businessRisk.StartControl, ToolsPdf.BorderAll, alignLeft, 4));

        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_LabelField_Notes"]));
        table.AddCell(TextAreaCell(Environment.NewLine + businessRisk.Notes, ToolsPdf.BorderAll, alignLeft, 4));

        table.AddCell(SeparationRow());

        table.AddCell(TitleCell(dictionary["Item_BusinessRisk_Tab_Graphics"], 4));

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_IPR"]));
        table.AddCell(TitleData(businessRisk.Rules.Limit.ToString()));

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Status"]));
        table.AddCell(TitleData(dictionary["Item_BusinessRisk_Status_Assumed"]));

        string finalProbabilityText = businessRisk.FinalProbability.ToString();
        if (finalProbabilityText == "0")
        {
            finalProbabilityText = "-";
        }

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Probability"]));
        table.AddCell(TitleData(finalProbabilityText));

        string finalSeverityText = businessRisk.FinalProbability.ToString();
        if (finalSeverityText == "0")
        {
            finalSeverityText = "-";
        }

        table.AddCell(TitleLabel(dictionary["Item_BusinessRisk_LabelField_Severity"]));
        table.AddCell(TitleData(finalSeverityText));

        document.Add(table);
        #endregion

        if (user.HasGrantToRead(ApplicationGrant.IncidentActions))
        {
            // Añadir posible acción
            var action = IncidentAction.ByBusinessRiskId(businessRisk.Id, companyId);
            if (action.Id > 0)
            {
                var tableAction = new PdfPTable(4)
                {
                    WidthPercentage     = 100,
                    HorizontalAlignment = 0
                };

                tableAction.SetWidths(new float[] { 15f, 30f, 15f, 30f });

                // Descripción
                //tableAction.AddCell(valueCell(dictionary["Item_Incident_PDF_ActionPageTitle"]+"*", borderNone, alignLeft, 4));



                var headerFont = new Font(this.arial, 15, Font.NORMAL, BaseColor.BLACK);

                /*
                 *              tableAction.AddCell(new PdfPCell(new Phrase(dictionary["Item_Incident_PDF_ActionPageTitle"] + ": " + action.Description, descriptionFont))
                 *              {
                 *                      Colspan = 4,
                 *                      Border = ToolsPdf.BorderNone,
                 *                      HorizontalAlignment = Rectangle.ALIGN_CENTER
                 *              });
                 */

                tableAction.AddCell(new PdfPCell(new Phrase(dictionary["Item_Incident_PDF_ActionPageTitle"], descriptionFont))
                {
                    Colspan             = 4,
                    Border              = ToolsPdf.BorderNone,
                    HorizontalAlignment = Rectangle.ALIGN_CENTER
                });

                tableAction.AddCell(new PdfPCell(new Phrase(action.Description, descriptionFont))
                {
                    Colspan             = 4,
                    Border              = ToolsPdf.BorderNone,
                    HorizontalAlignment = Rectangle.ALIGN_CENTER
                });



                //tableAction.AddCell(LabelCell(dictionary["Item_IncidentAction_Label_Description"], Rectangle.NO_BORDER));
                //tableAction.AddCell(ValueCell(action.Description, ToolsPdf.BorderNone, alignLeft, 3));


                // WhatHappend
                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_WhatHappened"]));
                tableAction.AddCell(TextAreaCell(Environment.NewLine + action.WhatHappened, borderSides, alignLeft, 4));
                tableAction.AddCell(BlankRow());
                tableAction.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + action.WhatHappenedBy.FullName, borderBL, alignLeft, 2));
                tableAction.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1:dd/MM/yyyy}", dictionary["Common_Date"], action.WhatHappenedOn), borderBR, alignRight, 2));

                // Causes
                var causesFullName = string.Empty;
                var causesDate     = string.Empty;
                if (action.CausesBy != null)
                {
                    causesFullName = action.CausesBy.FullName;
                    causesDate     = string.Format(CultureInfo.InvariantCulture, "{0:dd/MM/yyyy}", action.CausesOn);
                }

                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Causes"]));
                tableAction.AddCell(TextAreaCell(Environment.NewLine + action.Causes, borderSides, alignLeft, 4));
                tableAction.AddCell(BlankRow());
                tableAction.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + causesFullName, borderBL, alignLeft, 2));
                tableAction.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1}", dictionary["Common_Date"], causesDate), borderBR, alignRight, 2));

                // Actions
                var actionFullName = string.Empty;
                var actionDate     = string.Empty;
                if (action.ActionsBy != null)
                {
                    actionFullName = action.ActionsBy.FullName;
                    actionDate     = string.Format(CultureInfo.InvariantCulture, "{0:dd/MM/yyyy}", action.ActionsOn);
                }

                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Actions"]));
                tableAction.AddCell(TextAreaCell(Environment.NewLine + action.Actions, borderSides, alignLeft, 4));
                tableAction.AddCell(BlankRow());
                tableAction.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + actionFullName, borderBL, alignLeft, 2));
                tableAction.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1}", dictionary["Common_DateExecution"], actionDate), borderBR, alignRight, 2));

                // Monitoring
                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Monitoring"]));
                tableAction.AddCell(TextAreaCell(Environment.NewLine + action.Monitoring, ToolsPdf.BorderAll, alignLeft, 4));

                // Close
                var closedFullName = string.Empty;
                var closedDate     = string.Empty;
                if (action.ClosedBy != null)
                {
                    closedFullName = action.ClosedBy.FullName;
                    closedDate     = string.Format(CultureInfo.InvariantCulture, "{0:dd/MM/yyyy}", action.ClosedOn);
                }

                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Close"]));
                tableAction.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "\n{0}: {1}", dictionary["Item_IncidentAction_Field_Responsible"], closedFullName), borderTBL, alignLeft, 2));
                tableAction.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "\n{0}: {1}", dictionary["Common_DateClose"], closedDate), borderTBR, alignRight, 2));

                // Notes
                tableAction.AddCell(SeparationRow());
                tableAction.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Notes"]));
                tableAction.AddCell(TextAreaCell(Environment.NewLine + action.Notes, ToolsPdf.BorderAll, alignLeft, 4));

                document.NewPage();
                document.Add(tableAction);
            }

            #region Historico acciones
            var historico = IncidentAction.ByBusinessRiskCode(businessRisk.Code, company.Id).Where(ia => ia.BusinessRiskId != businessRisk.Id).OrderBy(incidentAction => incidentAction.WhatHappenedOn).ToList();
            if (historico.Count > 0)
            {
                var backgroundColor = new iTS.BaseColor(225, 225, 225);
                var rowPair         = new iTS.BaseColor(255, 255, 255);
                var rowEven         = new iTS.BaseColor(240, 240, 240);
                var headerFontFinal = new iTS.Font(headerFont, 9, iTS.Font.NORMAL, iTS.BaseColor.BLACK);

                document.SetPageSize(PageSize.A4.Rotate());
                document.NewPage();

                var tableHistoric = new iTSpdf.PdfPTable(5)
                {
                    WidthPercentage     = 100,
                    HorizontalAlignment = 1,
                    SpacingBefore       = 20f
                };

                tableHistoric.SetWidths(new float[] { 20f, 30f, 120f, 20f, 20f });

                tableHistoric.AddCell(new PdfPCell(new Phrase(dictionary["Item_BusinessRisk_Tab_HistoryActions"], descriptionFont))
                {
                    Colspan             = 5,
                    Border              = Rectangle.NO_BORDER,
                    PaddingTop          = 20f,
                    PaddingBottom       = 20f,
                    HorizontalAlignment = Element.ALIGN_CENTER
                });

                var valueFont = new Font(this.headerFont, 11, Font.BOLD, BaseColor.BLACK);
                tableHistoric.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentAction_Header_Open"]));
                tableHistoric.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentAction_Header_Status"]));
                tableHistoric.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentAction_Header_Description"]));
                tableHistoric.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentAction_Header_ImplementDate"]));
                tableHistoric.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentAction_Header_Close"]));

                int cont = 0;
                foreach (var accion in historico)
                {
                    string statusText = dictionary["Item_Incident_Status1"];

                    if (accion.CausesOn.HasValue)
                    {
                        statusText = dictionary["Item_Incident_Status2"];
                    }

                    if (accion.ActionsOn.HasValue)
                    {
                        statusText = dictionary["Item_Incident_Status3"];
                    }

                    if (accion.ClosedOn.HasValue)
                    {
                        statusText = dictionary["Item_Incident_Status4"];
                    }

                    tableHistoric.AddCell(ToolsPdf.DataCellCenter(accion.WhatHappenedOn, ToolsPdf.LayoutFonts.Times));
                    tableHistoric.AddCell(ToolsPdf.DataCell(statusText, ToolsPdf.LayoutFonts.Times));
                    tableHistoric.AddCell(ToolsPdf.DataCell(accion.Description, ToolsPdf.LayoutFonts.Times));
                    tableHistoric.AddCell(ToolsPdf.DataCellCenter(accion.ActionsOn, ToolsPdf.LayoutFonts.Times));
                    tableHistoric.AddCell(ToolsPdf.DataCellCenter(accion.ClosedOn, ToolsPdf.LayoutFonts.Times));

                    cont++;
                }

                tableHistoric.AddCell(new iTSpdf.PdfPCell(new iTS.Phrase(dictionary["Common_Total"].ToUpperInvariant() + ": " + cont.ToString(), ToolsPdf.LayoutFonts.Times))
                {
                    Border  = ToolsPdf.BorderTop,
                    Colspan = 5,
                    Padding = 8f
                });

                document.Add(tableHistoric);
            }
            #endregion

            #region Costes
            var costs = IncidentActionCost.ByBusinessRiskId(businessRisk.Id, company.Id);
            if (costs.Count > 0)
            {
                var backgroundColor = new iTS.BaseColor(225, 225, 225);
                var rowPair         = new iTS.BaseColor(255, 255, 255);
                var rowEven         = new iTS.BaseColor(240, 240, 240);
                var headerFontFinal = new iTS.Font(headerFont, 9, iTS.Font.NORMAL, iTS.BaseColor.BLACK);

                document.SetPageSize(PageSize.A4.Rotate());
                document.NewPage();

                var tableCost = new iTSpdf.PdfPTable(5)
                {
                    WidthPercentage     = 100,
                    HorizontalAlignment = 1,
                    SpacingBefore       = 20f
                };

                tableCost.SetWidths(new float[] { 120f, 30f, 30f, 50f, 60f });

                tableCost.AddCell(new PdfPCell(new Phrase(dictionary["Item_Incident_Tab_Costs"], descriptionFont))
                {
                    Colspan             = 5,
                    Border              = Rectangle.NO_BORDER,
                    PaddingTop          = 15f,
                    PaddingBottom       = 15f,
                    HorizontalAlignment = Element.ALIGN_CENTER
                });

                var valueFont = new Font(this.headerFont, 11, Font.BOLD, BaseColor.BLACK);
                tableCost.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Description"]));
                tableCost.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Amount"]));
                tableCost.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Quantity"]));
                tableCost.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Total"]));
                tableCost.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_ReportedBy"]));

                int     cont      = 0;
                decimal costTotal = 0;
                foreach (var cost in costs)
                {
                    tableCost.AddCell(ToolsPdf.DataCell(cost.Description, ToolsPdf.LayoutFonts.Times));
                    tableCost.AddCell(ToolsPdf.DataCellMoney(cost.Amount, ToolsPdf.LayoutFonts.Times));
                    tableCost.AddCell(ToolsPdf.DataCellMoney(cost.Quantity, ToolsPdf.LayoutFonts.Times));
                    tableCost.AddCell(ToolsPdf.DataCellMoney(cost.Amount * cost.Quantity, ToolsPdf.LayoutFonts.Times));
                    tableCost.AddCell(ToolsPdf.DataCell(cost.Responsible.FullName, ToolsPdf.LayoutFonts.Times));

                    costTotal += cost.Amount * cost.Quantity;
                    cont++;
                }

                tableCost.AddCell(new iTSpdf.PdfPCell(new iTS.Phrase(dictionary["Common_RegisterCount"].ToUpperInvariant() + ": " + cont.ToString(), ToolsPdf.LayoutFonts.Times))
                {
                    Border  = ToolsPdf.BorderTop,
                    Colspan = 2,
                    Padding = 8f
                });

                tableCost.AddCell(new iTSpdf.PdfPCell(new iTS.Phrase(dictionary["Common_Total"].ToUpperInvariant() + ":", ToolsPdf.LayoutFonts.Times))
                {
                    Border              = ToolsPdf.BorderTop,
                    Colspan             = 1,
                    Padding             = 8f,
                    HorizontalAlignment = alignRight
                });

                tableCost.AddCell(new iTSpdf.PdfPCell(new iTS.Phrase(Tools.PdfMoneyFormat(costTotal), ToolsPdf.LayoutFonts.Times))
                {
                    Border              = ToolsPdf.BorderTop,
                    Colspan             = 1,
                    Padding             = 8f,
                    HorizontalAlignment = alignRight
                });



                tableCost.AddCell(new iTSpdf.PdfPCell(new iTS.Phrase(string.Empty, ToolsPdf.LayoutFonts.Times))
                {
                    Border              = ToolsPdf.BorderTop,
                    Colspan             = 1,
                    Padding             = 8f,
                    HorizontalAlignment = alignRight
                });

                document.Add(tableCost);
            }

            #endregion
        }

        document.Close();
        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "inline;filename=outfile.pdf");
        Response.ContentType = "application/pdf";
        Response.WriteFile(Request.PhysicalApplicationPath + "\\Temp\\" + fileName);
        Response.Flush();
        Response.Clear();
    }
예제 #11
0
        public ActionResult BusinessRiskUpdate(BusinessRisk newBusinessRisk, int companyId, int userId)
        {
            var res = newBusinessRisk.Update(userId);

            if (res.Success)
            {
                if (newBusinessRisk.FinalDate.HasValue && newBusinessRisk.FinalAction == 3)
                {
                    var newBusinessRiskEvaluated = new BusinessRisk
                    {
                        Description            = newBusinessRisk.Description,
                        Code                   = newBusinessRisk.Code,
                        DateStart              = newBusinessRisk.FinalDate.Value,
                        Notes                  = newBusinessRisk.Notes,
                        ItemDescription        = newBusinessRisk.ItemDescription,
                        Causes                 = newBusinessRisk.Causes,
                        FinalSeverity          = 0,
                        FinalProbability       = 0,
                        FinalResult            = 0,
                        FinalDate              = null,
                        StartProbability       = newBusinessRisk.FinalProbability,
                        StartSeverity          = newBusinessRisk.FinalSeverity,
                        StartResult            = newBusinessRisk.FinalResult,
                        StartAction            = 3,
                        Active                 = true,
                        CompanyId              = newBusinessRisk.CompanyId,
                        PreviousBusinessRiskId = newBusinessRisk.Id,
                        Result                 = Convert.ToInt32(newBusinessRisk.FinalResult),
                        Process                = newBusinessRisk.Process,
                        ProcessId              = newBusinessRisk.Process.Id,
                        Rules                  = newBusinessRisk.Rules
                    };

                    res = newBusinessRiskEvaluated.Insert(userId);

                    var newUser = ApplicationUser.GetById(userId, companyId);

                    var newAction = new IncidentAction
                    {
                        IncidentId     = 0,
                        BusinessRiskId = newBusinessRiskEvaluated.Id,
                        Description    = newBusinessRisk.Description,
                        WhatHappened   = newBusinessRisk.ItemDescription,
                        WhatHappenedBy = newUser.Employee,
                        WhatHappenedOn = newBusinessRisk.FinalDate,
                        Causes         = newBusinessRiskEvaluated.Causes,
                        CausesBy       = newUser.Employee,
                        CausesOn       = newBusinessRisk.FinalDate,
                        CompanyId      = newBusinessRiskEvaluated.CompanyId,
                        ReporterType   = 1,
                        Origin         = 4,
                        ActionType     = 3
                    };

                    newAction.Insert(userId);
                }

                this.Session["Company"] = new Company(companyId);
            }

            return(res);
        }
예제 #12
0
    /// <summary>Begin page running after session validations</summary>
    private void Go()
    {
        if (this.Request.QueryString["id"] != null)
        {
            this.IncidentActionId = Convert.ToInt64(this.Request.QueryString["id"]);
        }

        if (this.Request.QueryString["New"] != null)
        {
            this.returnScript = "document.location = 'ActionsList.aspx';";
        }
        else
        {
            this.returnScript = "document.location = referrer;";
        }

        this.ApplicationUser  = Session["User"] as ApplicationUser;
        this.Company          = Session["company"] as Company;
        this.Dictionary       = Session["Dictionary"] as Dictionary <string, string>;
        this.master           = this.Master as Giso;
        this.master.AdminPage = true;
        string serverPath = this.Request.Url.AbsoluteUri.Replace(this.Request.RawUrl.Substring(1), string.Empty);

        if (this.ApplicationUser.HasGrantToRead(ApplicationGrant.IncidentActions))
        {
            this.master.AddBreadCrumb("Item_IncidentActions", "ActionList.aspx", Constant.NotLeaft);
        }
        else
        {
            this.master.AddBreadCrumb("Item_IncidentActions");
        }

        this.master.AddBreadCrumb("Item_IncidentActions_Detail");
        this.grantToWrite = this.ApplicationUser.HasGrantToWrite(ApplicationGrant.IncidentActions);
        this.Incident     = Incident.Empty;

        if (this.IncidentActionId > 0)
        {
            this.IncidentAction = IncidentAction.ById(this.IncidentActionId, this.Company.Id);
            if (this.IncidentAction.CompanyId != this.Company.Id)
            {
                this.Response.Redirect("NoAccesible.aspx", Constant.EndResponse);
                Context.ApplicationInstance.CompleteRequest();
                this.IncidentAction = IncidentAction.Empty;
            }

            this.master.TitleInvariant = true;
            this.master.Titulo         = string.Format(CultureInfo.InvariantCulture, "{0}: <strong>{2} - {1}</strong>", this.Dictionary["Item_IncidentAction"], this.IncidentAction.Description, this.IncidentAction.Number.ToString());

            this.formFooter = new FormFooter
            {
                ModifiedBy = this.IncidentAction.ModifiedBy.Description,
                ModifiedOn = this.IncidentAction.ModifiedOn
            };

            this.formFooter.AddButton(new UIButton {
                Id = "BtnRestaurar", Icon = "icon-undo", Text = this.Dictionary["Item_IncidentAction_Btn_Restaurar"], Action = "primary"
            });
            this.formFooter.AddButton(new UIButton {
                Id = "BtnAnular", Icon = "icon-ban-circle", Text = this.Dictionary["Item_IncidentAction_Btn_Anular"], Action = "danger"
            });
            this.formFooter.AddButton(new UIButton {
                Id = "BtnPrint", Icon = "icon-file-pdf", Text = this.Dictionary["Common_PrintPdf"], Action = "success", ColumnsSpan = 12
            });
            this.formFooter.AddButton(new UIButton {
                Id = "BtnSave", Icon = "icon-ok", Text = this.Dictionary["Common_Accept"], Action = "success", ColumnsSpan = 12
            });
            this.formFooter.AddButton(new UIButton {
                Id = "BtnCancel", Icon = "icon-undo", Text = this.Dictionary["Common_Cancel"], ColumnsSpan = 12
            });

            this.master.ItemCode = this.IncidentAction.Description;
            this.OriginItemLink  = this.Dictionary["Item_IncidentAction_Origin2"];

            if (this.IncidentAction.IncidentId.HasValue && this.IncidentAction.IncidentId > 0)
            {
                this.Incident       = Incident.GetById(this.IncidentAction.IncidentId.Value, this.Company.Id);
                this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin3"] + " " + this.Incident.Link;
            }

            if (this.IncidentAction.BusinessRiskId.HasValue && this.IncidentAction.BusinessRiskId > 0)
            {
                this.BusinessRisk   = BusinessRisk.ById(this.Company.Id, this.IncidentAction.BusinessRiskId.Value);
                this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin4"] + " " + this.BusinessRisk.Link;
            }

            if (this.IncidentAction.Objetivo.Id > 0)
            {
                this.Objetivo       = this.IncidentAction.Objetivo;
                this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin5"] + " " + this.Objetivo.Link;
            }

            if (this.IncidentAction.Oportunity.Id > 0)
            {
                this.Oportunity     = this.IncidentAction.Oportunity;
                this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin6"] + " " + this.Oportunity.Link;
            }

            if (this.IncidentAction.Origin == 1)
            {
                if (this.IncidentAction.AuditoryId != null && this.IncidentAction.AuditoryId > 0)
                {
                    var auditory = Auditory.ById(this.IncidentAction.AuditoryId.Value, this.Company.Id);
                    this.OriginItemLink = string.Format(
                        CultureInfo.InvariantCulture,
                        @"{0} - {1}",
                        this.Dictionary["Item_IncidentAction_Origin1"],
                        auditory.Link);
                }
                else
                {
                    this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin1"];
                }
            }

            this.RenderDocuments();
        }
        else
        {
            this.master.Titulo  = "Item_IncidentActions_Detail";
            this.IncidentAction = IncidentAction.Empty;
            this.formFooter     = new FormFooter(this.Dictionary, this.grantToWrite);

            if (this.Request.QueryString["o"] != null)
            {
                var objetivoId = Convert.ToInt32(this.Request.QueryString["o"]);
                this.Objetivo = Objetivo.ById(objetivoId, this.Company.Id);
                this.IncidentAction.Description    = this.Objetivo.Name;
                this.IncidentAction.Origin         = 5;
                this.IncidentAction.Objetivo       = this.Objetivo;
                this.IncidentAction.WhatHappened   = this.Objetivo.Description;
                this.IncidentAction.WhatHappenedOn = DateTime.Now;
            }

            this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin2"];

            if (this.IncidentAction.Origin == 1)
            {
                this.OriginItemLink = this.Dictionary["Item_IncidentAction_Origin1"];
            }
            else if (this.IncidentAction.Origin == 5)
            {
                this.OriginItemLink = string.Format(
                    CultureInfo.InvariantCulture,
                    "{0}: {1}",
                    this.Dictionary["Item_IncidentAction_Origin5"],
                    this.Objetivo.Link);
            }
        }

        this.tabBar.AddTab(new Tab {
            Id = "home", Selected = true, Active = true, Label = this.Dictionary["Item_IncidentAction_Tab_Basic"], Available = true
        });
        this.tabBar.AddTab(new Tab {
            Id = "costes", Available = this.ApplicationUser.HasGrantToRead(ApplicationGrant.Cost) && this.IncidentActionId > 0, Active = this.IncidentActionId > 0, Label = this.Dictionary["Item_IncidentAction_Tab_Costs"]
        });
        this.tabBar.AddTab(new Tab {
            Id = "uploadFiles", Available = true, Active = this.IncidentActionId > 0, Hidden = this.IncidentActionId < 1, Label = this.Dictionary["Item_IncidentAction_Tab_UploadFiles"]
        });
        // this.tabBar.AddTab(new Tab { Id = "trazas", Available = this.user.HasTraceGrant() && this.IncidentActionId > 0, Active = this.IncidentActionId > 0, Label = this.dictionary["Item_IncidentAction_Tab_Traces"] });

        this.RenderForm();

        this.ProviderBarPopups = new BarPopup
        {
            Id                = "Provider",
            DeleteMessage     = this.Dictionary["Common_DeleteMessage"],
            BarWidth          = 600,
            UpdateWidth       = 600,
            DeleteWidth       = 600,
            Required          = true,
            RequiredMessage   = this.Dictionary["Common_Required"],
            Duplicated        = true,
            DuplicatedMessage = this.Dictionary["Common_Error_NameAlreadyExists"],
            Description       = "Proveedor",
            FieldName         = this.Dictionary["Item_Provider"],
            BarTitle          = this.Dictionary["Item_Providers"]
        };

        this.CustomerBarPopups = new BarPopup
        {
            Id                = "Customer",
            DeleteMessage     = this.Dictionary["Common_DeleteMessage"],
            BarWidth          = 600,
            UpdateWidth       = 600,
            DeleteWidth       = 600,
            Required          = true,
            RequiredMessage   = this.Dictionary["Common_Required"],
            Duplicated        = true,
            DuplicatedMessage = this.Dictionary["Common_Error_NameAlreadyExists"],
            Description       = "Cliente",
            FieldName         = this.Dictionary["Item_Customer"],
            BarTitle          = this.Dictionary["Item_Customers"]
        };
    }
예제 #13
0
    /// <summary>Main action to load page elements</summary>
    private void Go()
    {
        this.Company         = this.Session["company"] as Company;
        this.Dictionary      = this.Session["Dictionary"] as Dictionary <string, string>;
        this.ApplicationUser = this.Session["User"] as ApplicationUser;
        this.Session["User"] = this.ApplicationUser;

        this.GrantToWriteBusinessRisk   = this.ApplicationUser.HasGrantToWrite(ApplicationGrant.BusinessRisk);
        this.GrantToWriteIncidentAction = this.ApplicationUser.HasGrantToWrite(ApplicationGrant.IncidentActions);

        if (this.Request.QueryString["id"] != null)
        {
            this.BusinessRiskId = Convert.ToInt64(this.Request.QueryString["id"]);
        }

        string label = "Item_BusinessRisk_Title_BusinessRiskDetails";

        this.master           = this.Master as Giso;
        this.master.AdminPage = true;
        string serverPath = this.Request.Url.AbsoluteUri.Replace(this.Request.RawUrl.Substring(1), string.Empty);

        if (ApplicationUser.HasGrantToRead(ApplicationGrant.BusinessRisk))
        {
            this.master.AddBreadCrumb("Item_BusinessRisksAndOportunities", "BusinessRisksList.aspx", Constant.NotLeaft);
        }
        else
        {
            this.master.AddBreadCrumb("Item_BusinessRisksAndOportunities");
        }

        this.master.AddBreadCrumb(label);
        this.master.Titulo = label;
        if (!this.Page.IsPostBack)
        {
            //this.LtTrazas.Text = ActivityTrace.RenderTraceTableForItem(this.businessRisk, TargetTypes.BusinessRisk);
        }

        this.formFooter = new FormFooter();
        this.formFooter.AddButton(new UIButton {
            Id = "BtnPrint", Icon = "icon-file-pdf", Text = this.Dictionary["Common_PrintPdf"], Action = "success"
        });
        this.formFooter.AddButton(new UIButton {
            Id = "BtnSave", Icon = "icon-ok", Action = "success", Text = this.Dictionary["Common_Accept"]
        });
        this.formFooter.AddButton(new UIButton {
            Id = "BtnCancel", Icon = "icon-undo", Text = this.Dictionary["Common_Cancel"]
        });

        this.formFooterActions = new FormFooter();
        this.formFooterActions.AddButton(new UIButton {
            Id = "BtnSave2", Icon = "icon-ok", Action = "success", Text = this.Dictionary["Common_Accept"]
        });
        this.formFooterActions.AddButton(new UIButton {
            Id = "BtnCancel2", Icon = "icon-undo", Text = this.Dictionary["Common_Cancel"], Hidden = this.incidentAction.Id < 1
        });

        if (this.BusinessRiskId != -1)
        {
            this.businessRisk   = ById(this.Company.Id, this.BusinessRiskId);
            this.incidentAction = IncidentAction.ByBusinessRiskId(this.businessRisk.Id, this.Company.Id);
            if (this.businessRisk.CompanyId != this.Company.Id)
            {
                this.Response.Redirect("NoAccesible.aspx", Constant.EndResponse);
                Context.ApplicationInstance.CompleteRequest();
                this.businessRisk = BusinessRisk.Empty;
            }

            this.formFooter.ModifiedBy = this.businessRisk.ModifiedBy.Description;
            this.formFooter.ModifiedOn = this.businessRisk.ModifiedOn;
            label = string.Format(CultureInfo.InvariantCulture, "{0}: <strong>{1}</strong>", this.Dictionary["Item_BusinessRisk"], this.businessRisk.Description);
            this.master.TitleInvariant = true;
            this.master.Titulo         = label;
        }
        else
        {
            this.businessRisk   = BusinessRisk.Empty;
            this.incidentAction = IncidentAction.Empty;
        }

        historyActionActive = false;
        RenderActionHistory();

        this.tabBar.AddTab(new Tab {
            Id = "home", Selected = true, Active = true, Label = this.Dictionary["Item_BusinessRisk_Tab_Basic"], Available = true
        });
        this.tabBar.AddTab(new Tab {
            Id = "accion", Available = this.ApplicationUser.HasGrantToRead(ApplicationGrant.IncidentActions), Active = true, Label = this.Dictionary["Item_BusinessRisk_Tab_Action"]
        });
        this.tabBar.AddTab(new Tab {
            Id = "costes", Available = this.ApplicationUser.HasGrantToRead(ApplicationGrant.Cost), Active = true, Label = this.Dictionary["Item_BusinessRisk_Tab_Costs"]
        });
        this.tabBar.AddTab(new Tab {
            Id = "graphic", Available = true, Active = true, Label = this.Dictionary["Item_BusinessRisk_Tab_Graphics"]
        });
        this.tabBar.AddTab(new Tab {
            Id = "historyActions", Available = this.ApplicationUser.HasGrantToRead(ApplicationGrant.IncidentActions), Active = historyActionActive == true, Label = this.Dictionary["Item_BusinessRisk_Tab_HistoryActions"], Hidden = !historyActionActive
        });
        this.tabBar.AddTab(new Tab {
            Id = "uploadFiles", Available = true, Active = true, Label = this.Dictionary["Item_Learning_Tab_UploadFiles"], Hidden = this.businessRisk.Id < 1
        });

        this.RenderProcess();
        this.RenderProbabilitySeverity();
        this.RenderActionsForm();
        this.RenderDocuments();
    }
예제 #14
0
    private BusinessRisk ById(int companyId, long id)
    {
        var    res   = BusinessRisk.Empty;
        string query = "BusinessRisk_GetById";

        using (var cmd = new SqlCommand(query))
        {
            cmd.CommandType = CommandType.StoredProcedure;
            using (var cnn = new SqlConnection(ConfigurationManager.ConnectionStrings["cns"].ConnectionString))
            {
                cmd.Connection = cnn;
                cmd.Parameters.Add(DataParameter.Input("@CompanyId", companyId));
                cmd.Parameters.Add(DataParameter.Input("@Id", id));
                try
                {
                    cmd.Connection.Open();
                    using (var rdr = cmd.ExecuteReader())
                    {
                        if (rdr.HasRows)
                        {
                            rdr.Read();
                            res = new BusinessRisk()
                            {
                                Id          = rdr.GetInt64(ColumnsBusinessRiskGetAll.Id),
                                Description = rdr.GetString(ColumnsBusinessRiskGetAll.Description),
                                Notes       = rdr.GetString(ColumnsBusinessRiskGetAll.Notes),
                                CompanyId   = companyId,
                                CreatedOn   = rdr.GetDateTime(ColumnsBusinessRiskGetAll.CreatedOn),
                                CreatedBy   = new ApplicationUser()
                                {
                                    Id       = rdr.GetInt32(ColumnsBusinessRiskGetAll.CreatedBy),
                                    UserName = rdr.GetString(ColumnsBusinessRiskGetAll.CreatedByName)
                                },
                                ModifiedOn = rdr.GetDateTime(ColumnsBusinessRiskGetAll.ModifiedOn),
                                ModifiedBy = new ApplicationUser()
                                {
                                    Id       = rdr.GetInt32(ColumnsBusinessRiskGetAll.ModifiedBy),
                                    UserName = rdr.GetString(ColumnsBusinessRiskGetAll.ModifiedByName)
                                },
                                Code  = rdr.GetInt64(ColumnsBusinessRiskGetAll.Code),
                                Rules = new Rules()
                                {
                                    Id          = rdr.GetInt64(ColumnsBusinessRiskGetAll.RuleId),
                                    Description = rdr.GetString(ColumnsBusinessRiskGetAll.RuleDescription),
                                    Limit       = rdr.GetInt64(ColumnsBusinessRiskGetAll.RuleRangeId)
                                },
                                ItemDescription = rdr.GetString(ColumnsBusinessRiskGetAll.ItemDescription),
                                StartControl    = rdr.GetString(ColumnsBusinessRiskGetAll.StartControl)
                            };

                            res.Active = rdr.GetBoolean(ColumnsBusinessRiskGetAll.Active);
                            //res.InitialValue = rdr.GetInt32(ColumnsBusinessRiskGetAll.InitialValue);
                            res.DateStart = rdr.GetDateTime(ColumnsBusinessRiskGetAll.DateStart);
                            res.ProcessId = rdr.GetInt64(ColumnsBusinessRiskGetAll.ProcessId);
                            res.Assumed   = rdr.GetBoolean(ColumnsBusinessRiskGetAll.Assumed);

                            res.StartAction      = rdr.GetInt32(ColumnsBusinessRiskGetAll.StartAction);
                            res.StartProbability = rdr.GetInt32(ColumnsBusinessRiskGetAll.ProbabilityId);
                            res.StartSeverity    = rdr.GetInt32(ColumnsBusinessRiskGetAll.Severity);
                            res.StartResult      = rdr.GetInt32(ColumnsBusinessRiskGetAll.StartResult);

                            res.FinalProbability = rdr.GetInt32(ColumnsBusinessRiskGetAll.FinalProbability);
                            res.FinalSeverity    = rdr.GetInt32(ColumnsBusinessRiskGetAll.FinalSeverity);
                            res.FinalResult      = rdr.GetInt32(ColumnsBusinessRiskGetAll.FinalResult);
                            res.FinalAction      = rdr.GetInt32(ColumnsBusinessRiskGetAll.FinalAction);

                            if (!rdr.IsDBNull(ColumnsBusinessRiskGetAll.FinalDate))
                            {
                                res.FinalDate = rdr.GetDateTime(ColumnsBusinessRiskGetAll.FinalDate);
                            }

                            if (!rdr.IsDBNull(ColumnsBusinessRiskGetAll.Causes))
                            {
                                res.Causes = rdr.GetString(ColumnsBusinessRiskGetAll.Causes);
                            }

                            //// Field can be Null in Database (no link to a previous BusinessRisk)
                            if (!rdr.IsDBNull(ColumnsBusinessRiskGetAll.PreviousBusinessRiskId))
                            {
                                res.PreviousBusinessRiskId = rdr.GetInt64(ColumnsBusinessRiskGetAll.PreviousBusinessRiskId);
                            }
                            else
                            {
                                //// The previous BusinessRisk does not exist
                                res.PreviousBusinessRiskId = -1;
                            }

                            res.ModifiedBy.Employee = Employee.ByUserId(res.ModifiedBy.Id);
                        }
                    }

                    res.Process = new Process(res.ProcessId, companyId);
                }
                catch (Exception ex)
                {
                    ExceptionManager.Trace(ex, "BusinessRiskView --> ById(" + this.BusinessRiskId.ToString() + ")");
                }
                finally
                {
                    if (cmd.Connection.State != ConnectionState.Closed)
                    {
                        cmd.Connection.Close();
                    }
                }
            }
        }

        return(res);
    }
예제 #15
0
    /// <summary>Main action to load the page's elements</summary>
    private void Go()
    {
        this.user    = Session["User"] as ApplicationUser;
        this.Company = Session["company"] as Company;

        if (Session["BusinessRiskFilter"] == null)
        {
            this.FilterBusinessRisk = Constant.JavaScriptNull;
        }
        else
        {
            this.FilterBusinessRisk = Session["BusinessRiskFilter"].ToString();
        }

        if (this.Session["OportunityFilter"] == null)
        {
            this.FilterOportunity = Constant.JavaScriptNull;
        }
        else
        {
            this.FilterOportunity = Session["OportunityFilter"].ToString();
        }

        this.Dictionary       = this.Session["Dictionary"] as Dictionary <string, string>;
        this.master           = this.Master as Giso;
        this.master.AdminPage = false;
        this.master.AddBreadCrumb("Item_BusinessRisksAndOportunities");
        this.master.Titulo = "Item_BusinessRisksAndOportunities";

        this.RenderBusinessRiskData();

        if (this.user.HasGrantToWrite(ApplicationGrant.BusinessRisk))
        {
            this.master.ButtonNewItem = UIButton.NewItemButton("Item_BusinessRisk_Button_New", "BusinessRiskView.aspx");
        }

        if (this.Session["BusinessRiskFilter"] == null)
        {
            this.DataHeader = new UIDataHeader {
                Id = "ListDataHeader", ActionsItem = 2
            };
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th1", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Date"], Sortable = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th2", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Description"], Filterable = true, Sortable = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th3", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Process"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th4", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Rule"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th5", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_StartValue"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th6", HeaderId = "ListDataHeader", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Result"], HiddenMobile = true
            });
        }
        else
        {
            this.DataHeader = new UIDataHeader {
                Id = "ListDataHeaderOportunity", ActionsItem = 2
            };
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th1", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Date"], Sortable = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th2", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Description"], Filterable = true, Sortable = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th3", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Process"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th4", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Rule"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th5", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_StartValue"], HiddenMobile = true
            });
            this.DataHeader.AddItem(new UIDataHeaderItem {
                Id = "th6", HeaderId = "ListDataHeaderOportunity", DataId = "ListDataTable", Text = this.Dictionary["Item_BusinesRisk_ListHeader_Result"], HiddenMobile = true
            });
        }

        if (this.Request.QueryString["id"] != null)
        {
            this.businessRiskId = Convert.ToInt64(this.Request.QueryString["id"]);
        }

        if (this.businessRiskId != -1)
        {
            this.businessRisk = BusinessRisk.ById(Company.Id, this.businessRiskId);
            if (this.businessRisk.CompanyId != Company.Id)
            {
                Context.ApplicationInstance.CompleteRequest();
                this.businessRisk = BusinessRisk.Empty;
            }
        }
        else
        {
            this.businessRisk = BusinessRisk.Empty;
        }
    }
예제 #16
0
    protected void Page_Load(object sender, EventArgs e)
    {
        long actionId   = Convert.ToInt64(Request.QueryString["id"]);
        int  companyId  = Convert.ToInt32(Request.QueryString["companyId"]);
        var  company    = new Company(companyId);
        var  res        = ActionResult.NoAction;
        var  user       = HttpContext.Current.Session["User"] as ApplicationUser;
        var  dictionary = HttpContext.Current.Session["Dictionary"] as Dictionary <string, string>;
        var  action     = IncidentAction.ById(actionId, user.CompanyId);

        string path = HttpContext.Current.Request.PhysicalApplicationPath;

        if (!path.EndsWith(@"\", StringComparison.OrdinalIgnoreCase))
        {
            path = string.Format(CultureInfo.InvariantCulture, @"{0}\", path);
        }

        var formatedDescription = ToolsPdf.NormalizeFileName(action.Description);

        formatedDescription = formatedDescription.Replace(@"\", "/");

        string fileName = string.Format(
            CultureInfo.InvariantCulture,
            @"{0}_{1}_Data_{2:yyyyMMddhhmmss}.pdf",
            dictionary["Item_IncidentAction"],
            formatedDescription,
            DateTime.Now);

        string type         = string.Empty;
        string origin       = string.Empty;
        string originSufix  = string.Empty;
        string reporterType = string.Empty;
        string reporter     = string.Empty;

        if (action.ActionType == 1)
        {
            type = dictionary["Item_IncidentAction_Type1"];
        }
        if (action.ActionType == 2)
        {
            type = dictionary["Item_IncidentAction_Type2"];
        }
        if (action.ActionType == 3)
        {
            type = dictionary["Item_IncidentAction_Type3"];
        }

        if (action.Origin == 1)
        {
            origin = dictionary["Item_IncidentAction_Origin1"];
        }
        if (action.Origin == 2)
        {
            origin = dictionary["Item_IncidentAction_Origin2"];
        }
        if (action.Origin == 3)
        {
            if (action.IncidentId.HasValue)
            {
                var incident = Incident.GetById(action.IncidentId.Value, action.CompanyId);
                origin = string.Format(
                    CultureInfo.InvariantCulture,
                    @"{0}: {1}",
                    dictionary["Item_Incident"],
                    incident.Description);
            }
        }

        if (action.Origin == 4)
        {
            if (action.BusinessRiskId.HasValue)
            {
                if (action.BusinessRiskId > Constant.DefaultId)
                {
                    var businessRisk = BusinessRisk.ById(action.CompanyId, action.BusinessRiskId.Value);
                    origin      = businessRisk.Description;
                    originSufix = " (" + dictionary["Item_BusinessRisk"] + ")";
                }
            }
        }
        if (action.Origin == 5)
        {
            if (action.ObjetivoId.HasValue)
            {
                if (action.ObjetivoId > Constant.DefaultId)
                {
                    var objetivo = Objetivo.ById(Convert.ToInt32(action.ObjetivoId.Value), action.CompanyId);
                    origin      = objetivo.Name;
                    originSufix = " (" + dictionary["Item_Objetivo"] + ")";
                }
            }
        }
        if (action.Origin == 6)
        {
            if (action.Oportunity.Id > Constant.DefaultId)
            {
                var oportunidad = Oportunity.ById(Convert.ToInt32(action.Oportunity.Id), action.CompanyId);
                origin      = oportunidad.Description;
                originSufix = " (" + dictionary["Item_Oportunity"] + ")";
            }
        }
        else
        {
            switch (action.ReporterType)
            {
            case 1:
                reporterType = dictionary["Item_IncidentAction_ReporterType1"];
                if (action.Department != null && action.Department.Id > 0)
                {
                    var department = Department.ById(action.Department.Id, action.CompanyId);
                    reporter = department.Description;
                }
                break;

            case 2:
                reporterType = dictionary["Item_IncidentAction_ReporterType2"];
                if (action.Provider != null && action.Provider.Id > 0)
                {
                    var provider = Provider.ById(action.Provider.Id, action.CompanyId);
                    reporter = provider.Description;
                }
                break;

            case 3:
                reporterType = dictionary["Item_IncidentAction_ReporterType3"];
                if (action.Customer != null && action.Customer.Id > 0)
                {
                    var customer = Customer.ById(action.Customer.Id, action.CompanyId);
                    reporter = customer.Description;
                }
                break;

            default:
                break;
            }
        }

        string status   = string.Empty;
        var    document = new iTextSharp.text.Document(PageSize.A4, 30, 30, 65, 55);
        var    writer   = PdfWriter.GetInstance(document, new FileStream(Request.PhysicalApplicationPath + "\\Temp\\" + fileName, FileMode.Create));

        writer.PageEvent = new TwoColumnHeaderFooter
        {
            CompanyLogo = string.Format(CultureInfo.InvariantCulture, @"{0}\images\logos\{1}.jpg", path, companyId),
            IssusLogo   = string.Format(CultureInfo.InvariantCulture, "{0}issus.png", path),
            Date        = string.Format(CultureInfo.InvariantCulture, "{0:dd/MM/yyyy}", DateTime.Now),
            CreatedBy   = user.UserName,
            CompanyId   = action.CompanyId,
            CompanyName = company.Name,
            Title       = dictionary["Item_IncidentAction"].ToUpperInvariant()
        };

        document.Open();
        var styles = new iTextSharp.text.html.simpleparser.StyleSheet();
        var hw     = new iTextSharp.text.html.simpleparser.HTMLWorker(document);

        var widths = new float[] { 15f, 30f, 15f, 30f };
        var table  = new PdfPTable(4)
        {
            WidthPercentage     = 100,
            HorizontalAlignment = 0
        };

        table.SetWidths(widths);
        var borderSides = Rectangle.RIGHT_BORDER + Rectangle.LEFT_BORDER;
        var borderTBL   = Rectangle.TOP_BORDER + Rectangle.BOTTOM_BORDER + Rectangle.LEFT_BORDER;
        var borderTBR   = Rectangle.TOP_BORDER + Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER;
        var borderBL    = Rectangle.BOTTOM_BORDER + Rectangle.LEFT_BORDER;
        var borderBR    = Rectangle.BOTTOM_BORDER + Rectangle.RIGHT_BORDER;

        var alignLeft  = Element.ALIGN_LEFT;
        var alignRight = Element.ALIGN_RIGHT;

        var labelFont = new Font(this.arial, 10, Font.NORMAL, BaseColor.DARK_GRAY);
        var valueFont = new Font(this.arial, 10, Font.NORMAL, BaseColor.BLACK);

        // Descripción
        table.AddCell(LabelCell(dictionary["Item_IncidentAction"], Rectangle.NO_BORDER));
        table.AddCell(ValueCell(action.Number.ToString() + " - " + action.Description, ToolsPdf.BorderNone, alignLeft, 3));

        // Tipo
        table.AddCell(LabelCell(dictionary["Item_IncidentAction_Label_Type"], Rectangle.NO_BORDER));
        table.AddCell(ValueCell(type, ToolsPdf.BorderNone, alignLeft, 1));

        // Origen
        table.AddCell(LabelCell(dictionary["Item_IncidentAction_Label_Origin"], Rectangle.NO_BORDER));
        table.AddCell(ValueCell(origin + originSufix, ToolsPdf.BorderNone, alignLeft, 3));

        // Reportador
        if (action.Origin != 4 && action.Origin != 5 && !string.IsNullOrEmpty(reporter))
        {
            table.AddCell(LabelCell(dictionary["Item_IncidentAction_Label_Reporter"], Rectangle.NO_BORDER));
            table.AddCell(ValueCell(reporterType + " (" + reporter + ")", ToolsPdf.BorderNone, alignLeft, 3));
        }

        // WhatHappend
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_WhatHappened"]));
        table.AddCell(TextAreaCell(Environment.NewLine + action.WhatHappened, borderSides, alignLeft, 4));
        table.AddCell(BlankRow());
        table.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + action.WhatHappenedBy.FullName, borderBL, alignLeft, 2));
        table.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1:dd/MM/yyyy}", dictionary["Common_Date"], action.WhatHappenedOn), borderBR, alignRight, 2));

        // Causes
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Causes"]));
        table.AddCell(TextAreaCell(Environment.NewLine + action.Causes, borderSides, alignLeft, 4));
        table.AddCell(BlankRow());
        table.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + action.CausesBy.FullName, borderBL, alignLeft, 2));
        table.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1:dd/MM/yyyy}", dictionary["Common_Date"], action.CausesOn), borderBR, alignRight, 2));

        // Actions
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Actions"]));
        table.AddCell(TextAreaCell(Environment.NewLine + action.Actions, borderSides, alignLeft, 4));
        table.AddCell(BlankRow());
        table.AddCell(TextAreaCell(dictionary["Item_IncidentAction_Field_Responsible"] + ": " + action.ActionsBy.FullName, borderBL, alignLeft, 2));
        table.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "{0}: {1:dd/MM/yyyy}", dictionary["Common_DateExecution"], action.ActionsOn), borderBR, alignRight, 2));

        // Monitoring
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Monitoring"]));
        table.AddCell(TextAreaCell(Environment.NewLine + action.Monitoring, ToolsPdf.BorderAll, alignLeft, 4));

        // Close
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Close"]));
        table.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "\n{0}: {1}", dictionary["Item_IncidentAction_Field_Responsible"], action.ClosedBy.FullName), borderTBL, alignLeft, 2));
        table.AddCell(TextAreaCell(string.Format(CultureInfo.InvariantCulture, "\n{0}: {1:dd/MM/yyyy}", dictionary["Common_DateClose"], action.ClosedOn), borderTBR, alignRight, 2));

        // Notes
        table.AddCell(SeparationRow());
        table.AddCell(TitleCell(dictionary["Item_IncidentAction_Field_Notes"]));
        table.AddCell(TextAreaCell(Environment.NewLine + action.Notes, ToolsPdf.BorderAll, alignLeft, 4));

        document.Add(table);

        // Costes
        var costs = IncidentActionCost.GetByIncidentActionId(actionId, companyId);

        if (costs.Count > 0)
        {
            var times           = new Font(arial, 8, Font.NORMAL, BaseColor.BLACK);
            var fontSummary     = new Font(arial, 9, Font.BOLD, BaseColor.BLACK);
            var headerFontFinal = new Font(headerFont, 9, Font.NORMAL, BaseColor.BLACK);

            // @alex: hay que crear la tabla con 6 columnas en lugar de 5
            //var tableCosts = new PdfPTable(5)
            var tableCosts = new PdfPTable(6)
            {
                WidthPercentage     = 100,
                HorizontalAlignment = 1,
                SpacingBefore       = 20f,
                SpacingAfter        = 30f
            };

            // @alex: se añade una nueva columna de 10f para la fecha
            //tableCosts.SetWidths(new float[] { 35f, 10f, 10f, 10f, 20f });
            tableCosts.SetWidths(new float[] { 35f, 10f, 10f, 10f, 10f, 20f });

            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Description"]));
            // @alex: se añade una nueva cabecera
            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Common_Date"]));
            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Amount"]));
            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Quantity"]));
            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_Total"]));
            tableCosts.AddCell(ToolsPdf.HeaderCell(dictionary["Item_IncidentCost_Header_ReportedBy"]));

            decimal total       = 0;
            decimal totalAccion = 0;
            int     cont        = 0;
            int     contAccion  = 0;

            // Acciones
            foreach (var cost in costs.Where(c => c.Active == true))
            {
                tableCosts.AddCell(ToolsPdf.DataCell(cost.Description, times));

                // @alex: se añade la columna en la misma posición que en el listado de la ficha
                tableCosts.AddCell(ToolsPdf.DataCellCenter(cost.Date, times));

                tableCosts.AddCell(ToolsPdf.DataCellMoney(cost.Amount, times));
                tableCosts.AddCell(ToolsPdf.DataCellMoney(cost.Quantity, times));
                tableCosts.AddCell(ToolsPdf.DataCellMoney(cost.Quantity * cost.Amount, times));
                tableCosts.AddCell(ToolsPdf.DataCellCenter(cost.Responsible.FullName, times));
                total      += cost.Amount * cost.Quantity;
                totalAccion = cost.Amount * cost.Quantity;
                cont++;
                contAccion++;
            }

            tableCosts.AddCell(new PdfPCell(new Phrase(string.Format(
                                                           CultureInfo.InvariantCulture,
                                                           @"{0} {2}: {1}",
                                                           dictionary["Common_RegisterCount"],
                                                           contAccion,
                                                           dictionary["Item_IncidentAction"]), times))
            {
                Border          = Rectangle.TOP_BORDER,
                BackgroundColor = ToolsPdf.SummaryBackgroundColor,
                Padding         = 6f,
                PaddingTop      = 4f,
                Colspan         = 3//@ alex: al haber una columna más el colspan crece de 2 a 3
            });

            tableCosts.AddCell(new PdfPCell(new Phrase(dictionary["Common_Total"], times))
            {
                Border              = Rectangle.TOP_BORDER,
                BackgroundColor     = ToolsPdf.SummaryBackgroundColor,
                Padding             = 6f,
                PaddingTop          = 4f,
                Colspan             = 1,
                HorizontalAlignment = Rectangle.ALIGN_RIGHT
            });

            tableCosts.AddCell(new PdfPCell(new Phrase(Tools.PdfMoneyFormat(total), times))
            {
                Border              = Rectangle.TOP_BORDER,
                BackgroundColor     = ToolsPdf.SummaryBackgroundColor,
                Padding             = 6f,
                PaddingTop          = 4f,
                Colspan             = 1,
                HorizontalAlignment = Rectangle.ALIGN_RIGHT,
            });

            tableCosts.AddCell(new PdfPCell(new Phrase(string.Format(string.Empty, times)))
            {
                Border          = Rectangle.TOP_BORDER,
                BackgroundColor = ToolsPdf.SummaryBackgroundColor,
                Padding         = 6f,
                PaddingTop      = 4f,
                Colspan         = 1
            });


            document.SetPageSize(PageSize.A4.Rotate());
            document.NewPage();
            document.Add(tableCosts);
        }

        document.Close();

        Response.ClearContent();
        Response.ClearHeaders();
        Response.AddHeader("Content-Disposition", "inline;filename=Accion.pdf");
        Response.ContentType = "application/pdf";
        Response.WriteFile(Request.PhysicalApplicationPath + "\\Temp\\" + fileName);
        Response.Flush();
        Response.Clear();
    }