protected void submitButton_Click(object sender, EventArgs e)
        {
            #region Event Attendance
            // Logging event attendance
            string codeValue = codeEntryField.Text;
            int patronId = ((Patron)Session[SessionKey.Patron]).PID;
            var pointsAward = new AwardPoints(patronId);

            if(codeValue.Length == 0) {
                Session[SessionKey.PatronMessage] = "Please enter a code.";
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            } else {
                // verify event code was not previously redeemed
                if(PatronPoints.HasRedeemedKeywordPoints(patronId, codeValue)) {
                    Session[SessionKey.PatronMessage] = "You've already redeemed this code!";
                    Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }

                // get event for that code, get the # points
                var ds = Event.GetEventByEventCode(pointsAward.pgm.StartDate.ToShortDateString(),
                                                   DateTime.Now.ToShortDateString(), codeValue);
                if(ds.Tables[0].Rows.Count == 0) {
                    Session[SessionKey.PatronMessage] = "Sorry, that's an invalid code.";
                    Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }
                var EID = (int)ds.Tables[0].Rows[0]["EID"];
                var evt = Event.GetEvent(EID);
                var points = evt.NumberPoints;
                //var newPBID = 0;

                var earnedBadges = pointsAward.AwardPointsToPatron(points: points,
                                                                   reason: PointAwardReason.EventAttendance,
                                                                   eventCode: codeValue,
                                                                   eventID: EID);

                if(!string.IsNullOrWhiteSpace(earnedBadges)) {
                    new SessionTools(Session).EarnedBadges(earnedBadges);
                }

                // set message and earned badges
                string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points);
                if(string.IsNullOrEmpty(earnedMessage)) {
                    Session[SessionKey.PatronMessage] = "<strong>Excellent!</strong> Your secret code has been recorded.";
                } else {
                    Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Your secret code has been recorded. <strong>{0}</strong>",
                                                                      earnedMessage);
                }
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success;
                Session[SessionKey.PatronMessageGlyphicon] = "barcode";
                this.codeEntryField.Text = string.Empty;
            }
            #endregion
        }
