Пример #1
0
                /* L O A D  R W P T  F R O M  C S V */

                /*----------------------------------------------------------------------------
                *       %%Function: LoadRwptFromCsv
                *       %%Qualified: RwpSvc.Practice:Teams:CsvTeams.LoadRwptFromCsv
                *       %%Contact: rlittle
                *
                *  ----------------------------------------------------------------------------*/
                public RSR LoadRwptFromCsv(string sLine, TCore.Sql sql, out RwpTeam rwpt, out bool fAdd, out List <string> plsDiff)
                {
                    string [] rgs = LineToArray(sLine);
                    SqlWhere  sw  = new SqlWhere();

                    fAdd    = true;
                    rwpt    = new RwpTeam();
                    plsDiff = new List <string>();

                    sw.AddAliases(RwpTeam.s_mpAliases);
                    try
                    {
                        rwpt.Name = GetStringVal(rgs, "TEAMNAME");
                        if (rwpt.Name == "")
                        {
                            return(RSR.Success());
                        }

                        sw.Add(String.Format("$$rwllteams$$.TeamName = '{0}'", Sql.Sqlify(rwpt.Name)), SqlWhere.Op.And);
                        SqlReader sqlr = new SqlReader(sql);
                        if (sqlr.FExecuteQuery(sw.GetWhere(RwpTeam.s_sSqlQueryString), _sResourceConnString) &&
                            sqlr.Reader.Read())
                        {
                            sqlr.Close();
                            // found a match.  for now, this is an error
                            throw new Exception(String.Format("team name {0} already exists", rwpt.Name));
                        }
                        sqlr.Close();

                        rwpt.Division            = GetStringValNullable(rgs, "DIVISION");
                        rwpt.Password            = GetStringValNullable(rgs, "PW");
                        rwpt.Created             = GetDateValNullable(rgs, "DATECREATED");
                        rwpt.Updated             = GetDateValNullable(rgs, "DATEUPDATED");
                        rwpt.FieldsReleased      = GetIntVal(rgs, "FIELDSRELEASECOUNT");
                        rwpt.CagesReleased       = GetIntVal(rgs, "CAGESRELEASECOUNT");
                        rwpt.FieldsReleasedToday = GetIntVal(rgs, "RELEASEDFIELDSTODAY");
                        rwpt.CagesReleasedToday  = GetIntVal(rgs, "RELEASEDCAGESTODAY");
                        rwpt.ReleasedFieldsDate  = GetDateValNullable(rgs, "RELEASEDFIELDSDATE");
                        rwpt.ReleasedCagesDate   = GetDateValNullable(rgs, "RELEASEDCAGESDATE");
                        rwpt.Email1 = GetStringValNullable(rgs, "EMAIL1");
                        rwpt.Email2 = GetStringValNullable(rgs, "EMAIL2");
                    }
                    catch (Exception e)
                    {
                        return(RSR.Failed(e));
                    }

                    return(RSR.Success());
                }
Пример #2
0
                /* C S V  M A K E */

                /*----------------------------------------------------------------------------
                *       %%Function: CsvMake
                *       %%Qualified: RwpSvc.Practice:Teams:CsvTeams.CsvMake
                *       %%Contact: rlittle
                *
                *  ----------------------------------------------------------------------------*/
                public string CsvMake(RwpTeam rwpt)
                {
                    Dictionary <string, string> mpColData = new Dictionary <string, string>();

                    mpColData.Add("TeamName", rwpt.Name);
                    mpColData.Add("Division", rwpt.Division);
                    mpColData.Add("PW", rwpt.Password);
                    mpColData.Add("DateCreated", DttmValOrNull(rwpt.Created));
                    mpColData.Add("DateUpdated", DttmValOrNull(rwpt.Updated));
                    mpColData.Add("FieldsReleaseCount", rwpt.FieldsReleased.ToString());
                    mpColData.Add("CagesReleaseCount", rwpt.CagesReleased.ToString());
                    mpColData.Add("ReleasedFieldsToday", rwpt.FieldsReleasedToday.ToString());
                    mpColData.Add("ReleasedFieldsDate", DttmValOrNull(rwpt.ReleasedFieldsDate));
                    mpColData.Add("ReleasedCagesToday", rwpt.CagesReleasedToday.ToString());
                    mpColData.Add("ReleasedCagesDate", DttmValOrNull(rwpt.ReleasedCagesDate));
                    mpColData.Add("Email1", StringValOrNull(rwpt.Email1));
                    mpColData.Add("Email2", StringValOrNull(rwpt.Email2));

                    return(CsvMake(mpColData));
                }
