public static int Insert(PatronPoints o)
        {
            SqlParameter[] arrParams = new SqlParameter[22];

            arrParams[0]            = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1]            = new SqlParameter("@NumPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumPoints, o.NumPoints.GetTypeCode()));
            arrParams[2]            = new SqlParameter("@AwardDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardDate, o.AwardDate.GetTypeCode()));
            arrParams[3]            = new SqlParameter("@AwardReason", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReason, o.AwardReason.GetTypeCode()));
            arrParams[4]            = new SqlParameter("@AwardReasonCd", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReasonCd, o.AwardReasonCd.GetTypeCode()));
            arrParams[5]            = new SqlParameter("@BadgeAwardedFlag", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeAwardedFlag, o.BadgeAwardedFlag.GetTypeCode()));
            arrParams[6]            = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[7]            = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[8]            = new SqlParameter("@isReading", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isReading, o.isReading.GetTypeCode()));
            arrParams[9]            = new SqlParameter("@LogID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LogID, o.LogID.GetTypeCode()));
            arrParams[10]           = new SqlParameter("@isEvent", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isEvent, o.isEvent.GetTypeCode()));
            arrParams[11]           = new SqlParameter("@EventID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventID, o.EventID.GetTypeCode()));
            arrParams[12]           = new SqlParameter("@EventCode", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventCode, o.EventCode.GetTypeCode()));
            arrParams[13]           = new SqlParameter("@isBookList", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isBookList, o.isBookList.GetTypeCode()));
            arrParams[14]           = new SqlParameter("@BookListID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BookListID, o.BookListID.GetTypeCode()));
            arrParams[15]           = new SqlParameter("@isGame", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGame, o.isGame.GetTypeCode()));
            arrParams[16]           = new SqlParameter("@isGameLevelActivity", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGameLevelActivity, o.isGameLevelActivity.GetTypeCode()));
            arrParams[17]           = new SqlParameter("@GameID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameID, o.GameID.GetTypeCode()));
            arrParams[18]           = new SqlParameter("@GameLevel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevel, o.GameLevel.GetTypeCode()));
            arrParams[19]           = new SqlParameter("@GameLevelID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelID, o.GameLevelID.GetTypeCode()));
            arrParams[20]           = new SqlParameter("@GameLevelActivityID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelActivityID, o.GameLevelActivityID.GetTypeCode()));
            arrParams[21]           = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));
            arrParams[21].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Insert", arrParams);

            o.PPID = int.Parse(arrParams[21].Value.ToString());

            return(o.PPID);
        }
        public static int Delete(PatronPoints o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Delete", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
        public static int Update(PatronPoints o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[22];

            arrParams[0]  = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));
            arrParams[1]  = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[2]  = new SqlParameter("@NumPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumPoints, o.NumPoints.GetTypeCode()));
            arrParams[3]  = new SqlParameter("@AwardDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardDate, o.AwardDate.GetTypeCode()));
            arrParams[4]  = new SqlParameter("@AwardReason", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReason, o.AwardReason.GetTypeCode()));
            arrParams[5]  = new SqlParameter("@AwardReasonCd", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReasonCd, o.AwardReasonCd.GetTypeCode()));
            arrParams[6]  = new SqlParameter("@BadgeAwardedFlag", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeAwardedFlag, o.BadgeAwardedFlag.GetTypeCode()));
            arrParams[7]  = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[8]  = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[9]  = new SqlParameter("@isReading", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isReading, o.isReading.GetTypeCode()));
            arrParams[10] = new SqlParameter("@LogID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LogID, o.LogID.GetTypeCode()));
            arrParams[11] = new SqlParameter("@isEvent", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isEvent, o.isEvent.GetTypeCode()));
            arrParams[12] = new SqlParameter("@EventID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventID, o.EventID.GetTypeCode()));
            arrParams[13] = new SqlParameter("@EventCode", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventCode, o.EventCode.GetTypeCode()));
            arrParams[14] = new SqlParameter("@isBookList", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isBookList, o.isBookList.GetTypeCode()));
            arrParams[15] = new SqlParameter("@BookListID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BookListID, o.BookListID.GetTypeCode()));
            arrParams[16] = new SqlParameter("@isGame", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGame, o.isGame.GetTypeCode()));
            arrParams[17] = new SqlParameter("@isGameLevelActivity", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGameLevelActivity, o.isGameLevelActivity.GetTypeCode()));
            arrParams[18] = new SqlParameter("@GameID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameID, o.GameID.GetTypeCode()));
            arrParams[19] = new SqlParameter("@GameLevel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevel, o.GameLevel.GetTypeCode()));
            arrParams[20] = new SqlParameter("@GameLevelID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelID, o.GameLevelID.GetTypeCode()));
            arrParams[21] = new SqlParameter("@GameLevelActivityID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelActivityID, o.GameLevelActivityID.GetTypeCode()));

            try
            {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Update", arrParams);
            }

            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
        // 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;
        }
        public bool Fetch(int PPID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PPID", PPID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronPoints_GetByID", arrParams);

            if (dr.Read())
            {
                // declare return value

                PatronPoints result = new PatronPoints();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PPID"].ToString(), out _int))
                {
                    this.PPID = _int;
                }
                if (int.TryParse(dr["PID"].ToString(), out _int))
                {
                    this.PID = _int;
                }
                if (int.TryParse(dr["NumPoints"].ToString(), out _int))
                {
                    this.NumPoints = _int;
                }
                if (DateTime.TryParse(dr["AwardDate"].ToString(), out _datetime))
                {
                    this.AwardDate = _datetime;
                }
                this.AwardReason = dr["AwardReason"].ToString();
                if (int.TryParse(dr["AwardReasonCd"].ToString(), out _int))
                {
                    this.AwardReasonCd = _int;
                }
                this.BadgeAwardedFlag = bool.Parse(dr["BadgeAwardedFlag"].ToString());
                if (int.TryParse(dr["BadgeID"].ToString(), out _int))
                {
                    this.BadgeID = _int;
                }
                if (int.TryParse(dr["PBID"].ToString(), out _int))
                {
                    this.PBID = _int;
                }
                this.isReading = bool.Parse(dr["isReading"].ToString());
                if (int.TryParse(dr["LogID"].ToString(), out _int))
                {
                    this.LogID = _int;
                }
                this.isEvent = bool.Parse(dr["isEvent"].ToString());
                if (int.TryParse(dr["EventID"].ToString(), out _int))
                {
                    this.EventID = _int;
                }
                this.EventCode  = dr["EventCode"].ToString();
                this.isBookList = bool.Parse(dr["isBookList"].ToString());
                if (int.TryParse(dr["BookListID"].ToString(), out _int))
                {
                    this.BookListID = _int;
                }
                this.isGame = bool.Parse(dr["isGame"].ToString());
                this.isGameLevelActivity = bool.Parse(dr["isGameLevelActivity"].ToString());
                if (int.TryParse(dr["GameID"].ToString(), out _int))
                {
                    this.GameID = _int;
                }
                if (int.TryParse(dr["GameLevel"].ToString(), out _int))
                {
                    this.GameLevel = _int;
                }
                if (int.TryParse(dr["GameLevelID"].ToString(), out _int))
                {
                    this.GameLevelID = _int;
                }
                if (int.TryParse(dr["GameLevelActivityID"].ToString(), out _int))
                {
                    this.GameLevelActivityID = _int;
                }

                dr.Close();

                return(true);
            }

            dr.Close();

            return(false);
        }
        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");
                    }

                }

            }
        }
        public bool Fetch(int PPID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PPID", PPID);

            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_PatronPoints_GetByID", arrParams);

            if (dr.Read())
            {

                // declare return value

                PatronPoints result = new PatronPoints();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PPID"].ToString(), out _int)) this.PPID = _int;
                if (int.TryParse(dr["PID"].ToString(), out _int)) this.PID = _int;
                if (int.TryParse(dr["NumPoints"].ToString(), out _int)) this.NumPoints = _int;
                if (DateTime.TryParse(dr["AwardDate"].ToString(), out _datetime)) this.AwardDate = _datetime;
                this.AwardReason = dr["AwardReason"].ToString();
                if (int.TryParse(dr["AwardReasonCd"].ToString(), out _int)) this.AwardReasonCd = _int;
                this.BadgeAwardedFlag = bool.Parse(dr["BadgeAwardedFlag"].ToString());
                if (int.TryParse(dr["BadgeID"].ToString(), out _int)) this.BadgeID = _int;
                if (int.TryParse(dr["PBID"].ToString(), out _int)) this.PBID = _int;
                this.isReading = bool.Parse(dr["isReading"].ToString());
                if (int.TryParse(dr["LogID"].ToString(), out _int)) this.LogID = _int;
                this.isEvent = bool.Parse(dr["isEvent"].ToString());
                if (int.TryParse(dr["EventID"].ToString(), out _int)) this.EventID = _int;
                this.EventCode = dr["EventCode"].ToString();
                this.isBookList = bool.Parse(dr["isBookList"].ToString());
                if (int.TryParse(dr["BookListID"].ToString(), out _int)) this.BookListID = _int;
                this.isGame = bool.Parse(dr["isGame"].ToString());
                this.isGameLevelActivity = bool.Parse(dr["isGameLevelActivity"].ToString());
                if (int.TryParse(dr["GameID"].ToString(), out _int)) this.GameID = _int;
                if (int.TryParse(dr["GameLevel"].ToString(), out _int)) this.GameLevel = _int;
                if (int.TryParse(dr["GameLevelID"].ToString(), out _int)) this.GameLevelID = _int;
                if (int.TryParse(dr["GameLevelActivityID"].ToString(), out _int)) this.GameLevelActivityID = _int;

                dr.Close();

                return true;

            }

            dr.Close();

            return false;
        }
        public static int Update(PatronPoints o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[22];

            arrParams[0] = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@NumPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumPoints, o.NumPoints.GetTypeCode()));
            arrParams[3] = new SqlParameter("@AwardDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardDate, o.AwardDate.GetTypeCode()));
            arrParams[4] = new SqlParameter("@AwardReason", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReason, o.AwardReason.GetTypeCode()));
            arrParams[5] = new SqlParameter("@AwardReasonCd", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReasonCd, o.AwardReasonCd.GetTypeCode()));
            arrParams[6] = new SqlParameter("@BadgeAwardedFlag", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeAwardedFlag, o.BadgeAwardedFlag.GetTypeCode()));
            arrParams[7] = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[8] = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[9] = new SqlParameter("@isReading", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isReading, o.isReading.GetTypeCode()));
            arrParams[10] = new SqlParameter("@LogID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LogID, o.LogID.GetTypeCode()));
            arrParams[11] = new SqlParameter("@isEvent", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isEvent, o.isEvent.GetTypeCode()));
            arrParams[12] = new SqlParameter("@EventID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventID, o.EventID.GetTypeCode()));
            arrParams[13] = new SqlParameter("@EventCode", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventCode, o.EventCode.GetTypeCode()));
            arrParams[14] = new SqlParameter("@isBookList", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isBookList, o.isBookList.GetTypeCode()));
            arrParams[15] = new SqlParameter("@BookListID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BookListID, o.BookListID.GetTypeCode()));
            arrParams[16] = new SqlParameter("@isGame", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGame, o.isGame.GetTypeCode()));
            arrParams[17] = new SqlParameter("@isGameLevelActivity", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGameLevelActivity, o.isGameLevelActivity.GetTypeCode()));
            arrParams[18] = new SqlParameter("@GameID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameID, o.GameID.GetTypeCode()));
            arrParams[19] = new SqlParameter("@GameLevel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevel, o.GameLevel.GetTypeCode()));
            arrParams[20] = new SqlParameter("@GameLevelID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelID, o.GameLevelID.GetTypeCode()));
            arrParams[21] = new SqlParameter("@GameLevelActivityID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelActivityID, o.GameLevelActivityID.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Update", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;
        }
        public static int Insert(PatronPoints o)
        {
            SqlParameter[] arrParams = new SqlParameter[22];

            arrParams[0] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@NumPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumPoints, o.NumPoints.GetTypeCode()));
            arrParams[2] = new SqlParameter("@AwardDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardDate, o.AwardDate.GetTypeCode()));
            arrParams[3] = new SqlParameter("@AwardReason", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReason, o.AwardReason.GetTypeCode()));
            arrParams[4] = new SqlParameter("@AwardReasonCd", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AwardReasonCd, o.AwardReasonCd.GetTypeCode()));
            arrParams[5] = new SqlParameter("@BadgeAwardedFlag", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeAwardedFlag, o.BadgeAwardedFlag.GetTypeCode()));
            arrParams[6] = new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode()));
            arrParams[7] = new SqlParameter("@PBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PBID, o.PBID.GetTypeCode()));
            arrParams[8] = new SqlParameter("@isReading", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isReading, o.isReading.GetTypeCode()));
            arrParams[9] = new SqlParameter("@LogID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LogID, o.LogID.GetTypeCode()));
            arrParams[10] = new SqlParameter("@isEvent", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isEvent, o.isEvent.GetTypeCode()));
            arrParams[11] = new SqlParameter("@EventID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventID, o.EventID.GetTypeCode()));
            arrParams[12] = new SqlParameter("@EventCode", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.EventCode, o.EventCode.GetTypeCode()));
            arrParams[13] = new SqlParameter("@isBookList", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isBookList, o.isBookList.GetTypeCode()));
            arrParams[14] = new SqlParameter("@BookListID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BookListID, o.BookListID.GetTypeCode()));
            arrParams[15] = new SqlParameter("@isGame", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGame, o.isGame.GetTypeCode()));
            arrParams[16] = new SqlParameter("@isGameLevelActivity", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.isGameLevelActivity, o.isGameLevelActivity.GetTypeCode()));
            arrParams[17] = new SqlParameter("@GameID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameID, o.GameID.GetTypeCode()));
            arrParams[18] = new SqlParameter("@GameLevel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevel, o.GameLevel.GetTypeCode()));
            arrParams[19] = new SqlParameter("@GameLevelID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelID, o.GameLevelID.GetTypeCode()));
            arrParams[20] = new SqlParameter("@GameLevelActivityID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.GameLevelActivityID, o.GameLevelActivityID.GetTypeCode()));
            arrParams[21] = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));
            arrParams[21].Direction = ParameterDirection.Output;

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Insert", arrParams);

            o.PPID = int.Parse(arrParams[21].Value.ToString());

            return o.PPID;
        }
        public static int Delete(PatronPoints o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

            arrParams[0] = new SqlParameter("@PPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PPID, o.PPID.GetTypeCode()));

            try
            {

                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_PatronPoints_Delete", arrParams);

            }

            catch (SqlException exx)
            {

                System.Diagnostics.Debug.Write(exx.Message);

            }

            return iReturn;
        }