Esempio n. 1
0
        public static int Insert(PrizeDrawing o)
        {
            SqlParameter[] arrParams = new SqlParameter[19];

            arrParams[0] = new SqlParameter("@PrizeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PrizeName, o.PrizeName.GetTypeCode()));
            arrParams[1] = new SqlParameter("@TID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TID, o.TID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@DrawingDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DrawingDateTime, o.DrawingDateTime.GetTypeCode()));
            arrParams[3] = new SqlParameter("@NumWinners", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumWinners, o.NumWinners.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("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[9]  = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[10] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[11] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[12] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

            arrParams[18]           = new SqlParameter("@PDID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PDID, o.PDID.GetTypeCode()));
            arrParams[18].Direction = ParameterDirection.Output;

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

            o.PDID = int.Parse(arrParams[18].Value.ToString());

            return(o.PDID);
        }
Esempio n. 2
0
        public static int Delete(PrizeDrawing o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

            return(iReturn);
        }
Esempio n. 3
0
        public static int Update(PrizeDrawing o)
        {
            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[19];

            arrParams[0] = new SqlParameter("@PDID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PDID, o.PDID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PrizeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PrizeName, o.PrizeName.GetTypeCode()));
            arrParams[2] = new SqlParameter("@TID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TID, o.TID.GetTypeCode()));
            arrParams[3] = new SqlParameter("@DrawingDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DrawingDateTime, o.DrawingDateTime.GetTypeCode()));
            arrParams[4] = new SqlParameter("@NumWinners", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumWinners, o.NumWinners.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()));

            arrParams[9]  = new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[10] = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[11] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[12] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[18] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

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

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

            return(iReturn);
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Drawings/Default.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 obj = new PrizeDrawing();
                    obj.PrizeName = ((TextBox)((DetailsView)sender).FindControl("PrizeName")).Text;
                    obj.TID = FormatHelper.SafeToInt(((DropDownList) ((DetailsView) sender).FindControl("TID")).SelectedValue);
                    obj.DrawingDateTime = FormatHelper.SafeToDateTime("");
                    obj.NumWinners = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("NumWinners")).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;

                    if (obj.IsValid(BusinessRulesValidationMode.INSERT))
                    {
                        obj.Insert();
                        if (e.CommandName.ToLower() == "addandback")
                        {
                            Response.Redirect(returnURL);
                        }

                        lblPK.Text = obj.PDID.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 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);
                }
            }

            if (e.CommandName.ToLower() == "save" || e.CommandName.ToLower() == "saveandback")
            {
                try
                {
                    var obj = new PrizeDrawing();
                    int pk = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text);
                    obj.Fetch(pk);

                    obj.PrizeName = ((TextBox)((DetailsView)sender).FindControl("PrizeName")).Text;
                    obj.TID = FormatHelper.SafeToInt(((DropDownList) ((DetailsView) sender).FindControl("TID")).SelectedValue);
                   //obj.DrawingDateTime = FormatHelper.SafeToDateTime("");
                    obj.NumWinners = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("NumWinners")).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);
                }
            }

            if (e.CommandName.ToLower() == "draw")
            {
                try
                {
                    var obj = new PrizeDrawing();
                    int pk = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text);
                    obj.Fetch(pk);

                    obj.DrawingDateTime = DateTime.Now;

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

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

                        var num = PrizeDrawing.DrawWinners(pk, obj.NumWinners);

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

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = string.Format("{0} Winners have been drawn!", num);
                    }
                    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);
                }

            }

            if (e.CommandName.ToLower() == "drawadd")
            {
                try
                {
                    var obj = new PrizeDrawing();
                    int pk = int.Parse(((DetailsView)sender).Rows[0].Cells[1].Text);
                    obj.Fetch(pk);

                    obj.DrawingDateTime = DateTime.Now;

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

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

                        var addl = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("addl")).Text);

                        if (addl==0)
                        {
                            var mp = (IControlRoomMaster)Master;
                            mp.PageMessage = string.Format("Must enter a value greater than 0 for the Additional # To Draw!", addl);
                            return;
                        }
                        var num = PrizeDrawing.DrawWinners(pk, addl, 1);

                        odsData.DataBind();
                        dv.DataBind();
                        odsWinners.DataBind();
                        var gv2 = (GridView)((DetailsView)sender).FindControl("gv2");
                        gv2.DataBind();
                        dv.ChangeMode(DetailsViewMode.Edit);

                        var masterPage = (IControlRoomMaster)Master;
                        masterPage.PageMessage = string.Format("{0} Winners have been drawn!", num);
                    }
                    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);
                }

            }

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

                        try{DAL.Notifications.Delete(DAL.Notifications.FetchObject(obj.NotificationID));}catch{}
                        try { PatronPrizes.Delete(PatronPrizes.FetchObjectByDrawing(key)); }catch { }
                        obj.Delete();

                        odsWinners.DataBind();
                        var gv2 = (GridView)((DetailsView)sender).FindControl("gv2");
                        gv2.DataBind();

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

            if (e.CommandName.ToLower() == "pickup")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = PrizeDrawingWinners.FetchObject(key);
                    if (obj.IsValid(BusinessRulesValidationMode.UPDATE))
                    {

                        try { DAL.Notifications.Delete(DAL.Notifications.FetchObject(obj.NotificationID)); }
                        catch { }
                        try { var pp = PatronPrizes.FetchObjectByDrawing(key);
                            pp.RedeemedFlag = true;
                            pp.Update();
                        }
                        catch { }
                        obj.PrizePickedUpFlag = true;
                        obj.Update();

                        odsWinners.DataBind();
                        var gv2 = (GridView)((DetailsView)sender).FindControl("gv2");
                        gv2.DataBind();

                        var masterPage = (IControlRoomMaster)Master;
                        if (masterPage != null) masterPage.PageMessage = "Prize has been marked a picked up!";
                    }
                    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);
                }
            }
        }
