예제 #1
0
        public ActionResult DeleteFriendLink()
        {
            if (!AppData.IsManagerLogin)
            {
                return(Json(new { success = false, msg = "您未登录后台或会话已过期" }));
            }
            if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1903))
            {
                return(Json(new { success = false, msg = "您没有执行该操作的权限" }));
            }

            FriendLinkBLL friendLinkBLL = new FriendLinkBLL();

            Validation vld = new Validation();
            int        id  = vld.GetInt("id");

            if (id != 0)
            {
                FriendLinkObj friendLinkObj = friendLinkBLL.GetFriendLinkByID(id);
                System.IO.File.Delete(Config.MediaPath + friendLinkObj.Pic);
                friendLinkBLL.DeleteFriendLink(id);
            }

            return(Json(new { success = true }));
        }
예제 #2
0
        public void AddFriendLink(FriendLinkObj friendLinkObj)
        {
            using (helper = new SqlHelper())
            {
                helper.AddStringParameter("@FriendName", 200, friendLinkObj.FriendName);
                helper.AddStringParameter("@Url", 200, friendLinkObj.Url);
                helper.AddStringParameter("@Pic", 200, friendLinkObj.Pic);
                helper.AddIntParameter("@Sort", friendLinkObj.Sort);

                helper.ExecuteNonQuery("insert into FriendLinks (FriendName,Url,Pic,Sort) values (@FriendName,@Url,@Pic,@Sort)", CommandType.Text);
            }
        }
예제 #3
0
        public void ModifyFriendLink(FriendLinkObj friendLinkObj)
        {
            using (helper = new SqlHelper())
            {
                helper.AddIntParameter("@FriendID", friendLinkObj.FriendID);
                helper.AddStringParameter("@FriendName", 200, friendLinkObj.FriendName);
                helper.AddStringParameter("@Url", 200, friendLinkObj.Url);
                helper.AddStringParameter("@Pic", 200, friendLinkObj.Pic);
                helper.AddIntParameter("@Sort", friendLinkObj.Sort);

                helper.ExecuteNonQuery("update FriendLinks set FriendName=@FriendName,Url=@Url,Pic=@Pic,Sort=@Sort where FriendID=@FriendID", CommandType.Text);
            }
        }
예제 #4
0
        public FriendLinkObj GetFriendLinkByID(int friendId)
        {
            using (helper = new SqlHelper())
            {
                helper.AddIntParameter("@FriendID", friendId);

                using (SqlDataReader dr = helper.ExecuteReader("select FriendName,Url,Pic,Sort from FriendLinks where FriendID=@FriendID", CommandType.Text))
                {
                    if (dr.HasRows && dr.Read())
                    {
                        FriendLinkObj friendLinkObj = new FriendLinkObj();
                        friendLinkObj.FriendID   = friendId;
                        friendLinkObj.FriendName = dr[0] == DBNull.Value ? null : (string)dr[0];
                        friendLinkObj.Url        = dr[1] == DBNull.Value ? null : (string)dr[1];
                        friendLinkObj.Pic        = dr[2] == DBNull.Value ? null : (string)dr[2];
                        friendLinkObj.Sort       = dr[3] == DBNull.Value ? 0 : (int)dr[3];

                        return(friendLinkObj);
                    }
                    return(null);
                }
            }
        }
예제 #5
0
 public void ModifyFriendLink(FriendLinkObj friendLinkObj)
 {
     dal.ModifyFriendLink(friendLinkObj);
 }
예제 #6
0
 public void AddFriendLink(FriendLinkObj friendLinkObj)
 {
     dal.AddFriendLink(friendLinkObj);
 }
예제 #7
0
        public ActionResult AddFriendLink()
        {
            if (Request.HttpMethod != "POST")
            {
                if (!AppData.IsManagerLogin)
                {
                    return(Redirect("/Manage/Error/1.html"));
                }
                if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1901))
                {
                    return(Redirect("/Manage/Error/2.html"));
                }

                return(View());
            }
            else
            {
                if (!AppData.IsManagerLogin)
                {
                    return(Result(false, "您未登录后台或会话已过期"));
                }
                if (PrivilegeBLL.HasNotPrivilege(AppData.SessionUserID, 1901))
                {
                    return(Result(false, "您没有执行该操作的权限"));
                }

                FriendLinkBLL friendLinkBLL = new FriendLinkBLL();

                HttpPostedFileBase pic = Request.Files["pic"];
                if (pic == null || pic.ContentLength == 0)
                {
                    return(Result(false, "请选择一张图片上传"));
                }

                string ext = System.IO.Path.GetExtension(pic.FileName);
                if (!Regex.IsMatch(ext, @"^\.(gif|jpg|jpeg|png)$", RegexOptions.IgnoreCase))
                {
                    return(Result(false, "上传的图片格式不合要求,请上传gif,png,jpg格式的图片"));
                }


                Validation    vld           = new Validation();
                FriendLinkObj friendLinkObj = new FriendLinkObj();
                friendLinkObj.FriendName = vld.Get("name", false);
                friendLinkObj.Url        = vld.Get("url", false);

                if (vld.HasError)
                {
                    return(Result(false, "数据填写不完整"));
                }

                string dirPath = Config.MediaPath + @"\Upload";
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }

                string newFileName = DateTime.Now.ToString("yyyyMMddHHmmss_ffff") + ext;
                string savePath    = Path.Combine(dirPath, newFileName);
                friendLinkObj.Pic = "/Upload/" + newFileName;

                friendLinkBLL.AddFriendLink(friendLinkObj);

                pic.SaveAs(savePath);
                return(Result(true));
            }
        }