Exemplo n.º 1
0
        }         // CreateUiExtReport

        private void ProcessTableReportRow(ReportQuery rptDef, SafeReader sr, Tbody oTbody, int lineCounter, List <string> oColumnTypes)
        {
            var oTr = new Tr().Add <Class>(lineCounter % 2 == 0 ? "Odd" : "Even");

            oTbody.Append(oTr);

            var oClassesToApply = new List <string>();

            for (int columnIndex = 0; columnIndex < rptDef.Columns.Length; columnIndex++)
            {
                ColumnInfo col    = rptDef.Columns[columnIndex];
                var        oValue = sr.ColumnOrDefault(col.FieldName);

                if (col.IsVisible)
                {
                    var oTd = new Td();
                    oTr.Append(oTd);

                    if (IsNumber(oValue))
                    {
                        ATag oInnerTag = new Text(NumStr(oValue, col.Format(IsInt(oValue) ? 0 : 2)));

                        if (col.ValueType == ValueType.UserID || col.ValueType == ValueType.BrokerID)
                        {
                            var oLink = new A();

                            oLink.Append(oInnerTag);
                            oLink.Target.Append("_blank");

                            var titleText = "Open this customer in underwriter.";
                            if (col.ValueType == ValueType.UserID)
                            {
                                oLink.Href.Append("https://" + UnderwriterSite + "/UnderWriter/Customers?customerid=" + oValue);
                            }
                            else
                            {
                                oLink.Href.Append("https://" + UnderwriterSite + "/UnderWriter/Customers#broker/" + oValue);
                                titleText = "Open this broker in underwriter.";
                            }

                            oLink.Alt.Append(titleText);
                            oLink.Title.Append(titleText);

                            oInnerTag = oLink;

                            if (oColumnTypes != null)
                            {
                                oColumnTypes[columnIndex] = "user-id";
                            }
                        }
                        else
                        {
                            if (oColumnTypes != null)
                            {
                                oColumnTypes[columnIndex] = "formatted-num";
                            }
                        }                         // if user id

                        oTd.Add <Class>("R").Append(oInnerTag);
                    }
                    else
                    {
                        oTd.Add <Class>("L").Append(new Text(oValue.ToString()));

                        if ((oColumnTypes != null) && (oValue is DateTime))
                        {
                            oColumnTypes[columnIndex] = "date";
                        }
                    }                     // if
                }
                else
                {
                    if (col.ValueType == ValueType.CssClass)
                    {
                        oClassesToApply.Add(oValue.ToString());
                    }
                }         // if
            }             // for each column

            if (oClassesToApply.Count > 0)
            {
                oTr.ApplyToChildren <Class>(string.Join(" ", oClassesToApply.ToArray()));
            }
        }         // ProcessTableReportRow
Exemplo n.º 2
0
        }             // Run

        private void RunOnce()
        {
            this.cashRequestsToAlert.Clear();

            this.db.ForEachResult <ResetCashRequest>(
                rcr => this.cashRequestsToAlert.Add(rcr),
                "LoadResetCashRequests",
                CommandSpecies.StoredProcedure,
                new QueryParameter("@TimeSlice", this.timeSlice)
                );

            if (this.cashRequestsToAlert.Count < 1)
            {
                this.log.Info("No cash requests to alert on.");
                return;
            }             // if

            this.log.Info("{0} found to alert on.", Grammar.Number(this.cashRequestsToAlert.Count, "cash request"));

            var tbl = new Table();

            tbl.Append(
                new Thead().Append(
                    new Tr()
                    .Append(new Th().Append(new Text("Cash request ID")))
                    .Append(new Th().Append(new Text("Decision time")))
                    .Append(new Th().Append(new Text("Decision")))
                    .Append(new Th().Append(new Text("Customer ID")))
                    .Append(new Th().Append(new Text("Customer name")))
                    .Append(new Th().Append(new Text("Customer email")))
                    .Append(new Th().Append(new Text("Underwriter ID")))
                    .Append(new Th().Append(new Text("Underwriter name")))
                    .Append(new Th().Append(new Text("Note")))
                    )
                );

            var tbody = new Tbody();

            tbl.Append(tbody);

            foreach (var rcr in this.cashRequestsToAlert)
            {
                string note;

                try {
                    this.db.ExecuteNonQuery(
                        "RestoreResetCashRequest",
                        CommandSpecies.StoredProcedure,
                        new QueryParameter("@CashRequestID", rcr.CashRequestID)
                        );

                    note = "Restored.";
                } catch (Exception e) {
                    this.log.Alert(e, "Failed to restore cash request {0}.", rcr.CashRequestID);
                    note = "Restoring failed: " + e.Message;
                }                 // try

                tbody.Append(new Tr()
                             .Append(new Td().Append(new Text(rcr.CashRequestID.ToString())))
                             .Append(new Td().Append(new Text(rcr.DecisionTime.ToString("d/MMM/yyyy H:mm:ss", culture))))
                             .Append(new Td().Append(new Text(rcr.Decision.ToString())))
                             .Append(new Td().Append(new Text(rcr.CustomerID.ToString())))
                             .Append(new Td().Append(new Text(rcr.CustomerName)))
                             .Append(new Td().Append(new Text(rcr.CustomerEmail)))
                             .Append(new Td().Append(new Text(rcr.UnderwriterID.ToString())))
                             .Append(new Td().Append(new Text(rcr.UnderwriterName)))
                             .Append(new Td().Append(new Text(note)))
                             );
            }             // for each

            var email = new Html();

            email
            .Append(new Head())
            .Append(tbl);

            this.log.Debug("Sending an email...");

            Mailer.SendMail(
                sender,
                Password,
                "#Alert - reset cash requests " + DateTime.Now.ToString("d/MMM/yyyy H:mm:ss", culture),
                email.ToString(),
                string.Join(",", this.alertList),
                this.log
                );

            this.log.Debug("Sent.");
        }         // RunOnce
