protected void GvRowCommand(object sender, GridViewCommandEventArgs e) { string editpage = "~/ControlRoom/Modules/Patrons/PatronLogAddEdit.aspx"; if (e.CommandName.ToLower() == "addrecord") { Session["PLID"] = ""; Response.Redirect(editpage); } if (e.CommandName.ToLower() == "editrecord") { int key = Convert.ToInt32(e.CommandArgument); Session["PLID"] = key; Response.Redirect(editpage); } if (e.CommandName.ToLower() == "deleterecord") { int key = Convert.ToInt32(e.CommandArgument); try { var pp = PatronPoints.FetchObject(key); if (pp.IsValid(BusinessRulesValidationMode.DELETE)) { if (pp.isReading) { var prl = PatronReadingLog.FetchObject(pp.LogID); if (prl != null && prl.HasReview) { PatronReview.Delete(PatronReview.FetchObjectByLogId(pp.LogID)); prl.Delete(); } } pp.Delete(); LoadData(); var masterPage = (IControlRoomMaster)Master; if (masterPage != null) { masterPage.PageMessage = SRPResources.DeleteOK; } } else { var masterPage = (IControlRoomMaster)Master; string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in pp.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); if (masterPage != null) { masterPage.PageError = message; } } } catch (Exception ex) { var masterPage = (IControlRoomMaster)Master; if (masterPage != null) { masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message); } } } }
// points = 100 // reason = PointAwardReason.MiniGameCompletion // MGID = Mini Game ID, if the reason is MiniGameCompletion, else 0 // // // returns: a string based list of the badges they earned, or an empty string public string AwardPointsToPatron(int points, PointAwardReason reason, // Minigame int MGID = 0, // reading ActivityType readingActivity = ActivityType.Pages, int readingAmount = 0, string author = "", string title = "", string review = "", // event string eventCode = "", int eventID = 0, // book List int bookListID = 0, DateTime?forceDate = null ) { if (forceDate != null) { now = (DateTime)forceDate; } string retValue = string.Empty; #region Reading - Log to PatronReadingLog PatronReadingLog rl = null; if (reason == PointAwardReason.Reading) { rl = new PatronReadingLog { PID = patron.PID, ReadingType = (int)readingActivity, ReadingTypeLabel = (readingActivity).ToString(), ReadingAmount = readingAmount, ReadingPoints = points, LoggingDate = FormatHelper.ToNormalDate(now), Author = author.Trim(), Title = title.Trim(), HasReview = (review.Trim().Length > 0), ReviewID = 0 }; rl.Insert(); // If there is a review, record the review if (review.Trim().Length > 0) { var r = new PatronReview { PID = patron.PID, PRLID = rl.PRLID, Author = rl.Author, Title = rl.Title, Review = review.Trim(), isApproved = false }; r.Insert(); rl.ReviewID = r.PRID; rl.Update(); HttpContext.Current.Session["LastPRID"] = r.PRID; } } #endregion #region Award PatronPoints var pp = new PatronPoints { PID = patron.PID, NumPoints = points, AwardDate = now, AwardReasonCd = (int)reason, AwardReason = PatronPoints.PointAwardReasonCdToDescription(reason), BadgeAwardedFlag = false, isReading = (reason == PointAwardReason.Reading), isEvent = (reason == PointAwardReason.EventAttendance), isGameLevelActivity = (reason == PointAwardReason.MiniGameCompletion), isBookList = (reason == PointAwardReason.BookListCompletion), isGame = false, GameLevelActivityID = MGID, EventCode = eventCode, EventID = eventID, BookListID = bookListID, LogID = (rl == null ? 0 : rl.PRLID) }; pp.Insert(); var badgeAwarded = false; int badgeToAward = 0; // <=========== DAL.Minigame mg = null; if (reason == PointAwardReason.MiniGameCompletion) { mg = DAL.Minigame.FetchObject(MGID); badgeAwarded = mg.AwardedBadgeID > 0; badgeToAward = mg.AwardedBadgeID; } if (reason == PointAwardReason.EventAttendance) { var evt = Event.GetEvent(eventID); badgeAwarded = evt == null ? false : evt.BadgeID > 0; badgeToAward = evt == null ? 0 : evt.BadgeID; } if (reason == PointAwardReason.BookListCompletion) { var bl = BookList.FetchObject(bookListID); ; badgeAwarded = (bl.AwardBadgeID > 0); badgeToAward = bl.AwardBadgeID; } DataSet pbds = null; if (badgeAwarded) { if (AwardBadgeToPatron(badgeToAward, patron, ref EarnedBadges)) { if (pp.PPID != 0) { pp.BadgeAwardedFlag = true; pp.BadgeID = badgeToAward; pp.Update(); } } } #endregion #region If jumped level, award another badge(s) // since thay just earned points, check if they also advanced a level in the board game (if there is a board game for the program) EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID); EarnedBadge = null; var earnedBadges2 = new List <Badge>(); EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref earnedBadges2); pbds = PatronBadges.GetAll(patron.PID); foreach (var badge in earnedBadges2) { EarnedBadge = badge; if (EarnedBadge != null) { AwardBadgeToPatron(EarnedBadge.BID, patron, ref EarnedBadges); } } #endregion #region Check and give awards if any AwardBadgeToPatronViaMatchingAwards(patron, ref EarnedBadges); #endregion #region Prepare return code // did they earn one or more badges? if (EarnedBadges.Count > 0) { retValue = string.Join("|", EarnedBadges.Select(b => b.BID).Distinct()); } #endregion return(retValue); }
protected void ImageButton1_Command(object sender, CommandEventArgs e) { var masterPage = (IControlRoomMaster)((BaseControlRoomPage)Page).Master; lblError.Text = ""; 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 = ""; 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"); } } } }
// points = 100 // reason = PointAwardReason.MiniGameCompletion // MGID = Mini Game ID, if the reason is MiniGameCompletion, else 0 // // // returns: a string based list of the badges they earned, or an empty string public string AwardPointsToPatron(int points, PointAwardReason reason, // Minigame int MGID = 0, // reading ActivityType readingActivity = ActivityType.Pages, int readingAmount = 0, string author = "", string title = "", string review = "", // event string eventCode = "", int eventID = 0, // book List int bookListID = 0, DateTime?forceDate = null ) { if (forceDate != null) { now = (DateTime)forceDate; } string retValue = ""; #region Reading - Log to PatronReadingLog PatronReadingLog rl = null; if (reason == PointAwardReason.Reading) { rl = new PatronReadingLog { PID = patron.PID, ReadingType = (int)readingActivity, ReadingTypeLabel = (readingActivity).ToString(), ReadingAmount = readingAmount, ReadingPoints = points, LoggingDate = FormatHelper.ToNormalDate(now), Author = author.Trim(), Title = title.Trim(), HasReview = (review.Trim().Length > 0), ReviewID = 0 }; rl.Insert(); // If there is a review, record the review if (review.Trim().Length > 0) { var r = new PatronReview { PID = patron.PID, PRLID = rl.PRLID, Author = rl.Author, Title = rl.Title, Review = review.Trim(), isApproved = false }; r.Insert(); rl.ReviewID = r.PRID; rl.Update(); } } #endregion #region Award PatronPoints var pp = new PatronPoints { PID = patron.PID, NumPoints = points, AwardDate = now, AwardReasonCd = (int)reason, AwardReason = PatronPoints.PointAwardReasonCdToDescription(reason), BadgeAwardedFlag = false, isReading = (reason == PointAwardReason.Reading), isEvent = (reason == PointAwardReason.EventAttendance), isGameLevelActivity = (reason == PointAwardReason.MiniGameCompletion), isBookList = (reason == PointAwardReason.BookListCompletion), isGame = false, GameLevelActivityID = MGID, EventCode = eventCode, EventID = eventID, BookListID = bookListID, LogID = (rl == null ? 0 : rl.PRLID) }; pp.Insert(); var badgeAwarded = false; int badgeToAward = 0; // <=========== DAL.Minigame mg = null; if (reason == PointAwardReason.MiniGameCompletion) { mg = DAL.Minigame.FetchObject(MGID); badgeAwarded = mg.AwardedBadgeID > 0; badgeToAward = mg.AwardedBadgeID; } if (reason == PointAwardReason.EventAttendance) { var evt = Event.GetEvent(eventID); badgeAwarded = evt.BadgeID > 0; badgeToAward = evt.BadgeID; } if (reason == PointAwardReason.BookListCompletion) { var bl = BookList.FetchObject(bookListID);; badgeAwarded = (bl.AwardBadgeID > 0); badgeToAward = bl.AwardBadgeID; } DataSet pbds = null; //DataTable newTable = null; if (badgeAwarded) { if (AwardBadgeToPatron(badgeToAward, patron, ref EarnedBadges)) { if (pp.PPID != 0) { pp.BadgeAwardedFlag = true; pp.BadgeID = badgeToAward; pp.Update(); } } #region AwardBadgeToPatron code //// check if badge was already earned... //pbds = PatronBadges.GetAll(patron.PID); //var a = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward); //newTable = new DataTable(); //try { newTable = a.CopyToDataTable(); } catch { } //// badge not found, award it! //if (newTable.Rows.Count == 0) //{ // var pb = new PatronBadges { BadgeID = badgeToAward, DateEarned = now, PID = patron.PID }; // pb.Insert(); // EarnedBadge = Badge.GetBadge(badgeToAward); // 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(); // } // //if badge generates prize, then generate the prize // if (EarnedBadge.IncludesPhysicalPrizeFlag) // { // var ppp = new DAL.PatronPrizes // { // PID = patron.PID, // PrizeSource = 1, // PrizeName = EarnedBadge.PhysicalPrizeName, // RedeemedFlag = false, // AddedUser = patron.Username, // LastModUser = "******", // AddedDate = now, // LastModDate = now // }; // ppp.Insert(); // } // // if badge generates award code, then generate the code // if (EarnedBadge.AssignProgramPrizeCode) // { // var RewardCode = ""; // // get the Code value // // save the code value for the patron // RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID); // // generate the notification // var not = new Notifications // { // PID_To = patron.PID, // PID_From = 0, //0 == System Notification // Subject = EarnedBadge.PCNotificationSubject, // Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode), // isQuestion = false, // AddedDate = now, // LastModDate = now, // AddedUser = patron.Username, // LastModUser = "******" // }; // not.Insert(); // } // if (pp.PPID != 0) // { // pp.BadgeAwardedFlag = true; // pp.BadgeID = badgeToAward; // pp.Update(); // } //} #endregion } #endregion #region If jumped level, award another badge(s) // since thay just earned points, check if they also advanced a level in the board game (if there is a board game for the program) EndingPoints = PatronPoints.GetTotalPatronPoints(patron.PID); EarnedBadge = null; var earnedBadges2 = new List <Badge>(); EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref earnedBadges2); pbds = PatronBadges.GetAll(patron.PID); foreach (var badge in earnedBadges2) { EarnedBadge = badge; if (EarnedBadge != null) { AwardBadgeToPatron(EarnedBadge.BID, patron, ref EarnedBadges); } #region AwardBadgeToPatron call2 //// check if badge was already earned... //if (EarnedBadge != null) //{ // var aa = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward); // newTable = new DataTable(); // try { newTable = aa.CopyToDataTable(); } // catch { } // // badge not found, award it! //} //if (EarnedBadge != null && newTable != null && newTable.Rows.Count == 0) //{ // // Award the badge // EarnedBadges.Add(badge); // Add badge tot he list used to display to user ... // 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 badge generates prize, then generate the prize // if (EarnedBadge.IncludesPhysicalPrizeFlag) // { // var ppp = new DAL.PatronPrizes // { // PID = patron.PID, // PrizeSource = 1, // PrizeName = EarnedBadge.PhysicalPrizeName, // RedeemedFlag = false, // AddedUser = patron.Username, // LastModUser = "******", // AddedDate = now, // LastModDate = now // }; // ppp.Insert(); // } // // if badge generates award code, then generate the code // if (EarnedBadge.AssignProgramPrizeCode) // { // var RewardCode = ""; // // get the Code value // // save the code value for the patron // RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID); // // generate the notification // var not = new Notifications // { // PID_To = patron.PID, // PID_From = 0, //0 == System Notification // Subject = EarnedBadge.PCNotificationSubject, // Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode), // isQuestion = false, // AddedDate = now, // LastModDate = now, // AddedUser = patron.Username, // LastModUser = "******" // }; // not.Insert(); // } //} #endregion } #region deprecated - replaced by abbility to earn multiple badges above //EarnedBadge = TallyPoints(patron, pgm, StartingPoints, EndingPoints, ref EarnedBadges); //// check if badge was already earned... //if (EarnedBadge != null) { // pbds = PatronBadges.GetAll(patron.PID); // var aa = pbds.Tables[0].AsEnumerable().Where(r => r.Field<int>("BadgeID") == badgeToAward); // newTable = new DataTable(); // try { newTable = aa.CopyToDataTable(); } catch { } // // badge not found, award it! //} //if (EarnedBadge != null && newTable!= null && newTable.Rows.Count == 0) //{ // // 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 badge generates prize, then generate the prize // if (EarnedBadge.IncludesPhysicalPrizeFlag) // { // var ppp = new DAL.PatronPrizes // { // PID = patron.PID, // PrizeSource = 1, // PrizeName = EarnedBadge.PhysicalPrizeName, // RedeemedFlag = false, // AddedUser = patron.Username, // LastModUser = "******", // AddedDate = now, // LastModDate = now // }; // ppp.Insert(); // } // // if badge generates award code, then generate the code // if (EarnedBadge.AssignProgramPrizeCode) // { // var RewardCode = ""; // // get the Code value // // save the code value for the patron // RewardCode = ProgramCodes.AssignCodeForPatron(patron.ProgID, patron.ProgID); // // generate the notification // var not = new Notifications // { // PID_To = patron.PID, // PID_From = 0, //0 == System Notification // Subject = EarnedBadge.PCNotificationSubject, // Body = EarnedBadge.PCNotificationBody.Replace("{ProgramRewardCode}", RewardCode), // isQuestion = false, // AddedDate = now, // LastModDate = now, // AddedUser = patron.Username, // LastModUser = "******" // }; // not.Insert(); // } #endregion #endregion #region Check and give awards if any AwardBadgeToPatronViaMatchingAwards(patron, ref EarnedBadges); #endregion #region Prepare return code // did they earn one or more badges? if (EarnedBadges.Count > 0) { 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()); //Response.Redirect("~/BadgeAward.aspx?b=" + badges); retValue = badges; } #endregion return(retValue); }