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

            SqlParameter[] arrParams = new SqlParameter[7];

            arrParams[0] = new SqlParameter("@HPBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPBID, o.HPBID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@HPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPID, o.HPID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[3] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[4] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[5] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[6] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

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

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

            return(iReturn);
        }
        public static MGHiddenPicBk FetchObject(int HPBID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

                MGHiddenPicBk result = new MGHiddenPicBk();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["HPBID"].ToString(), out _int))
                {
                    result.HPBID = _int;
                }
                if (int.TryParse(dr["HPID"].ToString(), out _int))
                {
                    result.HPID = _int;
                }
                if (int.TryParse(dr["MGID"].ToString(), out _int))
                {
                    result.MGID = _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);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            MasterPage.RequiredPermission = 4300;
            MasterPage.IsSecure = true;
            MasterPage.PageTitle = string.Format("{0}", "Background/Coloring Page Edit");
            
            if (!IsPostBack)
            {
                SetPageRibbon(StandardModuleRibbons.SetupRibbon());
            
                if (Request["HPID"] != null)
                {
                    lblMGID.Text = Session["MGID"].ToString();
                    lblHPID.Text = Request["HPID"];

                    var o = Minigame.FetchObject(int.Parse(lblMGID.Text));
                    AdminName.Text = o.AdminName;

                    var obj = new MGHiddenPicBk();
                    obj.HPID = int.Parse(lblHPID.Text);
                    obj.MGID = int.Parse(lblMGID.Text);
                    obj.AddedDate = DateTime.Now;
                    obj.AddedUser = ((SRPUser)Session[SessionData.UserProfile.ToString()]).Username;  //"N/A";  // Get from session
                    obj.LastModDate = obj.AddedDate;
                    obj.LastModUser = obj.AddedUser;
                    obj.Insert();
                    lblPK.Text = obj.HPBID.ToString();

                    dv.ChangeMode(DetailsViewMode.Edit);

                }
                else
                {
                    lblPK.Text = Request["PK"];

                    var o1 = MGHiddenPicBk.FetchObject(int.Parse(lblPK.Text));
                    lblMGID.Text = o1.MGID.ToString();
                    lblHPID.Text = o1.HPID.ToString();

                    var o = Minigame.FetchObject(int.Parse(lblMGID.Text));
                    AdminName.Text = o.AdminName;

                    dv.ChangeMode(DetailsViewMode.Edit);
                }
                Page.DataBind();
            }

        }
        public static int Insert(MGHiddenPicBk o)
        {
            SqlParameter[] arrParams = new SqlParameter[7];

            arrParams[0]           = new SqlParameter("@HPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPID, o.HPID.GetTypeCode()));
            arrParams[1]           = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2]           = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[3]           = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[4]           = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[5]           = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[6]           = new SqlParameter("@HPBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPBID, o.HPBID.GetTypeCode()));
            arrParams[6].Direction = ParameterDirection.Output;

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

            o.HPBID = int.Parse(arrParams[6].Value.ToString());

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

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

            return(iReturn);
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            //var returnURL = "~/ControlRoom/Modules/Setup/MGHiddenPicBkList.aspx?MGID=" + lblMGID.Text;
            var returnURL = "~/ControlRoom/Modules/Setup/MGHiddenPicBkList.aspx";
            if (e.CommandName.ToLower() == "back")
            {
                Response.Redirect(returnURL);
            }
            if (e.CommandName.ToLower() == "refresh")
            {
                try
                {
                    odsData.DataBind();
                    dv.DataBind();
                    dv.ChangeMode(DetailsViewMode.Edit);

                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null) masterPage.PageMessage = SRPResources.RefreshOK;
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
            
            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var obj = new MGHiddenPicBk();
                    var pk = int.Parse(((TextBox)((DetailsView)sender).FindControl("HPBID")).Text);
                    obj.Fetch(pk);

                    obj.HPID = FormatHelper.SafeToInt(lblHPID.Text);
                    obj.MGID = FormatHelper.SafeToInt(lblMGID.Text);

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

                    if (obj.IsValid(BusinessRulesValidationMode.UPDATE))
                    {
                        obj.Update();
                        if (e.CommandName.ToLower() == "saveandback")
                        {
                            Response.Redirect(returnURL);
                        }

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

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = SRPResources.SaveOK;
                    }
                    else
                    {
                        var masterPage = (IControlRoomMaster)Master;
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        masterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/MGHiddenPicBkAddEdit.aspx";
            if (e.CommandName.ToLower() == "addrecord")
            {
                Response.Redirect(String.Format("{0}?MGID={1}&HPID={2}", editpage, lblMGID.Text, lblHPID.Text));
            }

            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Response.Redirect(String.Format("{0}?PK={1}", editpage, key));
            }

            if (e.CommandName.ToLower() == "back")
            {
                //Response.Redirect(String.Format("~/ControlRoom/Modules/Setup/MGHiddenPicAddEdit.aspx?PK={0}", lblMGID.Text));
                Response.Redirect(String.Format("~/ControlRoom/Modules/Setup/MGHiddenPicAddEdit.aspx"));
            }


           
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new MGHiddenPicBk();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        MGHiddenPicBk.FetchObject(key).Delete();

                        LoadData();
                        var masterPage = (IControlRoomMaster)Master;
                        if (masterPage != null) masterPage.PageMessage = SRPResources.DeleteOK;
                    }
                    else
                    {
                        var masterPage = (IControlRoomMaster)Master;
                        string message = String.Format(SRPResources.ApplicationError1, "<ul>");
                        foreach (BusinessRulesValidationMessage m in obj.ErrorCodes)
                        {
                            message = string.Format(String.Format("{0}<li>{{0}}</li>", message), m.ErrorMessage);
                        }
                        message = string.Format("{0}</ul>", message);
                        if (masterPage != null) masterPage.PageError = message;
                    }
                }
                catch (Exception ex)
                {
                    var masterPage = (IControlRoomMaster)Master;
                    if (masterPage != null)
                        masterPage.PageError = String.Format(SRPResources.ApplicationError1, ex.Message);
                }
            }
        }
        public static MGHiddenPicBk FetchObject(int HPBID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                MGHiddenPicBk result = new MGHiddenPicBk();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["HPBID"].ToString(), out _int)) result.HPBID = _int;
                if (int.TryParse(dr["HPID"].ToString(), out _int)) result.HPID = _int;
                if (int.TryParse(dr["MGID"].ToString(), out _int)) result.MGID = _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(MGHiddenPicBk o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Update(MGHiddenPicBk o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[7];

            arrParams[0] = new SqlParameter("@HPBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPBID, o.HPBID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@HPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPID, o.HPID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[3] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[4] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[5] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[6] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Insert(MGHiddenPicBk o)
        {

            SqlParameter[] arrParams = new SqlParameter[7];

            arrParams[0] = new SqlParameter("@HPID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPID, o.HPID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@MGID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.MGID, o.MGID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode()));
            arrParams[3] = new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode()));
            arrParams[4] = new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode()));
            arrParams[5] = new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode()));
            arrParams[6] = new SqlParameter("@HPBID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.HPBID, o.HPBID.GetTypeCode()));
            arrParams[6].Direction = ParameterDirection.Output;

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

            o.HPBID = int.Parse(arrParams[6].Value.ToString());

            return o.HPBID;

        }