/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.CM.Model.CMArticle GetModel(int AId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select AId,ColId,ATId,Title,Description,Author,Source,Content,Hits,Status,IsTop,IsSplendid,PEmplId,CEmplId,AddTime,CheckTime,SeoTitle,SeoKeyword,SeoDes,AttType,OrgId,DisplayTime from CMArticle "); strSql.Append(" where AId=@AId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AId", DbType.Int32, AId); ECommerce.CM.Model.CMArticle model = null; using (IDataReader dataReader = db.ExecuteReader(dbCommand)) { if (dataReader.Read()) { model = ReaderBind(dataReader); } } return(model); }
/// <summary> /// 保存方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { #region 获取字段值并赋给变量 string title = txtTitle.Value.Trim();//标题 string col = ddlColumn.SelectedValue;//栏目 //string type = ddlType.SelectedValue;//类型 string author = txtAuthor.Value.Trim();//作者 string from = txtFrom.Value.Trim();//来源 string description = tarDescription.Value.Trim();//导读 string content = tarContent.Value.Trim();//详细内容 bool isTop = rboIsTopTrue.Checked;//是否置顶 //bool isFlash = rboIsFlashTrue.Checked;//是否幻灯 #endregion #region 验证输入内容 if (string.IsNullOrEmpty(title)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>"); txtTitle.Focus(); return; } if (string.IsNullOrEmpty(col) || col == "0") //判断栏目 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>"); ddlColumn.Focus(); return; } //if (string.IsNullOrEmpty(type) || type == "0") //判断类型 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>"); // ddlType.Focus(); // return; //} //if (string.IsNullOrEmpty(author)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>"); // txtAuthor.Focus(); // return; //} //if (string.IsNullOrEmpty(from)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>"); // txtFrom.Focus(); // return; //} //if (Request.QueryString["AId"] == "0") //{ // if (isFlash) // { // if (!fuPFlash.HasFile) // { // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>"); // fuPFlash.Focus(); // return; // } // } //} if (string.IsNullOrEmpty(description)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>"); tarDescription.Focus(); return; } if (string.IsNullOrEmpty(content)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>"); tarContent.Focus(); return; } #endregion //修改信息 if (!string.IsNullOrEmpty(AId)) //判断商品Id是否为空,如果不为空就是编辑数据 { #region 修改内容 try { #region 查询编辑对象,并赋值给对象字段 //查询编辑的商品信息 aModel = aDAL.GetModel(Convert.ToInt32(AId)); //查询产品信息 if (aModel != null) //判断编辑果品对象是否为空 { aModel.Title = title; //商品名称 aModel.ColId = Convert.ToInt32(col); //产品概述 //aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.CheckTime = DateTime.Now; //aModel.PEmplId= 修改人 //审核人 if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } //if (isFlash) //{ // aModel.IsSplendid = 1; //} //else //{ // aModel.IsSplendid = 0; //} #endregion if (!fuPFlash.HasFile && attDAL.GetModel(Convert.ToInt32(AId), 0) == null) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯');</script>"); fuPFlash.Focus(); return; } if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; if (attDAL.Exists(Convert.ToInt32(AId), 0)) //判断图片地址是否存在 { attModel = attDAL.GetModel(Convert.ToInt32(AId), 0); DirFile.DeleteFile(attModel.AttName); // 删除图片地址 UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 if (!attDAL.Update(attModel)) { return; } } else { UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Type = 0; attModel.AId = Convert.ToInt32(AId); attModel.Status = 1; if (!(attDAL.Add(attModel) > 0)) { return; } } } bool re = aDAL.Update(aModel); if (re) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改成功'); window.location = 'CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改失败'); ", false); } } } catch (Exception ex) { throw ex; } #endregion } else //新增信息 { #region 新增信息 try { #region 给果品实体对象字段赋值 aModel.Title = title; //商品名称 aModel.ColId = Convert.ToInt32(col); //产品概述 //aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.Status = 0; aModel.AddTime = DateTime.Now; if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } //if (isFlash) //{ // aModel.IsSplendid = 1; //} //else //{ // aModel.IsSplendid = 0; //} #endregion if (!fuPFlash.HasFile) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯');</script>"); fuPFlash.Focus(); return; } if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);//上传图片 if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.Type = 0; attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Status = 1; } aModel.ATId = 1; int re = aDAL.Add(aModel); //增加方法 if (re > 0) //判断商品增加是否成功 { attModel.AId = re; if (attDAL.Add(attModel) > 0) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增成功'); window.location = 'CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); ", false); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); ", false); } } catch (Exception ex) { throw ex; } #endregion } }
/// <summary> /// 对象实体绑定数据 /// </summary> public ECommerce.CM.Model.CMArticle ReaderBind(IDataReader dataReader) { ECommerce.CM.Model.CMArticle model = new ECommerce.CM.Model.CMArticle(); object ojb; ojb = dataReader["AId"]; if (ojb != null && ojb != DBNull.Value) { model.AId = Convert.ToInt32(ojb); } ojb = dataReader["ColId"]; if (ojb != null && ojb != DBNull.Value) { model.ColId = Convert.ToInt32(ojb); } ojb = dataReader["ATId"]; if (ojb != null && ojb != DBNull.Value) { model.ATId = Convert.ToInt32(ojb); } model.Title = dataReader["Title"].ToString(); model.Description = dataReader["Description"].ToString(); model.Author = dataReader["Author"].ToString(); model.Source = dataReader["Source"].ToString(); model.Content = dataReader["Content"].ToString(); ojb = dataReader["Hits"]; if (ojb != null && ojb != DBNull.Value) { model.Hits = Convert.ToInt32(ojb); } ojb = dataReader["Status"]; if (ojb != null && ojb != DBNull.Value) { model.Status = Convert.ToInt32(ojb); } ojb = dataReader["IsTop"]; if (ojb != null && ojb != DBNull.Value) { model.IsTop = Convert.ToInt32(ojb); } ojb = dataReader["IsSplendid"]; if (ojb != null && ojb != DBNull.Value) { model.IsSplendid = Convert.ToInt32(ojb); } ojb = dataReader["PEmplId"]; if (ojb != null && ojb != DBNull.Value) { model.PEmplId = Convert.ToInt32(ojb); } ojb = dataReader["CEmplId"]; if (ojb != null && ojb != DBNull.Value) { model.CEmplId = Convert.ToInt32(ojb); } ojb = dataReader["AddTime"]; if (ojb != null && ojb != DBNull.Value) { model.AddTime = Convert.ToDateTime(ojb); } ojb = dataReader["CheckTime"]; if (ojb != null && ojb != DBNull.Value) { model.CheckTime = Convert.ToDateTime(ojb); } model.SeoTitle = dataReader["SeoTitle"].ToString(); model.SeoKeyword = dataReader["SeoKeyword"].ToString(); model.SeoDes = dataReader["SeoDes"].ToString(); ojb = dataReader["AttType"]; if (ojb != null && ojb != DBNull.Value) { model.AttType = Convert.ToInt32(ojb); } ojb = dataReader["OrgId"]; if (ojb != null && ojb != DBNull.Value) { model.OrgId = Convert.ToInt64(ojb); } ojb = dataReader["DisplayTime"]; if (ojb != null && ojb != DBNull.Value) { model.DisplayTime = Convert.ToInt32(ojb); } return(model); }
/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.CM.Model.CMArticle DataRowToModel(DataRow row) { ECommerce.CM.Model.CMArticle model = new ECommerce.CM.Model.CMArticle(); if (row != null) { if (row["AId"] != null && row["AId"].ToString() != "") { model.AId = Convert.ToInt32(row["AId"].ToString()); } if (row["ColId"] != null && row["ColId"].ToString() != "") { model.ColId = Convert.ToInt32(row["ColId"].ToString()); } if (row["ATId"] != null && row["ATId"].ToString() != "") { model.ATId = Convert.ToInt32(row["ATId"].ToString()); } if (row["Title"] != null) { model.Title = row["Title"].ToString(); } if (row["Description"] != null) { model.Description = row["Description"].ToString(); } if (row["Author"] != null) { model.Author = row["Author"].ToString(); } if (row["Source"] != null) { model.Source = row["Source"].ToString(); } if (row["Content"] != null) { model.Content = row["Content"].ToString(); } if (row["Hits"] != null && row["Hits"].ToString() != "") { model.Hits = Convert.ToInt32(row["Hits"].ToString()); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = Convert.ToInt32(row["Status"].ToString()); } if (row["IsTop"] != null && row["IsTop"].ToString() != "") { model.IsTop = Convert.ToInt32(row["IsTop"].ToString()); } if (row["IsSplendid"] != null && row["IsSplendid"].ToString() != "") { model.IsSplendid = Convert.ToInt32(row["IsSplendid"].ToString()); } if (row["PEmplId"] != null && row["PEmplId"].ToString() != "") { model.PEmplId = Convert.ToInt32(row["PEmplId"].ToString()); } if (row["CEmplId"] != null && row["CEmplId"].ToString() != "") { model.CEmplId = Convert.ToInt32(row["CEmplId"].ToString()); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = Convert.ToDateTime(row["AddTime"].ToString()); } if (row["CheckTime"] != null && row["CheckTime"].ToString() != "") { model.CheckTime = Convert.ToDateTime(row["CheckTime"].ToString()); } if (row["SeoTitle"] != null) { model.SeoTitle = row["SeoTitle"].ToString(); } if (row["SeoKeyword"] != null) { model.SeoKeyword = row["SeoKeyword"].ToString(); } if (row["SeoDes"] != null) { model.SeoDes = row["SeoDes"].ToString(); } if (row["AttType"] != null && row["AttType"].ToString() != "") { model.AttType = Convert.ToInt32(row["AttType"].ToString()); } if (row["OrgId"] != null && row["OrgId"].ToString() != "") { model.OrgId = Convert.ToInt64(row["OrgId"].ToString()); } if (row["DisplayTime"] != null && row["DisplayTime"].ToString() != "") { model.DisplayTime = Convert.ToInt32(row["DisplayTime"].ToString()); } } return(model); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(ECommerce.CM.Model.CMArticle model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update CMArticle set "); strSql.Append("ColId=@ColId,"); strSql.Append("ATId=@ATId,"); strSql.Append("Title=@Title,"); strSql.Append("Description=@Description,"); strSql.Append("Author=@Author,"); strSql.Append("Source=@Source,"); strSql.Append("Content=@Content,"); strSql.Append("Hits=@Hits,"); strSql.Append("Status=@Status,"); strSql.Append("IsTop=@IsTop,"); strSql.Append("IsSplendid=@IsSplendid,"); strSql.Append("PEmplId=@PEmplId,"); strSql.Append("CEmplId=@CEmplId,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("CheckTime=@CheckTime,"); strSql.Append("SeoTitle=@SeoTitle,"); strSql.Append("SeoKeyword=@SeoKeyword,"); strSql.Append("SeoDes=@SeoDes,"); strSql.Append("AttType=@AttType,"); strSql.Append("OrgId=@OrgId,"); strSql.Append("DisplayTime=@DisplayTime"); strSql.Append(" where AId=@AId "); Database db = DatabaseFactory.CreateDatabase(); DbCommand dbCommand = db.GetSqlStringCommand(strSql.ToString()); db.AddInParameter(dbCommand, "AId", DbType.Int32, model.AId); db.AddInParameter(dbCommand, "ColId", DbType.Int32, model.ColId); db.AddInParameter(dbCommand, "ATId", DbType.Int32, model.ATId); db.AddInParameter(dbCommand, "Title", DbType.String, model.Title); db.AddInParameter(dbCommand, "Description", DbType.String, model.Description); db.AddInParameter(dbCommand, "Author", DbType.String, model.Author); db.AddInParameter(dbCommand, "Source", DbType.String, model.Source); db.AddInParameter(dbCommand, "Content", DbType.String, model.Content); db.AddInParameter(dbCommand, "Hits", DbType.Int32, model.Hits); db.AddInParameter(dbCommand, "Status", DbType.Byte, model.Status); db.AddInParameter(dbCommand, "IsTop", DbType.Byte, model.IsTop); db.AddInParameter(dbCommand, "IsSplendid", DbType.Byte, model.IsSplendid); db.AddInParameter(dbCommand, "PEmplId", DbType.Int32, model.PEmplId); db.AddInParameter(dbCommand, "CEmplId", DbType.Int32, model.CEmplId); db.AddInParameter(dbCommand, "AddTime", DbType.DateTime, model.AddTime); db.AddInParameter(dbCommand, "CheckTime", DbType.DateTime, model.CheckTime); db.AddInParameter(dbCommand, "SeoTitle", DbType.String, model.SeoTitle); db.AddInParameter(dbCommand, "SeoKeyword", DbType.String, model.SeoKeyword); db.AddInParameter(dbCommand, "SeoDes", DbType.String, model.SeoDes); db.AddInParameter(dbCommand, "AttType", DbType.Byte, model.AttType); db.AddInParameter(dbCommand, "OrgId", DbType.Int64, model.OrgId); db.AddInParameter(dbCommand, "DisplayTime", DbType.Int32, model.DisplayTime); int rows = db.ExecuteNonQuery(dbCommand); if (rows > 0) { return(true); } else { return(false); } }
protected void Page_Load(object sender, EventArgs e) { VerifyPage("", false); try { if (!IsPostBack) { Session["OrgAreaIds"] = null; Session["AID"] = null; Session["PIDS"] = null; Session["OrgId"] = null; AId = Request.QueryString["AId"] == null ? "" : Request.QueryString["AId"]; //获取文章分类Id hidAId.Value = AId; DBindLm(); DBingType(); GetArea(); //查询区域信息 if (!string.IsNullOrEmpty(hidAId.Value)) //判断文章分类Id是否为空 { this.lblTitle.Text = "修改内容"; ECommerce.CM.Model.CMArticle aModel = aDAL.GetModel(Convert.ToInt32(hidAId.Value)); //通过文章分类Id查询文章分类信息 if (aModel != null) { this.txtTitle.Value = aModel.Title; //给文章分类名称文本框赋值 this.ddlColumn.SelectedValue = aModel.ColId.ToString(); this.ddlType.SelectedValue = aModel.ATId.ToString(); if (aModel.IsTop == 1) //是否幻灯 { rboIsTopTrue.Checked = true; rboIsTopFalse.Checked = false; } else { rboIsTopTrue.Checked = false; rboIsTopFalse.Checked = true; } var attInfo = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0); if (attInfo != null) //幻灯图 { Image2.ImageUrl = imgPath + "S_" + attInfo.AttName; } List <SqlParameter> parameters = new List <SqlParameter>(); string sqlWhere = " AId =@AId and Type=1"; var parameter = new SqlParameter("@AId", DbType.Int32); parameter.Value = hidAId.Value; parameters.Add(parameter); string attNames = ""; string attNas = ""; DataSet dts = attDAL.GetList(sqlWhere, parameters); if (dts != null) { if (dts.Tables[0].Rows.Count > 0) { for (int i = 0; i < dts.Tables[0].Rows.Count; i++) { attNames += "<li><span><a href=\"javascript:void(0);\" onclick=\"delTr(this,'" + dts.Tables[0].Rows[i]["AttId"] + "','" + dts.Tables[0].Rows[i]["AttName"] + "');return false;\">删除</a></span>" + dts.Tables[0].Rows[i]["AttName"] + "</li>"; attNas += dts.Tables[0].Rows[i]["AttName"] + ","; } } } att.InnerHtml = attNames; atts.Value = attNas; this.txtAuthor.Value = aModel.Author; this.txtFrom.Value = aModel.Source; this.tarDescription.Value = aModel.Description; this.tarContent.Value = aModel.Content; this.txtDisplayTime.Value = aModel.DisplayTime.ToString(); } } } } catch { Response.Redirect("AddArticle.aspx"); } }
/// <summary> /// 保存方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { #region 获取字段值并赋给变量 string title = txtTitle.Value.Trim(); //标题 string col = ddlColumn.SelectedValue; //栏目 string type = ddlType.SelectedValue; //类型 string author = txtAuthor.Value.Trim(); //作者 string from = txtFrom.Value.Trim(); //来源 string description = tarDescription.Value.Trim(); //导读 string content = tarContent.Value.Trim(); //详细内容 bool isTop = rboIsTopTrue.Checked; //是否置顶 string displayTime = txtDisplayTime.Value; //显示时长 #endregion #region 验证输入内容 if (string.IsNullOrEmpty(title)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>"); txtTitle.Focus(); return; } if (string.IsNullOrEmpty(col) || col == "0") //判断栏目 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>"); ddlColumn.Focus(); return; } if (string.IsNullOrEmpty(type) || type == "0") //判断类型 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>"); ddlType.Focus(); return; } //if (string.IsNullOrEmpty(author)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>"); // txtAuthor.Focus(); // return; //} //if (string.IsNullOrEmpty(from)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>"); // txtFrom.Focus(); // return; //} //if (Request.QueryString["AId"] == "0") //{ // if (isFlash) // { // if (!fuPFlash.HasFile) // { // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>"); // fuPFlash.Focus(); // return; // } // } //} if (string.IsNullOrEmpty(description)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>"); tarDescription.Focus(); return; } if (string.IsNullOrEmpty(content)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>"); tarContent.Focus(); return; } if (string.IsNullOrEmpty(displayTime)) //判断商品概述是否为空 { displayTime = "0"; } else { try { Convert.ToInt32(displayTime); } catch (Exception) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('显示时长请输入数字');</script>"); tarContent.Focus(); return; } } #endregion //修改信息 if (!string.IsNullOrEmpty(hidAId.Value)) //判断商品Id是否为空,如果不为空就是编辑数据 { #region 修改内容 try { List <Logs.InfoLog> infolist = new List <Logs.InfoLog>(); #region 查询编辑对象,并赋值给对象字段 //查询编辑的商品信息 aModel = aDAL.GetModel(Convert.ToInt32(hidAId.Value)); //查询产品信息 if (aModel != null) //判断编辑果品对象是否为空 { if (title != aModel.Title) { infolist.Add(new Logs.InfoLog(title, aModel.Title, "文章标题")); } aModel.Title = title; //文章标题 string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : ""; if (!string.IsNullOrEmpty(orgId)) { if (Convert.ToInt32(orgId) != aModel.OrgId) { infolist.Add(new Logs.InfoLog(orgId, aModel.OrgId.ToString(), "生产厂商")); } aModel.OrgId = Convert.ToInt32(orgId); //生产厂商 } if (Convert.ToInt32(col) != aModel.ColId) { ECommerce.CM.DAL.CMColumn cmColumnDal = new ECommerce.CM.DAL.CMColumn(); var cmColimnInfo = cmColumnDal.GetModel(Convert.ToInt32(aModel.ColId)); infolist.Add(new Logs.InfoLog(ddlColumn.SelectedItem.Text, cmColimnInfo.ColName.ToString(), "栏目")); } aModel.ColId = Convert.ToInt32(col); //栏目 if (Convert.ToInt32(type) != aModel.ATId) { ECommerce.CM.DAL.CMArticleType cmArticleDal = new ECommerce.CM.DAL.CMArticleType(); var cmColimnInfo = cmArticleDal.GetModel(Convert.ToInt32(aModel.ATId)); infolist.Add(new Logs.InfoLog(ddlType.SelectedItem.Text, cmColimnInfo.ATName.ToString(), "类型")); } aModel.ATId = Convert.ToInt32(type); //类型 if (author != aModel.Author) { infolist.Add(new Logs.InfoLog(author, aModel.Author, "作者")); } aModel.Author = author; if (from != aModel.Source) { infolist.Add(new Logs.InfoLog(from, aModel.Source, "来源")); } aModel.Source = from; if (description != aModel.Description) { infolist.Add(new Logs.InfoLog(description, aModel.Description, "内容导读")); } aModel.Description = description; if (content != aModel.Content) { infolist.Add(new Logs.InfoLog(content, aModel.Content, "详细内容")); } aModel.Content = content; aModel.CheckTime = DateTime.Now; aModel.DisplayTime = Convert.ToInt32(displayTime); //aModel.PEmplId= 修改人 //审核人 if (isTop) { if (1 != aModel.IsTop) { infolist.Add(new Logs.InfoLog("1", aModel.IsTop.ToString(), "是否置顶")); } aModel.IsTop = 1; } else { if (0 != aModel.IsTop) { infolist.Add(new Logs.InfoLog("0", aModel.IsTop.ToString(), "是否置顶")); } aModel.IsTop = 0; } #endregion if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; if (attDAL.Exists(Convert.ToInt32(hidAId.Value), 0)) //判断图片地址是否存在 { attModel = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0); attMod = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0); DirFile.DeleteFile(attModel.AttName); // 删除图片地址 UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 if (!attDAL.Update(attModel)) { return; } } else { UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Type = 0; attModel.AId = Convert.ToInt32(hidAId.Value); attModel.Status = 1; if (!(attDAL.Add(attModel) > 0)) { return; } } } attDAL.DeleteByAid(Convert.ToInt32(hidAId.Value)); string attName = atts.Value; if (!string.IsNullOrEmpty(attName)) { var attNames = attName.Split(','); for (int i = 0; i < attNames.Length - 1; i++) { if (!string.IsNullOrEmpty(attNames[i])) { attMod.AId = Convert.ToInt32(hidAId.Value); attMod.Type = 1; attMod.AttName = attNames[i]; attMod.Status = 1; attDAL.Add(attMod); } } } bool re = aDAL.Update(aModel); if (re) { string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : ""; if (!string.IsNullOrEmpty(orgAreaIds)) { bool res = cmAreaDal.AddList(hidAId.Value, orgAreaIds); if (res) { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改区域失败'); </script>", false); } } else { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } Session["OrgAreaIds"] = null; string aid = hidAId.Value; string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : ""; if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids)) { int res = cmProDal.AddPro(Convert.ToInt32(aid), pids); if (res > 0) { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMPro"); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改关联商品失败'); </script>", false); } } else { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } Session["AID"] = null; Session["PIDS"] = null; Session["OrgId"] = null; System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改失败'); </script>", false); } } } catch (Exception ex) { throw ex; } #endregion } else //新增信息 { #region 新增信息 try { #region 给果品实体对象字段赋值 aModel.Title = title; //商品名称 string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : ""; if (!string.IsNullOrEmpty(orgId)) { aModel.OrgId = Convert.ToInt32(orgId); //生产厂商 } aModel.ColId = Convert.ToInt32(col); //产品概述 aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.Hits = 0; aModel.Status = 0; aModel.AddTime = DateTime.Now; aModel.DisplayTime = Convert.ToInt32(displayTime); if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } #endregion int re = aDAL.Add(aModel); //增加方法 if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);//上传图片 if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.Type = 0; attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Status = 1; attModel.AId = re; attDAL.Add(attModel); } string attName = atts.Value; if (!string.IsNullOrEmpty(attName)) { var attNames = attName.Split(','); for (int i = 0; i < attNames.Length - 1; i++) { if (!string.IsNullOrEmpty(attNames[i])) { attMod.AId = re; attMod.Type = 1; attMod.AttName = attNames[i]; attMod.Status = 1; attDAL.Add(attMod); } } } if (re > 0) //判断商品增加是否成功 { string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : ""; if (!string.IsNullOrEmpty(orgAreaIds)) { bool res = cmAreaDal.AddList(re.ToString(), orgAreaIds); if (res) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增区域失败'); </script>", false); } } Session["OrgAreaIds"] = null; string aid = re.ToString(); string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : ""; if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids)) { int res = cmProDal.AddPro(Convert.ToInt32(aid), pids); if (res > 0) { page = Request.QueryString["Page"] == null ? 1 : Convert.ToInt32(Request.QueryString["Page"]); System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增关联商品失败');</script> ", false); } } Session["AID"] = null; Session["PIDS"] = null; Session["OrgId"] = null; System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); </script>", false); } } catch (Exception ex) { throw ex; } #endregion } }
/// <summary> /// 对象实体绑定数据 /// </summary> public ECommerce.CM.Model.CMArticle ReaderBind(IDataReader dataReader) { ECommerce.CM.Model.CMArticle model=new ECommerce.CM.Model.CMArticle(); object ojb; ojb = dataReader["AId"]; if(ojb != null && ojb != DBNull.Value) { model.AId=Convert.ToInt32(ojb); } ojb = dataReader["ColId"]; if(ojb != null && ojb != DBNull.Value) { model.ColId=Convert.ToInt32(ojb); } ojb = dataReader["ATId"]; if(ojb != null && ojb != DBNull.Value) { model.ATId=Convert.ToInt32(ojb); } model.Title=dataReader["Title"].ToString(); model.Description=dataReader["Description"].ToString(); model.Author=dataReader["Author"].ToString(); model.Source=dataReader["Source"].ToString(); model.Content=dataReader["Content"].ToString(); ojb = dataReader["Hits"]; if(ojb != null && ojb != DBNull.Value) { model.Hits=Convert.ToInt32(ojb); } ojb = dataReader["Status"]; if(ojb != null && ojb != DBNull.Value) { model.Status=Convert.ToInt32(ojb); } ojb = dataReader["IsTop"]; if(ojb != null && ojb != DBNull.Value) { model.IsTop=Convert.ToInt32(ojb); } ojb = dataReader["IsSplendid"]; if(ojb != null && ojb != DBNull.Value) { model.IsSplendid=Convert.ToInt32(ojb); } ojb = dataReader["PEmplId"]; if(ojb != null && ojb != DBNull.Value) { model.PEmplId=Convert.ToInt32(ojb); } ojb = dataReader["CEmplId"]; if(ojb != null && ojb != DBNull.Value) { model.CEmplId=Convert.ToInt32(ojb); } ojb = dataReader["AddTime"]; if(ojb != null && ojb != DBNull.Value) { model.AddTime=Convert.ToDateTime(ojb); } ojb = dataReader["CheckTime"]; if(ojb != null && ojb != DBNull.Value) { model.CheckTime=Convert.ToDateTime(ojb); } model.SeoTitle=dataReader["SeoTitle"].ToString(); model.SeoKeyword=dataReader["SeoKeyword"].ToString(); model.SeoDes=dataReader["SeoDes"].ToString(); ojb = dataReader["AttType"]; if(ojb != null && ojb != DBNull.Value) { model.AttType=Convert.ToInt32(ojb); } ojb = dataReader["OrgId"]; if(ojb != null && ojb != DBNull.Value) { model.OrgId=Convert.ToInt64(ojb); } ojb = dataReader["DisplayTime"]; if(ojb != null && ojb != DBNull.Value) { model.DisplayTime=Convert.ToInt32(ojb); } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public ECommerce.CM.Model.CMArticle DataRowToModel(DataRow row) { ECommerce.CM.Model.CMArticle model=new ECommerce.CM.Model.CMArticle(); if (row != null) { if(row["AId"]!=null && row["AId"].ToString()!="") { model.AId=Convert.ToInt32(row["AId"].ToString()); } if(row["ColId"]!=null && row["ColId"].ToString()!="") { model.ColId=Convert.ToInt32(row["ColId"].ToString()); } if(row["ATId"]!=null && row["ATId"].ToString()!="") { model.ATId=Convert.ToInt32(row["ATId"].ToString()); } if(row["Title"]!=null) { model.Title=row["Title"].ToString(); } if(row["Description"]!=null) { model.Description=row["Description"].ToString(); } if(row["Author"]!=null) { model.Author=row["Author"].ToString(); } if(row["Source"]!=null) { model.Source=row["Source"].ToString(); } if(row["Content"]!=null) { model.Content=row["Content"].ToString(); } if(row["Hits"]!=null && row["Hits"].ToString()!="") { model.Hits=Convert.ToInt32(row["Hits"].ToString()); } if(row["Status"]!=null && row["Status"].ToString()!="") { model.Status=Convert.ToInt32(row["Status"].ToString()); } if(row["IsTop"]!=null && row["IsTop"].ToString()!="") { model.IsTop=Convert.ToInt32(row["IsTop"].ToString()); } if(row["IsSplendid"]!=null && row["IsSplendid"].ToString()!="") { model.IsSplendid=Convert.ToInt32(row["IsSplendid"].ToString()); } if(row["PEmplId"]!=null && row["PEmplId"].ToString()!="") { model.PEmplId=Convert.ToInt32(row["PEmplId"].ToString()); } if(row["CEmplId"]!=null && row["CEmplId"].ToString()!="") { model.CEmplId=Convert.ToInt32(row["CEmplId"].ToString()); } if(row["AddTime"]!=null && row["AddTime"].ToString()!="") { model.AddTime=Convert.ToDateTime(row["AddTime"].ToString()); } if(row["CheckTime"]!=null && row["CheckTime"].ToString()!="") { model.CheckTime=Convert.ToDateTime(row["CheckTime"].ToString()); } if(row["SeoTitle"]!=null) { model.SeoTitle=row["SeoTitle"].ToString(); } if(row["SeoKeyword"]!=null) { model.SeoKeyword=row["SeoKeyword"].ToString(); } if(row["SeoDes"]!=null) { model.SeoDes=row["SeoDes"].ToString(); } if(row["AttType"]!=null && row["AttType"].ToString()!="") { model.AttType=Convert.ToInt32(row["AttType"].ToString()); } if(row["OrgId"]!=null && row["OrgId"].ToString()!="") { model.OrgId=Convert.ToInt64(row["OrgId"].ToString()); } if(row["DisplayTime"]!=null && row["DisplayTime"].ToString()!="") { model.DisplayTime=Convert.ToInt32(row["DisplayTime"].ToString()); } } return model; }
/// <summary> /// 保存方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { #region 获取字段值并赋给变量 string title = txtTitle.Value.Trim();//标题 string col = ddlColumn.SelectedValue;//栏目 string type = ddlType.SelectedValue;//类型 string author = txtAuthor.Value.Trim();//作者 string from = txtFrom.Value.Trim();//来源 string description = tarDescription.Value.Trim();//导读 string content = tarContent.Value.Trim();//详细内容 bool isTop = rboIsTopTrue.Checked;//是否置顶 string displayTime = txtDisplayTime.Value; //显示时长 #endregion #region 验证输入内容 if (string.IsNullOrEmpty(title)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>"); txtTitle.Focus(); return; } if (string.IsNullOrEmpty(col) || col == "0") //判断栏目 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>"); ddlColumn.Focus(); return; } if (string.IsNullOrEmpty(type) || type == "0") //判断类型 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>"); ddlType.Focus(); return; } //if (string.IsNullOrEmpty(author)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>"); // txtAuthor.Focus(); // return; //} //if (string.IsNullOrEmpty(from)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>"); // txtFrom.Focus(); // return; //} //if (Request.QueryString["AId"] == "0") //{ // if (isFlash) // { // if (!fuPFlash.HasFile) // { // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>"); // fuPFlash.Focus(); // return; // } // } //} if (string.IsNullOrEmpty(description)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>"); tarDescription.Focus(); return; } if (string.IsNullOrEmpty(content)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>"); tarContent.Focus(); return; } if (string.IsNullOrEmpty(displayTime)) //判断商品概述是否为空 { displayTime = "0"; } else { try { Convert.ToInt32(displayTime); } catch (Exception) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('显示时长请输入数字');</script>"); tarContent.Focus(); return; } } #endregion //修改信息 if (!string.IsNullOrEmpty(hidAId.Value)) //判断商品Id是否为空,如果不为空就是编辑数据 { #region 修改内容 try { List<Logs.InfoLog> infolist = new List<Logs.InfoLog>(); #region 查询编辑对象,并赋值给对象字段 //查询编辑的商品信息 aModel = aDAL.GetModel(Convert.ToInt32(hidAId.Value)); //查询产品信息 if (aModel != null) //判断编辑果品对象是否为空 { if (title != aModel.Title) { infolist.Add(new Logs.InfoLog(title, aModel.Title, "文章标题")); } aModel.Title = title; //文章标题 string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : ""; if (!string.IsNullOrEmpty(orgId)) { if (Convert.ToInt32(orgId) != aModel.OrgId) { infolist.Add(new Logs.InfoLog(orgId, aModel.OrgId.ToString(), "生产厂商")); } aModel.OrgId = Convert.ToInt32(orgId); //生产厂商 } if (Convert.ToInt32(col) != aModel.ColId) { ECommerce.CM.DAL.CMColumn cmColumnDal = new ECommerce.CM.DAL.CMColumn(); var cmColimnInfo = cmColumnDal.GetModel(Convert.ToInt32(aModel.ColId)); infolist.Add(new Logs.InfoLog(ddlColumn.SelectedItem.Text, cmColimnInfo.ColName.ToString(), "栏目")); } aModel.ColId = Convert.ToInt32(col); //栏目 if (Convert.ToInt32(type) != aModel.ATId) { ECommerce.CM.DAL.CMArticleType cmArticleDal = new ECommerce.CM.DAL.CMArticleType(); var cmColimnInfo = cmArticleDal.GetModel(Convert.ToInt32(aModel.ATId)); infolist.Add(new Logs.InfoLog(ddlType.SelectedItem.Text, cmColimnInfo.ATName.ToString(), "类型")); } aModel.ATId = Convert.ToInt32(type); //类型 if (author != aModel.Author) { infolist.Add(new Logs.InfoLog(author, aModel.Author, "作者")); } aModel.Author = author; if (from != aModel.Source) { infolist.Add(new Logs.InfoLog(from, aModel.Source, "来源")); } aModel.Source = from; if (description != aModel.Description) { infolist.Add(new Logs.InfoLog(description, aModel.Description, "内容导读")); } aModel.Description = description; if (content != aModel.Content) { infolist.Add(new Logs.InfoLog(content, aModel.Content, "详细内容")); } aModel.Content = content; aModel.CheckTime = DateTime.Now; aModel.DisplayTime = Convert.ToInt32(displayTime); //aModel.PEmplId= 修改人 //审核人 if (isTop) { if (1 != aModel.IsTop) { infolist.Add(new Logs.InfoLog("1", aModel.IsTop.ToString(), "是否置顶")); } aModel.IsTop = 1; } else { if (0 != aModel.IsTop) { infolist.Add(new Logs.InfoLog("0", aModel.IsTop.ToString(), "是否置顶")); } aModel.IsTop = 0; } #endregion if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; if (attDAL.Exists(Convert.ToInt32(hidAId.Value), 0)) //判断图片地址是否存在 { attModel = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0); attMod = attDAL.GetModel(Convert.ToInt32(hidAId.Value), 0); DirFile.DeleteFile(attModel.AttName); // 删除图片地址 UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 if (!attDAL.Update(attModel)) { return; } } else { UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Type = 0; attModel.AId = Convert.ToInt32(hidAId.Value); attModel.Status = 1; if (!(attDAL.Add(attModel) > 0)) { return; } } } attDAL.DeleteByAid(Convert.ToInt32(hidAId.Value)); string attName = atts.Value; if (!string.IsNullOrEmpty(attName)) { var attNames = attName.Split(','); for (int i = 0; i < attNames.Length - 1; i++) { if (!string.IsNullOrEmpty(attNames[i])) { attMod.AId = Convert.ToInt32(hidAId.Value); attMod.Type = 1; attMod.AttName = attNames[i]; attMod.Status = 1; attDAL.Add(attMod); } } } bool re = aDAL.Update(aModel); if (re) { string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : ""; if (!string.IsNullOrEmpty(orgAreaIds)) { bool res = cmAreaDal.AddList(hidAId.Value, orgAreaIds); if (res) { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改区域失败'); </script>", false); } } else { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } Session["OrgAreaIds"] = null; string aid = hidAId.Value; string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : ""; if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids)) { int res = cmProDal.AddPro(Convert.ToInt32(aid), pids); if (res > 0) { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMPro"); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改关联商品失败'); </script>", false); } } else { if (infolist.Count > 0) { _logsDal.WriteLogs(infolist, CurrentUser.EmplId.ToString(), aModel.AId, DateTime.Now, "CMArticle"); } } Session["AID"] = null; Session["PIDS"] = null; Session["OrgId"] = null; System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改失败'); </script>", false); } } } catch (Exception ex) { throw ex; } #endregion } else //新增信息 { #region 新增信息 try { #region 给果品实体对象字段赋值 aModel.Title = title; //商品名称 string orgId = Session["OrgId"] != null ? Session["OrgId"].ToString() : ""; if (!string.IsNullOrEmpty(orgId)) { aModel.OrgId = Convert.ToInt32(orgId); //生产厂商 } aModel.ColId = Convert.ToInt32(col); //产品概述 aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.Hits = 0; aModel.Status = 0; aModel.AddTime = DateTime.Now; aModel.DisplayTime = Convert.ToInt32(displayTime); if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } #endregion int re = aDAL.Add(aModel); //增加方法 if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash);//上传图片 if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.Type = 0; attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Status = 1; attModel.AId = re; attDAL.Add(attModel); } string attName = atts.Value; if (!string.IsNullOrEmpty(attName)) { var attNames = attName.Split(','); for (int i = 0; i < attNames.Length - 1; i++) { if (!string.IsNullOrEmpty(attNames[i])) { attMod.AId = re; attMod.Type = 1; attMod.AttName = attNames[i]; attMod.Status = 1; attDAL.Add(attMod); } } } if (re > 0) //判断商品增加是否成功 { string orgAreaIds = Session["OrgAreaIds"] != null ? Session["OrgAreaIds"].ToString() : ""; if (!string.IsNullOrEmpty(orgAreaIds)) { bool res = cmAreaDal.AddList(re.ToString(), orgAreaIds); if (res) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增区域失败'); </script>", false); } } Session["OrgAreaIds"] = null; string aid = re.ToString(); string pids = Session["PIDS"] != null ? Session["PIDS"].ToString() : ""; if (!string.IsNullOrEmpty(aid) && !string.IsNullOrEmpty(pids)) { int res = cmProDal.AddPro(Convert.ToInt32(aid), pids); if (res > 0) { page = Request.QueryString["Page"] == null ? 1 : Convert.ToInt32(Request.QueryString["Page"]); System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx?Page=" + page + "';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增关联商品失败');</script> ", false); } } Session["AID"] = null; Session["PIDS"] = null; Session["OrgId"] = null; System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>window.location = '/Manage/CM/CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); </script>", false); } } catch (Exception ex) { throw ex; } #endregion } }
/// <summary> /// 保存方法 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void btnSave_Click(object sender, EventArgs e) { #region 获取字段值并赋给变量 string title = txtTitle.Value.Trim(); //标题 string col = ddlColumn.SelectedValue; //栏目 //string type = ddlType.SelectedValue;//类型 string author = txtAuthor.Value.Trim(); //作者 string from = txtFrom.Value.Trim(); //来源 string description = tarDescription.Value.Trim(); //导读 string content = tarContent.Value.Trim(); //详细内容 bool isTop = rboIsTopTrue.Checked; //是否置顶 //bool isFlash = rboIsFlashTrue.Checked;//是否幻灯 #endregion #region 验证输入内容 if (string.IsNullOrEmpty(title)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入标题');</script>"); txtTitle.Focus(); return; } if (string.IsNullOrEmpty(col) || col == "0") //判断栏目 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择栏目');</script>"); ddlColumn.Focus(); return; } //if (string.IsNullOrEmpty(type) || type == "0") //判断类型 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择类型');</script>"); // ddlType.Focus(); // return; //} //if (string.IsNullOrEmpty(author)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入作者');</script>"); // txtAuthor.Focus(); // return; //} //if (string.IsNullOrEmpty(from)) //判断库存是否为空 //{ // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入来源');</script>"); // txtFrom.Focus(); // return; //} //if (Request.QueryString["AId"] == "0") //{ // if (isFlash) // { // if (!fuPFlash.HasFile) // { // Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯图片');</script>"); // fuPFlash.Focus(); // return; // } // } //} if (string.IsNullOrEmpty(description)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入导读');</script>"); tarDescription.Focus(); return; } if (string.IsNullOrEmpty(content)) //判断商品概述是否为空 { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请输入详细内容');</script>"); tarContent.Focus(); return; } #endregion //修改信息 if (!string.IsNullOrEmpty(AId)) //判断商品Id是否为空,如果不为空就是编辑数据 { #region 修改内容 try { #region 查询编辑对象,并赋值给对象字段 //查询编辑的商品信息 aModel = aDAL.GetModel(Convert.ToInt32(AId)); //查询产品信息 if (aModel != null) //判断编辑果品对象是否为空 { aModel.Title = title; //商品名称 aModel.ColId = Convert.ToInt32(col); //产品概述 //aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.CheckTime = DateTime.Now; //aModel.PEmplId= 修改人 //审核人 if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } //if (isFlash) //{ // aModel.IsSplendid = 1; //} //else //{ // aModel.IsSplendid = 0; //} #endregion if (!fuPFlash.HasFile && attDAL.GetModel(Convert.ToInt32(AId), 0) == null) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯');</script>"); fuPFlash.Focus(); return; } if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; if (attDAL.Exists(Convert.ToInt32(AId), 0)) //判断图片地址是否存在 { attModel = attDAL.GetModel(Convert.ToInt32(AId), 0); DirFile.DeleteFile(attModel.AttName); // 删除图片地址 UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 if (!attDAL.Update(attModel)) { return; } } else { UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片(无水印) if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Type = 0; attModel.AId = Convert.ToInt32(AId); attModel.Status = 1; if (!(attDAL.Add(attModel) > 0)) { return; } } } bool re = aDAL.Update(aModel); if (re) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改成功'); window.location = 'CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('修改失败'); ", false); } } } catch (Exception ex) { throw ex; } #endregion } else //新增信息 { #region 新增信息 try { #region 给果品实体对象字段赋值 aModel.Title = title; //商品名称 aModel.ColId = Convert.ToInt32(col); //产品概述 //aModel.ATId = Convert.ToInt32(type); //产品描述 aModel.Author = author; aModel.Source = from; aModel.Description = description; aModel.Content = content; aModel.Status = 0; aModel.AddTime = DateTime.Now; if (isTop) { aModel.IsTop = 1; } else { aModel.IsTop = 0; } //if (isFlash) //{ // aModel.IsSplendid = 1; //} //else //{ // aModel.IsSplendid = 0; //} #endregion if (!fuPFlash.HasFile) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('请选择幻灯');</script>"); fuPFlash.Focus(); return; } if (fuPFlash.HasFile) { int sizeFlash; string msgFlash; string imgFlashUrl; UpImg(ref fuPFlash, out imgFlashUrl, out msgFlash, imgPath, out sizeFlash); //上传图片 if (string.IsNullOrEmpty(imgFlashUrl)) { Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + msgFlash + "');</script>"); return; } attModel.Type = 0; attModel.AttName = imgFlashUrl; //幻灯地址 attModel.Status = 1; } aModel.ATId = 1; int re = aDAL.Add(aModel); //增加方法 if (re > 0) //判断商品增加是否成功 { attModel.AId = re; if (attDAL.Add(attModel) > 0) { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增成功'); window.location = 'CMArticle.aspx';</script>", false);//跳转页面 } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); ", false); } } else { System.Web.UI.ScriptManager.RegisterStartupScript(Page, GetType(), "", "<script>alert('新增失败'); ", false); } } catch (Exception ex) { throw ex; } #endregion } }