private void Bind() { var Id = Guid.Empty; if (!string.IsNullOrWhiteSpace(Request.QueryString["Id"])) { Guid.TryParse(Request.QueryString["Id"], out Id); } if (!Id.Equals(Guid.Empty)) { Page.Title = "编辑广告"; //获取当前Id的数据,并赋值到表单即可 InformationAd bll = new InformationAd(); DataSet ds = bll.GetModelOW(Id); if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows != null && ds.Tables[0].Rows.Count > 0) { DataTable dt = ds.Tables[0]; txtTitle.Value = dt.Rows[0]["Title"].ToString(); txtContent.Value = dt.Rows[0]["ContentText"].ToString(); txtDescr.Value = dt.Rows[0]["Descr"].ToString(); hId.Value = Id.ToString(); startDate.Value = Convert.ToDateTime(dt.Rows[0]["StartDate"]).ToString("yyyy-MM-dd HH:mm"); endDate.Value = Convert.ToDateTime(dt.Rows[0]["EndDate"]).ToString("yyyy-MM-dd HH:mm"); txtUrl.Value = dt.Rows[0]["Url"].ToString(); InformationAdPicture bllPP = new InformationAdPicture(); DataSet dsPP = bllPP.GetListOW(Id.ToString()); if (dsPP != null && dsPP.Tables.Count > 0 && dsPP.Tables[0].Rows != null && dsPP.Tables[0].Rows.Count > 0) { DataTable dtPP = dsPP.Tables[0]; foreach (DataRow row in dtPP.Rows) { string html = "<div class=\"row_col w110 mb10\" style=\"width:200px;\">" + "<table style=\"width:100%;\">" + "<tr>" + "<td style=\"width:130px; vertical-align:top;\">" + "<img src=\"{0}\" alt=\"\" width=\"110px\" height=\"110px\" />" + "<input type=\"hidden\" name=\"PicId\" value=\"{1}\"/>" + "</td>" + "<td style=\"width:70px;\">" + "<a href=\"javascript:void(0)\" class=\"easyui-linkbutton\" data-options=\"iconCls:'icon-remove',plain:true\" onclick=\"$(this).parents('.row_col').remove()\">删 除</a>" + "</td>" + "</tr>" + "</table>" + "</div>"; string picSrc = row["PictureId"] is DBNull ? "../../Images/nopic.gif" : string.Format("{0}{1}/PC/{1}_1{2}", row["FileDirectory"], row["RandomFolder"], row["FileExtension"]); html = string.Format(html, picSrc, row["PictureId"].ToString()); imgContentPicture.InnerHtml += html; } } if (0 == Convert.ToInt32(dt.Rows[0]["ViewType"])) { rdViewType1.Checked = false; rdViewType0.Checked = true; divContent.Style.Add("display", "none"); divUrl.Style.Add("display", "block"); } else { rdViewType1.Checked = true; rdViewType0.Checked = false; divContent.Style.Add("display", "block"); divUrl.Style.Add("display", "none"); } } } }
public void SaveInformationAd(HttpContext context) { try { string id = context.Request.Form["ctl00$cphMain$hId"].Trim(); string sTitle = context.Request.Form["ctl00$cphMain$txtTitle"].Trim(); string sDescr = context.Request.Form["ctl00$cphMain$txtDescr"].Trim(); string sContent = context.Request.Form["content"].Trim(); string sViewType = context.Request.Form["rdViewType"].Trim(); string startDate = context.Request.Form["ctl00$cphMain$startDate"].Trim(); string endDate = context.Request.Form["ctl00$cphMain$endDate"].Trim(); string sUrl = context.Request.Form["ctl00$cphMain$txtUrl"].Trim(); string sPictureIdList = context.Request.Form["pictureId"].TrimEnd(','); sContent = HttpUtility.HtmlDecode(sContent); Guid gId = Guid.Empty; if (id != "") { Guid.TryParse(id, out gId); } InformationAdInfo model = new InformationAdInfo(); InformationAdPicture bllPP = new InformationAdPicture(); model.LastUpdatedDate = DateTime.Now; model.Id = gId; model.Title = sTitle; model.Descr = sDescr; model.ContentText = sContent; model.ViewType = byte.Parse(sViewType); model.Url = sUrl; model.StartDate = DateTime.Parse(startDate); model.EndDate = DateTime.Parse(endDate); if (1 == model.ViewType && string.IsNullOrWhiteSpace(model.ContentText)) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Params_InvalidError + "\"}"); return; } InformationAd bll = new InformationAd(); int effect = -1; if (!gId.Equals(Guid.Empty)) { effect = bll.Update(model); if (effect > 0) { bllPP.Delete(model.Id); if (!string.IsNullOrWhiteSpace(sPictureIdList)) { foreach (string sPictureId in sPictureIdList.Split(',')) { InformationAdPictureInfo infoPP = new InformationAdPictureInfo(); Guid pictureId = Guid.Empty; Guid.TryParse(sPictureId, out pictureId); infoPP.InformationAdId = model.Id; infoPP.PictureId = pictureId; bllPP.InsertModel(infoPP); } } } } else { model.LastUpdatedDate = DateTime.Now; Guid anformationAdId = bll.InsertByOutput(model); if (!anformationAdId.Equals(Guid.Empty)) { effect = 1; if (!string.IsNullOrWhiteSpace(sPictureIdList)) { foreach (string sPictureId in sPictureIdList.Split(',')) { InformationAdPictureInfo infoPP = new InformationAdPictureInfo(); Guid pictureId = Guid.Empty; Guid.TryParse(sPictureId, out pictureId); infoPP.InformationAdId = anformationAdId; infoPP.PictureId = pictureId; bllPP.InsertModel(infoPP); } } } } if (effect == 110) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Exist + "\"}"); return; } if (effect < 1) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.Submit_Error + "\"}"); return; } context.Response.Write("{\"success\": true,\"message\": \"" + MessageContent.Submit_Success + "\"}"); } catch (Exception ex) { context.Response.Write("{\"success\": false,\"message\": \"" + MessageContent.AlertTitle_Ex_Error + ":" + ex.Message + "\"}"); } }