예제 #1
0
        /// <summary>
        /// 删除商品
        /// </summary>
        /// <param name="inCommodityID"></param>
        /// <param name="inUserID"></param>
        /// <returns></returns>
        public static int DeleteCommodity(int inCommodityID, int inUserID)
        {
            StringBuilder deleteTrigger = new StringBuilder();

            deleteTrigger.Append(" IF( OBJECT_ID ('ComAutoDelete') IS NOT NULL ) ");
            deleteTrigger.Append(" DROP TRIGGER ComAutoDelete ");
            SqlHelper.ExecuteNonQueryVoid(deleteTrigger.ToString(), CommandType.Text, false);

            StringBuilder createTrigger = new StringBuilder();

            createTrigger.Append(" CREATE TRIGGER ComAutoDelete ");
            createTrigger.Append(" ON Tx_CommodityList FOR DELETE AS ");
            createTrigger.Append(" DELETE FROM Tx_UserCommodityList ");
            createTrigger.Append(" WHERE UserID = " + inUserID + " AND CommodityID = " + inCommodityID);
            SqlHelper.ExecuteNonQueryTrigger(createTrigger.ToString());

            string sql = @" DELETE FROM Tx_CommodityList WHERE CommodityID = @inCommodityID ";

            SqlParameter para = new SqlParameter("@inCommodityID", SqlDbType.Int, 32);

            para.Value = inCommodityID;

            int result = SqlHelper.ExecuteNonQuery(CommandType.Text, sql, para);

            return(result);
        }
예제 #2
0
        /// <summary>
        /// 创建商品
        /// </summary>
        /// <param name="inModel"></param>
        /// <returns></returns>
        public static int CreateCommodity(Model.CommodityList inModel)
        {
            StringBuilder deleteTrigger = new StringBuilder();

            deleteTrigger.Append(" IF( OBJECT_ID ('AutoInsert') IS NOT NULL ) ");
            deleteTrigger.Append(" DROP TRIGGER AutoInsert ");
            SqlHelper.ExecuteNonQueryVoid(deleteTrigger.ToString(), CommandType.Text, false);

            StringBuilder createTrigger = new StringBuilder();

            createTrigger.Append(" CREATE TRIGGER AutoInsert ");
            createTrigger.Append(" ON Tx_CommodityList FOR INSERT AS ");
            createTrigger.Append(" DECLARE @CommodityID INT ");
            createTrigger.Append(" SELECT @CommodityID = CommodityID FROM inserted ");
            createTrigger.Append(" INSERT INTO Tx_UserCommodityList( UserID, CommodityID ) ");
            createTrigger.Append(" VALUES( " + inModel.UserID + " , @CommodityID ) ");
            SqlHelper.ExecuteNonQueryTrigger(createTrigger.ToString());

            StringBuilder sql = new StringBuilder();

            sql.Append(" INSERT INTO Tx_CommodityList ( ");
            sql.Append(" Title, Category, Price, TxPrice, Unit, ImgUrl, Description, ComContent ");
            sql.Append(" ) VALUES ( ");
            sql.Append(" @inTitle, @inCategory, @inPrice, @inTxPrice, @inUnit, @inImgUrl, @inDescription, @inComContent ) ");

            SqlParameter[] paras = GetParas(inModel);

            int result = SqlHelper.ExecuteNonQuery(CommandType.Text, sql.ToString(), paras);

            return(result);
        }