Пример #1
0
        private void Edit()
        {
            Models.Anime anime = new Models.Anime()
            {
                Title  = txtTitle.Text.Trim(),
                Origin = txtOrigin.Text.Trim(),
                Year   = Convert.ToInt32(dropYear.SelectedValue),
                Month  = Convert.ToInt32(dropMonth.SelectedValue),
                Level  = dropDepict.SelectedIndex + 1
            };
            string oldTitle = HttpUtility.UrlDecode(Request.QueryString["title"]);
            bool   success;

            if (fupPage.FileName == "")
            {
                success = new AnimeService().UpdateAnime(anime, oldTitle);
            }
            else
            {
                string[] name = fupPage.FileName.Split('.');
                if (name[name.Length - 1].ToLower() != "jpg")
                {
                    ltlMsg.Text = "<script>alert('图片必须jpg')</script>";
                    return;
                }
                if (fupPage.FileContent.Length > 1024 * 1024)
                {
                    ltlMsg.Text = "<script>alert('不能超过1M')</script>";
                    return;
                }
                success = new AnimeService().UpdateAnime(anime, oldTitle, fupPage.PostedFile.InputStream);
            }
            if (success)
            {
                Response.Redirect(string.Format("~/Anime/SetAnime.aspx?title={0}&modify={1}", HttpUtility.UrlEncode(anime.Title), 1));
            }
            else
            {
                ltlMsg.Text = "<script>alert('保存异常')</script>";
            }
        }
Пример #2
0
        private void Save()
        {
            Models.Anime anime = new Models.Anime()
            {
                Title  = txtTitle.Text.Trim(),
                Origin = txtOrigin.Text.Trim(),
                Year   = Convert.ToInt32(dropYear.SelectedValue),
                Month  = Convert.ToInt32(dropMonth.SelectedValue),
                Level  = dropDepict.SelectedIndex + 1
            };
            bool success;

            if (fupPage.FileName == "")
            {
                success = new AnimeService().AddAnime(anime, null);
            }
            else
            {
                string[] name = fupPage.FileName.Split('.');
                if (name[name.Length - 1].ToLower() != "jpg")
                {
                    ltlMsg.Text = "<script>alert('图片必须jpg')</script>";
                    return;
                }
                if (fupPage.FileContent.Length > 1024 * 1024)
                {
                    ltlMsg.Text = "<script>alert('不能超过1M')</script>";
                    return;
                }
                success = new AnimeService().AddAnime(anime, fupPage.PostedFile.InputStream);
            }
            if (success)
            {
                Response.Redirect("~/Anime/SetAnime.aspx?add=1");
            }
            else
            {
                ltlMsg.Text = "<script>alert('添加异常')</script>";
            }
        }