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()); } }