/// <summary> /// 得到一个对象实体 /// </summary> public InformationVsKeyWordModel GetModel(string KeyWord, decimal InformationId) { StringBuilder strSql = new StringBuilder(); strSql.Append("select KeyWord, InformationId, vsType "); strSql.Append(" from CORE.dbo.InformationVsKeyWord "); strSql.Append(" where KeyWord=@KeyWord and InformationId=@InformationId "); SqlParameter[] parameters = { new SqlParameter("@KeyWord", SqlDbType.VarChar, 30), new SqlParameter("@InformationId", SqlDbType.Decimal, 9) }; parameters[0].Value = KeyWord; parameters[1].Value = InformationId; InformationVsKeyWordModel model = new InformationVsKeyWordModel(); DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { model.KeyWord = ds.Tables[0].Rows[0]["KeyWord"].ToString(); if (ds.Tables[0].Rows[0]["InformationId"].ToString() != "") { model.InformationId = decimal.Parse(ds.Tables[0].Rows[0]["InformationId"].ToString()); } model.vsType = ds.Tables[0].Rows[0]["vsType"].ToString(); return(model); } else { return(model); } }
/// <summary> /// 增加一条数据 /// </summary> public bool Add(InformationVsKeyWordModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into CORE.dbo.InformationVsKeyWord ("); strSql.Append("KeyWord,InformationId,vsType"); strSql.Append(") values ("); strSql.Append("@KeyWord,@InformationId,@vsType"); strSql.Append(") "); SqlParameter[] parameters = { new SqlParameter("@KeyWord", SqlDbType.VarChar, 30), new SqlParameter("@InformationId", SqlDbType.Decimal, 9), new SqlParameter("@vsType", SqlDbType.VarChar, 10) }; parameters[0].Value = model.KeyWord; parameters[1].Value = model.InformationId; parameters[2].Value = model.vsType; bool result = false; try { helper.ExecSqlReInt(strSql.ToString(), parameters); result = true; } catch (Exception ex) { this.helper.Close(); throw ex; } finally { } return(result); }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(InformationVsKeyWordModel model) { bool reValue = true; int reCount = 0; StringBuilder strSql = new StringBuilder(); strSql.Append("update CORE.dbo.InformationVsKeyWord set "); strSql.Append(" KeyWord = @KeyWord , "); strSql.Append(" InformationId = @InformationId , "); strSql.Append(" vsType = @vsType "); strSql.Append(" where KeyWord=@KeyWord and InformationId=@InformationId "); SqlParameter[] parameters = { new SqlParameter("@KeyWord", SqlDbType.VarChar, 30), new SqlParameter("@InformationId", SqlDbType.Decimal, 9), new SqlParameter("@vsType", SqlDbType.VarChar, 10) }; parameters[0].Value = model.KeyWord; parameters[1].Value = model.InformationId; parameters[2].Value = model.vsType; try {//异常处理 reCount = this.helper.ExecSqlReInt(strSql.ToString(), parameters); } catch (Exception ex) { this.helper.Close(); throw ex; } if (reCount <= 0) { reValue = false; } return(reValue); }
private void SaveInformation() { Model.InformationModel model = new InformationModel(); BLL.InformationBLL bll = new BLL.InformationBLL(); model.InformationId = ReDecimal("InformationId", 0); if (model.InformationId > 0) { bll.GetInformationModel(model.InformationId); } model.InformationClassId = 0; model.InformationTypeId = ReInt("InformationTypeId", 1); model.InformationContent = ReStrDeCode("InformationContent"); model.ContactName = ReStr("ContactName"); model.Property = "<root></root>"; model.InformationTitle = ReStr("InformationTitle", ""); string title = Common.StringPlus.OutHtmlText(model.InformationContent); title = Common.StringPlus.GetLeftStr(title, 40, "..."); model.InformationTitle = title; model.QQ = ReStr("QQ", ""); model.Tel = ReStr("Tel", ""); model.Email = ReStr("Email"); #region 事务开启 TransactionOptions transactionOption = new TransactionOptions(); transactionOption.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted; using (TransactionScope transactionScope = new TransactionScope(TransactionScopeOption.Required, transactionOption)) { #endregion bll.SaveInformation(model); DataTable dtImg = ReTable("imgArray"); dtImg = BLL.BJ.ImgSetting.ImgArraySetting(dtImg, model.InformationContent); if (dtImg != null) { if (dtImg.Rows.Count > 0) { model.InformationImgId = dtImg.Rows[0]["ImgId"].ToString(); } } DataTable dtKeyWord = ReTable("KeyWordArray"); if (dtKeyWord != null) { DAL.InformationVsKeyWordDAL IvkDal = new DAL.InformationVsKeyWordDAL(); IvkDal.DeleteList(" InformationId='" + model.InformationId + "' "); //删除所有关联 if (dtKeyWord.Rows.Count > 0) { foreach (DataRow drKeyWord in dtKeyWord.Rows) { Model.InformationVsKeyWordModel IvK = new InformationVsKeyWordModel(); IvK.InformationId = model.InformationId; IvK.KeyWord = drKeyWord["KeyWord"].ToString(); //重新绑定关联 IvK.vsType = "sys"; IvkDal.Add(IvK); } } } bll.DeleteInformationImg(" InformationId='" + model.InformationId + "' "); if (dtImg != null) { foreach (DataRow dr in dtImg.Rows) { Model.InformationVsImgModel IvI = new InformationVsImgModel(); IvI.ImgId = dr["ImgId"].ToString(); IvI.InformationId = model.InformationId; IvI.vsType = ""; bll.SaveInformationImg(IvI); } } #region 事务结束 transactionScope.Complete(); } #endregion ReTrue(); }