Ejemplo n.º 2
0
 public bool ProcessTheWin()
 {
     var mg = DAL.Minigame.FetchObject(int.Parse(MGID.Text));
     var pa = new AwardPoints(int.Parse(PID.Text));
     var sBadges = pa.AwardPointsToPatron(mg.NumberPoints, PointAwardReason.MiniGameCompletion, mg.MGID);
     if(sBadges.Length > 0) {
         new SessionTools(Session).EarnedBadges(sBadges);
         return true;
     }
     return false;
 }
        protected void Button1_Click(object sender, EventArgs e)
        {
            var startPID = int.Parse(txtStart.Text);
            var numPoints = 500;
            var cnt1 = 0;
            var cnt2 = 0;
            var code = "final_push";


            //            var strSQL = string.Format("SELECT PID FROM Patron WHERE PID > {0} AND PrimaryLibrary NOT IN ({1}) ORDER BY PID ", startPID, "57,58,59,60,61,62");
            var strSQL = string.Format("SELECT PID FROM Patron WHERE PID > {0} AND PrimaryLibrary IN ({1}) ORDER BY PID ", startPID, "62");
            var ds = SqlHelper.ExecuteDataset(conn, CommandType.Text, strSQL);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                cnt1++;
                cnt2++;
                int PID = Convert.ToInt32(row["PID"]);
                //int PGID = Convert.ToInt32(row["ProgID"]);

                var pa = new AwardPoints(PID);
                var sBadges= string.Empty;
                var points = numPoints;
                
                if (!PatronPoints.HasRedeemedKeywordPoints(PID, code))
                {
                    sBadges = pa.AwardPointsToPatron(points, PointAwardReason.EventAttendance,
                                                         eventCode: code, eventID: -1);

                    Response.Write(string.Format("{0}: {1}<br>",cnt1,PID));
                    Response.Flush();                    
                }
                else
                {
                    Response.Write(string.Format("XX{0}: {1}<br>",cnt2,PID));
                    Response.Flush();          
                }

            }

        }
        protected void SubmitActivity()
        {
            var txtCount = readingActivityField.Text.Trim();
            var intCount = 0;
            if(txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0) {
                Session[SessionKey.PatronMessage] = "You must enter how much you've read as a positive whole number.";
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            }

            var selectedActivityType = activityTypeSelector.SelectedValue;

            // check that we aren't over the max
            int maxAmountForLogging = 0;
            switch(int.Parse(selectedActivityType)) {
                case 0:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt();
                    break;
                case 1:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt();
                    break;
                //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt();
                //    break;
                case 3:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;
                default:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;
            }
            if(intCount > maxAmountForLogging) {
                Session[SessionKey.PatronMessage] = string.Format("That's an awful lot of reading! You can only submit {0} {1} at a time.",
                                                                  maxAmountForLogging,
                                                                  ((ActivityType)int.Parse(selectedActivityType)).ToString());
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var patronId = ((Patron)Session[SessionKey.Patron]).PID;
            var programGameId = int.Parse(ViewState["ProgramGameId"].ToString());

            var pa = new AwardPoints(patronId);
            var points = 0;

            // convert pages/minutes/etc. to points
            var pc = new ProgramGamePointConversion();
            pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue));
            // round up to ensure they get at least 1 point
            decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount;
            points = (int)Math.Ceiling(computedPoints);

            // ensure they aren't over teh day total
            var allPointsToday = PatronPoints.GetTotalPatronPoints(patronId, DateTime.Now);
            int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt();
            if(intCount + allPointsToday > maxPointsPerDayForLogging) {
                Session[SessionKey.PatronMessage] = "Sorry but you have already reached the maximum amount of points that you can log in a day. Keep reading and come back tomorrow!";
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var earnedBadges = pa.AwardPointsToPatron(points: points,
                reason: PointAwardReason.Reading,
                MGID: 0,
                readingActivity: (ActivityType)pc.ActivityTypeId,
                readingAmount: intCount,
                author: authorField.Text,
                title: titleField.Text);

            // clear out the form
            var bookButton = activityTypeSelector.Items.Count == 1
                             && int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books;

            if(!bookButton) {
                readingActivityField.Text = string.Empty;
            }
            authorField.Text = string.Empty;
            titleField.Text = string.Empty;

            // set message and earned badges
            string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points);
            if(string.IsNullOrEmpty(earnedMessage)) {
                Session[SessionKey.PatronMessage] = "<strong>Good job!</strong> Your reading activity has been logged.";
            } else {
                Session[SessionKey.PatronMessage] = string.Format("<strong>Good job!</strong> Your reading activity has been logged. <strong>{0}</strong>",
                                                                  earnedMessage);
            }
            Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success;
            Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up";
            new SessionTools(Session).EarnedBadges(earnedBadges);
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ProgramOpen)
            {
                return;
            }

            var now = DateTime.Now;
            var onlyCheckedBoxes = true;
            var selBLI = 0;
            var readCount = 0;
            var neeedCount = 0;
            var BLID = -1;
            foreach (RepeaterItem item in rptr2.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    if (BLID < 0)
                    {
                        BLID = int.Parse(((Label)item.FindControl("BLID")).Text);
                        neeedCount = BookList.FetchObject(BLID).NumBooksToComplete;
                    }
                    var chkRead = (CheckBox)item.FindControl("chkRead");
                    var PBLBID = int.Parse(((Label)item.FindControl("PBLBID")).Text);
                    var BLBID = int.Parse(((Label)item.FindControl("BLBID")).Text);

                    selBLI = BLID;
                    var pbl = new PatronBookLists();
                    if (PBLBID != 0)
                    {
                        pbl = PatronBookLists.FetchObject(PBLBID);
                    }
                    pbl.BLBID = BLBID;
                    pbl.BLID = BLID;
                    pbl.PID = this.CurrentPatron.PID;
                    pbl.LastModDate = now;

                    pbl.HasReadFlag = chkRead.Checked;
                    if (!pbl.HasReadFlag)
                    {
                        onlyCheckedBoxes = false;
                    }
                    else
                    {
                        readCount++;
                    }

                    if (PBLBID != 0)
                    {
                        pbl.Update();
                    }
                    else
                    {
                        pbl.Insert();
                    }
                }
            }

            string success = StringResources.getString("challenges-progress-saved");
            new SessionTools(Session).AlertPatron(success,
                glyphicon: "check");

            // read the entire book list!  Award points and badges 
            if ((neeedCount == 0 && onlyCheckedBoxes) || (neeedCount <= readCount))
            {
                success = StringResources.getString("challenges-completed");

                new SessionTools(Session).AlertPatron(success, glyphicon: "star");

                var bl = BookList.FetchObject(selBLI);

                if (PatronPoints.HasEarnedBookList(this.CurrentPatron.PID, selBLI))
                {
                    PopulateChallengeList();
                    return;
                }

                if (bl.AwardBadgeID != 0 || bl.AwardPoints != 0)
                {
                    success = StringResources.getString("challenges-completed-badge");
                    new SessionTools(Session).AlertPatron(success,
                        glyphicon: "certificate");

                    var pa = new AwardPoints(this.CurrentPatron.PID);
                    var sBadges = pa.AwardPointsToPatron(bl.AwardPoints, PointAwardReason.BookListCompletion,
                                                            bookListID: bl.BLID);
                    if (sBadges.Length > 0)
                    {
                        new SessionTools(Session).EarnedBadges(sBadges);
                    }
                }
            }
            PopulateChallengeList();
        }
        protected void SubmitActivity()
        {
            var txtCount = readingActivityField.Text.Trim();
            var intCount = 0;
            if (txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0)
            {
                Session[SessionKey.PatronMessage] = StringResources.getString("readinglog-entry-invalid");
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            }

            var selectedActivityType = activityTypeSelector.SelectedValue;

            // check that we aren't over the max
            int maxAmountForLogging = 0;
            switch (int.Parse(selectedActivityType))
            {
                case 0:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt();
                    break;
                case 1:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt();
                    break;
                //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt();
                //    break;
                case 3:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;
                default:
                    maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                    break;
            }
            if (intCount > maxAmountForLogging)
            {
                Session[SessionKey.PatronMessage] = string.Format(StringResources.getString("readinglog-entry-limit"),
                                                                  maxAmountForLogging,
                                                                  ((ActivityType)int.Parse(selectedActivityType)).ToString());
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var patronId = ((Patron)Session[SessionKey.Patron]).PID;
            var programGameId = int.Parse(ViewState[ProgramGameIdKey].ToString());

            var pa = new AwardPoints(patronId);
            var points = 0;

            // convert pages/minutes/etc. to points
            var pc = new ProgramGamePointConversion();
            pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue));
            // round up to ensure they get at least 1 point
            decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount;
            points = (int)Math.Ceiling(computedPoints);


            // ensure they aren't over teh day total
            var allPointsToday = PatronPoints.GetTotalPatronPointsOnDate(patronId, DateTime.Now);
            int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt();
            if (intCount + allPointsToday > maxPointsPerDayForLogging)
            {
                Session[SessionKey.PatronMessage] = StringResources.getString("readinglog-daily-limit");
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var review = "";

            if (ViewState[PatronCanReviewKey] as bool? == true)
            {
                review = reviewField.Text;
            }

            var earnedBadges = pa.AwardPointsToPatron(points: points,
                reason: PointAwardReason.Reading,
                MGID: 0,
                readingActivity: (ActivityType)pc.ActivityTypeId,
                readingAmount: intCount,
                author: authorField.Text,
                title: titleField.Text,
                review: review);

            // clear out the form
            var bookButton = activityTypeSelector.Items.Count == 1
                             && int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books;

            if (!bookButton)
            {
                readingActivityField.Text = string.Empty;
            }
            authorField.Text = string.Empty;
            titleField.Text = string.Empty;
            reviewField.Text = string.Empty;

            // set message and earned badges
            string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points);
            if (string.IsNullOrEmpty(earnedMessage))
            {
                Session[SessionKey.PatronMessage] = "<strong>Good job!</strong> Your reading activity has been logged.";
            }
            else {
                Session[SessionKey.PatronMessage] = string.Format("<strong>Good job!</strong> Your reading activity has been logged. <strong>{0}</strong>",
                                                                  earnedMessage);
            }
            Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success;
            Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up";
            new SessionTools(Session).EarnedBadges(earnedBadges);
        }
        protected void ImageButton1_Command(object sender, CommandEventArgs e)
        {
            var masterPage = (IControlRoomMaster)((BaseControlRoomPage)Page).Master;
            lblError.Text= string.Empty;
            Page.Validate();
            if (Page.IsValid)
            {
                var patron = Patron.FetchObject(int.Parse(PID.Text));
                var pgm = Programs.FetchObject(patron.ProgID);

                if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
                {
                    //var p = new Patron();
                    var o = new PatronPoints();
                    var sBadges= string.Empty;
                    var pa = new AwardPoints(patron.PID);
                    var points = int.Parse(NumPoints.Text);

                    if (!IsAdd())
                    {
                        //p = Patron.FetchObject(int.Parse(PID.Text));
                        o = PatronPoints.FetchObject(int.Parse(PatronPointsID));
                        o.Delete();

                        var pl = PatronReadingLog.FetchObject(o.LogID);
                        if (pl != null && pl.HasReview)
                        {
                            var r = PatronReview.FetchObjectByLogId(o.LogID);
                            if (r != null) r.Delete();
                        }
                        if (pl != null) pl.Delete();
                    }

                    //o.PID = patron.PID;
                    //o.NumPoints = int.Parse(NumPoints.Text);
                    //o.AwardDate = DateTime.Parse(AwardDate.Text);
                    //o.AwardReasonCd = int.Parse(AwardReasonCd.SelectedValue);
                    //o.AwardReason = PatronPoints.PointAwardReasonCdToDescription((PointAwardReason)o.AwardReasonCd);
                    //o.isReading = o.isBookList = o.isEvent = o.isGame = o.isGameLevelActivity = false;
                    if ((PointAwardReason)o.AwardReasonCd == PointAwardReason.Reading)
                    {
                        var pc = new ProgramGamePointConversion();
                        pc.FetchByActivityId(pgm.PID, 1);//ActivityType.Pages);
                        var pages = 1;
                        try { Convert.ToInt32(pc.ActivityCount * points / pc.PointCount);} catch{}
                        sBadges = pa.AwardPointsToPatron(points, PointAwardReason.Reading,
                                                            0,
                                                            ActivityType.Pages, pages, "", "", "", forceDate: DateTime.Parse(AwardDate.Text));
                    }

                    if ((PointAwardReason)o.AwardReasonCd == PointAwardReason.EventAttendance)
                    {
                        var ds = Event.GetEventByEventCode(pa.pgm.StartDate.ToShortDateString(),
                                                   DateTime.Now.ToShortDateString(), EventCode.Text);
                        var EID = 0;
                        if (ds.Tables[0].Rows.Count == 0)
                        {
                            EID = 0;
                        }
                        else
                        {
                            EID = (int)ds.Tables[0].Rows[0]["EID"];
                        }
                        sBadges = pa.AwardPointsToPatron(points, PointAwardReason.EventAttendance,
                                                     eventCode: EventCode.Text, eventID: EID, forceDate: DateTime.Parse(AwardDate.Text));
                    }
                    if ((PointAwardReason)o.AwardReasonCd == PointAwardReason.BookListCompletion)
                    {
                        var BLID = 0;
                        int.TryParse(lblBookList.Text, out BLID);
                        sBadges = pa.AwardPointsToPatron(points, PointAwardReason.BookListCompletion,
                                                            bookListID: BLID, forceDate: DateTime.Parse(AwardDate.Text));

                    }
                    if ((PointAwardReason)o.AwardReasonCd == PointAwardReason.GameCompletion)
                    {
                        var GID = 0;
                        int.TryParse(lblGame.Text, out GID);
                        sBadges = pa.AwardPointsToPatron(points, PointAwardReason.GameCompletion, GID, forceDate: DateTime.Parse(AwardDate.Text));
                    }
                    if ((PointAwardReason)o.AwardReasonCd == PointAwardReason.MiniGameCompletion)
                    {
                        var MGID = 0;
                        int.TryParse(lblMGame.Text, out MGID);
                        sBadges = pa.AwardPointsToPatron(points, PointAwardReason.MiniGameCompletion, MGID, forceDate: DateTime.Parse(AwardDate.Text));
                    }

                    PatronPointsID = PatronPoints.GetLastPatronEntryID(int.Parse(PatronID)).ToString();

                    LoadControl();
                    masterPage.PageMessage = SRPResources.AddedOK;

                    if (e.CommandName.ToLower() == "saveandback")
                    {
                        Response.Redirect("PatronLog.aspx");
                    }

                }

            }
        }
        protected void submitButton_Click(object sender, EventArgs e) {

            #region Event Attendance
            // Logging event attendance
            string codeValue = Logic.Code.SanitizeCode(codeEntryField.Text);
            codeEntryField.Text = codeValue;
            int patronId = (int)ViewState["SubmitAsPatronId"];
            var pointsAward = new AwardPoints(patronId);
            var patron = Patron.FetchObject(patronId);
            var patronName = DisplayHelper.FormatName(patron.FirstName, patron.LastName, patron.Username);

            if(codeValue.Length == 0) {
                Session[SessionKey.PatronMessage] = "Please enter a code.";
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            } else { 
                // verify event code was not previously redeemed
                if(PatronPoints.HasRedeemedKeywordPoints(patronId, codeValue)) {
                    Session[SessionKey.PatronMessage] = string.Format("{0} has already redeemed this code!", patronName);
                    Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }

                // get event for that code, get the # points
                var ds = Event.GetEventByEventCode(codeValue);
                if(ds.Tables[0].Rows.Count == 0) {
                    Session[SessionKey.PatronMessage] = "Sorry, that's an invalid code.";
                    Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }
                var EID = (int)ds.Tables[0].Rows[0]["EID"];
                var evt = Event.GetEvent(EID);
                var points = evt.NumberPoints;
                //var newPBID = 0;

                var earnedBadges = pointsAward.AwardPointsToPatron(points: points,
                                                                   reason: PointAwardReason.EventAttendance,
                                                                   eventCode: codeValue,
                                                                   eventID: EID);

                // don't show badge earnings to the parent
                //if(!string.IsNullOrWhiteSpace(earnedBadges)) {
                //    new SessionTools(Session).EarnedBadges(earnedBadges);
                //}

                // set message and earned badges
                string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points, patronName);
                if(string.IsNullOrEmpty(earnedMessage)) {
                    Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded for {0}.", patronName);
                } else {
                    Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded. <strong>{0}</strong>",
                                                                      earnedMessage);
                }
                Session[SessionKey.PatronMessageLevel] = PatronMessageLevels.Success;
                Session[SessionKey.PatronMessageGlyphicon] = "barcode";
                this.codeEntryField.Text = string.Empty;
            }
            #endregion

        }
        protected void SubmitActivity()
        {
            var txtCount = readingActivityField.Text.Trim();
            var intCount = 0;

            if (txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0)
            {
                Session[SessionKey.PatronMessage]          = StringResources.getString("readinglog-entry-invalid");
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            }

            var selectedActivityType = activityTypeSelector.SelectedValue;

            // check that we aren't over the max
            int maxAmountForLogging = 0;

            switch (int.Parse(selectedActivityType))
            {
            case 0:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt();
                break;

            case 1:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt();
                break;

            //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt();
            //    break;
            case 3:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                break;

            default:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                break;
            }
            if (intCount > maxAmountForLogging)
            {
                Session[SessionKey.PatronMessage] = string.Format(StringResources.getString("readinglog-entry-limit"),
                                                                  maxAmountForLogging,
                                                                  ((ActivityType)int.Parse(selectedActivityType)).ToString());
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var patronId      = ((Patron)Session[SessionKey.Patron]).PID;
            var programGameId = int.Parse(ViewState[ProgramGameIdKey].ToString());

            var pa     = new AwardPoints(patronId);
            var points = 0;

            // convert pages/minutes/etc. to points
            var pc = new ProgramGamePointConversion();

            pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue));
            // round up to ensure they get at least 1 point
            decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount;

            points = (int)Math.Ceiling(computedPoints);


            // ensure they aren't over teh day total
            var allPointsToday            = PatronPoints.GetTotalPatronPointsOnDate(patronId, DateTime.Now);
            int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt();

            if (intCount + allPointsToday > maxPointsPerDayForLogging)
            {
                Session[SessionKey.PatronMessage]          = StringResources.getString("readinglog-daily-limit");
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var review = "";

            if (ViewState[PatronCanReviewKey] as bool? == true)
            {
                review = reviewField.Text;
            }

            var earnedBadges = pa.AwardPointsToPatron(points: points,
                                                      reason: PointAwardReason.Reading,
                                                      MGID: 0,
                                                      readingActivity: (ActivityType)pc.ActivityTypeId,
                                                      readingAmount: intCount,
                                                      author: authorField.Text,
                                                      title: titleField.Text,
                                                      review: review);

            // clear out the form
            var bookButton = activityTypeSelector.Items.Count == 1 &&
                             int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books;

            if (!bookButton)
            {
                readingActivityField.Text = string.Empty;
            }
            authorField.Text = string.Empty;
            titleField.Text  = string.Empty;
            reviewField.Text = string.Empty;

            // set message and earned badges
            string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points);

            if (string.IsNullOrEmpty(earnedMessage))
            {
                Session[SessionKey.PatronMessage] = "<strong>Good job!</strong> Your reading activity has been logged.";
            }
            else
            {
                Session[SessionKey.PatronMessage] = string.Format("<strong>Good job!</strong> Your reading activity has been logged. <strong>{0}</strong>",
                                                                  earnedMessage);
            }
            Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Success;
            Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up";
            new SessionTools(Session).EarnedBadges(earnedBadges);
        }
