Example #1
0
        private static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity, TDBTransaction ATransaction)
        {
            SUserRow   ReturnValue;
            SUserTable UserDT = null;
            SUserRow   UserDR;
            DateTime   LastLoginDateTime;
            DateTime   FailedLoginDateTime;

            // Check if user exists in s_user DB Table
            if (!SUserAccess.Exists(AUserID, ATransaction))
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }

            // User exists, so load User record
            UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ATransaction);

            UserDR = UserDT[0];

            if (!UserDR.IsFailedLoginDateNull())
            {
                FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
            }
            else
            {
                FailedLoginDateTime = DateTime.MinValue;
            }

            if (!UserDR.IsLastLoginDateNull())
            {
                LastLoginDateTime = UserDR.LastLoginDate.Value;
                LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
            }
            else
            {
                LastLoginDateTime = DateTime.MinValue;
            }

            Int64 PartnerKey;

            if (!UserDR.IsPartnerKeyNull())
            {
                PartnerKey = UserDR.PartnerKey;
            }
            else
            {
                // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                PartnerKey = -1;
            }

            // Create PetraIdentity
            APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.AccountLocked,
                UserDR.Retired, UserDR.CanModify);
            ReturnValue = UserDR;

            return(ReturnValue);
        }
Example #2
0
        /// <summary>
        /// AddUser
        /// </summary>
        public override bool AddUser(string AUserID, string APassword = "")
        {
            // we need a GUserInfo object for submitting the changes to the database later on
            TPetraIdentity PetraIdentity = new TPetraIdentity(
                "SYSADMIN", "", "", "", "", DateTime.MinValue,
                DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false,
                false);

            UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

            return FUserManager.AddUser(AUserID, APassword);
        }
Example #3
0
        public static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity)
        {
            SUserRow ReturnValue;
            TDBTransaction ReadTransaction = null;
            SUserTable UserDT = null;
            SUserRow UserDR;
            DateTime LastLoginDateTime;
            DateTime FailedLoginDateTime;

            DBAccess.GDBAccessObj.GetNewOrExistingAutoReadTransaction(
                IsolationLevel.Serializable, TEnforceIsolationLevel.eilMinimum, ref ReadTransaction,
                delegate
                {
                    // Check if user exists in s_user DB Table
                    if (!SUserAccess.Exists(AUserID, ReadTransaction))
                    {
                        throw new EUserNotExistantException(StrInvalidUserIDPassword);
                    }

                    // User exists, so load User record
                    UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ReadTransaction);
                });

            UserDR = UserDT[0];

            if (!UserDR.IsFailedLoginDateNull())
            {
                FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
            }
            else
            {
                FailedLoginDateTime = DateTime.MinValue;
            }

            if (!UserDR.IsLastLoginDateNull())
            {
                LastLoginDateTime = UserDR.LastLoginDate.Value;
                LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
            }
            else
            {
                LastLoginDateTime = DateTime.MinValue;
            }

            Int64 PartnerKey;

            if (!UserDR.IsPartnerKeyNull())
            {
                PartnerKey = UserDR.PartnerKey;
            }
            else
            {
                // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                PartnerKey = -1;
            }

            // Create PetraIdentity
            APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.Retired,
                UserDR.CanModify);
            ReturnValue = UserDR;

            return ReturnValue;
        }
Example #4
0
        /// <summary>
        /// processes the delegate
        /// </summary>
        private static void GenericProcessor(object ADelegateName, bool ARunManually)
        {
            if (!FProcessDelegates.ContainsKey((string)ADelegateName))
            {
                return;
            }

            TDataBase db = EstablishDBConnection();

            TPetraIdentity PetraIdentity = new TPetraIdentity(
                "SYSADMIN", "", "", "", "", DateTime.MinValue,
                DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false,
                false);

            UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

            TProcessDelegate TypedDelegate = FProcessDelegates[(string)ADelegateName];

            TypedDelegate(db, ARunManually);

            CloseDBConnection(db);

            if (TLogging.DebugLevel >= 9)
            {
                TLogging.Log("delegate " + ADelegateName + " has run.");
            }
        }
