示例#1
0
        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public InformationVsImgModel GetModel(decimal InformationId, string ImgId)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("select InformationId, ImgId, vsType  ");
            strSql.Append("  from InformationVsImg ");
            strSql.Append(" where InformationId=@InformationId and ImgId=@ImgId ");
            SqlParameter[] parameters =
            {
                new SqlParameter("@InformationId", SqlDbType.Decimal, 9),
                new SqlParameter("@ImgId",         SqlDbType.VarChar, 50)
            };
            parameters[0].Value = InformationId;
            parameters[1].Value = ImgId;


            InformationVsImgModel model = new InformationVsImgModel();
            DataSet ds = helper.ExecSqlReDs(strSql.ToString(), parameters);

            if (ds.Tables[0].Rows.Count > 0)
            {
                if (ds.Tables[0].Rows[0]["InformationId"].ToString() != "")
                {
                    model.InformationId = decimal.Parse(ds.Tables[0].Rows[0]["InformationId"].ToString());
                }
                model.ImgId  = ds.Tables[0].Rows[0]["ImgId"].ToString();
                model.vsType = ds.Tables[0].Rows[0]["vsType"].ToString();

                return(model);
            }
            else
            {
                return(model);
            }
        }
示例#2
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(InformationVsImgModel model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into InformationVsImg(");
            strSql.Append("InformationId,ImgId,vsType");
            strSql.Append(") values (");
            strSql.Append("@InformationId,@ImgId,@vsType");
            strSql.Append(") ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@InformationId", SqlDbType.Decimal,  9),
                new SqlParameter("@ImgId",         SqlDbType.VarChar, 50),
                new SqlParameter("@vsType",        SqlDbType.VarChar, 10)
            };

            parameters[0].Value = model.InformationId;
            parameters[1].Value = model.ImgId;
            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);
        }
示例#3
0
        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(InformationVsImgModel model)
        {
            bool          reValue = true;
            int           reCount = 0;
            StringBuilder strSql  = new StringBuilder();

            strSql.Append("update InformationVsImg set ");

            strSql.Append(" InformationId = @InformationId , ");
            strSql.Append(" ImgId = @ImgId , ");
            strSql.Append(" vsType = @vsType  ");
            strSql.Append(" where InformationId=@InformationId and ImgId=@ImgId  ");

            SqlParameter[] parameters =
            {
                new SqlParameter("@InformationId", SqlDbType.Decimal,  9),
                new SqlParameter("@ImgId",         SqlDbType.VarChar, 50),
                new SqlParameter("@vsType",        SqlDbType.VarChar, 10)
            };

            parameters[0].Value = model.InformationId;
            parameters[1].Value = model.ImgId;
            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();
    }