Пример #3
0
            /* L O A D  R W P T  F R O M  C S V */

            /*----------------------------------------------------------------------------
            *   %%Function: LoadRwptFromCsv
            *   %%Qualified: RwpSvc.Practice:Teams:CsvTeams.LoadRwptFromCsv
            *   %%Contact: rlittle
            *
            *  ----------------------------------------------------------------------------*/
            public RSR LoadRwptFromCsv(string sLine, TCore.Sql sql, out RwpTeam rwpt, out bool fAdd,
                                       out List <string> plsDiff)
            {
                string[] rgs = LineToArray(sLine);
                SqlWhere sw  = new SqlWhere();

                fAdd    = true;
                rwpt    = new RwpTeam();
                plsDiff = new List <string>();

                sw.AddAliases(RwpTeam.s_mpAliases);
                try
                {
                    rwpt.Name = GetStringVal(rgs, "TEAMNAME");
                    if (rwpt.Name == "")
                    {
                        return(RSR.Success());
                    }

                    rwpt.Division            = GetStringValNullable(rgs, "DIVISION");
                    rwpt.Password            = GetStringValNullable(rgs, "PW");
                    rwpt.Created             = GetDateValNullable(rgs, "DATECREATED");
                    rwpt.Updated             = GetDateValNullable(rgs, "DATEUPDATED");
                    rwpt.FieldsReleased      = GetIntVal(rgs, "FIELDSRELEASECOUNT");
                    rwpt.CagesReleased       = GetIntVal(rgs, "CAGESRELEASECOUNT");
                    rwpt.FieldsReleasedToday = GetIntVal(rgs, "RELEASEDFIELDSTODAY");
                    rwpt.CagesReleasedToday  = GetIntVal(rgs, "RELEASEDCAGESTODAY");
                    rwpt.ReleasedFieldsDate  = GetDateValNullable(rgs, "RELEASEDFIELDSDATE");
                    rwpt.ReleasedCagesDate   = GetDateValNullable(rgs, "RELEASEDCAGESDATE");
                    rwpt.Email1   = GetStringValNullable(rgs, "EMAIL1");
                    rwpt.Email2   = GetStringValNullable(rgs, "EMAIL2");
                    rwpt.Identity = GetStringValNullable(rgs, "IDENTITY");
                    rwpt.Tenant   = GetStringValNullable(rgs, "TENANT");
                }
                catch (Exception e)
                {
                    return(RSR.Failed(e));
                }

                return(RSR.Success());
            }
