Exemplo n.º 1
0
        public static int Update(AvatarPart o)
        {
            var parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode())));
            parameters.Add(new SqlParameter("@ComponentID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ComponentID, o.ComponentID.GetTypeCode())));
            parameters.Add(new SqlParameter("@Ordering", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Ordering, o.Ordering.GetTypeCode())));
            parameters.Add(new SqlParameter("@Name", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Name, o.Name.GetTypeCode())));
            parameters.Add(new SqlParameter("@Gender", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Gender, o.Gender.GetTypeCode())));

            parameters.Add(new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode())));

            parameters.Add(new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode())));
            parameters.Add(new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode())));

            int returnStatus = -1;

            try
            {
                returnStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Update", parameters.ToArray());
            }
            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return(returnStatus);
        }
Exemplo n.º 2
0
        public static int Delete(AvatarPart o)
        {
            int returnStatus = -1;

            var arrParams = new SqlParameter[2];

            arrParams[0] = new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@TenID",
                                            (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                                             -1 :
                                             (int)HttpContext.Current.Session["TenantID"])
                                            );

            try
            {
                var fileName = (HttpContext.Current.Server.MapPath("~/Images/AvatarParts/") + "\\" + o.APID.ToString() + ".png");
                File.Delete(fileName);
                fileName = (HttpContext.Current.Server.MapPath("~/Images/AvatarParts/") + "\\sm_" + o.APID.ToString() + ".png");
                File.Delete(fileName);

                returnStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Delete", arrParams);
            }

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

            return(returnStatus);
        }
Exemplo n.º 3
0
        public static int Insert(AvatarPart o)
        {
            var parameters = new List <SqlParameter>();

            parameters.Add(new SqlParameter("@ComponentID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ComponentID, o.ComponentID.GetTypeCode())));
            parameters.Add(new SqlParameter("@Ordering", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Ordering, o.Ordering.GetTypeCode())));
            parameters.Add(new SqlParameter("@Name", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Name, o.Name.GetTypeCode())));
            parameters.Add(new SqlParameter("@Gender", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Gender, o.Gender.GetTypeCode())));

            parameters.Add(new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode())));

            parameters.Add(new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode())));
            parameters.Add(new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode())));

            SqlParameter aidParmater = new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode()));

            aidParmater.Direction = ParameterDirection.Output;

            parameters.Add(aidParmater);

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Insert", parameters.ToArray());
            o.APID = int.Parse(aidParmater.Value.ToString());
            return(o.APID);
        }
Exemplo n.º 4
0
        public static AvatarPart FetchObject(int APID)
        {
            SqlParameter[] arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@APID", APID);

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

            if (dr.Read())
            {
                AvatarPart result = new AvatarPart();

                DateTime _datetime;
                int      _int;

                if (int.TryParse(dr["APID"].ToString(), out _int))
                {
                    result.APID = _int;
                }
                result.Name   = dr["Name"].ToString();
                result.Gender = dr["Gender"].ToString();
                if (int.TryParse(dr["ComponentID"].ToString(), out _int))
                {
                    result.ComponentID = _int;
                }
                if (int.TryParse(dr["Ordering"].ToString(), out _int))
                {
                    result.Ordering = _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();
                if (int.TryParse(dr["BadgeID"].ToString(), out _int))
                {
                    result.BadgeID = _int;
                }
                if (int.TryParse(dr["TenID"].ToString(), out _int))
                {
                    result.TenID = _int;
                }

                dr.Close();
                return(result);
            }

            dr.Close();
            return(null);
        }
        public static AvatarPart FetchObject(int APID)
        {
            SqlParameter[] arrParams = new SqlParameter[1];
            arrParams[0] = new SqlParameter("@APID", APID);

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

            if (dr.Read())
            {
                AvatarPart result = new AvatarPart();

                DateTime _datetime;
                int _int;

                if (int.TryParse(dr["APID"].ToString(), out _int))
                    result.APID = _int;
                result.Name = dr["Name"].ToString();
                result.Gender = dr["Gender"].ToString();
                if (int.TryParse(dr["ComponentID"].ToString(), out _int))
                    result.ComponentID = _int;
                if (int.TryParse(dr["Ordering"].ToString(), out _int))
                    result.Ordering = _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();
                if (int.TryParse(dr["BadgeID"].ToString(), out _int))
                    result.BadgeID = _int;
                if (int.TryParse(dr["TenID"].ToString(), out _int))
                    result.TenID = _int;

                dr.Close();
                return result;
            }

            dr.Close();
            return null;
        }
        protected void DvItemCommand(object sender, DetailsViewCommandEventArgs e)
        {
            string returnURL = "~/ControlRoom/Modules/Setup/AvatarList.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 AvatarPart();
                    obj.Name = ((TextBox)((DetailsView)sender).FindControl("Name")).Text;
                    obj.BadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("BadgeID")).SelectedValue);
                    obj.ComponentID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("ComponentID")).SelectedValue);
                    obj.Ordering = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("Ordering")).Text);
                    obj.Gender = "O";//"((DropDownList) ((DetailsView) sender).FindControl("Gender")).SelectedValue;
                    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();

                        try {
                            var badgePath = string.Format(Server.MapPath("~/images/AvatarParts/"));
                            System.IO.File.Copy(string.Format("{0}no_avatar.png", badgePath),
                                                string.Format("{0}{1}.png", badgePath, obj.APID));
                            System.IO.File.Copy(string.Format("{0}no_avatar_sm.png", badgePath),
                                                string.Format("{0}sm_{1}.png", badgePath, obj.APID));
                        } catch(Exception ex) {
                            this.Log().Error("Couldn't copy no_avatar images into new avatar: {0}",
                                             ex.Message);
                        }


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

                        lblPK.Text = obj.APID.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 AvatarPart();
                    int pk = int.Parse(lblPK.Text);
                    obj = obj.GetAvatarPart(pk);
                    obj.Name = ((TextBox)((DetailsView)sender).FindControl("Name")).Text;
                    obj.BadgeID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("BadgeID")).SelectedValue);
                    obj.ComponentID = FormatHelper.SafeToInt(((DropDownList)((DetailsView)sender).FindControl("ComponentID")).SelectedValue);
                    obj.Ordering = FormatHelper.SafeToInt(((TextBox)((DetailsView)sender).FindControl("Ordering")).Text);
                    obj.Gender = "O";//"((DropDownList)((DetailsView)sender).FindControl("Gender")).SelectedValue;
                    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;
                        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);

                }

            }
        }
