Beispiel #1
0
            public static RSR_CalItems GetCalendarItemsForTeam(string sTeam)
            {
                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 = '{0}'", Sql.Sqlify(sTeam)), SqlWhere.Op.And);

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

                    if (!rsr.Succeeded)
                    {
                        rci        = RSR_CalItems.FromRSR(rsr);
                        rci.Reason = String.Format("{0} {1}", rci.Reason, _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       = StartTimeFromDateAndTime(slot.SlotDate, slot.StartTime);
                            ci.End         = StartTimeFromDateAndTime(slot.SlotDate, slot.EndTime);
                            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.SlotDate.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, sTeam);
                    return(rci);
                }
            }
Beispiel #2
0
            /* G E T  C S V */

            /*----------------------------------------------------------------------------
            *       %%Function: GetCsv
            *       %%Qualified: RwpSvc.Practice:Teams.GetCsv
            *       %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public RSR GetCsv(Stream stm)
            {
                CsvTeams   csvt = new CsvTeams();
                SqlWhere   sw   = new SqlWhere();
                TextWriter tw   = new StreamWriter(stm);

                sw.AddAliases(RwpTeam.s_mpAliases);

                m_plrwpt = new List <RwpTeam>();
//                StringBuilder sb = new StringBuilder(4096);

                RSR sr = RSR.FromSR(Sql.ExecuteQuery(sw.GetWhere(RwpTeam.s_sSqlQueryString), this, _sResourceConnString));

                tw.WriteLine(csvt.Header());
                foreach (RwpTeam rwpt in m_plrwpt)
                {
                    tw.WriteLine(csvt.CsvMake(rwpt));
                }

                tw.Flush();
                return(RSR.Success());
            }
Beispiel #3
0
 public static RSR ClearTeams()
 {
     return(RSR.FromSR(Sql.ExecuteNonQuery("DELETE FROM rwllteams WHERE TeamName <> 'Administrator'", _sResourceConnString)));
 }
Beispiel #4
0
            /* I M P O R T  C S V */

            /*----------------------------------------------------------------------------
            *   %%Function: ImportCsv
            *   %%Qualified: RwpSvc.Practice:Teams.ImportCsv
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public static RSR ImportCsv(Stream stm)
            {
                RSR      sr;
                Sql      sql;
                CsvTeams csv = new CsvTeams();
                Random   rnd = new Random(System.Environment.TickCount);

                TextReader tr = new StreamReader(stm);

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

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

                bool          fHeadingRead = false;
                string        sLine;
                int           iLine = 0;
                RwpTeam       rwpt;
                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.LoadRwptFromCsv(sLine, sql, out rwpt, out fAdd, out plsDiff);
                        if (!sr.Result)
                        {
                            throw new Exception(String.Format("Failed to process line {0}: {1}", iLine - 1, sr.Reason));
                        }

                        if (rwpt.Name == "")
                        {
                            continue;
                        }

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

                        if (string.IsNullOrEmpty(rwpt.Password))
                        {
                            rwpt.Password = RwpTeam.SGenRandomPassword(rnd, rwpt.Name);
                        }

                        if (rwpt.Created == null)
                        {
                            rwpt.Created = DateTime.Now;
                        }

                        if (rwpt.Updated == null)
                        {
                            rwpt.Updated = rwpt.Created;
                        }

                        if (rwpt.ReleasedCagesDate == null)
                        {
                            rwpt.ReleasedCagesDate = DateTime.Parse("1/1/2013");
                        }

                        if (rwpt.ReleasedFieldsDate == null)
                        {
                            rwpt.ReleasedFieldsDate = DateTime.Parse("1/1/2013");
                        }

                        // at this point, we would insert...
                        string sInsert = rwpt.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());
            }
Beispiel #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), _sResourceConnString)));
 }
Beispiel #6
0
 public static RSR ClearAll()
 {
     return(RSR.FromSR(Sql.ExecuteNonQuery("DELETE FROM rwllpractice", _sResourceConnString)));
 }
Beispiel #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)
            {
                RSR      sr;
                Sql      sql;
                CsvSlots csv = new CsvSlots();

                TextReader tr = new StreamReader(stm);

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

                sr = RSR.FromSR(sql.BeginTransaction());
                if (!sr.Result)
                {
                    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);
                        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());
            }