Ejemplo n.º 10
0
        public bool SaveAccount()
        {
            try {
                //var patron = (Patron)Session["Patron"];
                Patron patron = null;
                if ((int)Session["MasterAcctPID"] == 0)
                {
                    // we are the parent
                    patron = (Patron)Session["Patron"];
                }
                else
                {
                    patron = Patron.FetchObject((int)Session["MasterAcctPID"]);
                }
                var      p = new Patron();
                DateTime _d;
                var      DOB = rptr.Items[0].FindControl("DOB") as TextBox;
                if (DOB != null && !string.IsNullOrEmpty(DOB.Text))
                {
                    if (DateTime.TryParse(DOB.Text, out _d))
                    {
                        p.DOB = _d;
                    }
                }

                p.Age = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("Age")).Text);

                p.ProgID      = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("ProgID")).SelectedValue);
                p.Username    = ((TextBox)rptr.Items[0].FindControl("Username")).Text;
                p.NewPassword = ((TextBox)rptr.Items[0].FindControl("Password")).Text;

                p.IsMasterAccount = false;
                p.MasterAcctPID   = patron.PID;

                p.SchoolGrade    = ((TextBox)rptr.Items[0].FindControl("SchoolGrade")).Text;
                p.FirstName      = ((TextBox)rptr.Items[0].FindControl("FirstName")).Text;
                p.MiddleName     = ((TextBox)rptr.Items[0].FindControl("MiddleName")).Text;
                p.LastName       = ((TextBox)rptr.Items[0].FindControl("LastName")).Text;
                p.Gender         = ((DropDownList)rptr.Items[0].FindControl("Gender")).SelectedValue;
                p.EmailAddress   = ((TextBox)rptr.Items[0].FindControl("EmailAddress")).Text;
                p.PhoneNumber    = ((TextBox)rptr.Items[0].FindControl("PhoneNumber")).Text;
                p.PhoneNumber    = FormatHelper.FormatPhoneNumber(p.PhoneNumber);
                p.StreetAddress1 = ((TextBox)rptr.Items[0].FindControl("StreetAddress1")).Text;
                p.StreetAddress2 = ((TextBox)rptr.Items[0].FindControl("StreetAddress2")).Text;
                p.City           = ((TextBox)rptr.Items[0].FindControl("City")).Text;
                p.State          = ((TextBox)rptr.Items[0].FindControl("State")).Text;
                p.ZipCode        = ((TextBox)rptr.Items[0].FindControl("ZipCode")).Text;
                p.ZipCode        = FormatHelper.FormatZipCode(p.ZipCode);

                p.Country = ((TextBox)rptr.Items[0].FindControl("Country")).Text;
                p.County  = ((TextBox)rptr.Items[0].FindControl("County")).Text;
                p.ParentGuardianFirstName  = ((TextBox)rptr.Items[0].FindControl("ParentGuardianFirstName")).Text;
                p.ParentGuardianLastName   = ((TextBox)rptr.Items[0].FindControl("ParentGuardianLastName")).Text;
                p.ParentGuardianMiddleName = ((TextBox)rptr.Items[0].FindControl("ParentGuardianMiddleName")).Text;
                p.LibraryCard = ((TextBox)rptr.Items[0].FindControl("LibraryCard")).Text;

                //p.District = ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue;
                //p.SDistrict = ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt();

                p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("PrimaryLibrary")).SelectedValue);
                p.SchoolName     = ((DropDownList)rptr.Items[0].FindControl("SchoolName")).SelectedValue;
                p.SchoolType     = FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("SchoolType")).SelectedValue);

                var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary);
                if (lc != null)
                {
                    p.District = lc.DistrictID == 0 ? ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue : lc.DistrictID.ToString();
                }
                else
                {
                    p.District = ((DropDownList)rptr.Items[0].FindControl("District")).SelectedValue;
                }
                var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt());
                if (sc != null)
                {
                    p.SDistrict  = sc.DistrictID == 0 ? ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt() : sc.DistrictID;
                    p.SchoolType = sc.SchTypeID == 0 ? FormatHelper.SafeToInt(((DropDownList)rptr.Items[0].FindControl("SchoolType")).SelectedValue) : sc.SchTypeID;
                }
                else
                {
                    p.SDistrict = ((DropDownList)rptr.Items[0].FindControl("SDistrict")).SelectedValue.SafeToInt();
                }

                p.Teacher        = ((TextBox)rptr.Items[0].FindControl("Teacher")).Text;
                p.GroupTeamName  = ((TextBox)rptr.Items[0].FindControl("GroupTeamName")).Text;
                p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("LiteracyLevel1")).Text);
                p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)rptr.Items[0].FindControl("LiteracyLevel2")).Text);

                p.ParentPermFlag = true;
                p.Over18Flag     = p.Age >= 18;
                p.ShareFlag      = ((CheckBox)rptr.Items[0].FindControl("ShareFlag")).Checked;
                p.TermsOfUseflag = true;

                p.Custom1 = string.IsNullOrEmpty(this.CustomFields.DDValues1)
                    ? ((TextBox)rptr.Items[0].FindControl("Custom1")).Text
                    : ((DropDownList)rptr.Items[0].FindControl("Custom1DD")).SelectedValue;
                p.Custom2 = string.IsNullOrEmpty(this.CustomFields.DDValues2)
                    ? ((TextBox)rptr.Items[0].FindControl("Custom2")).Text
                    : ((DropDownList)rptr.Items[0].FindControl("Custom2DD")).SelectedValue;
                p.Custom3 = string.IsNullOrEmpty(this.CustomFields.DDValues3)
                    ? ((TextBox)rptr.Items[0].FindControl("Custom3")).Text
                    : ((DropDownList)rptr.Items[0].FindControl("Custom3DD")).SelectedValue;
                p.Custom4 = string.IsNullOrEmpty(this.CustomFields.DDValues4)
                    ? ((TextBox)rptr.Items[0].FindControl("Custom4")).Text
                    : ((DropDownList)rptr.Items[0].FindControl("Custom4DD")).SelectedValue;
                p.Custom5 = string.IsNullOrEmpty(this.CustomFields.DDValues5)
                    ? ((TextBox)rptr.Items[0].FindControl("Custom5")).Text
                    : ((DropDownList)rptr.Items[0].FindControl("Custom5DD")).SelectedValue;

                if (p.IsValid(BusinessRulesValidationMode.INSERT))
                {
                    p.Insert();

                    var prog = Programs.FetchObject(p.ProgID);
                    var list = new List <Badge>();
                    if (prog.RegistrationBadgeID != 0)
                    {
                        AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID, p, ref list);
                    }
                    try {
                        this.Log().Debug("Running AwardBadgeToPatronViaMatchingAwards on patron ", p.PID);
                    } catch (Exception) { }

                    try {
                        AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref list);
                    } catch (Exception ex) {
                        this.Log().Error("Unable to run AwardBadgeToPatronViaMatchingAwards: {0} - {1}",
                                         ex.Message,
                                         ex.StackTrace);
                    }

                    patron.IsMasterAccount = true;
                    patron.Update();

                    // update patron session for things like MasterAcctPID and IsMasterAccount
                    new SessionTools(Session).EstablishPatron(patron);

                    new SessionTools(Session).AlertPatron("Your family member has been added!",
                                                          glyphicon: "check");
                }
                else
                {
                    StringBuilder message = new StringBuilder("<strong>");
                    message.AppendFormat(SRPResources.ApplicationError1, "<ul>");
                    foreach (BusinessRulesValidationMessage m in p.ErrorCodes)
                    {
                        message.AppendFormat("<li>{0}</li>", m.ErrorMessage);
                    }
                    message.Append("</ul></strong>");
                    new SessionTools(Session).AlertPatron(message.ToString(),
                                                          PatronMessageLevels.Warning,
                                                          "exclamation-sign");
                    return(false);
                }
            } catch (Exception ex) {
                this.Log().Error(string.Format("An exception was thrown adding a family member: {0}",
                                               ex.Message));
                this.Log().Error(string.Format("Stack trace: {0}", ex.StackTrace));
                new SessionTools(Session).AlertPatron(string.Format("<strong>{0}</strong>",
                                                                    ex.Message),
                                                      PatronMessageLevels.Warning,
                                                      "exclamation-sign");
                return(false);
            }
            return(true);
        }
        protected void submitButton_Click(object sender, EventArgs e)
        {
            #region Event Attendance
            // Logging event attendance
            string codeValue   = codeEntryField.Text;
            int    patronId    = (int)ViewState["SubmitAsPatronId"];
            var    pointsAward = new AwardPoints(patronId);
            var    patron      = Patron.FetchObject(patronId);
            var    patronName  = DisplayHelper.FormatName(patron.FirstName, patron.LastName, patron.Username);

            if (codeValue.Length == 0)
            {
                Session[SessionKey.PatronMessage]          = "Please enter a code.";
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            }
            else
            {
                // verify event code was not previously redeemed
                if (PatronPoints.HasRedeemedKeywordPoints(patronId, codeValue))
                {
                    Session[SessionKey.PatronMessage]          = string.Format("{0} has already redeemed this code!", patronName);
                    Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }

                // get event for that code, get the # points
                var ds = Event.GetEventByEventCode(pointsAward.pgm.StartDate.ToShortDateString(),
                                                   DateTime.Now.ToShortDateString(), codeValue);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    Session[SessionKey.PatronMessage]          = "Sorry, that's an invalid code.";
                    Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return;
                }
                var EID    = (int)ds.Tables[0].Rows[0]["EID"];
                var evt    = Event.GetEvent(EID);
                var points = evt.NumberPoints;
                //var newPBID = 0;

                var earnedBadges = pointsAward.AwardPointsToPatron(points: points,
                                                                   reason: PointAwardReason.EventAttendance,
                                                                   eventCode: codeValue,
                                                                   eventID: EID);

                // don't show badge earnings to the parent
                //if(!string.IsNullOrWhiteSpace(earnedBadges)) {
                //    new SessionTools(Session).EarnedBadges(earnedBadges);
                //}

                // set message and earned badges
                string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points, patronName);
                if (string.IsNullOrEmpty(earnedMessage))
                {
                    Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded for {0}.", patronName);
                }
                else
                {
                    Session[SessionKey.PatronMessage] = string.Format("<strong>Excellent!</strong> Secret code recorded. <strong>{0}</strong>",
                                                                      earnedMessage);
                }
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Success;
                Session[SessionKey.PatronMessageGlyphicon] = "barcode";
                this.codeEntryField.Text = string.Empty;
            }
            #endregion
        }
        protected void SubmitActivity()
        {
            var txtCount = familyReadingActivityField.Text.Trim();
            var intCount = 0;

            if (txtCount.Length == 0 || !int.TryParse(txtCount, out intCount) || intCount < 0)
            {
                Session[SessionKey.PatronMessage]          = "You must enter how much was read as a positive whole number.";
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Danger;
                Session[SessionKey.PatronMessageGlyphicon] = "remove";
                return;
            }

            var selectedActivityType = activityTypeSelector.SelectedValue;

            // check that we aren't over the max
            int maxAmountForLogging = 0;

            switch (int.Parse(selectedActivityType))
            {
            case 0:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxBook").SafeToInt();
                break;

            case 1:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxPage").SafeToInt();
                break;

            //case 2: maxAmountForLogging = SRPSettings.GetSettingValue("MaxPar").SafeToInt();
            //    break;
            case 3:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                break;

            default:
                maxAmountForLogging = SRPSettings.GetSettingValue("MaxMin").SafeToInt();
                break;
            }
            if (intCount > maxAmountForLogging)
            {
                Session[SessionKey.PatronMessage] = string.Format("That's an awful lot of reading! You can only submit {0} {1} at a time.",
                                                                  maxAmountForLogging,
                                                                  ((ActivityType)int.Parse(selectedActivityType)).ToString());
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var patronId      = int.Parse(ViewState["SubmitAsPatronId"].ToString());
            var programGameId = int.Parse(ViewState["ProgramGameId"].ToString());
            var patron        = Patron.FetchObject(patronId);
            var patronName    = DisplayHelper.FormatName(patron.FirstName, patron.LastName, patron.Username);
            var pa            = new AwardPoints(patronId);
            var points        = 0;

            // convert pages/minutes/etc. to points
            var pc = new ProgramGamePointConversion();

            pc.FetchByActivityId(programGameId, int.Parse(activityTypeSelector.SelectedValue));
            // round up to ensure they get at least 1 point
            decimal computedPoints = intCount * pc.PointCount / pc.ActivityCount;

            points = (int)Math.Ceiling(computedPoints);

            // ensure they aren't over teh day total
            var allPointsToday            = PatronPoints.GetTotalPatronPoints(patronId, DateTime.Now);
            int maxPointsPerDayForLogging = SRPSettings.GetSettingValue("MaxPtsDay").SafeToInt();

            if (intCount + allPointsToday > maxPointsPerDayForLogging)
            {
                Session[SessionKey.PatronMessage]          = string.Format("{0} has already reached the maximum amount of points that can be logged in a day. Keep reading and come back tomorrow!", patronName);
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return;
            }

            var earnedBadges = pa.AwardPointsToPatron(points: points,
                                                      reason: PointAwardReason.Reading,
                                                      MGID: 0,
                                                      readingActivity: (ActivityType)pc.ActivityTypeId,
                                                      readingAmount: intCount,
                                                      author: authorField.Text,
                                                      title: titleField.Text);

            // clear out the form
            var bookButton = activityTypeSelector.Items.Count == 1 &&
                             int.Parse(activityTypeSelector.Items[0].Value) == (int)ActivityType.Books;

            if (!bookButton)
            {
                familyReadingActivityField.Text = string.Empty;
            }
            authorField.Text = string.Empty;
            titleField.Text  = string.Empty;

            // set message and earned badges
            string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points, patronName);

            if (string.IsNullOrEmpty(earnedMessage))
            {
                Session[SessionKey.PatronMessage] = string.Format("Reading activity has been logged for {0}.",
                                                                  patronName);
            }
            else
            {
                Session[SessionKey.PatronMessage] = string.Format("Reading activity has been logged. <strong>{0}</strong>",
                                                                  earnedMessage);
            }
            Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Success;
            Session[SessionKey.PatronMessageGlyphicon] = "thumbs-up";
            // don't show earned badges when entering points for someone else
            //new SessionTools(Session).EarnedBadges(earnedBadges);
        }
