Пример #1
0
        public static int Update(PatronReadingLog o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[11];

            arrParams[0]  = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode()));
            arrParams[1]  = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[2]  = new SqlParameter("@ReadingType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingType, o.ReadingType.GetTypeCode()));
            arrParams[3]  = new SqlParameter("@ReadingTypeLabel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingTypeLabel, o.ReadingTypeLabel.GetTypeCode()));
            arrParams[4]  = new SqlParameter("@ReadingAmount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingAmount, o.ReadingAmount.GetTypeCode()));
            arrParams[5]  = new SqlParameter("@ReadingPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingPoints, o.ReadingPoints.GetTypeCode()));
            arrParams[6]  = new SqlParameter("@LoggingDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LoggingDate, o.LoggingDate.GetTypeCode()));
            arrParams[7]  = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode()));
            arrParams[8]  = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode()));
            arrParams[9]  = new SqlParameter("@HasReview", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HasReview, o.HasReview.GetTypeCode()));
            arrParams[10] = new SqlParameter("@ReviewID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewID, o.ReviewID.GetTypeCode()));

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

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

            return(iReturn);
        }
Пример #2
0
        public static int Delete(PatronReadingLog o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

            return(iReturn);
        }
Пример #3
0
        public static int Insert(PatronReadingLog o)
        {
            SqlParameter[] arrParams = new SqlParameter[11];

            arrParams[0]            = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1]            = new SqlParameter("@ReadingType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingType, o.ReadingType.GetTypeCode()));
            arrParams[2]            = new SqlParameter("@ReadingTypeLabel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingTypeLabel, o.ReadingTypeLabel.GetTypeCode()));
            arrParams[3]            = new SqlParameter("@ReadingAmount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingAmount, o.ReadingAmount.GetTypeCode()));
            arrParams[4]            = new SqlParameter("@ReadingPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingPoints, o.ReadingPoints.GetTypeCode()));
            arrParams[5]            = new SqlParameter("@LoggingDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LoggingDate, o.LoggingDate.GetTypeCode()));
            arrParams[6]            = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode()));
            arrParams[7]            = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode()));
            arrParams[8]            = new SqlParameter("@HasReview", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HasReview, o.HasReview.GetTypeCode()));
            arrParams[9]            = new SqlParameter("@ReviewID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewID, o.ReviewID.GetTypeCode()));
            arrParams[10]           = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode()));
            arrParams[10].Direction = ParameterDirection.Output;

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

            o.PRLID = int.Parse(arrParams[10].Value.ToString());

            return(o.PRLID);
        }
Пример #4
0
        public bool Fetch(int PRLID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

                PatronReadingLog result = new PatronReadingLog();

                //DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PRLID"].ToString(), out _int))
                {
                    this.PRLID = _int;
                }
                if (int.TryParse(dr["PID"].ToString(), out _int))
                {
                    this.PID = _int;
                }
                if (int.TryParse(dr["ReadingType"].ToString(), out _int))
                {
                    this.ReadingType = _int;
                }
                this.ReadingTypeLabel = dr["ReadingTypeLabel"].ToString();
                if (int.TryParse(dr["ReadingAmount"].ToString(), out _int))
                {
                    this.ReadingAmount = _int;
                }
                if (int.TryParse(dr["ReadingPoints"].ToString(), out _int))
                {
                    this.ReadingPoints = _int;
                }
                this.LoggingDate = dr["LoggingDate"].ToString();
                this.Author      = dr["Author"].ToString();
                this.Title       = dr["Title"].ToString();
                this.HasReview   = bool.Parse(dr["HasReview"].ToString());
                if (int.TryParse(dr["ReviewID"].ToString(), out _int))
                {
                    this.ReviewID = _int;
                }

                dr.Close();

                return(true);
            }

            dr.Close();

            return(false);
        }
Пример #5
0
        // 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 static int Delete(PatronReadingLog o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Update(PatronReadingLog o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[11];

            arrParams[0] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@ReadingType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingType, o.ReadingType.GetTypeCode()));
            arrParams[3] = new SqlParameter("@ReadingTypeLabel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingTypeLabel, o.ReadingTypeLabel.GetTypeCode()));
            arrParams[4] = new SqlParameter("@ReadingAmount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingAmount, o.ReadingAmount.GetTypeCode()));
            arrParams[5] = new SqlParameter("@ReadingPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingPoints, o.ReadingPoints.GetTypeCode()));
            arrParams[6] = new SqlParameter("@LoggingDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LoggingDate, o.LoggingDate.GetTypeCode()));
            arrParams[7] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode()));
            arrParams[8] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode()));
            arrParams[9] = new SqlParameter("@HasReview", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HasReview, o.HasReview.GetTypeCode()));
            arrParams[10] = new SqlParameter("@ReviewID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewID, o.ReviewID.GetTypeCode()));

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Insert(PatronReadingLog o)
        {

            SqlParameter[] arrParams = new SqlParameter[11];

            arrParams[0] = new SqlParameter("@PID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PID, o.PID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@ReadingType", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingType, o.ReadingType.GetTypeCode()));
            arrParams[2] = new SqlParameter("@ReadingTypeLabel", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingTypeLabel, o.ReadingTypeLabel.GetTypeCode()));
            arrParams[3] = new SqlParameter("@ReadingAmount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingAmount, o.ReadingAmount.GetTypeCode()));
            arrParams[4] = new SqlParameter("@ReadingPoints", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReadingPoints, o.ReadingPoints.GetTypeCode()));
            arrParams[5] = new SqlParameter("@LoggingDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LoggingDate, o.LoggingDate.GetTypeCode()));
            arrParams[6] = new SqlParameter("@Author", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Author, o.Author.GetTypeCode()));
            arrParams[7] = new SqlParameter("@Title", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Title, o.Title.GetTypeCode()));
            arrParams[8] = new SqlParameter("@HasReview", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HasReview, o.HasReview.GetTypeCode()));
            arrParams[9] = new SqlParameter("@ReviewID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ReviewID, o.ReviewID.GetTypeCode()));
            arrParams[10] = new SqlParameter("@PRLID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PRLID, o.PRLID.GetTypeCode()));
            arrParams[10].Direction = ParameterDirection.Output;

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

            o.PRLID = int.Parse(arrParams[10].Value.ToString());

            return o.PRLID;

        }
        public bool Fetch(int PRLID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                PatronReadingLog result = new PatronReadingLog();

                //DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PRLID"].ToString(), out _int)) this.PRLID = _int;
                if (int.TryParse(dr["PID"].ToString(), out _int)) this.PID = _int;
                if (int.TryParse(dr["ReadingType"].ToString(), out _int)) this.ReadingType = _int;
                this.ReadingTypeLabel = dr["ReadingTypeLabel"].ToString();
                if (int.TryParse(dr["ReadingAmount"].ToString(), out _int)) this.ReadingAmount = _int;
                if (int.TryParse(dr["ReadingPoints"].ToString(), out _int)) this.ReadingPoints = _int;
                this.LoggingDate = dr["LoggingDate"].ToString();
                this.Author = dr["Author"].ToString();
                this.Title = dr["Title"].ToString();
                this.HasReview = bool.Parse(dr["HasReview"].ToString());
                if (int.TryParse(dr["ReviewID"].ToString(), out _int)) this.ReviewID = _int;

                dr.Close();

                return true;

            }

            dr.Close();

            return false;

        }