public static ProgramGamePointConversion FetchObject(int PGCID) {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if(dr.Read()) {

                // declare return value

                ProgramGamePointConversion result = new ProgramGamePointConversion();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if(int.TryParse(dr["PGCID"].ToString(), out _int))
                    result.PGCID = _int;
                if(int.TryParse(dr["PGID"].ToString(), out _int))
                    result.PGID = _int;
                if(int.TryParse(dr["ActivityTypeId"].ToString(), out _int))
                    result.ActivityTypeId = _int;
                if(int.TryParse(dr["ActivityCount"].ToString(), out _int))
                    result.ActivityCount = _int;
                if(int.TryParse(dr["PointCount"].ToString(), out _int))
                    result.PointCount = _int;
                if(DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                    result.LastModDate = _datetime;
                result.LastModUser = dr["LastModUser"].ToString();
                if(DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                    result.AddedDate = _datetime;
                result.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return result;

            }

            dr.Close();

            return null;

        }
        public static int Delete(ProgramGamePointConversion o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_ProgramGamePointConversion_Delete", arrParams);
            } catch (SqlException exx) {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
Ejemplo n.º 3
0
        public static void CheckAndPopulatePointConversions(Programs obj)
        {
            var ds = ProgramGamePointConversion.GetAll(obj.PID);

            if (ds.Tables[0].Rows.Count == 0)
            {
                foreach (ActivityType val in Enum.GetValues(typeof(ActivityType)))
                {
                    var o = new ProgramGamePointConversion();
                    o.PGID           = obj.PID;
                    o.ActivityTypeId = (int)val;
                    o.ActivityCount  = 1;
                    o.PointCount     = 0;
                    o.AddedDate      = obj.AddedDate;
                    o.AddedUser      = obj.AddedUser;
                    o.LastModDate    = o.AddedDate;
                    o.LastModUser    = o.AddedUser;

                    o.Insert();
                }
            }
            else
            {
                foreach (ActivityType val in Enum.GetValues(typeof(ActivityType)))
                {
                    var o = ProgramGamePointConversion.FetchObjectByActivityId(obj.PID, (int)val);
                    if (o == null)
                    {
                        o = new ProgramGamePointConversion
                        {
                            PGID           = obj.PID,
                            ActivityTypeId = (int)val,
                            ActivityCount  = 1,
                            PointCount     = 0,
                            AddedDate      = obj.AddedDate,
                            AddedUser      = obj.AddedUser
                        };
                        o.LastModDate = o.AddedDate;
                        o.LastModUser = o.AddedUser;

                        o.Insert();
                    }
                }
            }
        }
        public static int Insert(ProgramGamePointConversion o)
        {
            SqlParameter[] arrParams = new SqlParameter[9];

            arrParams[0]           = new SqlParameter("@PGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGID, o.PGID.GetTypeCode()));
            arrParams[1]           = new SqlParameter("@ActivityTypeId", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityTypeId, o.ActivityTypeId.GetTypeCode()));
            arrParams[2]           = new SqlParameter("@ActivityCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityCount, o.ActivityCount.GetTypeCode()));
            arrParams[3]           = new SqlParameter("@PointCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PointCount, o.PointCount.GetTypeCode()));
            arrParams[4]           = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[5]           = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[6]           = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[7]           = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[8]           = new SqlParameter("@PGCID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGCID, o.PGCID.GetTypeCode()));
            arrParams[8].Direction = ParameterDirection.Output;

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

            o.PGCID = int.Parse(arrParams[8].Value.ToString());

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

            SqlParameter[] arrParams = new SqlParameter[9];

            arrParams[0] = new SqlParameter("@PGCID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGCID, o.PGCID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGID, o.PGID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@ActivityTypeId", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityTypeId, o.ActivityTypeId.GetTypeCode()));
            arrParams[3] = new SqlParameter("@ActivityCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityCount, o.ActivityCount.GetTypeCode()));
            arrParams[4] = new SqlParameter("@PointCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PointCount, o.PointCount.GetTypeCode()));
            arrParams[5] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[6] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[7] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[8] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            try {
                iReturn = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_ProgramGamePointConversion_Update", arrParams);
            } catch (SqlException exx) {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(iReturn);
        }
        public bool FetchByActivityId(int PGID, int ActivityId)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[2];

            arrParams[0] = new SqlParameter("@PGID", PGID);
            arrParams[1] = new SqlParameter("@ActivityTypeID", ActivityId);
            dr           = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_ProgramGamePointConversion_GetByActivityType", arrParams);

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

                ProgramGamePointConversion result = new ProgramGamePointConversion();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PGCID"].ToString(), out _int))
                {
                    this.PGCID = _int;
                }
                if (int.TryParse(dr["PGID"].ToString(), out _int))
                {
                    this.PGID = _int;
                }
                if (int.TryParse(dr["ActivityTypeId"].ToString(), out _int))
                {
                    this.ActivityTypeId = _int;
                }
                if (int.TryParse(dr["ActivityCount"].ToString(), out _int))
                {
                    this.ActivityCount = _int;
                }
                if (int.TryParse(dr["PointCount"].ToString(), out _int))
                {
                    this.PointCount = _int;
                }
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                {
                    this.LastModDate = _datetime;
                }
                this.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                {
                    this.AddedDate = _datetime;
                }
                this.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return(true);
            }

            dr.Close();

            return(false);
        }
        public bool FetchByActivityId(int PGID, int ActivityId)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[2];

            arrParams[0] = new SqlParameter("@PGID", PGID);
            arrParams[1] = new SqlParameter("@ActivityTypeID", ActivityId);
            dr = SqlHelper.ExecuteReader(conn, CommandType.StoredProcedure, "app_ProgramGamePointConversion_GetByActivityType", arrParams);

            if(dr.Read()) {

                // declare return value

                ProgramGamePointConversion result = new ProgramGamePointConversion();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if(int.TryParse(dr["PGCID"].ToString(), out _int))
                    this.PGCID = _int;
                if(int.TryParse(dr["PGID"].ToString(), out _int))
                    this.PGID = _int;
                if(int.TryParse(dr["ActivityTypeId"].ToString(), out _int))
                    this.ActivityTypeId = _int;
                if(int.TryParse(dr["ActivityCount"].ToString(), out _int))
                    this.ActivityCount = _int;
                if(int.TryParse(dr["PointCount"].ToString(), out _int))
                    this.PointCount = _int;
                if(DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                    this.LastModDate = _datetime;
                this.LastModUser = dr["LastModUser"].ToString();
                if(DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                    this.AddedDate = _datetime;
                this.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return true;

            }

            dr.Close();

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

            SqlParameter[] arrParams = new SqlParameter[9];

            arrParams[0] = new SqlParameter("@PGCID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGCID, o.PGCID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGID, o.PGID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@ActivityTypeId", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityTypeId, o.ActivityTypeId.GetTypeCode()));
            arrParams[3] = new SqlParameter("@ActivityCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityCount, o.ActivityCount.GetTypeCode()));
            arrParams[4] = new SqlParameter("@PointCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PointCount, o.PointCount.GetTypeCode()));
            arrParams[5] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[6] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[7] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[8] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            try {

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

            } catch(SqlException exx) {

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

            }

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

            arrParams[0] = new SqlParameter("@PGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGID, o.PGID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@ActivityTypeId", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityTypeId, o.ActivityTypeId.GetTypeCode()));
            arrParams[2] = new SqlParameter("@ActivityCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ActivityCount, o.ActivityCount.GetTypeCode()));
            arrParams[3] = new SqlParameter("@PointCount", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PointCount, o.PointCount.GetTypeCode()));
            arrParams[4] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[5] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[6] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[7] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[8] = new SqlParameter("@PGCID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PGCID, o.PGCID.GetTypeCode()));
            arrParams[8].Direction = ParameterDirection.Output;

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

            o.PGCID = int.Parse(arrParams[8].Value.ToString());

            return o.PGCID;
        }
Ejemplo n.º 10
0
        public int RecalculateGoalCache(Programs program, ProgramGamePointConversion conversion)
        {

            int goal = this.Goal;
            GoalInterval interval = program.GetGoalInterval;

            if (program != null)
            {
                int programLength = 1;

                switch (interval)
                {
                    case GoalInterval.Program:
                        programLength = 1;
                        break;
                    case GoalInterval.Daily:
                        programLength = (int)((program.LoggingEnd - program.LoggingStart).TotalDays);
                        break;
                    case GoalInterval.Weekly:
                        programLength = (int)((program.LoggingEnd - program.LoggingStart).TotalDays) / 7;
                        break;
                }

                goal *= programLength;
            }


            if (conversion != null)
            {
                goal *= conversion.PointCount;
            }

            /* protect against divide by zero error */
            if (goal < 1)
            {
                goal = 0;
            }

            this.GoalCache = goal;
            return this.GoalCache;
        }
        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 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 DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Programs/ProgramList.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() == "add" || e.CommandName.ToLower() == "addandback")
            {
                try
                {
                    var program = new DAL.Programs();
                    //obj.GenNotificationFlag = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("GenNotificationFlag")).Checked;

                    program.AdminName = ((TextBox)((DetailsView)sender).FindControl("AdminName")).Text;
                    program.Title = ((TextBox)((DetailsView)sender).FindControl("Title")).Text;
                    program.TabName = ((TextBox)((DetailsView)sender).FindControl("TabName")).Text;
                    //obj.POrder = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("POrder")).Text);
                    program.IsActive = ((CheckBox)((DetailsView)sender).FindControl("IsActive")).Checked;
                    program.IsHidden = ((CheckBox)((DetailsView)sender).FindControl("IsHidden")).Checked;
                    program.StartDate = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("StartDate")).Text);
                    program.EndDate = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("EndDate")).Text);
                    //obj.MaxAge = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("MaxAge")).Text);
                    //obj.MaxGrade = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("MaxGrade")).Text);
                    program.LoggingStart = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("LoggingStart")).Text);
                    program.LoggingEnd = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("LoggingEnd")).Text);
                    program.CompletionPoints = 0;
                    //obj.ParentalConsentFlag = ((CheckBox)((DetailsView)sender).FindControl("ParentalConsentFlag")).Checked;
                    //obj.ParentalConsentText = ((HtmlTextArea)((DetailsView)sender).FindControl("ParentalConsentText")).Text;
                    //obj.PatronReviewFlag = ((CheckBox)((DetailsView)sender).FindControl("PatronReviewFlag")).Checked;
                    //obj.LogoutURL = ((TextBox)((DetailsView)sender).FindControl("LogoutURL")).Text;
                    //obj.ProgramGameID = FormatHelper.SafeToInt(((DropDownList) ((DetailsView) sender).FindControl("ProgramGameID")).SelectedValue);
                    //obj.HTML1 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML1")).Text;
                    //obj.HTML2 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML2")).Text;
                    //obj.HTML3 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML3")).Text;
                    //obj.HTML4 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML4")).Text;
                    //obj.HTML5 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML5")).Text;
                    //obj.HTML6 = ((HtmlTextArea)((DetailsView)sender).FindControl("HTML6")).Text;
                    //obj.BannerImage = ((TextBox)((DetailsView)sender).FindControl("BannerImage")).Text;
                    //obj.RegistrationBadgeID = FormatHelper.SafeToInt(((DropDownList) ((DetailsView) sender).FindControl("RegistrationBadgeID")).SelectedValue);

                    program.AddedDate = DateTime.Now;
                    program.AddedUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session
                    program.LastModDate = program.AddedDate;
                    program.LastModUser = program.AddedUser;

                    if (program.IsValid(BusinessRulesValidationMode.INSERT))
                    {
                        program.Insert();

                        File.Copy(Server.MapPath("~/css/program/default.css"), Server.MapPath("~/css/program/" + program.PID.ToString() + ".css"), true);
                        File.Copy(Server.MapPath("~/images/meadow.jpg"), Server.MapPath("~/images/banners/" + program.PID.ToString() + ".jpg"), true);
                        File.Copy(Server.MapPath("~/images/[email protected]"), Server.MapPath("~/images/banners/" + program.PID.ToString() + ".jpg"), true);
                        File.Copy(Server.MapPath("~/resources/program.default.en-US.txt"), Server.MapPath("~/resources/program." + program.PID.ToString() + ".en-US.txt"), true);
                        //CompileResourceFile(Server.MapPath("~/resources/program." + obj.PID.ToString() + ".en-US.txt"));

                        foreach (ActivityType val in Enum.GetValues(typeof(ActivityType)))
                        {
                            var o = new ProgramGamePointConversion();
                            o.PGID = program.PID;
                            o.ActivityTypeId = (int)val;
                            o.ActivityCount = 1;
                            o.PointCount = 0;
                            o.AddedDate = program.AddedDate;
                            o.AddedUser = program.AddedUser;
                            o.LastModDate = o.AddedDate;
                            o.LastModUser = o.AddedUser;

                            o.Insert();

                            string cacheValue = string.Format("{0}.{1}.{2}",
                                  CacheKey.PointGameConversionStub,
                                  o.PGID,
                                  o.ActivityTypeId);
                            new SessionTools(Session).RemoveCache(Cache, cacheValue);
                        }

                        if (e.CommandName.ToLower() == "addandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        lblPK.Text = program.PID.ToString();

                        odsData.DataBind();
                        dv.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.AddedOK;
                    }
                    else
                    {
                        var masterPage = (IControlRoomMaster)Master;
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in program.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);
                }
            }
            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var program = new DAL.Programs();
                    int pk = int.Parse(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("PID")).Text);
                    program.Fetch(pk);

                    program.AdminName = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("AdminName")).Text;
                    program.Title = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("Title")).Text;
                    program.TabName = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("TabName")).Text;
                    //obj.POrder = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("POrder")).Text);
                    program.IsActive = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("IsActive")).Checked;
                    program.IsHidden = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("IsHidden")).Checked;
                    program.StartDate = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("StartDate")).Text);
                    program.EndDate = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("EndDate")).Text);
                    program.MaxAge = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("MaxAge")).Text);
                    program.MaxGrade = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("MaxGrade")).Text);
                    program.LoggingStart = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("LoggingStart")).Text);
                    program.LoggingEnd = FormatHelper.SafeToDateTime(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("LoggingEnd")).Text);
                    program.ParentalConsentFlag = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("ParentalConsentFlag")).Checked;
                    program.ParentalConsentText = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("ParentalConsentText")).InnerHtml;
                    program.PatronReviewFlag = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("PatronReviewFlag")).Checked;
                    program.RequireBookDetails = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("RequireBookDetails")).Checked;
                    program.LogoutURL = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("LogoutURL")).Text;

                    program.CompletionPoints = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("CompletionPoints")).Text);
                    program.ProgramGameID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("ProgramGameID")).Text);
                    //obj.ProgramGameID = 0;
                    program.RegistrationBadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("RegistrationBadgeID")).Text);
                    //obj.RegistrationBadgeID = 0;
                    program.HTML1 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("HTML1")).InnerHtml;
                    program.HTML2 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp2").FindControl("HTML2")).InnerHtml;

                    program.HTML3 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp3").FindControl("HTML3")).InnerHtml;
                    program.HTML4 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp3").FindControl("HTML4")).InnerHtml;

                    program.HTML5 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp4").FindControl("HTML5")).InnerHtml;
                    program.HTML6 = ((HtmlTextArea)((DetailsView)sender).FindControl("tc1").FindControl("tp4").FindControl("HTML6")).InnerHtml;

                    program.BannerImage = string.Empty;//((TextBox)((DetailsView)sender).FindControl("BannerImage")).Text;

                    program.PreTestEndDate = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("PreTestEndDate")).Text.SafeToDateTime();
                    program.PostTestStartDate = ((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("PostTestStartDate")).Text.SafeToDateTime();
                    program.PreTestID = ((DropDownList)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("PreTestID")).SelectedValue.SafeToInt();
                    program.PostTestID = ((DropDownList)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("PostTestID")).SelectedValue.SafeToInt();
                    program.PreTestMandatory = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("PreTestMandatory")).Checked;

                    program.GoalDefault = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("GoalDefault")).Text);
                    program.GoalMin = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("GoalMin")).Text);
                    program.GoalMax = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("GoalMax")).Text);
                    program.GoalIntervalId = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("GoalIntervalId")).SelectedValue);

                    program.HideSchoolInRegistration = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("HideSchoolInRegistration")).Checked;
                    program.DisplayDailyImage = ((CheckBox)((DetailsView)sender).FindControl("tc1").FindControl("tp1").FindControl("DisplayDailyImage")).Checked;

                    program.LastModDate = DateTime.Now;
                    program.LastModUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session

                    if (program.IsValid(BusinessRulesValidationMode.UPDATE))
                    {
                        program.Update();

                        var rptr = ((Repeater)((DetailsView)sender).FindControl("tc1").FindControl("tp5").FindControl("rptr"));
                        if (rptr != null)
                        {
                            foreach (RepeaterItem item in rptr.Items)
                            {
                                var PGCID = int.Parse(((TextBox)item.FindControl("PGCID")).Text);
                                var ActivityCountTxt = ((TextBox)item.FindControl("ActivityCount")).Text;
                                var PointCountTxt = ((TextBox)item.FindControl("PointCount")).Text;
                                int ActivityCount = 1, PointCount = 0;
                                int.TryParse(ActivityCountTxt, out ActivityCount);
                                int.TryParse(PointCountTxt, out PointCount);

                                var o = ProgramGamePointConversion.FetchObject(PGCID);
                                if (o == null)
                                    continue;
                                o.ActivityCount = ActivityCount;
                                o.PointCount = PointCount;
                                o.LastModDate = program.LastModDate;
                                o.LastModUser = program.LastModUser;
                                o.Update();

                                string cacheValue = string.Format("{0}.{1}.{2}",
                                                                  CacheKey.PointGameConversionStub,
                                                                  o.PGID,
                                                                  o.ActivityTypeId);
                                new SessionTools(Session).RemoveCache(Cache, cacheValue);
                            }

                        }


                        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 program.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);
                }
            }
            if (e.CommandName.ToLower() == "gen")
            {

                int PK = int.Parse(lblPK.Text);
                var ds = ProgramCodes.GetProgramStats(PK);

                int TotalCodes = (int)ds.Tables[0].Rows[0]["TotalCodes"];
                var txt = (TextBox)dv.FindControl("tc1").FindControl("tp6").FindControl("txtGen");
                int addl = int.Parse(txt.Text);

                string result = ProgramCodes.Generate(TotalCodes + 1, TotalCodes + addl, PK);

                odsData.DataBind();
                dv.DataBind();
                dv.ChangeMode(DetailsViewMode.Edit);

                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = result;

            }
            if (e.CommandName.ToLower() == "exp")
            {

                int PK = int.Parse(lblPK.Text);

                var ds = ProgramCodes.GetExportList(PK);

                string excelFilename = Server.MapPath("~/ProgramRewardCodes.xlsx");
                CreateExcelFile.CreateExcelDocument(ds, excelFilename);

                Response.ContentType = "application/vnd.ms-excel";
                Response.AppendHeader("Content-Disposition", "attachment; filename=ProgramRewardCodes.xlsx");
                EnableViewState = false;
                Response.BinaryWrite(File.ReadAllBytes(excelFilename));
                File.Delete(excelFilename);
                Response.End();


                var masterPage = (IControlRoomMaster)Master;
                masterPage.PageMessage = "Codes Exported!";

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

                }

            }
        }