Ejemplo n.º 13
0
        public bool SaveAccount()
        {
            try {
                var      p = new Patron();
                DateTime _d;
                var      DOB = rptr.Items[0].FindControl("DOB") as TextBox;
                if (DOB != null && !string.IsNullOrEmpty(DOB.Text))
                {
                    if (DateTime.TryParse(DOB.Text, out _d))
                    {
                        p.DOB = _d;
                    }
                }

                p.Age = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("Age")).Text);

                p.ProgID      = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("ProgID")).SelectedValue);
                p.Username    = ((TextBox)(rptr.Items[0]).FindControl("Username")).Text;
                p.NewPassword = ((TextBox)(rptr.Items[0]).FindControl("Password")).Text;

                var famAcct = (DropDownList)rptr.Items[0].FindControl("FamilyAccount");
                p.IsMasterAccount = (famAcct.SelectedValue == "Yes" && MasterPID.Text.Length == 0);

                p.SchoolGrade    = ((TextBox)(rptr.Items[0]).FindControl("SchoolGrade")).Text;
                p.FirstName      = ((TextBox)(rptr.Items[0]).FindControl("FirstName")).Text;
                p.MiddleName     = ((TextBox)(rptr.Items[0]).FindControl("MiddleName")).Text;
                p.LastName       = ((TextBox)(rptr.Items[0]).FindControl("LastName")).Text;
                p.Gender         = ((DropDownList)(rptr.Items[0]).FindControl("Gender")).SelectedValue;
                p.EmailAddress   = ((TextBox)(rptr.Items[0]).FindControl("EmailAddress")).Text;
                p.PhoneNumber    = ((TextBox)(rptr.Items[0]).FindControl("PhoneNumber")).Text;
                p.PhoneNumber    = FormatHelper.FormatPhoneNumber(p.PhoneNumber);
                p.StreetAddress1 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress1")).Text;
                p.StreetAddress2 = ((TextBox)(rptr.Items[0]).FindControl("StreetAddress2")).Text;
                p.City           = ((TextBox)(rptr.Items[0]).FindControl("City")).Text;
                p.State          = ((TextBox)(rptr.Items[0]).FindControl("State")).Text;
                p.ZipCode        = ((TextBox)(rptr.Items[0]).FindControl("ZipCode")).Text;
                p.ZipCode        = FormatHelper.FormatZipCode(p.ZipCode);

                p.Country = ((TextBox)(rptr.Items[0]).FindControl("Country")).Text;
                p.County  = ((TextBox)(rptr.Items[0]).FindControl("County")).Text;
                p.ParentGuardianFirstName  = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianFirstName")).Text;
                p.ParentGuardianLastName   = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianLastName")).Text;
                p.ParentGuardianMiddleName = ((TextBox)(rptr.Items[0]).FindControl("ParentGuardianMiddleName")).Text;
                p.LibraryCard = ((TextBox)(rptr.Items[0]).FindControl("LibraryCard")).Text;

                p.PrimaryLibrary = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("PrimaryLibrary")).SelectedValue);
                p.SchoolName     = ((DropDownList)(rptr.Items[0]).FindControl("SchoolName")).SelectedValue;
                p.SchoolType     = FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue);

                var lc = LibraryCrosswalk.FetchObjectByLibraryID(p.PrimaryLibrary);
                if (lc != null)
                {
                    p.District = lc.DistrictID == 0
                        ? ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue
                        : lc.DistrictID.ToString();
                }
                else
                {
                    p.District = ((DropDownList)(rptr.Items[0]).FindControl("District")).SelectedValue;
                }
                var sc = SchoolCrosswalk.FetchObjectBySchoolID(p.SchoolName.SafeToInt());
                if (sc != null)
                {
                    p.SDistrict = sc.DistrictID == 0
                        ? ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt()
                        : sc.DistrictID;

                    p.SchoolType = sc.SchTypeID == 0
                        ? FormatHelper.SafeToInt(((DropDownList)(rptr.Items[0]).FindControl("SchoolType")).SelectedValue)
                        : sc.SchTypeID;
                }
                else
                {
                    p.SDistrict = ((DropDownList)(rptr.Items[0]).FindControl("SDistrict")).SelectedValue.SafeToInt();
                }


                p.Teacher        = ((TextBox)(rptr.Items[0]).FindControl("Teacher")).Text;
                p.GroupTeamName  = ((TextBox)(rptr.Items[0]).FindControl("GroupTeamName")).Text;
                p.LiteracyLevel1 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel1")).Text);
                p.LiteracyLevel2 = FormatHelper.SafeToInt(((TextBox)(rptr.Items[0]).FindControl("LiteracyLevel2")).Text);

                p.ParentPermFlag = ((CheckBox)(rptr.Items[0]).FindControl("ParentPermFlag")).Checked;
                p.Over18Flag     = int.Parse(RegistrationAge.Text) >= 18;
                p.ShareFlag      = ((CheckBox)(rptr.Items[0]).FindControl("ShareFlag")).Checked;
                p.TermsOfUseflag = ((CheckBox)(rptr.Items[0]).FindControl("TermsOfUseflag")).Checked;

                var cr = this.CustomFields;
                p.Custom1 = string.IsNullOrEmpty(cr.DDValues1)
                    ? ((TextBox)(rptr.Items[0]).FindControl("Custom1")).Text
                    : ((DropDownList)(rptr.Items[0]).FindControl("Custom1DD")).SelectedValue;

                p.Custom2 = string.IsNullOrEmpty(cr.DDValues2)
                    ? ((TextBox)(rptr.Items[0]).FindControl("Custom2")).Text
                    : ((DropDownList)(rptr.Items[0]).FindControl("Custom2DD")).SelectedValue;

                p.Custom3 = string.IsNullOrEmpty(cr.DDValues3)
                    ? ((TextBox)(rptr.Items[0]).FindControl("Custom3")).Text
                    : ((DropDownList)(rptr.Items[0]).FindControl("Custom3DD")).SelectedValue;

                p.Custom4 = string.IsNullOrEmpty(cr.DDValues4)
                    ? ((TextBox)(rptr.Items[0]).FindControl("Custom4")).Text
                    : ((DropDownList)(rptr.Items[0]).FindControl("Custom4DD")).SelectedValue;

                p.Custom5 = string.IsNullOrEmpty(cr.DDValues5)
                    ? ((TextBox)(rptr.Items[0]).FindControl("Custom5")).Text
                    : ((DropDownList)(rptr.Items[0]).FindControl("Custom5DD")).SelectedValue;

                p.AvatarID = FormatHelper.SafeToInt(((System.Web.UI.HtmlControls.HtmlInputText)rptr.Items[0].FindControl("AvatarID")).Value);

                var registeringMasterAccount = true;
                if (!RegisteringFamily.Text.Equals("0"))
                {
                    registeringMasterAccount = false;
                    p.MasterAcctPID          = int.Parse(MasterPID.Text);
                }

                if (p.IsValid(BusinessRulesValidationMode.INSERT))
                {
                    p.Insert();

                    var prog             = Programs.FetchObject(p.ProgID);
                    var earnedBadgesList = new List <Badge>();
                    if (prog.RegistrationBadgeID != 0)
                    {
                        AwardPoints.AwardBadgeToPatron(prog.RegistrationBadgeID,
                                                       p,
                                                       ref earnedBadgesList);
                    }
                    AwardPoints.AwardBadgeToPatronViaMatchingAwards(p, ref earnedBadgesList);

                    var earnedBadges = string.Join("|", earnedBadgesList.Select(b => b.BID).Distinct());

                    if (p.IsMasterAccount && earnedBadges.Length > 0)
                    {
                        // if family account and is master, and has badges, rememebr to show them
                        new SessionTools(Session).EarnedBadges(earnedBadges);
                    }
                    if (!p.IsMasterAccount && p.MasterAcctPID == 0 && earnedBadges.Length > 0)
                    {
                        // if not family master or not family at all and badges, rememebr to show ...
                        new SessionTools(Session).EarnedBadges(earnedBadges);
                    }

                    if (p.IsMasterAccount)
                    {
                        parentGuardianFirst.Text  = p.FirstName;
                        parentGuardianMiddle.Text = p.MiddleName;
                        parentGuardianLast.Text   = p.LastName;
                    }

                    if (registeringMasterAccount)
                    {
                        MasterPID.Text = p.PID.ToString();
                        new SessionTools(Session).EstablishPatron(p);
                    }
                }
                else
                {
                    StringBuilder message = new StringBuilder("<strong>");
                    message.AppendFormat(SRPResources.ApplicationError1, "<ul>");
                    foreach (BusinessRulesValidationMessage m in p.ErrorCodes)
                    {
                        message.AppendFormat("<li>{0}</li>", m.ErrorMessage);
                    }
                    message.Append("</ul></strong>");
                    Session[SessionKey.PatronMessage]          = message.ToString();
                    Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                    Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                    return(false);
                }
            } catch (Exception ex) {
                this.Log().Error(string.Format("A problem occurred during registration: {0}",
                                               ex.Message));
                Session[SessionKey.PatronMessage] = string.Format("<strong>{0}</strong>",
                                                                  ex.Message);
                Session[SessionKey.PatronMessageLevel]     = PatronMessageLevels.Warning;
                Session[SessionKey.PatronMessageGlyphicon] = "exclamation-sign";
                return(false);
            }
            return(true);
        }
        protected void submitButton_Click(object sender, EventArgs e)
        {
            #region Event Attendance
            // Logging event attendance
            string codeValue = Logic.Code.SanitizeCode(codeEntryField.Text);
            codeEntryField.Text = codeValue;
            var patron = (Patron)Session[SessionKey.Patron];
            var pointsAward = new AwardPoints(patron.PID);

            if (codeValue.Length == 0)
            {
                new SessionTools(Session).AlertPatron("Please enter a code.",
                    PatronMessageLevels.Danger,
                    "remove");
                return;
            }
            else
            {
                // verify event code was not previously redeemed
                if (PatronPoints.HasRedeemedKeywordPoints(patron.PID, codeValue))
                {
                    new SessionTools(Session).AlertPatron("You've already redeemed this code!",
                        PatronMessageLevels.Warning,
                        "exclamation-sign");
                    return;
                }

                // get event for that code, get the # points
                var ds = Event.GetEventByEventCode(codeValue);
                if (ds.Tables[0].Rows.Count == 0)
                {
                    new SessionTools(Session).AlertPatron("Sorry, that's an invalid code.",
                        PatronMessageLevels.Warning,
                        "exclamation-sign");
                    var invalidCodeCount = (int?)Session[SessionKey.InvalidCodeCount] ?? 0;
                    invalidCodeCount++;
                    Session[SessionKey.InvalidCodeCount] = invalidCodeCount;
                    if (patron == null)
                    {
                        this.Log().Info("Invalid code '{0}' entered by {1}/{2} from {3}, invalid code(s) this session: {4}",
                            codeValue,
                            patron.PID,
                            patron.Username,
                            new WebTools().RemoteUserAddress(Request),
                            invalidCodeCount);
                    }
                    else
                    {
                        this.Log().Info("Invalid code '{0}' entered by unknown patron from {1}, invalid code(s) this session: {2}",
                            codeValue,
                            new WebTools().RemoteUserAddress(Request),
                            invalidCodeCount);
                    }
                    return;
                }
                var EID = (int)ds.Tables[0].Rows[0]["EID"];
                var evt = Event.GetEvent(EID);
                var points = evt.NumberPoints;
                //var newPBID = 0;

                var earnedBadges = pointsAward.AwardPointsToPatron(points: points,
                                                                   reason: PointAwardReason.EventAttendance,
                                                                   eventCode: codeValue,
                                                                   eventID: EID);

                if (!string.IsNullOrWhiteSpace(earnedBadges))
                {
                    new SessionTools(Session).EarnedBadges(earnedBadges);
                }

                string userMessage = null;
                // set message and earned badges
                string earnedMessage = new PointCalculation().EarnedMessage(earnedBadges, points);
                if (string.IsNullOrEmpty(earnedMessage))
                {
                    userMessage = "<strong>Excellent!</strong> Your secret code has been recorded.";
                }
                else
                {
                    userMessage = string.Format("<strong>Excellent!</strong> Your secret code has been recorded. <strong>{0}</strong>",
                                                earnedMessage);
                }
                new SessionTools(Session).AlertPatron(userMessage,
                    PatronMessageLevels.Success,
                    "barcode");
                this.codeEntryField.Text = string.Empty;
            }
            #endregion

        }
