Пример #1
0
            /*----------------------------------------------------------------------------
            *   %%Function: SRFromPls
            *   %%Qualified: RwpApi.CalendarLinks.CalendarLinkItem.SRFromPls
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public static RSR SRFromPls(string sReason, List <string> plsDiff)
            {
                string s = sReason;

                foreach (string sItem in plsDiff)
                {
                    s += sItem + ", ";
                }

                return(RSR.Failed(s));
            }
Пример #2
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);
            }
        }
Пример #3
0
            /* L O A D  R W P T  F R O M  C S V */

            /*----------------------------------------------------------------------------
            *   %%Function: LoadRwptFromCsv
            *   %%Qualified: RwpSvc.Practice:RwpSlots:CsvSlots.LoadRwptFromCsv
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public RSR LoadRwpsFromCsv(string sLine, Sql sql, out RwpSlot rwps, out bool fAdd, out List <string> plsDiff, TimeZoneInfo tzi)
            {
                string[] rgs = LineToArray(sLine);
                SqlWhere sw  = new SqlWhere();

                fAdd    = true;
                plsDiff = new List <string>();
                rwps    = null;

                if (rgs[0] == "")
                {
                    return(RSR.Success());
                }

                rwps = new RwpSlot();

                sw.AddAliases(RwpSlot.s_mpAliases);
                try
                {
                    rwps.Slot = GetIntVal(rgs, "SLOTNO");

                    sw.Add(String.Format("$$rwllpractice$$.SlotNo = {0}", rwps.Slot), SqlWhere.Op.And);
                    SqlReader sqlr = new SqlReader(sql);
                    if (sqlr.FExecuteQuery(sw.GetWhere(RwpSlot.s_sSqlQueryString), Startup._sResourceConnString) &&
                        sqlr.Reader.Read())
                    {
                        sqlr.Close();
                        // found a match.  for now, this is an error
                        throw new Exception(String.Format("slot {0} already exists", rwps.Slot));
                    }

                    sqlr.Close();

                    rwps.Slot         = GetIntVal(rgs, "SLOTNO");
                    rwps.Week         = GetDoubleVal(rgs, "WEEK");
                    rwps.Status       = GetStringVal(rgs, "STATUS");
                    rwps.Venue        = GetStringVal(rgs, "VENUE");
                    rwps.Field        = GetStringVal(rgs, "FIELD");
                    rwps.SlotStart    = GetDateVal(rgs, "SLOTSTART", tzi);
                    rwps.SlotLength   = GetIntVal(rgs, "SLOTLENGTH");
                    rwps.Reserved     = GetStringVal(rgs, "RESERVED");
                    rwps.Divisions    = GetStringVal(rgs, "DIVISIONS");
                    rwps.ReservedDate = GetDateValNullable(rgs, "SLOTRESERVEDDATETIME", tzi);
                    rwps.Type         = GetStringVal(rgs, "TYPE");
                    rwps.Released     = GetDateValNullable(rgs, "SLOTRELEASEDDATETIME", tzi);
                    rwps.ReleaseTeam  = GetStringValNullable(rgs, "RELEASETEAM");
                }
                catch (Exception e)
                {
                    return(RSR.Failed(e));
                }

                return(RSR.Success());
            }
Пример #4
0
            /*----------------------------------------------------------------------------
            *   %%Function: Preflight
            *   %%Qualified: RwpApi.CalendarLinks.CalendarLinkItem.Preflight
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public RSR Preflight(TCore.Sql sql)
            {
                List <string> plsFail = new List <string>();

                CheckLength(m_sComment, "Comment", 255, plsFail);

                if (plsFail.Count > 0)
                {
                    return(SRFromPls("preflight failed", plsFail));
                }

                return(RSR.Success());
            }
Пример #5
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);
            }
        }
Пример #6
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());
            }
Пример #7
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());
            }
Пример #8
0
        /* R E A D  H E A D E R  F R O M  S T R I N G */

        /*----------------------------------------------------------------------------
        *   %%Function: ReadHeaderFromString
        *   %%Qualified: tw.twsvc:TwUser:Csv.ReadHeaderFromString
        *   %%Contact: rlittle
        *
        *   m_plsHeadings has the current set of headings that the database supports
        *
        *   read in the heading line from the CSV file and validate what it wants
        *   to upload
        *  ----------------------------------------------------------------------------*/
        public RSR ReadHeaderFromString(string sLine)
        {
            string[] rgs = LineToArray(sLine);
            m_mpColHeader = new Dictionary <int, string>();
            m_mpHeaderCol = new Dictionary <string, int>();
            int i = 0;

            foreach (string s in rgs)
            {
                if (!m_mpHeadingsMatch.ContainsKey(s.ToUpper()))
                {
                    return(RSR.Failed(String.Format("header {0} not in database", s)));
                }

                m_mpColHeader.Add(i, s.ToUpper());
                m_mpHeaderCol.Add(s.ToUpper(), i);
                i++;
            }

            return(RSR.Success());
        }
Пример #9
0
            /* P R E F L I G H T */

            /*----------------------------------------------------------------------------
            *   %%Function: Preflight
            *   %%Qualified: RwpSvc.Practice:Teams:RwpTeam.Preflight
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public RSR Preflight(TCore.Sql sql)
            {
                List <string> plsFail = new List <string>();

                CheckLength(m_sStatus, "Status", 255, plsFail);
                CheckLength(m_sVenue, "Venue", 255, plsFail);
                CheckLength(m_sField, "Field", 255, plsFail);
                CheckLength(m_sReserved, "Reserved", 255, plsFail);
                CheckLength(m_sDivisions, "Divisions", 15, plsFail);
                CheckLength(m_sType, "Type", 50, plsFail);
                if (!s_plsTypes.Contains(m_sType.ToUpper()))
                {
                    plsFail.Add(String.Format("Type '{0}' is not valid", m_sType));
                }

                if (plsFail.Count > 0)
                {
                    return(SRFromPls("preflight failed", plsFail));
                }

                return(RSR.Success());
            }
Пример #10
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)));
 }
Пример #11
0
 public static RSR ClearAll()
 {
     return(RSR.FromSR(Sql.ExecuteNonQuery("DELETE FROM rwllpractice", Startup._sResourceConnString)));
 }
Пример #12
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());
        }