Example #5
0
        public static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity)
        {
            SUserRow ReturnValue;
            TDBTransaction ReadWriteTransaction;
            Boolean NewTransaction;
            SUserTable UserDT;
            SUserRow UserDR;
            Boolean UserExists;
            DateTime LastLoginDateTime;
            DateTime FailedLoginDateTime;

            ReadWriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                TEnforceIsolationLevel.eilMinimum,
                out NewTransaction);

            // Check if user exists in s_user DB Table
            try
            {
                UserExists = SUserAccess.Exists(AUserID, ReadWriteTransaction);
            }
            catch
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                throw;
            }

            if (!UserExists)
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }
            else
            {
                try
                {
                    // Load User record
                    UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ReadWriteTransaction);
                }
                catch (Exception Exp)
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                    }

                    TLogging.LogAtLevel(8, "Exception occured while loading a s_user record: " + Exp.ToString());

                    throw;
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                UserDR = UserDT[0];

                if (!UserDR.IsFailedLoginDateNull())
                {
                    FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                    FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
                }
                else
                {
                    FailedLoginDateTime = DateTime.MinValue;
                }

                if (!UserDR.IsLastLoginDateNull())
                {
                    LastLoginDateTime = UserDR.LastLoginDate.Value;
                    LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
                }
                else
                {
                    LastLoginDateTime = DateTime.MinValue;
                }

                Int64 PartnerKey;

                if (!UserDR.IsPartnerKeyNull())
                {
                    PartnerKey = UserDR.PartnerKey;
                }
                else
                {
                    // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                    PartnerKey = -1;
                }

                // Create PetraIdentity
                APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                    AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                    LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.Retired,
                    UserDR.CanModify);
                ReturnValue = UserDR;
            }

            return ReturnValue;
        }
        /// <summary>
        /// Gets called in regular intervals from a Timer in Class TTimedProcessing.
        /// </summary>
        /// <param name="ADBAccessObj">Already instatiated DB Access object with opened DB connection.</param>
        /// <param name="ARunManually">this is true if the process was called manually from the server admin console</param>
        public static void Process(TDataBase ADBAccessObj, bool ARunManually)
        {
            TDBTransaction ReadWriteTransaction;
            bool NewTransaction;
            bool LastReminderDateAcquired;
            DateTime LastReminderDate;
            DataSet ReminderResultsDS;
            SSystemDefaultsRow SystemDefaultsDR;
            PPartnerReminderTable PartnerReminderDT;
            int ReminderFreqency;
            TDataBase DBAccessObj;

            if (TLogging.DebugLevel >= 6)
            {
                TLogging.Log("Entering TProcessPartnerReminders.Process...");
            }

            // TODO: it is quite ipossible at the moment to use ADBAccessObj instead of DBAccess.GDBAccessObj due to SubmitChanges etc
            //DBAccessObj = ADBAccessObj;
            DBAccessObj = DBAccess.GDBAccessObj;

            // SubmitChanges references a user
            TPetraIdentity PetraIdentity = new TPetraIdentity(
                "SYSADMIN", "", "", "", "", DateTime.MinValue,
                DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false,
                false);

            UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

            ReadWriteTransaction = DBAccessObj.GetNewOrExistingTransaction(IsolationLevel.ReadCommitted,
                out NewTransaction);

            /*
             * This whole process must either succeed or fail, therefore the whole thing is in a try-catch.
             */
            try
            {
                /*
                 * Obtain date when PartnerReminders last ran. This is stored in a SystemDefault. If it doesn't exist already,
                 * a new SystemDefault with an ancient date is created for us.
                 */
                LastReminderDateAcquired = GetLastReminderDate(out LastReminderDate, out SystemDefaultsDR, ReadWriteTransaction);

                if (!LastReminderDateAcquired)
                {
                    TLogging.Log(
                        TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                        ": Could not send Partner Reminders because Petra couldn't create the required SystemDefault setting for the Last Reminder Date!");

                    DBAccessObj.RollbackTransaction();

                    return;
                }

                TSmtpSender Sender = new TSmtpSender();

                if (!Sender.FInitOk)
                {
                    TLogging.Log(
                        TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                        ": Could not send Partner Reminders because SMTP server didn't initialise.");

                    DBAccessObj.RollbackTransaction();
                    return;
                }

                // Retrieve all PartnerReminders we need to process.
                ReminderResultsDS = GetRemindersToProcess(LastReminderDate, out PartnerReminderDT,
                    DBAccessObj, ReadWriteTransaction);

                /*
                 * We now have a Typed DataTable with the PartnerReminders that we need to process.
                 * Iterate through the PartnerReminders, update data, and send an email for each PartnerReminder.
                 */
                if (TLogging.DebugLevel >= 6)
                {
                    TLogging.Log("_---------------------------------_");
                    TLogging.Log("PartnerReminders data before we start processing all PartnerReminders....");
                    TLogging.Log(ReminderResultsDS.GetXml().ToString());
                }

                foreach (PPartnerReminderRow PartnerReminderDR in PartnerReminderDT.Rows)
                {
                    if (TLogging.DebugLevel >= 4)
                    {
                        TLogging.Log(String.Format(TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                                ": Processing Reminder ID {0} for Partner {1}.", PartnerReminderDR.ReminderId, PartnerReminderDR.PartnerKey));
                    }

                    ReminderFreqency = (PartnerReminderDR.IsReminderFrequencyNull()) ? 0 : PartnerReminderDR.ReminderFrequency;

                    PartnerReminderDR.BeginEdit();
                    PartnerReminderDR.LastReminderSent = DateTime.Now.Date;
                    PartnerReminderDR.NextReminderDate = DateTime.Now.Date.AddDays(ReminderFreqency);

                    if (!PartnerReminderDR.IsEventDateNull())   // Reminder has an Event Date
                    {
                        if (PartnerReminderDR.NextReminderDate > PartnerReminderDR.EventDate)
                        {
                            if (TLogging.DebugLevel >= 5)
                            {
                                TLogging.Log(String.Format(TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                                        ": Deactivating Reminder ID {0} for Partner {1} as its Event Date is in the past.",
                                        PartnerReminderDR.ReminderId, PartnerReminderDR.PartnerKey));
                            }

                            PartnerReminderDR.ReminderActive = false;
                        }
                    }

                    if (TLogging.DebugLevel >= 4)
                    {
                        TLogging.Log(String.Format(TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                                ": Sending email for Reminder ID {0} for Partner {1}.", PartnerReminderDR.ReminderId, PartnerReminderDR.PartnerKey));
                    }

                    if (SendReminderEmail(PartnerReminderDR, ReadWriteTransaction, Sender))
                    {
                        // Accept the edit
                        if (TLogging.DebugLevel >= 4)
                        {
                            TLogging.Log(String.Format(TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                                    ": Reminder ID {0} for Partner {1} accepted by SMTP server.", PartnerReminderDR.ReminderId,
                                    PartnerReminderDR.PartnerKey));
                        }

                        PartnerReminderDR.EndEdit();
                    }
                    else
                    {
                        // Cancel the edit
                        TLogging.Log(String.Format(TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing +
                                ": Reminder ID {0} for Partner {1} REJECTED by SMTP server.", PartnerReminderDR.ReminderId,
                                PartnerReminderDR.PartnerKey));

                        PartnerReminderDR.CancelEdit();
                    }
                }

                if (TLogging.DebugLevel >= 6)
                {
                    TLogging.Log("_---------------------------------_");
                    TLogging.Log("PartnerReminders data after processing all PartnerReminders, before writing it to DB....");
                    TLogging.Log(PartnerReminderDT.DataSet.GetXml().ToString());
                }

                // Update all the changed PartnerReminder Rows
                PPartnerReminderAccess.SubmitChanges(PartnerReminderDT, ReadWriteTransaction);

                if (TLogging.DebugLevel >= 6)
                {
                    TLogging.Log("_---------------------------------_");
                }

                /*
                 * Update the SystemDefault that keeps track of when Partner Reminders last ran.
                 * (SystemDefaultsDR will point to the row we loaded earlier on, OR the row we added earlier on
                 * if there wasn't already a SystemDefault row.)
                 */
                UpdateLastReminderDate(SystemDefaultsDR, ReadWriteTransaction);

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                }

                TLogging.LogAtLevel(1, TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing + " ran succesfully.");
            }
            catch (Exception Exc)
            {
                TLogging.Log(
                    TTimedProcessing.StrAutomaticProcessing + StrRemindersProcessing + " encountered an Exception:" + Environment.NewLine +
                    Exc.ToString());

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.RollbackTransaction();
                }

                throw;
            }
        }
