Esempio n. 1
0
        public static RSR_CalItems GetCalendarItemsForTeam(string sLinkID)
        {
            SqlWhere     sw = new SqlWhere();
            RSR          rsr;
            RSR_CalItems rci;
            RwpSlots     slots = new RwpSlots();

            sw.AddAliases(RwpSlot.s_mpAliases);
            try
            {
                sw.Add(String.Format("$$rwllpractice$$.Reserved = (select TeamID from rwllcalendarlinks where linkid='{0}')", Sql.Sqlify(sLinkID)), SqlWhere.Op.And);

                rsr = RSR.FromSR(Sql.ExecuteQuery(null, sw.GetWhere(RwpSlot.s_sSqlQueryString), slots,
                                                  Startup._sResourceConnString));

                if (!rsr.Succeeded)
                {
                    rci        = RSR_CalItems.FromRSR(rsr);
                    rci.Reason = String.Format("{0} {1}", rci.Reason, Startup._sResourceConnString);
                    return(rci);
                }

                rci = RSR_CalItems.FromRSR(RSR.FromSR(SR.Success()));

                List <CalItem> plci = new List <CalItem>();

                if (slots.Slots != null)
                {
                    foreach (RwpSlot slot in slots.Slots)
                    {
                        CalItem ci = new CalItem();

                        ci.Start       = slot.SlotStart;
                        ci.End         = slot.SlotStart.AddMinutes(slot.SlotLength);
                        ci.Location    = String.Format("{0}: {1}", slot.Venue, slot.Field);
                        ci.Title       = String.Format("Team Practice: {0}", slot.Reserved);
                        ci.Description =
                            String.Format("Redmond West Little League team practice at {0} ({1}), for team {2}",
                                          slot.Venue, slot.Field, slot.Reserved);
                        ci.UID = String.Format("{0}-rwllpractice-{1}", slot.Slot, slot.SlotStart.ToString("yyyyMMdd"));
                        plci.Add(ci);
                    }
                }

                rci.TheValue = plci;
                return(rci);
            }
            catch (Exception e)
            {
                rci        = RSR_CalItems.FromRSR(RSR.Failed(e));
                rci.Reason = String.Format("{0} ({1})", rci.Reason, sLinkID);
                return(rci);
            }
        }
