コード例 #1
0
        public static bool checkApplicationLogin(string loginName, string loginPassword)
        {
            int userId = 0;

            // open db..
            cData db = new cData();

            db.openDB();

            userId = db.getUserIDFromLogin(loginName, loginPassword, "application");
            loadUser(userId);

            // audit trail..
            if (userId == 0)
            {
                db.auditEvent(cConstants.eventUserLoginFailed, 0, loginName);  // login failed..
            }
            else
            {
                db.auditEvent(cConstants.eventUserLogin, 0, "Application Login"); // login successful
            }
            db.closeDB();                                                         // cleanup

            return(userId != 0);
        }
コード例 #2
0
        private string m_prevclientid = ""; // for client data grid handling
        #endregion

        #region Page Loading  & Startup

        /*
         * ====================================
         *          PAGE LOADING
         * ====================================
         */
        protected void Page_PreLoad()
        {
            // open up the db
            m_data = new cData();
            if (!m_data.openDB())
            {
                Response.Write("Error opening database. Cannot continue<br><br>" + m_data.lasterrmsg);
                Response.End();
            }
        }
コード例 #3
0
        /*
         * ====================================
         *          PAGE LOADING
         * ====================================
         */
        protected void Page_PreLoad()
        {
            Server.ScriptTimeout = 300; // 5 mins for some reports (unlikely but better to handle it now)

            // open up the db
            m_data = new cData();
            if (!m_data.openDB())
            {
                Response.Write("Error opening database. Cannot continue<br><br>" + m_data.lasterrmsg);
                Response.End();
            }
        }
コード例 #4
0
        // load up the user details and store in the session
        public static void loadUser(int userId)
        {
            WebUser webUser = new WebUser();

            cData db = new cData();

            if (db.openDB())
            {
                webUser = db.loadUser(userId);
                db.closeDB();   // cleanup
            }

            HttpContext.Current.Session["user.id"]     = userId.ToString();
            HttpContext.Current.Session["user.object"] = webUser;
        }
コード例 #5
0
        public static WebUser getUser(int userid)
        {
            // no longer using session as the photos change and I want this updated every time..
            WebUser webUser = new WebUser();

            cData db = new cData();

            if (db.openDB())
            {
                webUser = db.loadUser(userid);
                db.closeDB();   // cleanup
            }

            return(webUser);
        }
コード例 #6
0
        public static int checkMobileLogin(string loginName, string loginPassword)
        {
            int userId = 0;

            // open db..
            cData db = new cData();

            db.openDB();

            userId = db.getUserIDFromLogin(loginName, loginPassword, "application");



            db.closeDB();   // cleanup

            return(userId);
        }
コード例 #7
0
        public static void logout()
        {
            // audit trail..
            if (userID() != 0)
            {
                cData db = new cData();
                if (db.openDB())
                {
                    db.auditEvent(cConstants.eventUserLogout);
                    db.closeDB();   // cleanup
                }
            }

            HttpContext.Current.Session["user.id"]         = "0";
            HttpContext.Current.Session["user.object"]     = null;
            HttpContext.Current.Session["UserAgreesTerms"] = "";
            HttpContext.Current.Response.Redirect("~/login");
        }
コード例 #8
0
        /*
         * ====================================
         *          PAGE LOADING
         * ====================================
         */

        //  Note: Page_PreLoad() not firing so using Page_Load() instead
        protected void Page_Load(object sender, EventArgs e)
        {
            // open up the db
            m_data = new cData();
            if (!m_data.openDB())
            {
                Response.Write("Error opening database. Cannot continue<br><br>" + m_data.lasterrmsg);
                Response.End();
            }

            initPage();

            // on first load of the app, load up the doc listing..
            if (!Page.IsPostBack)
            {
                initApp();
            }

            // cleanup
            m_data.closeDB();
        }
