Пример #1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["tId"] == null && Request.QueryString["Id"] == null)
            {
                Response.Redirect("index.aspx");
                return;
            }
            int tId = 0;

            try
            {
                tId = int.Parse(Request.QueryString["tId"].ToString());
            }
            catch
            {
                Response.Redirect("index.aspx");
                return;
            }
            if (!IsPostBack)
            {
                getNav(tId);
            }
            Maticsoft.Model.tArticle model = null;
            Maticsoft.BLL.tArticle   BLL   = new Maticsoft.BLL.tArticle();
            model       = BLL.GetModel(int.Parse(Request.QueryString["Id"]));
            model.Click = (model.Click + 1);
            BLL.Update(model);
            lit_title.Text   = model.Title;
            this.Title      += "-" + model.Title;
            lit_content.Text = model.ArticleContent;
            lit_edit.Text    = model.Editor;
            lit_click.Text   = model.Click.ToString();
            lit_time.Text    = Convert.ToDateTime(model.UpdateTime).ToString("yyyy-MM-dd");
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Maticsoft.BLL.tArticle bll = new Maticsoft.BLL.tArticle();
            if (imgPhoto.ImageUrl == "")
            {
                filePhoto.MarkInvalid("请先上传封面图片!");

                Alert.ShowInTop("请先上传封面图片!");
                return;
            }
            if (Calendar1.SelectedDate == null)
            {
                Calendar1.SelectedDate = DateTime.Now;
            }
            string content = Request.Form["editor1"] == null ? "" : Request.Form["editor1"];

            if (!String.IsNullOrEmpty(Request.QueryString["tyId"]))
            {
                Maticsoft.Model.tArticle model = new Maticsoft.Model.tArticle();
                model.FengMian       = imgPhoto.ImageUrl;
                model.Title          = txtTile.Text;
                model.Remark         = txtRemark.Text;
                model.Editor         = txtEdit.Text;
                model.UpdateTime     = Calendar1.SelectedDate;
                model.ArtTyID        = int.Parse(ddlfatherId.SelectedValue);
                model.Sort           = int.Parse(txtSort.Text);
                model.ArticleContent = content;
                model.IsEnable       = 1;
                int k = bll.Add(model);



                if (k > 0)
                {
                    PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
                }
            }
            if (!String.IsNullOrEmpty(Request.QueryString["Id"]))
            {
                Maticsoft.Model.tArticle model = bll.GetModel(int.Parse(Request.QueryString["Id"]));
                if (imgPhoto.ImageUrl != model.FengMian)
                {
                    if (!string.IsNullOrEmpty(model.FengMian) && (model.FengMian != "../../upload/blank.png"))
                    {
                        string directoryPath = Server.MapPath(model.FengMian);
                        File.Delete(directoryPath);
                        //删除掉原来的图片
                    }
                }
                model.FengMian       = imgPhoto.ImageUrl;
                model.Title          = txtTile.Text;
                model.Remark         = txtRemark.Text;
                model.Editor         = txtEdit.Text;
                model.UpdateTime     = Calendar1.SelectedDate;
                model.ArtTyID        = int.Parse(ddlfatherId.SelectedValue);
                model.Sort           = int.Parse(txtSort.Text);
                model.ArticleContent = content;
                model.IsEnable       = 1;
                bll.Update(model);
                PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
            }
        }