Ejemplo n.º 15
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (!this.ProgramOpen)
            {
                return;
            }

            var now = DateTime.Now;
            var onlyCheckedBoxes = true;
            var selBLI           = 0;
            var readCount        = 0;
            var neeedCount       = 0;
            var BLID             = -1;

            foreach (RepeaterItem item in rptr2.Items)
            {
                if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem)
                {
                    if (BLID < 0)
                    {
                        BLID       = int.Parse(((Label)item.FindControl("BLID")).Text);
                        neeedCount = BookList.FetchObject(BLID).NumBooksToComplete;
                    }
                    var chkRead = (CheckBox)item.FindControl("chkRead");
                    var PBLBID  = int.Parse(((Label)item.FindControl("PBLBID")).Text);
                    var BLBID   = int.Parse(((Label)item.FindControl("BLBID")).Text);

                    selBLI = BLID;
                    var pbl = new PatronBookLists();
                    if (PBLBID != 0)
                    {
                        pbl = PatronBookLists.FetchObject(PBLBID);
                    }
                    pbl.BLBID       = BLBID;
                    pbl.BLID        = BLID;
                    pbl.PID         = ((Patron)Session["Patron"]).PID;
                    pbl.LastModDate = now;

                    pbl.HasReadFlag = chkRead.Checked;
                    if (!pbl.HasReadFlag)
                    {
                        onlyCheckedBoxes = false;
                    }
                    else
                    {
                        readCount++;
                    }

                    if (PBLBID != 0)
                    {
                        pbl.Update();
                    }
                    else
                    {
                        pbl.Insert();
                    }
                }
            }

            new SessionTools(Session).AlertPatron("Your progress has been saved!",
                                                  glyphicon: "check");

            // read the entire book list!  Award points and badges
            if ((neeedCount == 0 && onlyCheckedBoxes) || (neeedCount <= readCount))
            {
                new SessionTools(Session).AlertPatron("Good work, you've completed a Challenge!",
                                                      glyphicon: "star");

                var bl = BookList.FetchObject(selBLI);

                if (PatronPoints.HasEarnedBookList(((Patron)Session["Patron"]).PID, selBLI))
                {
                    PopulateChallengeList();
                    return;
                }

                if (bl.AwardBadgeID != 0 || bl.AwardPoints != 0)
                {
                    new SessionTools(Session).AlertPatron("Congratulations, you completed a Challenge and were awarded a badge!",
                                                          glyphicon: "certificate");

                    var pa      = new AwardPoints(((Patron)Session["Patron"]).PID);
                    var sBadges = pa.AwardPointsToPatron(bl.AwardPoints, PointAwardReason.BookListCompletion,
                                                         bookListID: bl.BLID);
                    if (sBadges.Length > 0)
                    {
                        new SessionTools(Session).EarnedBadges(sBadges);
                    }
                }
            }
            PopulateChallengeList();
        }