Example #1
0
        public static SReportTemplateTable GetTemplateVariants(String AReportType, String AAuthor, Boolean ADefaultOnly = false)
        {
            SReportTemplateTable Tbl          = new SReportTemplateTable();
            SReportTemplateTable Ret          = new SReportTemplateTable();
            TDBTransaction       Transaction  = null;
            TDataBase            dbConnection = new TDataBase();

            try
            {
                dbConnection = TReportingDbAdapter.EstablishDBConnection(true, "GetTemplateVariants");
                LoadTemplatesFromBackupFile(AReportType, dbConnection);

                dbConnection.BeginAutoReadTransaction(
                    ref Transaction,
                    delegate
                {
                    SReportTemplateRow TemplateRow = Tbl.NewRowTyped(false);
                    TemplateRow.ReportType         = AReportType;

                    Tbl = SReportTemplateAccess.LoadUsingTemplate(TemplateRow, Transaction);
                });

                String filter = String.Format("(s_author_c ='{0}' OR s_private_l=false)", AAuthor);

                if (ADefaultOnly)
                {
                    filter += " AND (s_default_l=true OR s_private_default_l=true)";
                }

                Tbl.DefaultView.RowFilter = filter;

                if (Tbl.DefaultView.Count > 0)
                {
                    Tbl.DefaultView.Sort =
                        (ADefaultOnly) ? "s_private_default_l DESC, s_default_l DESC" :
                        "s_readonly_l DESC, s_default_l DESC, s_private_default_l DESC";
                }
                else // Something went wrong, but I'll try not to return empty-handed.
                {
                    Tbl.DefaultView.RowFilter = "";
                }

                Ret.Merge(Tbl.DefaultView.ToTable());
                Ret.AcceptChanges();
            }
            finally
            {
                dbConnection.CloseDBConnection();
            }
            return(Ret);
        }
Example #2
0
        public static SReportTemplateTable GetTemplateById(int TemplateId)
        {
            TDataBase            dbConnection  = null;
            TDBTransaction       Transaction   = null;
            SReportTemplateTable TemplateTable = null;

            try
            {
                dbConnection = TReportingDbAdapter.EstablishDBConnection(true, "GetTemplateById");
                dbConnection.BeginAutoReadTransaction(
                    ref Transaction,
                    delegate
                {
                    TemplateTable = SReportTemplateAccess.LoadByPrimaryKey(TemplateId, Transaction);
                });
            }
            finally
            {
                dbConnection.CloseDBConnection();
            }
            return(TemplateTable);
        }
Example #3
0
        private static void SendEmailForUser(TDataBase ADataBaseObj, string AUserId, DataTable AErrors)
        {
            TDBTransaction ReadTransaction = null;
            SUserRow       userrow         = null;

            // get the email address of the user
            ADataBaseObj.BeginAutoReadTransaction(IsolationLevel.ReadCommitted, ref ReadTransaction,
                                                  delegate
            {
                userrow = SUserAccess.LoadByPrimaryKey(AUserId, ReadTransaction)[0];
            });

            string excelfile = TAppSettingsManager.GetValue("DataChecks.TempPath") + "/errors" + AUserId + ".xlsx";

            DataView v = new DataView(AErrors,
                                      "(CreatedBy='" + AUserId + "' AND ModifiedBy IS NULL AND DateCreated > #" + Errors_SinceDate.ToString("MM/dd/yyyy") + "#) " +
                                      "OR (ModifiedBy='" + AUserId + "' AND DateModified > #" + Errors_SinceDate.ToString("MM/dd/yyyy") + "#)",
                                      string.Empty, DataViewRowState.CurrentRows);

            try
            {
                using (StreamWriter sw = new StreamWriter(excelfile))
                {
                    using (MemoryStream m = new MemoryStream())
                    {
                        if (!TCsv2Xml.DataTable2ExcelStream(v.ToTable(), m))
                        {
                            return;
                        }

                        m.WriteTo(sw.BaseStream);
                        m.Close();
                        sw.Close();
                    }
                }
            }
            catch (Exception e)
            {
                TLogging.Log("Problems writing to file " + excelfile);
                TLogging.Log(e.ToString());
                return;
            }

            string recipientEmail = string.Empty;

            if (!userrow.IsEmailAddressNull())
            {
                recipientEmail = userrow.EmailAddress;
            }
            else if (TAppSettingsManager.HasValue("DataChecks.Email.Recipient.UserDomain"))
            {
                recipientEmail = userrow.FirstName + "." + userrow.LastName + "@" + TAppSettingsManager.GetValue(
                    "DataChecks.Email.Recipient.UserDomain");
            }
            else if (TAppSettingsManager.HasValue("DataChecks.Email.Recipient"))
            {
                recipientEmail = TAppSettingsManager.GetValue("DataChecks.Email.Recipient");
            }

            if (recipientEmail.Length > 0)
            {
                new TSmtpSender().SendEmail("<" + TAppSettingsManager.GetValue("DataChecks.Email.Sender") + ">",
                                            "OpenPetra DataCheck Robot",
                                            recipientEmail,
                                            "Data Check for " + AUserId,
                                            "there are " + v.Count.ToString() + " errors. Please see attachment!",
                                            new string[] { excelfile });
            }
            else
            {
                TLogging.Log("no email can be sent to " + AUserId);
            }
        }