コード例 #9
0
        public static void handleEvent(int eventId, int surveyId)
        {
            // open up the db
            cData m_data = new cData();

            if (!m_data.openDB())
            {
                return;
            }

            /*
             *  load up the audit details & convert id's to text
             */
            SurveySummaryData survey   = m_data.loadSurvey(surveyId);
            LocationData      location = m_data.loadLocation(survey.locationid);
            ClientData        client   = m_data.loadClient(location.clientid);

            // convert id's to text
            string sqlCmd       = "SELECT templatename FROM templates WHERE templateid=" + survey.templateid;
            string templateName = m_data.runSql(sqlCmd);
            string jobRef       = client.clientname + " - " + location.businessunit + " - " + location.locationname + " - " + templateName + " - " + survey.dateofaudit;


            /*
             *  Set up the email, SMTP settings and links to the job
             */
            //load up the standard template file.
            string emailTemplate = loadTemplateFile();

            if (emailTemplate == string.Empty)
            {
                return;
            }

            // get our email server settings..
            string emailSenderName      = cTools.cStrExt(ConfigurationManager.AppSettings["SenderName"]);
            string emailSenderEmail     = cTools.cStrExt(ConfigurationManager.AppSettings["SenderEMail"]);
            string emailRootFolder      = cTools.cStrExt(ConfigurationManager.AppSettings["EmailFolder"]);
            int    notifyUserOnSendToHQ = cTools.cIntExt(ConfigurationManager.AppSettings["NotifyUserOnSendToHQ"]);

            string emailSubjectLine   = string.Empty;
            string emailHtml          = string.Empty;
            string notificationsBlock = string.Empty;
            string sendToEmail        = string.Empty;
            string sendToName         = string.Empty;
            string siteUrl            = "http://" + HttpContext.Current.Request.ServerVariables["SERVER_NAME"];

            if (siteUrl.Contains("localhost"))
            {
                siteUrl += "/coylegroup";                              // dev server
            }
            string linkToJob = siteUrl + "/audit/summary/" + surveyId; // all notification links go to summary page..

            /*
             *  Customise the email depending on what action was just taken
             */
            switch (eventId)
            {
            case cConstants.eventSurveyConsultantChanged_Notification:
                emailSubjectLine   = "Audit Notification: Contractor Assigned";
                notificationsBlock = "You have been assigned as the <b>Contractor</b> for the following audit.";
                if (survey.auditorid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.auditorid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventQuestionSubmitToHQ_Notification:
                emailSubjectLine   = "Audit Notification: For Internal Review";
                notificationsBlock = "This audit has been <b>Sent to HQ</b> for internal review.";
                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventSurveyStatusReadyForClientReview_Notification:
                emailSubjectLine   = "Audit Notification: Pending Client Approval";
                notificationsBlock = "An audit is available <b>Pending Client Approval</b>";
                if (survey.client_mgruserid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_mgruserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientApprovalAccept_Notification:
                emailSubjectLine   = "Audit Notification: Approved by Client";
                notificationsBlock = "This audit has been <b>Approved by the Client</b>.";
                if (survey.client_approvalcomments != "")
                {
                    notificationsBlock += "<br><br>Client Comments:<br>" +
                                          "<i>" + survey.client_approvalcomments + "</i>";
                }

                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientApprovalReject_Notification:
                emailSubjectLine   = "Audit Notification: Rejected by Client";
                notificationsBlock = "This audit has been <b>Rejected by the Client</b>.";
                if (survey.client_approvalcomments != "")
                {
                    notificationsBlock += "<br><br>Client Comments:<br>" +
                                          "<i>" + survey.client_approvalcomments + "</i>";
                }
                if (notifyUserOnSendToHQ != 0)
                {
                    WebUser userDetails = m_data.loadUser(notifyUserOnSendToHQ);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientResponsesClosed_NotifyClientMgr:
                emailSubjectLine   = "Audit Notification: All Client Actions Closed";
                notificationsBlock = "Congratulations - All action items have been <b>closed</b> on this audit.";
                if (survey.client_mgruserid != 0)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_mgruserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;

            case cConstants.eventClientResponsesClosed_NotifyClientAdmin:
                emailSubjectLine   = "Audit Notification: All Client Actions Closed";
                notificationsBlock = "Congratulations - All action items have been <b>closed</b> on this audit.";
                // don't send if no admin user set or if it's the same as the manager..
                if (survey.client_adminuserid != 0 && survey.client_adminuserid != survey.client_mgruserid)
                {
                    WebUser userDetails = m_data.loadUser(survey.client_adminuserid);
                    sendToEmail = userDetails.emailaddress;
                    sendToName  = userDetails.firstname;
                }
                break;
            }

            // while testing...
            // sendToName += " (" + sendToEmail + ")";
            // sendToEmail = "*****@*****.**";

            // if no email associated with this task then off ye go..
            if (sendToEmail == string.Empty)
            {
                return;
            }

            // record in the audit trail that we've handled this notification
            string auditEntry = string.Format("To: {0} ({1})\n{2}",
                                              sendToName, sendToEmail, notificationsBlock);

            m_data.auditEvent(eventId, surveyId, auditEntry);

            // start with a fresh template & replace with content for this user
            emailHtml = emailTemplate;
            emailHtml = emailHtml.Replace("%sendtoname%", sendToName);
            emailHtml = emailHtml.Replace("%content%", notificationsBlock);
            emailHtml = emailHtml.Replace("%datestamp%", cTools.cDateAndShortTime(DateTime.Now));
            emailHtml = emailHtml.Replace("%linktojob%", linkToJob);
            emailHtml = emailHtml.Replace("%jobref%", jobRef);

            // set up today's email folder..
            string folderName = String.Format("{0}/{1}",
                                              emailRootFolder,
                                              DateTime.Now.ToString("ddMMMyyyy")); // folder changes daily

            System.IO.Directory.CreateDirectory(folderName);

            string mailFilename = String.Format("{0}/notifications_{1}.htm",
                                                folderName,
                                                sendToEmail); // append all emails for person per day to one file

            // write the file to the local server for later retrieval
            cFiles.writeFile(mailFilename, emailHtml, true);

            // send the email now..we store the output in a subfolder in the logs if enabled
            cTools.log("Sending notification email to: " + sendToEmail);

            // send the email now..unless it's on my dev machine..
            if (!siteUrl.Contains("localhost"))
            {
                cMailer.sendMail(sendToName, sendToEmail, emailSenderName, emailSenderEmail, emailSubjectLine, emailHtml);
            }

            // send me a copy..
            cMailer.sendMail("Gary Alerts", "*****@*****.**", emailSenderName, emailSenderEmail, emailSubjectLine, emailHtml);

            // cleanup
            m_data.closeDB();
        }
コード例 #10
0
        // from an sql command, build up a dropdown combo
        public static void setDropdown(RepeaterItemEventArgs e, string ctrlName, string fieldName, string sqlCmd, cData oData, string sBlankOptionText = "", string sBlankOptionVal = "")
        {
            // get a handle on the dropdown
            DropDownList cboTarget = (DropDownList)e.Item.FindControl(ctrlName);

            // run the sql command and build up our dropdown list..
            oData.createDropdown(sqlCmd, cboTarget, sBlankOptionText, sBlankOptionVal);

            // now auto-select the value for this dropdown from the db
            string selectedVal = cTools.cStrExt(System.Web.UI.DataBinder.Eval(e.Item.DataItem, fieldName));

            cTools.autoSelectListItem(cboTarget, selectedVal);
        }