Exemplo n.º 7
0
 public AvatarPart GetAvatarPart(int APID)
 {
     return(AvatarPart.FetchObject(APID));
 }
        protected void GvRowCommand(object sender, GridViewCommandEventArgs e)
        {
            string editpage = "~/ControlRoom/Modules/Setup/AvatarAddEdit.aspx";
            if (e.CommandName.ToLower() == "addrecord")
            {
                Session["APID"]= string.Empty;
                Response.Redirect(editpage);
            }
            if (e.CommandName.ToLower() == "editrecord")
            {
                int key = Convert.ToInt32(e.CommandArgument);
                Session["APID"] = key;
                Response.Redirect(editpage);
                //Response.Redirect(String.Format("{0}?PK={1}", editpage, key));
            }
            if (e.CommandName.ToLower() == "deleterecord")
            {
                var key = Convert.ToInt32(e.CommandArgument);
                try
                {

                    var obj = new AvatarPart();
                    if (obj.IsValid(BusinessRulesValidationMode.DELETE))
                    {
                        obj.GetAvatarPart(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(AvatarPart o)
        {
            int returnStatus = -1;

            var arrParams = new SqlParameter[2];
            arrParams[0] = new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode()));
            arrParams[1] = new SqlParameter("@TenID",
                (HttpContext.Current.Session["TenantID"] == null || HttpContext.Current.Session["TenantID"].ToString() == "" ?
                        -1 :
                        (int)HttpContext.Current.Session["TenantID"])
            );

            try
            {
                var fileName = (HttpContext.Current.Server.MapPath("~/Images/AvatarParts/") + "\\" + o.APID.ToString() + ".png");
                File.Delete(fileName);
                fileName = (HttpContext.Current.Server.MapPath("~/Images/AvatarParts/") + "\\sm_" + o.APID.ToString() + ".png");
                File.Delete(fileName);

                returnStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Delete", arrParams);
            }

            catch (SqlException exx)
            {

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

            }

            return returnStatus;
        }
        public static int Update(AvatarPart o)
        {

            var parameters = new List<SqlParameter>();

            parameters.Add(new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode())));
            parameters.Add(new SqlParameter("@ComponentID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ComponentID, o.ComponentID.GetTypeCode())));
            parameters.Add(new SqlParameter("@Ordering", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Ordering, o.Ordering.GetTypeCode())));
            parameters.Add(new SqlParameter("@Name", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Name, o.Name.GetTypeCode())));
            parameters.Add(new SqlParameter("@Gender", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Gender, o.Gender.GetTypeCode())));

            parameters.Add(new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode())));

            parameters.Add(new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode())));
            parameters.Add(new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode())));

            int returnStatus = -1; 

            try
            {
                returnStatus = SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Update", parameters.ToArray());
            }
            catch (SqlException exx)
            {
                System.Diagnostics.Debug.Write(exx.Message);
            }

            return returnStatus;
        }
        public static int Insert(AvatarPart o)
        {
            var parameters = new List<SqlParameter>();

            parameters.Add(new SqlParameter("@ComponentID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.ComponentID, o.ComponentID.GetTypeCode())));
            parameters.Add(new SqlParameter("@Ordering", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Ordering, o.Ordering.GetTypeCode())));
            parameters.Add(new SqlParameter("@Name", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Name, o.Name.GetTypeCode())));
            parameters.Add(new SqlParameter("@Gender", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.Gender, o.Gender.GetTypeCode())));

            parameters.Add(new SqlParameter("@LastModDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModDate, o.LastModDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@LastModUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.LastModUser, o.LastModUser.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedDate", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedDate, o.AddedDate.GetTypeCode())));
            parameters.Add(new SqlParameter("@AddedUser", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.AddedUser, o.AddedUser.GetTypeCode())));

            parameters.Add(new SqlParameter("@BadgeID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.BadgeID, o.BadgeID.GetTypeCode())));
            parameters.Add(new SqlParameter("@TenID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.TenID, o.TenID.GetTypeCode())));

            SqlParameter aidParmater = new SqlParameter("@APID", GRA.SRP.Core.Utilities.GlobalUtilities.DBSafeValue(o.APID, o.APID.GetTypeCode()));
            aidParmater.Direction = ParameterDirection.Output;

            parameters.Add(aidParmater);

            SqlHelper.ExecuteNonQuery(conn, CommandType.StoredProcedure, "app_AvatarPart_Insert", parameters.ToArray());
            o.APID = int.Parse(aidParmater.Value.ToString());
            return o.APID;
        }