Esempio n. 5
0
        public static int DrawWinners(int PDID, int numWinners, int additional = 0)
        {
            SqlParameter[] arrParams = new SqlParameter[3];
            arrParams[0] = new SqlParameter("@PDID", PDID);
            arrParams[1] = new SqlParameter("@NumWinners", numWinners);
            arrParams[2] = new SqlParameter("@Additional", additional);
            var ds = SqlHelper.ExecuteDataset(conn, CommandType.StoredProcedure, "app_PrizeDrawing_DrawWinners", arrParams);

            var ret = ds.Tables[0].Rows.Count;

            var pd  = PrizeDrawing.FetchObject(PDID);
            var pt  = PrizeTemplate.FetchObject(pd.TID);
            var now = DateTime.Now;

            for (var i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                int PID   = (int)ds.Tables[0].Rows[i]["PatronID"];
                int NID   = (int)ds.Tables[0].Rows[i]["NotificationID"];
                int PDWID = (int)ds.Tables[0].Rows[i]["PDWID"];

                // insert patron prize
                var pp = new PatronPrizes
                {
                    PID          = PID,
                    PrizeSource  = 0,
                    BadgeID      = 0,
                    DrawingID    = PDWID,
                    PrizeName    = pd.PrizeName,
                    RedeemedFlag = false,
                    AddedDate    = now,
                    LastModDate  = now,
                    AddedUser    = "******",
                    LastModUser  = "******"
                };
                pp.Insert();

                if (pt.SendNotificationFlag)
                {
                    // generate notification
                    var not = new Notifications
                    {
                        PID_To      = PID,
                        PID_From    = 0, //0 == System Notification
                        Subject     = pt.NotificationSubject,
                        Body        = pt.NotificationMessage,
                        isQuestion  = false,
                        AddedDate   = now,
                        LastModDate = now,
                        AddedUser   = "******",
                        LastModUser = "******"
                    };
                    not.Insert();

                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = not.NID;
                    w.Update();
                }
                else
                {
                    var w = PrizeDrawingWinners.FetchObject(PDWID);
                    w.NotificationID = -1;
                    w.Update();
                }
            }

            return(ret);
        }