Exemplo n.º 3
0
        }         // TableReport

        public ATag TableReport(ReportQuery rptDef, DataTable oReportData, bool isSharones = false, string sRptTitle = "", List <string> oColumnTypes = null)
        {
            int   lineCounter = 0;
            var   tbl         = new Table().Add <Class>("Report");
            Tbody oTbody;

            try {
                if (!isSharones)
                {
                    tbl.Add <ID>("tableReportData");
                }
            }
            catch (Exception e) {
                Alert(e, "Failed to add HTML id to report table.");
                return(tbl);
            }             // try

            try {
                var tr = new Tr().Add <Class>("HR");

                for (int columnIndex = 0; columnIndex < rptDef.Columns.Length; columnIndex++)
                {
                    if (rptDef.Columns[columnIndex].IsVisible)
                    {
                        tr.Append(new Th().Add <Class>("H").Append(new Text(rptDef.Columns[columnIndex].Caption)));
                    }
                }

                tbl.Append(new Thead().Append(tr));
            }
            catch (Exception e) {
                Alert(e, "Failed to initialise table header row.");
                return(tbl);
            }             // try

            try {
                oTbody = new Tbody();
                tbl.Append(oTbody);

                if (oColumnTypes != null)
                {
                    oColumnTypes.Clear();

                    for (int columnIndex = 0; columnIndex < rptDef.Columns.Length; columnIndex++)
                    {
                        oColumnTypes.Add("string");
                    }
                }                 // if
            }
            catch (Exception e) {
                Alert(e, "Failed to initialise report table column types.");
                return(tbl);
            }             // try

            if (oReportData == null)
            {
                try {
                    rptDef.Execute(DB, (sr, bRowsetStart) => {
                        ProcessTableReportRow(rptDef, sr, oTbody, lineCounter, oColumnTypes);
                        lineCounter++;
                        return(ActionResult.Continue);
                    });                     // for each data row
                }
                catch (Exception e) {
                    Alert(e, "Failed to fetch data from DB or create report table body.");
                    return(tbl);
                }                 // try
            }
            else
            {
                try {
                    foreach (DataRow row in oReportData.Rows)
                    {
                        ProcessTableReportRow(rptDef, new SafeReader(row), oTbody, lineCounter, oColumnTypes);
                        lineCounter++;
                    }                     // for each data row
                }
                catch (Exception e) {
                    Alert(e, "Failed to create report table body.");
                    return(tbl);
                }         // try
            }             // if

            try {
                if (oColumnTypes != null)
                {
                    for (int columnIndex = rptDef.Columns.Length - 1; columnIndex >= 0; columnIndex--)
                    {
                        if (!rptDef.Columns[columnIndex].IsVisible)
                        {
                            oColumnTypes.RemoveAt(columnIndex);
                        }
                    }
                }                 // if
            }
            catch (Exception e) {
                Alert(e, "Failed to finalise report table column types.");
            }             // try

            return(tbl);
        }         // TableReport