Esempio n. 1
0
    /// <summary>
    /// 根据OpenID查询用户参加的所有团购活动
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="openID"></param>
    /// <param name="isLoadGroupEventMember">是否加载团购活动成员</param>
    /// <returns></returns>
    public static List <GroupPurchaseEvent> FindGroupPurchaseEventByOpenID(SqlConnection conn, string openID, bool isLoadGroupEventMember)
    {
        List <GroupPurchaseEvent> groupEventList = new List <GroupPurchaseEvent>();
        GroupPurchaseEvent        groupEvent     = null;

        try
        {
            using (SqlCommand cmdGroup = conn.CreateCommand())
            {
                SqlParameter paramID = cmdGroup.CreateParameter();
                paramID.ParameterName = "@GroupMember";
                paramID.SqlDbType     = System.Data.SqlDbType.NVarChar;
                paramID.SqlValue      = openID;
                cmdGroup.Parameters.Add(paramID);

                cmdGroup.CommandText = "select * from GroupPurchaseEvent where Id in (select GroupEventID from GroupPurchaseEventMember where GroupMember = @GroupMember)";

                using (SqlDataReader sdr = cmdGroup.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        groupEvent               = new GroupPurchaseEvent();
                        groupEvent.ID            = int.Parse(sdr["Id"].ToString());
                        groupEvent.Organizer     = WeChatUserDAO.FindUserByOpenID(conn, sdr["Organizer"].ToString(), false);
                        groupEvent.LaunchDate    = DateTime.Parse(sdr["LaunchDate"].ToString());
                        groupEvent.GroupPurchase = GroupPurchase.FindGroupPurchaseByID(conn, int.Parse(sdr["GroupID"].ToString()), false, false);
                        groupEvent.IsNotify      = bool.Parse(sdr["IsNotify"].ToString());
                        if (isLoadGroupEventMember)
                        {
                            groupEvent.GroupPurchaseEventMembers = groupEvent.FindGroupPurchaseEventMembers(conn);
                        }
                        else
                        {
                            groupEvent.GroupPurchaseEventMembers = null;
                        }

                        groupEventList.Add(groupEvent);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error("根据OpenID查询用户参加的所有团购活动", ex.ToString());
            throw ex;
        }

        return(groupEventList);
    }
Esempio n. 2
0
    /// <summary>
    /// 查询未通知用户的团购活动
    /// </summary>
    /// <param name="conn"></param>
    /// <param name="isLoadGroupEventMember"></param>
    /// <returns></returns>
    public static List <GroupPurchaseEvent> FindGroupPurchaseEventForNotify(SqlConnection conn, bool isLoadGroupEventMember)
    {
        List <GroupPurchaseEvent> groupEventList = new List <GroupPurchaseEvent>();
        GroupPurchaseEvent        groupEvent;

        try
        {
            using (SqlCommand cmdGroup = conn.CreateCommand())
            {
                cmdGroup.CommandText = "select * from GroupPurchaseEvent where IsNotify = 0";

                using (SqlDataReader sdr = cmdGroup.ExecuteReader())
                {
                    while (sdr.Read())
                    {
                        groupEvent               = new GroupPurchaseEvent();
                        groupEvent.ID            = int.Parse(sdr["Id"].ToString());
                        groupEvent.Organizer     = WeChatUserDAO.FindUserByOpenID(conn, sdr["Organizer"].ToString(), false);
                        groupEvent.LaunchDate    = DateTime.Parse(sdr["LaunchDate"].ToString());
                        groupEvent.GroupPurchase = GroupPurchase.FindGroupPurchaseByID(conn, int.Parse(sdr["GroupID"].ToString()), false, false);
                        groupEvent.IsNotify      = bool.Parse(sdr["IsNotify"].ToString());
                        if (isLoadGroupEventMember)
                        {
                            groupEvent.GroupPurchaseEventMembers = groupEvent.FindGroupPurchaseEventMembers(conn);
                        }
                        else
                        {
                            groupEvent.GroupPurchaseEventMembers = null;
                        }

                        groupEventList.Add(groupEvent);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            Log.Error("查询所有团购活动", ex.ToString());
            throw ex;
        }

        return(groupEventList);
    }