Esempio n. 6
0
        public bool Fetch(int PDID)
        {
            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

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

                PrizeDrawing result = new PrizeDrawing();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PDID"].ToString(), out _int))
                {
                    this.PDID = _int;
                }
                this.PrizeName = dr["PrizeName"].ToString();
                if (int.TryParse(dr["TID"].ToString(), out _int))
                {
                    this.TID = _int;
                }
                if (DateTime.TryParse(dr["DrawingDateTime"].ToString(), out _datetime))
                {
                    this.DrawingDateTime = _datetime;
                }
                if (int.TryParse(dr["NumWinners"].ToString(), out _int))
                {
                    this.NumWinners = _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();

                if (int.TryParse(dr["TenID"].ToString(), out _int))
                {
                    this.TenID = _int;
                }
                if (int.TryParse(dr["FldInt1"].ToString(), out _int))
                {
                    this.FldInt1 = _int;
                }
                if (int.TryParse(dr["FldInt2"].ToString(), out _int))
                {
                    this.FldInt2 = _int;
                }
                if (int.TryParse(dr["FldInt3"].ToString(), out _int))
                {
                    this.FldInt3 = _int;
                }
                this.FldBit1  = bool.Parse(dr["FldBit1"].ToString());
                this.FldBit2  = bool.Parse(dr["FldBit2"].ToString());
                this.FldBit3  = bool.Parse(dr["FldBit3"].ToString());
                this.FldText1 = dr["FldText1"].ToString();
                this.FldText2 = dr["FldText2"].ToString();
                this.FldText3 = dr["FldText3"].ToString();

                dr.Close();

                return(true);
            }

            dr.Close();

            return(false);
        }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Drawings/PrizeDrawingAddEdit.aspx";
            if (e.CommandName.ToLower() == "addrecord")
            {
                Session["DID"]= string.Empty; Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Session["DID"] = key; Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {
                    var obj = new PrizeDrawing();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        PrizeDrawing.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 int Delete(PrizeDrawing o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[1];

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

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Update(PrizeDrawing o)
        {

            int iReturn = -1; //assume the worst

            SqlParameter[] arrParams = new SqlParameter[19];

            arrParams[0] = new SqlParameter("@PDID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PDID, o.PDID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@PrizeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PrizeName, o.PrizeName.GetTypeCode()));
            arrParams[2] = new SqlParameter("@TID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TID, o.TID.GetTypeCode()));
            arrParams[3] = new SqlParameter("@DrawingDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DrawingDateTime, o.DrawingDateTime.GetTypeCode()));
            arrParams[4] = new SqlParameter("@NumWinners", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumWinners, o.NumWinners.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()));

            arrParams[9] = new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[10] = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[11] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[12] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[18] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

            try
            {

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

            }

            catch (SqlException exx)
            {

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

            }

            return iReturn;

        }
        public static int Insert(PrizeDrawing o)
        {

            SqlParameter[] arrParams = new SqlParameter[19];

            arrParams[0] = new SqlParameter("@PrizeName", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PrizeName, o.PrizeName.GetTypeCode()));
            arrParams[1] = new SqlParameter("@TID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TID, o.TID.GetTypeCode()));
            arrParams[2] = new SqlParameter("@DrawingDateTime", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.DrawingDateTime, o.DrawingDateTime.GetTypeCode()));
            arrParams[3] = new SqlParameter("@NumWinners", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.NumWinners, o.NumWinners.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("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode()));
            arrParams[9] = new SqlParameter("@FldInt1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt1, o.FldInt1.GetTypeCode()));
            arrParams[10] = new SqlParameter("@FldInt2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt2, o.FldInt2.GetTypeCode()));
            arrParams[11] = new SqlParameter("@FldInt3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldInt3, o.FldInt3.GetTypeCode()));
            arrParams[12] = new SqlParameter("@FldBit1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit1, o.FldBit1.GetTypeCode()));
            arrParams[13] = new SqlParameter("@FldBit2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit2, o.FldBit2.GetTypeCode()));
            arrParams[14] = new SqlParameter("@FldBit3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldBit3, o.FldBit3.GetTypeCode()));
            arrParams[15] = new SqlParameter("@FldText1", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText1, o.FldText1.GetTypeCode()));
            arrParams[16] = new SqlParameter("@FldText2", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText2, o.FldText2.GetTypeCode()));
            arrParams[17] = new SqlParameter("@FldText3", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.FldText3, o.FldText3.GetTypeCode()));

            arrParams[18] = new SqlParameter("@PDID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.PDID, o.PDID.GetTypeCode()));
            arrParams[18].Direction = ParameterDirection.Output;

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

            o.PDID = int.Parse(arrParams[18].Value.ToString());

            return o.PDID;

        }
        public bool Fetch(int PDID)
        {

            // declare reader

            SqlDataReader dr;

            SqlParameter[] arrParams = new SqlParameter[1];

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

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

            if (dr.Read())
            {

                // declare return value

                PrizeDrawing result = new PrizeDrawing();

                DateTime _datetime;

                int _int;

                //decimal _decimal;

                if (int.TryParse(dr["PDID"].ToString(), out _int)) this.PDID = _int;
                this.PrizeName = dr["PrizeName"].ToString();
                if (int.TryParse(dr["TID"].ToString(), out _int)) this.TID = _int;
                if (DateTime.TryParse(dr["DrawingDateTime"].ToString(), out _datetime)) this.DrawingDateTime = _datetime;
                if (int.TryParse(dr["NumWinners"].ToString(), out _int)) this.NumWinners = _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();

                if (int.TryParse(dr["TenID"].ToString(), out _int)) this.TenID = _int;
                if (int.TryParse(dr["FldInt1"].ToString(), out _int)) this.FldInt1 = _int;
                if (int.TryParse(dr["FldInt2"].ToString(), out _int)) this.FldInt2 = _int;
                if (int.TryParse(dr["FldInt3"].ToString(), out _int)) this.FldInt3 = _int;
                this.FldBit1 = bool.Parse(dr["FldBit1"].ToString());
                this.FldBit2 = bool.Parse(dr["FldBit2"].ToString());
                this.FldBit3 = bool.Parse(dr["FldBit3"].ToString());
                this.FldText1 = dr["FldText1"].ToString();
                this.FldText2 = dr["FldText2"].ToString();
                this.FldText3 = dr["FldText3"].ToString();

                dr.Close();

                return true;

            }

            dr.Close();

            return false;

        }