Example #7
0
        void BtnPrintReportPDFClick(object sender, EventArgs e)
        {
            OpenFileDialog DialogOpen = new OpenFileDialog();

            // see file in sub directory test data.
            // create file with method TResultList.WriteBinaryFile
            DialogOpen.Filter = "Binary Report File (*.bin)|*.bin";
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title = "Open Binary Report File";

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                TResultList Results = new TResultList();
                TParameterList Parameters;
                Results.ReadBinaryFile(DialogOpen.FileName, out Parameters);

                TPetraIdentity PetraIdentity = new TPetraIdentity(
                    "TESTUSER", "", "", "", "", DateTime.MinValue,
                    DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false,
                    false);

                UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

                PrintDocument doc = new PrintDocument();

                TPdfPrinter pdfPrinter = new TPdfPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport);
                TReportPrinterLayout layout = new TReportPrinterLayout(Results, Parameters, pdfPrinter, true);

                pdfPrinter.Init(eOrientation.ePortrait, layout, eMarginType.ePrintableArea);

                pdfPrinter.SavePDF("test.pdf");

                System.Diagnostics.Process.Start(Path.GetFullPath("test.pdf"));
            }
        }
Example #8
0
        void TbbImportReportBinaryFileClick(object sender, EventArgs e)
        {
            OpenFileDialog DialogOpen = new OpenFileDialog();

            // see file in sub directory test data.
            // create file with method TResultList.WriteBinaryFile
            DialogOpen.Filter = "Binary Report File (*.bin)|*.bin";
            DialogOpen.RestoreDirectory = true;
            DialogOpen.Title = "Open Binary Report File";

            if (DialogOpen.ShowDialog() == DialogResult.OK)
            {
                TResultList Results = new TResultList();
                TParameterList Parameters;
                Results.ReadBinaryFile(DialogOpen.FileName, out Parameters);

                PrintDocument doc = new PrintDocument();

                TPetraIdentity PetraIdentity = new TPetraIdentity(
                    "TESTUSER", "", "", "", "", DateTime.MinValue,
                    DateTime.MinValue, DateTime.MinValue, 0, -1, -1, false,
                    false);

                UserInfo.GUserInfo = new TPetraPrincipal(PetraIdentity, null);

                FGfxPrinter = new TGfxPrinter(doc, TGfxPrinter.ePrinterBehaviour.eReport);
                new TReportPrinterLayout(Results, Parameters, FGfxPrinter, true);
                printPreviewControl1.Document = doc;
                doc.EndPrint += new PrintEventHandler(this.PrintDocument_EndPrint);
                printPreviewControl1.InvalidatePreview();
            }
        }
