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 }
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; }
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 submitButton_Click(object sender, EventArgs e) { #region Event Attendance // Logging event attendance string codeValue = Logic.Code.SanitizeCode(codeEntryField.Text); codeEntryField.Text = codeValue; int patronId = ((Patron)Session[SessionKey.Patron]).PID; var pointsAward = new AwardPoints(patronId); 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(patronId, 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"); 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 }
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 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 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(); } } } 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(((Patron)Session["Patron"]).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(((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(); }
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] = "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); }
public void 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); } //var mg = DAL.Minigame.FetchObject(int.Parse(MGID.Text)); //var patron = (Patron)Patron.FetchObject(int.Parse(PID.Text)); //var pgm = Programs.FetchObject(patron.ProgID); //var StartingPoints = PatronPoints.GetTotalPatronPoints(patron.PID); //var EndingPoints = StartingPoints; //var EarnedBadges = new List<Badge>(); //Badge EarnedBadge; //// 1 - log points to patron activity (mg.NumberPoints) //var now = DateTime.Now; //var pp = new PatronPoints //{ // PID = patron.PID, // NumPoints = mg.NumberPoints, // AwardDate = now, // AwardReasonCd = (int)PointAwardReason.MiniGameCompletion, // AwardReason = PatronPoints.PointAwardReasonCdToDescription(PointAwardReason.MiniGameCompletion), // BadgeAwardedFlag = false, // isBookList = false, // isEvent = false, // isGame = false, // isGameLevelActivity = true, // GameLevelActivityID = mg.MGID, // isReading = false, // LogID = 0 //}; //pp.Insert(); //if (mg.AwardedBadgeID > 0) //{ // var pbds = PatronBadges.GetAll(patron.PID); // var a = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == mg.AwardedBadgeID); // var newTable = new DataTable(); // try { newTable = a.CopyToDataTable(); } // catch { } // //DataTable newTable = a.CopyToDataTable(); // if (newTable.Rows.Count == 0) // { // var pb = new PatronBadges { BadgeID = mg.AwardedBadgeID, DateEarned = now, PID = patron.PID }; // pb.Insert(); // EarnedBadge = Badge.GetBadge(mg.AwardedBadgeID); // EarnedBadges.Add(EarnedBadge); // //if badge generates notification, then generate the notification // if (EarnedBadge.GenNotificationFlag) // { // var not = new Notifications // { // PID_To = patron.PID, // PID_From = 0, //0 == System Notification // Subject = EarnedBadge.NotificationSubject, // Body = EarnedBadge.NotificationBody, // isQuestion = false, // AddedDate = now, // LastModDate = now, // AddedUser = patron.Username, // LastModUser = "******" // }; // not.Insert(); // } // pp.BadgeAwardedFlag = true; // pp.BadgeID = mg.AwardedBadgeID; // pp.Update(); // } //} //EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID); //EarnedBadge = null; //EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref EarnedBadges); //if (EarnedBadge != null) //{ // // Award the badge // var newPBID = 0; // var pb = new PatronBadges { BadgeID = EarnedBadge.BID, DateEarned = now, PID = patron.PID }; // pb.Insert(); // newPBID = pb.PBID; // //if badge generates notification, then generate the notification // if (EarnedBadge.GenNotificationFlag) // { // var not = new Notifications // { // PID_To = patron.PID, // PID_From = 0, //0 == System Notification // Subject = EarnedBadge.NotificationSubject, // Body = EarnedBadge.NotificationBody, // isQuestion = false, // AddedDate = now, // LastModDate = now, // AddedUser = patron.Username, // LastModUser = "******" // }; // not.Insert(); // } //} //if (EarnedBadges.Count > 0) //{ // //Display Badges Awards messages // var badges = EarnedBadges.Count.ToString(); // //foreach(Badge b in EarnedBadges) // //{ // // badges = badges + "|" + b.BID.ToString(); // //} // badges = EarnedBadges.Aggregate(badges, (current, b) => current + "|" + b.BID.ToString()); // //Server.Transfer("~/BadgeAward.aspx?b=" + badges); // Response.Redirect("~/BadgeAward.aspx?b=" + badges); //} }
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 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 }