Ejemplo n.º 15
0
        public static void CheckAndPopulatePointConversions(Programs obj)
        {

            var ds = ProgramGamePointConversion.GetAll(obj.PID);
            if (ds.Tables[0].Rows.Count == 0)
            {
                foreach (ActivityType val in Enum.GetValues(typeof(ActivityType)))
                {
                    var o = new ProgramGamePointConversion();
                    o.PGID = obj.PID;
                    o.ActivityTypeId = (int)val;
                    o.ActivityCount = 1;
                    o.PointCount = 0;
                    o.AddedDate = obj.AddedDate;
                    o.AddedUser = obj.AddedUser;
                    o.LastModDate = o.AddedDate;
                    o.LastModUser = o.AddedUser;

                    o.Insert();
                }
            }
            else
            {
                foreach (ActivityType val in Enum.GetValues(typeof(ActivityType)))
                {
                    var o = ProgramGamePointConversion.FetchObjectByActivityId(obj.PID, (int)val);
                    if (o == null)
                    {
                        o = new ProgramGamePointConversion
                        {
                            PGID = obj.PID,
                            ActivityTypeId = (int)val,
                            ActivityCount = 1,
                            PointCount = 0,
                            AddedDate = obj.AddedDate,
                            AddedUser = obj.AddedUser
                        };
                        o.LastModDate = o.AddedDate;
                        o.LastModUser = o.AddedUser;

                        o.Insert();
                    }
                }
            }
        }
        public static ProgramGamePointConversion FetchObject(int PGCID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

                ProgramGamePointConversion result = new ProgramGamePointConversion();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PGCID"].ToString(), out _int))
                {
                    result.PGCID = _int;
                }
                if (int.TryParse(dr["PGID"].ToString(), out _int))
                {
                    result.PGID = _int;
                }
                if (int.TryParse(dr["ActivityTypeId"].ToString(), out _int))
                {
                    result.ActivityTypeId = _int;
                }
                if (int.TryParse(dr["ActivityCount"].ToString(), out _int))
                {
                    result.ActivityCount = _int;
                }
                if (int.TryParse(dr["PointCount"].ToString(), out _int))
                {
                    result.PointCount = _int;
                }
                if (DateTime.TryParse(dr["LastModDate"].ToString(), out _datetime))
                {
                    result.LastModDate = _datetime;
                }
                result.LastModUser = dr["LastModUser"].ToString();
                if (DateTime.TryParse(dr["AddedDate"].ToString(), out _datetime))
                {
                    result.AddedDate = _datetime;
                }
                result.AddedUser = dr["AddedUser"].ToString();

                dr.Close();

                return(result);
            }

            dr.Close();

            return(null);
        }
        public static int Delete(ProgramGamePointConversion o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try {

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

            } catch(SqlException exx) {

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

            }

            return iReturn;
        }