Exemple #1
0
        public EarnedGrauity(Gratuity g, Payment p) : this()
        {
            if (g == null)
            {
                throw new ArgumentNullException("g");
            }
            if (p == null)
            {
                throw new ArgumentNullException("p");
            }

            GratuityEarned = g;
            GratuityType   = g.GratuityType;
            Username       = p.Username;
            EarnedDate     = p.Timestamp;
            ExpirationDate = p.Timestamp.Add(g.Window);
        }
Exemple #2
0
 protected EarnedGrauity(MySqlDataReader dr) : this()
 {
     if (dr == null)
     {
         throw new ArgumentNullException("dr");
     }
     Username         = (string)dr["username"];
     GratuityType     = (Gratuity.GratuityTypes)(Convert.ToInt32(dr["idGratuityType"], CultureInfo.InvariantCulture));
     GratuityEarned   = Gratuity.GratuityFromType(GratuityType);
     EarnedDate       = Convert.ToDateTime(dr["dateEarned"], CultureInfo.InvariantCulture);
     ExpirationDate   = Convert.ToDateTime(dr["dateExpired"], CultureInfo.InvariantCulture);
     ReminderCount    = Convert.ToInt32(dr["remindersSent"], CultureInfo.InvariantCulture);
     LastReminderDate = Convert.ToDateTime(dr["dateLastReminder"], CultureInfo.InvariantCulture);
     UserProfile      = null;
     try
     {
         UserProfile = new Profile(dr);
     }
     catch (MyFlightbookException)
     {
         UserProfile = null;
     }
 }
Exemple #3
0
        /// <summary>
        /// Returns a list of gratuities earned by the specified user
        /// </summary>
        /// <param name="szUser">Username - pass an empty string or null for all users</param>
        /// <param name="gt">Type of gratuity - pass Unknown for all</param>
        /// <returns>The gratuityties earned for the userc</returns>
        public static List <EarnedGrauity> GratuitiesForUser(string szUser, Gratuity.GratuityTypes gt)
        {
            List <string> lstRestrictions = new List <string>();

            if (!String.IsNullOrEmpty(szUser))
            {
                lstRestrictions.Add(" eg.username=?user ");
            }
            if (gt != Gratuity.GratuityTypes.Unknown)
            {
                lstRestrictions.Add(" eg.idGratuityType=?gt ");
                string szUserRestriction = Gratuity.GratuityFromType(gt).UserRestriction;
                if (!String.IsNullOrEmpty(szUserRestriction))
                {
                    lstRestrictions.Add(String.Format(" ({0}) ", szUserRestriction));
                }
            }
            string szWhereClause = String.Join(" AND ", lstRestrictions.ToArray()).Trim();

            string               szQ = @"SELECT *, uir.Rolename AS Role 
                        FROM earnedgratuities eg 
INNER JOIN users ON eg.username=users.username
LEFT JOIN usersinroles uir ON users.username=uir.username
{0} 
ORDER BY dateEarned ASC ";
            DBHelper             dbh = new DBHelper(String.Format(szQ, String.IsNullOrEmpty(szWhereClause) ? string.Empty : String.Format("WHERE {0}", szWhereClause)));
            List <EarnedGrauity> lst = new List <EarnedGrauity>();

            dbh.ReadRows((comm) =>
            {
                comm.Parameters.AddWithValue("user", szUser);
                comm.Parameters.AddWithValue("gt", (int)gt);
            },
                         (dr) => { lst.Add(new EarnedGrauity(dr)); });
            return(lst);
        }