示例#1
0
文件: Coupon.cs 项目: zaieda/TemPOS
        public bool ApplyToTicket()
        {
            int catCount  = CouponCategory.Count(Id);
            int itemCount = CouponItem.Count(Id);

            return(catCount + itemCount == 0);
        }
示例#2
0
        /// <summary>
        /// Update an entry in the CouponItem table
        /// </summary>
        public static bool Update(CouponItem couponItem)
        {
            bool result = false;

            SqlConnection cn = GetConnection();

            result = Update(cn, couponItem);
            FinishedWithConnection(cn);
            return(result);
        }
示例#3
0
        /// <summary>
        /// Get an entry from the CouponItem table
        /// </summary>
        public static CouponItem Get(int id)
        {
            CouponItem result = null;

            SqlConnection cn = GetConnection();

            result = Get(cn, id);
            FinishedWithConnection(cn);
            return(result);
        }
示例#4
0
        private static bool Update(SqlConnection cn, CouponItem couponItem)
        {
            Int32 rowsAffected = 0;

            using (SqlCommand sqlCmd = cn.CreateCommand())
            {
                sqlCmd.CommandText = "UPDATE CouponItem SET CouponItemCouponId,@CouponItemCouponId,CouponItemItemId=@CouponItemItemId WHERE CouponItemId=@CouponItemId";

                BuildSqlParameter(sqlCmd, "@CouponItemId", SqlDbType.Int, couponItem.Id);
                BuildSqlParameter(sqlCmd, "@CouponItemCouponId", SqlDbType.Int, couponItem.CouponId);
                BuildSqlParameter(sqlCmd, "@CouponItemItemId", SqlDbType.Text, couponItem.ItemId);

                rowsAffected = sqlCmd.ExecuteNonQuery();
            }
            return(rowsAffected != 0);
        }
示例#5
0
        private static CouponItem Get(SqlConnection cn, int id)
        {
            CouponItem result = null;

            using (SqlCommand cmd = new SqlCommand("SELECT * FROM CouponItem WHERE CouponItemId=" + id, cn))
            {
                using (SqlDataReader rdr = cmd.ExecuteReader())
                {
                    if (rdr.Read())
                    {
                        result = BuildCouponItem(rdr);
                    }
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }
示例#6
0
        /// <summary>
        /// Delete an entry from the CouponItem table
        /// </summary>
        public static bool Delete(int id)
        {
            Int32         rowsAffected = 0;
            SqlConnection cn           = GetConnection();
            CouponItem    couponItem   = Get(cn, id);

            if (couponItem != null)
            {
                using (SqlCommand sqlCmd = cn.CreateCommand())
                {
                    sqlCmd.CommandText = "DELETE FROM CouponItem WHERE CouponItemId=" + id;
                    rowsAffected       = sqlCmd.ExecuteNonQuery();
                }
            }
            FinishedWithConnection(cn);
            return(rowsAffected != 0);
        }
示例#7
0
        /// <summary>
        /// Add a new entry to the CouponItem table
        /// </summary>
        public static CouponItem Add(int couponId, int itemId)
        {
            CouponItem result = null;

            SqlConnection cn  = GetConnection();
            string        cmd = "AddCouponItem";

            using (SqlCommand sqlCmd = new SqlCommand(cmd, cn))
            {
                sqlCmd.CommandType = CommandType.StoredProcedure;
                BuildSqlParameter(sqlCmd, "@CouponItemCouponId", SqlDbType.Int, couponId);
                BuildSqlParameter(sqlCmd, "@CouponItemItemId", SqlDbType.Int, itemId);
                BuildSqlParameter(sqlCmd, "@CouponItemId", SqlDbType.Int, ParameterDirection.ReturnValue);
                if (sqlCmd.ExecuteNonQuery() > 0)
                {
                    result = new CouponItem(Convert.ToInt32(sqlCmd.Parameters["@CouponItemId"].Value),
                                            couponId, itemId);
                }
            }
            FinishedWithConnection(cn);
            return(result);
        }