Esempio n. 2
0
        /*----------------------------------------------------------------------------
        *       %%Function: GetCalendarLinksForTeam
        *       %%Qualified: RwpApi.CalendarLinks.GetCalendarLinksForTeam
        *       %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public static RSR_CalendarLinks GetCalendarLinksForTeam(string sTeam)
        {
            SqlWhere          sw = new SqlWhere();
            RSR               rsr;
            RSR_CalendarLinks rci;
            CalendarLinks     links = new CalendarLinks();

            sw.AddAliases(CalendarLinkItem.s_mpAliases);
            try
            {
                sw.Add(String.Format("$$rwllcalendarlinks$$.TeamID = '{0}'", Sql.Sqlify(sTeam)), SqlWhere.Op.And);

                rsr = RSR.FromSR(Sql.ExecuteQuery(null, sw.GetWhere(RwpSlots.RwpSlot.s_sSqlQueryString), links,
                                                  Startup._sResourceConnString));

                if (!rsr.Succeeded)
                {
                    rci        = RSR_CalendarLinks.FromRSR(rsr);
                    rci.Reason = String.Format("{0} {1}", rci.Reason, Startup._sResourceConnString);
                    return(rci);
                }

                rci = RSR_CalendarLinks.FromRSR(RSR.FromSR(SR.Success()));

                List <CalendarLink> plcall = new List <CalendarLink>();

                if (links.Links != null)
                {
                    foreach (CalendarLinkItem linkItem in links.Links)
                    {
                        CalendarLink link = new CalendarLink()
                        {
                            Link       = linkItem.Link, Team = linkItem.Team, Authority = linkItem.Authority,
                            CreateDate = linkItem.CreateDate, Comment = linkItem.Comment
                        };
                        plcall.Add(link);
                    }
                }

                rci.TheValue = plcall;
                return(rci);
            }

            catch (Exception e)
            {
                rci        = RSR_CalendarLinks.FromRSR(RSR.Failed(e));
                rci.Reason = String.Format("{0} ({1})", rci.Reason, sTeam);
                return(rci);
            }
        }
Esempio n. 3
0
            /*----------------------------------------------------------------------------
            *   %%Function: AddCalendarLinkItem
            *   %%Qualified: RwpApi.CalendarLinks.CalendarLinkItem.AddCalendarLinkItem
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public static RSR AddCalendarLinkItem(CalendarLink link)
            {
                CalendarLinkItem item = FromCalendarLink(link);
                RSR sr = item.Preflight(null);

                if (!sr.Succeeded)
                {
                    return(sr);
                }

                Sql sql;

                sr = RSR.FromSR(Sql.OpenConnection(out sql, Startup._sResourceConnString));
                if (!sr.Result)
                {
                    return(sr);
                }

                sr = RSR.FromSR(sql.BeginTransaction());
                if (!sr.Result)
                {
                    sql.Close();
                    return(sr);
                }

                try
                {
                    string sAdd = item.SGenerateUpdateQuery(sql, true);

                    SqlCommand sqlcmd = sql.CreateCommand();
                    sqlcmd.CommandText = sAdd;
                    sqlcmd.Transaction = sql.Transaction;
                    sqlcmd.ExecuteNonQuery();
                }
                catch (Exception exc)
                {
                    sql.Rollback();
                    sql.Close();
                    return(RSR.Failed(exc));
                }

                sql.Commit();
                sql.Close();
                return(RSR.Success());
            }
Esempio n. 4
0
            /*----------------------------------------------------------------------------
            *   %%Function: RevokeCalendarLink
            *   %%Qualified: RwpApi.CalendarLinks.CalendarLinkItem.RevokeCalendarLink
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public static RSR RevokeCalendarLink(Guid guidLink)
            {
                RSR sr;

                if (guidLink == Guid.Empty)
                {
                    return(RSR.Failed("empty link id"));
                }

                Sql sql;

                sr = RSR.FromSR(Sql.OpenConnection(out sql, Startup._sResourceConnString));
                if (!sr.Result)
                {
                    return(sr);
                }

                sr = RSR.FromSR(sql.BeginTransaction());
                if (!sr.Result)
                {
                    sql.Close();
                    return(sr);
                }

                try
                {
                    string sDelete = String.Format(s_sSqlDelete, guidLink.ToString());

                    SqlCommand sqlcmd = sql.CreateCommand();
                    sqlcmd.CommandText = sDelete;
                    sqlcmd.Transaction = sql.Transaction;
                    sqlcmd.ExecuteNonQuery();
                }
                catch (Exception exc)
                {
                    sql.Rollback();
                    sql.Close();
                    return(RSR.Failed(exc));
                }

                sql.Commit();
                sql.Close();
                return(RSR.Success());
            }
Esempio n. 5
0
 public static RSR ClearYear(int nYear)
 {
     return(RSR.FromSR(Sql.ExecuteNonQuery(
                           String.Format("DELETE FROM rwllpractice WHERE ([Date] >= '{0}-01-01' And [Date] <= '{0}-12-31')",
                                         nYear), Startup._sResourceConnString)));
 }
Esempio n. 6
0
 public static RSR ClearAll()
 {
     return(RSR.FromSR(Sql.ExecuteNonQuery("DELETE FROM rwllpractice", Startup._sResourceConnString)));
 }
Esempio n. 7
0
        /* I M P O R T  C S V */

        /*----------------------------------------------------------------------------
        *   %%Function: ImportCsv
        *   %%Qualified: RwpSvc.Practice:RwpSlots.ImportCsv
        *   %%Contact: rlittle
        *
        *  ----------------------------------------------------------------------------*/
        public static RSR ImportCsv(Stream stm, TimeZoneInfo tzi)
        {
            RSR      sr;
            Sql      sql;
            CsvSlots csv = new CsvSlots();

            TextReader tr = new StreamReader(stm);

            // process each line
            sr = RSR.FromSR(Sql.OpenConnection(out sql, Startup._sResourceConnString));
            if (!sr.Result)
            {
                return(sr);
            }

            sr = RSR.FromSR(sql.BeginTransaction());
            if (!sr.Result)
            {
                sql.Close();
                return(sr);
            }

            bool          fHeadingRead = false;
            string        sLine;
            int           iLine = 0;
            RwpSlot       rwps;
            bool          fAdd;
            List <string> plsDiff;

            try
            {
                while ((sLine = tr.ReadLine()) != null)
                {
                    iLine++;
                    if (sLine.Length < 2)
                    {
                        continue;
                    }

                    if (!fHeadingRead)
                    {
                        sr = csv.ReadHeaderFromString(sLine);
                        if (!sr.Result)
                        {
                            throw new Exception(String.Format("Failed to make heading at line {0}: {1}", iLine - 1,
                                                              sr.Reason));
                        }
                        fHeadingRead = true;
                        continue;
                    }

                    sr = csv.LoadRwpsFromCsv(sLine, sql, out rwps, out fAdd, out plsDiff, tzi);
                    if (!sr.Result)
                    {
                        throw new Exception(String.Format("Failed to process line {0}: {1}", iLine - 1, sr.Reason));
                    }

                    if (rwps == null) // this means it was an empty csv line
                    {
                        continue;
                    }

                    // at this point, rwps is a fully loaded team; check for errors and generate a passowrd if necessary
                    sr = rwps.Preflight(sql);
                    if (!sr.Result)
                    {
                        throw new Exception(String.Format("Failed to preflight line {0}: {1}", iLine - 1, sr.Reason));
                    }

                    // at this point, we would insert...
                    string sInsert = rwps.SGenerateUpdateQuery(sql, fAdd);

                    SqlCommand sqlcmd = sql.CreateCommand();
                    sqlcmd.CommandText = sInsert;
                    sqlcmd.Transaction = sql.Transaction;
                    sqlcmd.ExecuteNonQuery();
                }
            }
            catch (Exception e)
            {
                sql.Rollback();
                sql.Close();

                return(RSR.Failed(e));
            }

            sql.Commit();
            sql.Close();
            return(RSR.Success());
        }