public static int Update(PatronReview o) { int iReturn = -1; //assume the worst SqlParameter[] arrParams = new SqlParameter[10]; arrParams[0] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); arrParams[1] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode())); arrParams[2] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode())); arrParams[3] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode())); arrParams[4] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode())); arrParams[5] = new SqlParameter("@Review", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Review, o.Review.GetTypeCode())); arrParams[6] = new SqlParameter("@isApproved", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isApproved, o.isApproved.GetTypeCode())); arrParams[7] = new SqlParameter("@ReviewDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewDate, o.ReviewDate.GetTypeCode())); arrParams[8] = new SqlParameter("@ApprovalDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovalDate, o.ApprovalDate.GetTypeCode())); arrParams[9] = new SqlParameter("@ApprovedBy", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovedBy, o.ApprovedBy.GetTypeCode())); try { iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Update", arrParams); } catch (SqlException exx) { System.Diagnostics.Debug.Write(exx.Message); } return(iReturn); }
public bool Fetch(int PRID) { // declare reader SqlDataReader dr; SqlParameter[] arrParams = new SqlParameter[1]; arrParams[0] = new SqlParameter("@PRID", PRID); dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronReview_GetByID", arrParams); if (dr.Read()) { // declare return value PatronReview result = new PatronReview(); DateTime _datetime; int _int; //decimal _decimal; if (int.TryParse(dr["PRID"].ToString(), out _int)) { this.PRID = _int; } if (int.TryParse(dr["PID"].ToString(), out _int)) { this.PID = _int; } if (int.TryParse(dr["PRLID"].ToString(), out _int)) { this.PRLID = _int; } this.Author = dr["Author"].ToString(); this.Title = dr["Title"].ToString(); this.Review = dr["Review"].ToString(); this.isApproved = bool.Parse(dr["isApproved"].ToString()); if (DateTime.TryParse(dr["ReviewDate"].ToString(), out _datetime)) { this.ReviewDate = _datetime; } if (DateTime.TryParse(dr["ApprovalDate"].ToString(), out _datetime)) { this.ApprovalDate = _datetime; } this.ApprovedBy = dr["ApprovedBy"].ToString(); dr.Close(); return(true); } dr.Close(); return(false); }
public static int Delete(PatronReview o) { int iReturn = -1; //assume the worst SqlParameter[] arrParams = new SqlParameter[1]; arrParams[0] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); try { iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Delete", arrParams); } catch (SqlException exx) { System.Diagnostics.Debug.Write(exx.Message); } return(iReturn); }
public static int Insert(PatronReview o) { SqlParameter[] arrParams = new SqlParameter[10]; arrParams[0] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode())); arrParams[1] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode())); arrParams[2] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode())); arrParams[3] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode())); arrParams[4] = new SqlParameter("@Review", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Review, o.Review.GetTypeCode())); arrParams[5] = new SqlParameter("@isApproved", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isApproved, o.isApproved.GetTypeCode())); arrParams[6] = new SqlParameter("@ReviewDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewDate, o.ReviewDate.GetTypeCode())); arrParams[7] = new SqlParameter("@ApprovalDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovalDate, o.ApprovalDate.GetTypeCode())); arrParams[8] = new SqlParameter("@ApprovedBy", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovedBy, o.ApprovedBy.GetTypeCode())); arrParams[9] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); arrParams[9].Direction = ParameterDirection.Output; SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Insert", arrParams); o.PRID = int.Parse(arrParams[9].Value.ToString()); return(o.PRID); }
public static int Delete(PatronReview o) { int iReturn = -1; //assume the worst SqlParameter[] arrParams = new SqlParameter[1]; arrParams[0] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); try { iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Delete", arrParams); } catch (SqlException exx) { System.Diagnostics.Debug.Write(exx.Message); } return iReturn; }
public static int Update(PatronReview o) { int iReturn = -1; //assume the worst SqlParameter[] arrParams = new SqlParameter[10]; arrParams[0] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); arrParams[1] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode())); arrParams[2] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode())); arrParams[3] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode())); arrParams[4] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode())); arrParams[5] = new SqlParameter("@Review", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Review, o.Review.GetTypeCode())); arrParams[6] = new SqlParameter("@isApproved", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isApproved, o.isApproved.GetTypeCode())); arrParams[7] = new SqlParameter("@ReviewDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewDate, o.ReviewDate.GetTypeCode())); arrParams[8] = new SqlParameter("@ApprovalDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovalDate, o.ApprovalDate.GetTypeCode())); arrParams[9] = new SqlParameter("@ApprovedBy", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovedBy, o.ApprovedBy.GetTypeCode())); try { iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Update", arrParams); } catch (SqlException exx) { System.Diagnostics.Debug.Write(exx.Message); } return iReturn; }
public static int Insert(PatronReview o) { SqlParameter[] arrParams = new SqlParameter[10]; arrParams[0] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode())); arrParams[1] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode())); arrParams[2] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode())); arrParams[3] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode())); arrParams[4] = new SqlParameter("@Review", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Review, o.Review.GetTypeCode())); arrParams[5] = new SqlParameter("@isApproved", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isApproved, o.isApproved.GetTypeCode())); arrParams[6] = new SqlParameter("@ReviewDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewDate, o.ReviewDate.GetTypeCode())); arrParams[7] = new SqlParameter("@ApprovalDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovalDate, o.ApprovalDate.GetTypeCode())); arrParams[8] = new SqlParameter("@ApprovedBy", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ApprovedBy, o.ApprovedBy.GetTypeCode())); arrParams[9] = new SqlParameter("@PRID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRID, o.PRID.GetTypeCode())); arrParams[9].Direction = ParameterDirection.Output; SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronReview_Insert", arrParams); o.PRID = int.Parse(arrParams[9].Value.ToString()); return o.PRID; }
public bool Fetch(int PRID) { // declare reader SqlDataReader dr; SqlParameter[] arrParams = new SqlParameter[1]; arrParams[0] = new SqlParameter("@PRID", PRID); dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronReview_GetByID", arrParams); if (dr.Read()) { // declare return value PatronReview result = new PatronReview(); DateTime _datetime; int _int; //decimal _decimal; if (int.TryParse(dr["PRID"].ToString(), out _int)) this.PRID = _int; if (int.TryParse(dr["PID"].ToString(), out _int)) this.PID = _int; if (int.TryParse(dr["PRLID"].ToString(), out _int)) this.PRLID = _int; this.Author = dr["Author"].ToString(); this.Title = dr["Title"].ToString(); this.Review = dr["Review"].ToString(); this.isApproved = bool.Parse(dr["isApproved"].ToString()); if (DateTime.TryParse(dr["ReviewDate"].ToString(), out _datetime)) this.ReviewDate = _datetime; if (DateTime.TryParse(dr["ApprovalDate"].ToString(), out _datetime)) this.ApprovalDate = _datetime; this.ApprovedBy = dr["ApprovedBy"].ToString(); dr.Close(); return true; } dr.Close(); return false; }
protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e) { string returnURL = "~/ControlRoom/Modules/Patrons/PatronReviews.aspx"; if (e.CommandName.ToLower() == "back") { Response.Redirect(returnURL); } if (e.CommandName.ToLower() == "refresh") { try { odsData.DataBind(); dv.DataBind(); dv.ChangeMode(DetailsViewMode.Edit); var masterPage = (IControlRoomMaster)Master; if (masterPage != null) masterPage.PageMessage = SRPResources.RefreshOK; } catch (Exception ex) { var masterPage = (IControlRoomMaster)Master; masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message); } } if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback") { try { var obj = new PatronReview(); int pk = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text); obj.Fetch(pk); obj.isApproved = ((CheckBox)((DetailsView)sender).FindControl("isApproved")).Checked; obj.ApprovalDate = DateTime.Now; obj.ApprovedBy = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username; if (obj.IsValid(BusinessRulesValidationMode.UPDATE)) { obj.Update(); // Always and back Response.Redirect(returnURL); //if (e.CommandName.ToLower() == "saveandback") //{ // Response.Redirect(returnURL); //} //odsData.DataBind(); //dv.DataBind(); //dv.ChangeMode(DetailsViewMode.Edit); //var masterPage = (IControlRoomMaster)Master; //masterPage.PageMessage = SRPResources.SaveOK; } else { var masterPage = (IControlRoomMaster)Master; string message = String.Format(SRPResources.ApplicationError1, "<ul>"); foreach (BusinessRulesValidationMessage m in obj.ErrorCodes) { message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage); } message = string.Format("{0}</ul>", message); masterPage.PageError = message; } } catch (Exception ex) { var masterPage = (IControlRoomMaster)Master; 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; }