Beispiel #1
0
    /// <summary>
    /// 确定提交
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        model.Title       = KillSqlIn.Form_ReplaceByString(this.txtTitle.Text, 100);
        model.DisplayMode = Convert.ToInt32(this.RadioButtonList1.SelectedValue);
        model.CategoryId  = Convert.ToInt32(this.DrCategory.SelectedValue);
        model.Link        = KillSqlIn.Form_ReplaceByString(this.txtLink.Text.Trim(), 100);
        model.sort        = Convert.ToInt32(KillSqlIn.Form_ReplaceByString(this.txtSort.Text, 10));
        model.StartTime   = !string.IsNullOrEmpty(this.txtStartTime.Text) ? Convert.ToDateTime(this.txtStartTime.Text) : System.DateTime.Now;
        model.EndTime     = !string.IsNullOrEmpty(this.txtEndTime.Text) ? Convert.ToDateTime(this.txtEndTime.Text) : System.DateTime.Now.AddDays(7);
        #region 保存图片
        if (!this.picUpload.Value.Equals(""))
        {
            string FileTZM = this.picUpload.PostedFile.FileName.Substring(this.picUpload.PostedFile.FileName.LastIndexOf(".") + 1);//得到文件的扩展名

            if (!IsPic(FileTZM.ToLower()))
            {
                JSUtility.Alert("上传图片格式不正确!");
                return;
            }
            if (this.picUpload.PostedFile.ContentLength > 1048576)
            {
                JSUtility.Alert("上传图片过大!");
                return;
            }
            Random rnd            = new Random();
            string UpLoadFileTime = DateTime.Now.ToString("HHmmss") + rnd.Next(9999).ToString("0000"); //生成一个新的数图片名称
            string fileName       = UpLoadFileTime + "." + FileTZM;                                    //产生上传图片的名称
            if (!Directory.Exists(Request.MapPath("~/upload/Link/")))
            {
                Directory.CreateDirectory(Request.MapPath("~/upload/Link/"));
            }
            string Url = Request.MapPath("~/upload/Link/" + fileName);
            picUpload.PostedFile.SaveAs(Url);
            model.Image = "/upload/Link/" + fileName;
        }
        else
        {
            model.Image = ViewState["Image"] == null ? "" : ViewState["Image"].ToString();
        }
        #endregion
        if (_Pid != "SysError")
        {
            model.AdId = Convert.ToInt32(_Pid);
            if (bll.Update(model))
            {
                this.ClientScript.RegisterStartupScript(this.GetType(), "close", "<script>alert('修改成功');layer_close_refresh();</script>");
            }
        }
        else
        {
            if (bll.Add(model) != 0)
            {
                JSUtility.AlertAndRedirect("添加成功,请继续添加!", Request.RawUrl.ToString());
            }
        }
    }
Beispiel #2
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取值
            int    id    = Convert.ToInt32(context.Request["Id"]);
            string title = context.Request["title"];
            //接受文件
            HttpPostedFile file = context.Request.Files["img"];

            //判断
            if (string.IsNullOrEmpty(title))
            {
                context.Response.Write("kong");
            }
            else
            {
                Ad ad = new Ad();
                ad.Id         = id;
                ad.Title      = title;
                ad.ImgUrl     = null;
                ad.CreateTime = DateTime.Now;
                ad.IsDelete   = false;
                if (file.ContentLength <= 0)
                {
                    ad.ImgUrl = new AdBll().GetModel(id).ImgUrl;
                }
                else
                {
                    //重命名文件
                    //相对路径
                    string img = "../../Home/images/" + Guid.NewGuid().ToString() + ".jpg";
                    //绝对路径
                    string abName = context.Server.MapPath(img);
                    file.SaveAs(abName);
                    ad.ImgUrl = img;
                }
                AdBll bll  = new AdBll();
                bool  flag = bll.Update(ad);
                if (flag)
                {
                    context.Response.Write("ok");
                }
                else
                {
                    context.Response.Write("no");
                }
            }
        }
Beispiel #3
0
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            //取值
            string id = context.Request["id"];

            AdBll bll = new AdBll();

            bool f*g = bll.Update(Convert.ToInt32(id));

            if (f*g)
            {
                context.Response.Write("ok");
            }
            else
            {
                context.Response.Write("no");
            }
        }