Пример #4
0
                /* L O A D  R W P T  F R O M  C S V */
                /*----------------------------------------------------------------------------
                    %%Function: LoadRwptFromCsv
                    %%Qualified: RwpSvc.Practice:Teams:CsvTeams.LoadRwptFromCsv
                    %%Contact: rlittle

                ----------------------------------------------------------------------------*/
                public RSR LoadRwptFromCsv(string sLine, TCore.Sql sql, out RwpTeam rwpt, out bool fAdd, out List<string> plsDiff)
                {
                    string []rgs = LineToArray(sLine);
                    SqlWhere sw = new SqlWhere();
                    fAdd = true;
                    rwpt = new RwpTeam();
                    plsDiff = new List<string>();

                    sw.AddAliases(RwpTeam.s_mpAliases);
                    try
                        {
                        rwpt.Name = GetStringVal(rgs, "TEAMNAME");
                        if (rwpt.Name == "")
                            return RSR.Success();

                        sw.Add(String.Format("$$rwllteams$$.TeamName = '{0}'", Sql.Sqlify(rwpt.Name)), SqlWhere.Op.And);
                        SqlReader sqlr = new SqlReader(sql);
                        if (sqlr.FExecuteQuery(sw.GetWhere(RwpTeam.s_sSqlQueryString), _sResourceConnString)
                            && sqlr.Reader.Read())
                            {
                            sqlr.Close();
                            // found a match.  for now, this is an error
                            throw new Exception(String.Format("team name {0} already exists", rwpt.Name));
                            }
                        sqlr.Close();

                        rwpt.Division = GetStringValNullable(rgs, "DIVISION");
                        rwpt.Password = GetStringValNullable(rgs, "PW");
                        rwpt.Created = GetDateValNullable(rgs, "DATECREATED");
                        rwpt.Updated = GetDateValNullable(rgs, "DATEUPDATED");
                        rwpt.FieldsReleased = GetIntVal(rgs, "FIELDSRELEASECOUNT");
                        rwpt.CagesReleased = GetIntVal(rgs, "CAGESRELEASECOUNT");
                        rwpt.FieldsReleasedToday = GetIntVal(rgs, "RELEASEDFIELDSTODAY");
                        rwpt.CagesReleasedToday = GetIntVal(rgs, "RELEASEDCAGESTODAY");
                        rwpt.ReleasedFieldsDate = GetDateValNullable(rgs, "RELEASEDFIELDSDATE");
                        rwpt.ReleasedCagesDate = GetDateValNullable(rgs, "RELEASEDCAGESDATE");
                        rwpt.Email1 = GetStringValNullable(rgs, "EMAIL1");
                        rwpt.Email2 = GetStringValNullable(rgs, "EMAIL2");
                        }
                    catch (Exception e)
                        {
                        return RSR.Failed(e);
                        }

                    return RSR.Success();
                }
Пример #5
0
                /* C S V  M A K E */
                /*----------------------------------------------------------------------------
                    %%Function: CsvMake
                    %%Qualified: RwpSvc.Practice:Teams:CsvTeams.CsvMake
                    %%Contact: rlittle

                ----------------------------------------------------------------------------*/
                public string CsvMake(RwpTeam rwpt)
                {
                    Dictionary<string, string> mpColData = new Dictionary<string, string>();

                    mpColData.Add("TeamName", rwpt.Name);
                    mpColData.Add("Division", rwpt.Division);
                    mpColData.Add("PW", rwpt.Password);
                    mpColData.Add("DateCreated", DttmValOrNull(rwpt.Created));
                    mpColData.Add("DateUpdated", DttmValOrNull(rwpt.Updated));
                    mpColData.Add("FieldsReleaseCount", rwpt.FieldsReleased.ToString());
                    mpColData.Add("CagesReleaseCount", rwpt.CagesReleased.ToString());
                    mpColData.Add("ReleasedFieldsToday", rwpt.FieldsReleasedToday.ToString());
                    mpColData.Add("ReleasedFieldsDate", DttmValOrNull(rwpt.ReleasedFieldsDate));
                    mpColData.Add("ReleasedCagesToday", rwpt.CagesReleasedToday.ToString());
                    mpColData.Add("ReleasedCagesDate", DttmValOrNull(rwpt.ReleasedCagesDate));
                    mpColData.Add("Email1", StringValOrNull(rwpt.Email1));
                    mpColData.Add("Email2", StringValOrNull(rwpt.Email2));

                    return CsvMake(mpColData);
                }
Пример #6
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());
            }