Example #9
0
        public static SUserRow LoadUser(String AUserID, out TPetraIdentity APetraIdentity)
        {
            SUserRow       ReturnValue;
            TDBTransaction ReadWriteTransaction;
            Boolean        NewTransaction;
            SUserTable     UserDT;
            SUserRow       UserDR;
            Boolean        UserExists;
            DateTime       LastLoginDateTime;
            DateTime       FailedLoginDateTime;

            ReadWriteTransaction = DBAccess.GDBAccessObj.GetNewOrExistingTransaction(IsolationLevel.Serializable,
                                                                                     TEnforceIsolationLevel.eilMinimum,
                                                                                     out NewTransaction);

            // Check if user exists in s_user DB Table
            try
            {
                UserExists = SUserAccess.Exists(AUserID, ReadWriteTransaction);
            }
            catch
            {
                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                throw;
            }

            if (!UserExists)
            {
                throw new EUserNotExistantException(StrInvalidUserIDPassword);
            }
            else
            {
                try
                {
                    // Load User record
                    UserDT = SUserAccess.LoadByPrimaryKey(AUserID, ReadWriteTransaction);
                }
                catch (Exception Exp)
                {
                    if (NewTransaction)
                    {
                        DBAccess.GDBAccessObj.CommitTransaction();
                        TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                    }

                    TLogging.LogAtLevel(8, "Exception occured while loading a s_user record: " + Exp.ToString());

                    throw;
                }

                if (NewTransaction)
                {
                    DBAccess.GDBAccessObj.CommitTransaction();
                    TLogging.LogAtLevel(7, "TUserManager.LoadUser: committed own transaction.");
                }

                UserDR = UserDT[0];

                if (!UserDR.IsFailedLoginDateNull())
                {
                    FailedLoginDateTime = UserDR.FailedLoginDate.Value;
                    FailedLoginDateTime = FailedLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.FailedLoginTime));
                }
                else
                {
                    FailedLoginDateTime = DateTime.MinValue;
                }

                if (!UserDR.IsLastLoginDateNull())
                {
                    LastLoginDateTime = UserDR.LastLoginDate.Value;
                    LastLoginDateTime = LastLoginDateTime.AddSeconds(Convert.ToDouble(UserDR.LastLoginTime));
                }
                else
                {
                    LastLoginDateTime = DateTime.MinValue;
                }

                Int64 PartnerKey;

                if (!UserDR.IsPartnerKeyNull())
                {
                    PartnerKey = UserDR.PartnerKey;
                }
                else
                {
                    // to make it not match PartnerKey 0, which might be stored in the DB or in a variable
                    PartnerKey = -1;
                }

                // Create PetraIdentity
                APetraIdentity = new Ict.Petra.Shared.Security.TPetraIdentity(
                    AUserID.ToUpper(), UserDR.LastName, UserDR.FirstName, UserDR.LanguageCode, UserDR.AcquisitionCode, DateTime.MinValue,
                    LastLoginDateTime, FailedLoginDateTime, UserDR.FailedLogins, PartnerKey, UserDR.DefaultLedgerNumber, UserDR.Retired,
                    UserDR.CanModify);
                ReturnValue = UserDR;
            }

            return(ReturnValue);
        }