Exemplo n.º 1
0
        protected void newActivity_Click(Object sender, EventArgs e)
        {
            // 新建活动,标题初始化为时间 + 一随机数
            var activity = new Objects.Activity()
            {
                timeStart        = DateTime.Now,
                timeEnd          = DateTime.Now,
                title            = OSecurity.DateTimeToTimeStamp(DateTime.Now).ToString() + new Random().Next(0, 100).ToString(),
                content          = "",
                brief            = "",
                template         = int.Parse(DataBase.Template.Gets()[0].id),
                templateAddition = ""
            };

            // 新建
            if (!DataBase.Activity.Add(activity))
            {
                ScriptManager.RegisterClientScriptBlock(this, GetType(), "error", "alert('新建失败,服务器错误')", true);
                return;
            }
            // 获取ID,转到编辑界面
            activity = DataBase.Activity.GetByTitle(activity);
            Response.Redirect("/ActivityEditor.aspx?aid=" + activity.id);
        }
Exemplo n.º 2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            // 不是微信内置浏览器
            if (!WXManage.IsWXBrowser(Request))
            {
                Response.Redirect("/RequireWX.aspx?url=" + Request.Url);
                return;
            }
            if (Session["phone"] == null || Session["iden"].ToString() != "5")
            {
                Response.Redirect("/UserIndex.aspx");
                return;
            }
            if (Request.QueryString["aid"] == null)
            {
                Response.Redirect("/Activity.aspx");
                return;
            }

            // 保存
            if (IsPostBack)
            {
                var      id               = Request.QueryString["aid"];
                DateTime timeStart        = DateTime.Parse(Request.Form["timeStart"]);
                DateTime timeEnd          = DateTime.Parse(Request.Form["timeEnd"]);
                var      title            = Request.Form["title"];
                var      content          = Request.Unvalidated["htmlInput"];
                int      template         = int.Parse(Request.Form["templateSelect"]);
                var      brief            = Request.Form["brief"];
                bool     valid            = checkValid.Checked;
                var      imgSrc           = "";
                var      templateAddition = Request.Form["templateAdditionInput"];

                if (title == "" ||
                    content == "" ||
                    brief == "" ||
                    templateAddition == "" ||
                    Request.Files.Count > 1)
                {
                    return;
                }

                if (Request.Files.Count == 1)
                {
                    var    imgName = Request.Files[0].FileName;
                    string path    = "/WXShare/uploads/" + DateTime.Now.ToString("yyyyMMdd");
                    if (!Directory.Exists("/WXShare/uploads"))
                    {
                        Directory.CreateDirectory("/WXShare/uploads");
                    }
                    if (!Directory.Exists(path))
                    {
                        Directory.CreateDirectory(path);
                    }
                    path += "/" + OSecurity.DateTimeToTimeStamp(DateTime.Now) +
                            "." + imgName.Substring(imgName.LastIndexOf('.') + 1);
                    Request.Files[0].SaveAs(path);
                    imgSrc = path.Substring(8);
                }

                Objects.Activity modActivity = new Objects.Activity()
                {
                    id               = id,
                    timeStart        = timeStart,
                    timeEnd          = timeEnd,
                    title            = title,
                    content          = content,
                    template         = template,
                    brief            = brief,
                    valid            = valid,
                    imgSrc           = imgSrc,
                    templateAddition = templateAddition
                };
                if (!DataBase.Activity.Modify(modActivity))
                {
                    ScriptManager.RegisterClientScriptBlock(this, GetType(), "saveFailed", "alert('保存失败');", true);
                    return;
                }
                Response.Redirect(Request.Url.ToString());
            }

            // 显示
            var activityID = Request.QueryString["aid"];
            var activity   = DataBase.Activity.Get(new Objects.Activity()
            {
                id = activityID
            });

            timeStart.Value    = activity.timeStart.ToString("yyyy-MM-ddTHH:mm:ss");
            timeEnd.Value      = activity.timeEnd.ToString("yyyy-MM-ddTHH:mm:ss");
            title.Value        = activity.title;
            textarea.InnerHtml = activity.content;

            var templates = DataBase.Template.Gets();

            templateSelect.Items.Clear();
            foreach (var template in templates)
            {
                templateSelect.Items.Add(new ListItem(template.name, template.id));
                if (template.id == activity.id)
                {
                    templateSelect.SelectedIndex = templateSelect.Items.Count - 1;
                }
            }
            templateAdditionInput.Value = activity.templateAddition;

            brief.Value        = activity.brief;
            checkValid.Checked = activity.valid;
            if (activity.imgSrc != "")
            {
                ScriptManager.RegisterStartupScript(this, GetType(), "showImgSrc", "showImgSrc('//" + Request.Url.Host + "" + activity.imgSrc + "');", true);
            }
        }