// ----------------------------------------------------------------------------------------
 /// <summary>
 ///      Formats a table horizontally with column names across the top and rows vertically
 ///      if horizontal is true (or the opposite if horozontal is false)
 /// </summary>
 /// <param name="dt"></param>
 /// <param name="horizontal">if true: columns horizontally, rows vertically</param>
 /// <returns></returns>
 private static string PrettyPrintTable(RichDataTable dt, bool horizontal)
 {
     // go through the columns
     // insert spaces in the headers
     // find the longest column name
     // show the value and the header for those with values
     // print vertically
     return("");
 }
Exemple #2
0
        // ----------------------------------------------------------------------------------------
        /// <!-- RichDataTable_Distinct_test -->
        /// <summary>
        ///
        /// </summary>
        public void RichDataTable_Distinct_test()
        {
            Assert.ThingsAbout("RichDataTable", "Distinct");

            RichDataTable rt   = SimpleTestTable();
            List <object> list = rt.Distinct("Age");

            Assert.That(list.Count, Is.equal_to, 2);

            _result += Assert.Conclusion;
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- FindDsmCodesLike -->
        /// <summary>
        ///
        /// </summary>
        /// <param name="keyword"></param>
        /// <param name="all"></param>
        /// <returns></returns>
        private static RichDataTable FindDsmCodesLike(string keyword, RichDataTable all)
        {
            int id = TreatAs.IntValue(keyword, 0);

            string whereClause = "    ConditionName    LIKE '%" + keyword + "%'"
                                 + " OR ConditionCode4TR LIKE  '" + keyword + "%'"
                                 + " OR ConditionCode5   LIKE  '" + keyword + "%'"
            ;

            return(all._Select(whereClause));
        }
Exemple #4
0
        // ----------------------------------------------------------------------------------------
        /// <!-- RichDataTable_Split_test -->
        /// <summary>
        ///
        /// </summary>
        public void RichDataTable_Split_test()
        {
            Assert.ThingsAbout("RichDataTable", "Split");


            RichDataTable        rt    = SimpleTestTable();
            List <RichDataTable> table = rt._Split("Age");

            Assert.That(table.Count, Is.equal_to, 2);

            _result += Assert.Conclusion;
        }
Exemple #5
0
        // ----------------------------------------------------------------------------------------
        /// <!-- SimpleTestTable -->
        /// <summary>
        ///      Returns a simple two column thre row table for testing various Data methods
        /// </summary>
        /// <returns></returns>
        private static RichDataTable SimpleTestTable()
        {
            RichDataTable rt = new RichDataTable();

            rt.Add("Name", typeof(string));
            rt.Add("Age", typeof(int));
            int row;

            row = rt.Add(); rt.Rows[row]["Name"] = "Fred";    rt.Rows[row]["Age"] = 26;
            row = rt.Add(); rt.Rows[row]["Name"] = "Jon";     rt.Rows[row]["Age"] = 48;
            row = rt.Add(); rt.Rows[row]["Name"] = "Melinda"; rt.Rows[row]["Age"] = 26;
            return(rt);
        }
Exemple #6
0
        // ----------------------------------------------------------------------------------------
        /// <!-- RichDataTable_Copy_test -->
        /// <summary>
        ///
        /// </summary>
        public void RichDataTable_Copy_test()
        {
            Assert.ThingsAbout("RichDataTable", "Copy");

            RichDataTable rt  = SimpleTestTable();
            RichDataTable rt2 = rt.Copy();
            int           row = rt.Count - 1;

            Assert.That(rt2.StrValue(row, 0, "b"), Is.equal_to, rt2.StrValue(row, 0, "a"));
            Assert.That(rt2.IntValue(row, 1, 1), Is.equal_to, rt2.IntValue(row, 1, 0));

            _result += Assert.Conclusion;
        }
 // ----------------------------------------------------------------------------------------
 /// <!-- AddSsnFinal4 -->
 /// <summary>
 ///      Adds a column to the table contining the final N digits of the SSN
 /// </summary>
 /// <param name="table">the table to change</param>
 /// <param name="columnFrom">the current ssn column</param>
 /// <param name="columnTo">the (new) column to put the ssn final 4 in</param>
 /// <returns></returns>
 public static RichDataTable AddSsnFinalN(RichDataTable table, int num, string columnFrom, string columnTo)
 {
     table.Add(columnTo, typeof(string));
     for (int row = 0; row < table.Count; ++row)
     {
         if (num > 0)
         {
             string str = table.StrValue(row, columnFrom, "");
             //string lastX = Regex.Replace(str, "^.*(.{" + num + "})$", "$1");
             string lastX = __.LastNChars(num, str);
             table.Rows[row][columnTo] = lastX;
         }
     }
     return(table);
 }
        // ----------------------------------------------------------------------------------------
        /// <!-- NameSourceList -->
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public static RichDataTable NameSourceList()
        {
            RichDataTable source = new RichDataTable("DsmCodeSource", "Id");

            source.Add("Id", typeof(string));
            source.Add("Source", typeof(string));


            source.Add("Id", "DSM4", "Source", "Official DSM4");
            source.Add("Id", "DSMV", "Source", "Official DSMV");
            source.Add("Id", "Both DSM4 & DSMV", "Source", "Both DSM4 & DSMV");
            source.Add("Id", "Alternate", "Source", "Alternate");
            source.Add("Id", "BHAS App Input", "Source", "BHAS App Input");
            source.Add("Id", "Unknown", "Source", "Unknown");

            return(source);
        }
Exemple #9
0
        // ----------------------------------------------------------------------------------------
        /// <!-- RichDataTable_Add_test -->
        /// <summary>
        ///
        /// </summary>
        public void RichDataTable_Add_test()
        {
            Assert.ThingsAbout("RichDataTable", "Add");

            RichDataTable rt  = SimpleTestTable();
            RichDataTable rt2 = rt.Clone();

            Assert.That(rt2.Columns[1].ColumnName, Is.equal_to, rt.Columns[1].ColumnName);

            rt2.Add(1, rt); // _CopyRowToTable(1, rt2);
            rt2.Add(0, rt); // _CopyRowToTable(0, rt2);
            int age1 = rt.IntValue(1, 1, 1);
            int age2 = rt2.IntValue(0, 1, 2);

            Assert.That(age2, Is.equal_to, age1);
            string name1 = rt.StrValue(0, 0, "a");
            string name2 = rt2.StrValue(1, 0, "b");

            Assert.That(name2, Is.equal_to, name1);

            _result += Assert.Conclusion;
        }
        // ----------------------------------------------------------------------------------------
        /// <!-- UnpackErrorMessages -->
        /// <summary>
        ///      Extracts the messages, sources and types from an exception
        /// </summary>
        /// <param name="ex"></param>
        /// <returns></returns>
        /// <remarks>
        ///      Moved from GlobalConstants
        ///
        ///      beta code
        /// </remarks>
        public static string Unpack(Exception ex)
        {
            string err = "";

            if (ex != null)
            {
                Exception e = ex;


                // ----------------------------------------------------------------------
                //  Interpretation header
                // ----------------------------------------------------------------------
                Type exType = ex.GetType();
                //  Start by saying 'you did nothing wrong' in case this ever reaches a user
                //string intro = "You did nothing wrong, ";
                string intro = "";
                string cr    = "\r\n";


                switch (exType.Name)
                {
                case "ActivationException":
                    err  = intro + "the program or data has experienced an anomaly masked by a web configuration problem:";
                    err += cr + " ---> " + ex.Message;
                    break;

                case "SqlException":
                    err  = intro + "an internal sql command has experienced an anomaly when run on the database:";
                    err += cr + " ---> " + ex.Message;
                    break;

                default:
                    err = intro + "anomaly message: " + ex.Message;
                    break;
                }


                // ----------------------------------------------------------------------
                //  Standard header
                // ----------------------------------------------------------------------
                err += cr;
                int width = 120;


                // ----------------------------------------------------------------------
                //  Unpack the exception and inner exception messages
                // ----------------------------------------------------------------------
                string delim = "";
                while (ex != null)
                {
                    RichDataTable dt = new RichDataTable(ex, "Exception", false, ""); dt.Add(ex);
                    exType = ex.GetType();


                    err += cr + "+-" + "---------------------------------------".PadRight(width - 3, '-') + "+";
                    err += cr + "| " + ("Exception Type:        " + exType.Name).PadRight(width - 3) + "|";
                    err += cr + "| " + dt.PrettyFormatRow(0, width - 3, "|\r\n| ") + "|";
                    err += cr + "+-" + "---------------------------------------".PadRight(width - 3, '-') + "+";


                    delim = cr + cr + "  <--" + cr + cr;
                    ex    = ex.InnerException;
                }


                // ----------------------------------------------------------------------
                //  Add a nice footer (stacktrace)
                // ----------------------------------------------------------------------
                err += cr + "|".PadRight(width - 1) + "|";
                err += cr + "|".PadRight(width - 1) + "|";
                err += cr + "|Stack Trace:".PadRight(width - 1) + "|";
                err += cr + __.PrettyPrintStackTrace(e.StackTrace, width);
            }
            return(err);
        }