示例#1
0
        public void testEncoding()
        {
            StagingTable table = _STAGING.getTable("serum_alb_pretx_level_58159");

            Assert.IsNotNull(table);

            // the notes of this table contain UTF-8 characters, specifically the single quote character in this phrase: "You may use a physician’s statement"

            // converting to UTF-8 should change nothing
            String OrigNotes = table.getNotes();

            byte[] utf8Bytes = Encoding.UTF8.GetBytes(OrigNotes);
            char[] utf8Chars = new char[Encoding.UTF8.GetCharCount(utf8Bytes, 0, utf8Bytes.Length)];
            Encoding.UTF8.GetChars(utf8Bytes, 0, utf8Bytes.Length, utf8Chars, 0);
            string utf8String = new string(utf8Chars);

            Assert.AreEqual(table.getNotes(), utf8String);


            // converting to other encoding should change the text
            byte[] asciiBytes = Encoding.ASCII.GetBytes(OrigNotes);
            char[] asciiChars = new char[Encoding.ASCII.GetCharCount(asciiBytes, 0, asciiBytes.Length)];
            Encoding.ASCII.GetChars(asciiBytes, 0, asciiBytes.Length, asciiChars, 0);
            string asciiString = new string(asciiChars);

            Assert.AreNotEqual(table.getNotes(), asciiString);
        }
        private void Setup()
        {
            int        iNumColumnsUsed       = 0;
            List <int> lstDescriptionColumns = new List <int>();
            String     sColumnName           = "";
            String     sColumnLabel          = "";

            StagingTable thisTable = mStaging.getTable(msTableId);

            //String sVariableTitle = thisTable.getTitle();
            //String sVariableSubtitle = thisTable.getSubtitle();

            Text = msInputVar;

            // Convert the notes, which are in MarkDown, to HTML
            String sNotes = thisTable.getNotes();

            if (sNotes == null)
            {
                sNotes = "";
            }
            CommonMark.CommonMarkSettings settings = CommonMark.CommonMarkSettings.Default.Clone();
            settings.RenderSoftLineBreaksAsLineBreaks = true;
            String result = CommonMark.CommonMarkConverter.Convert(sNotes, settings);

            result = result.Replace("<p>", "<p style=\"font-family=Microsoft Sans Serif;font-size:11px\">");
            webBrPickerNotes.DocumentText = result;


            // Set the rows to auto size to view the contents of larger text cells
            dataGridViewPicker.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

            // Obtain the number of columns and rows for the table
            List <IColumnDefinition> lstColDefs = thisTable.getColumnDefinitions();
            StagingColumnDefinition  thisColDef = null;
            int        iNumColumns = 0;
            int        iNumRows    = 0;
            ColumnType cType       = 0;

            if (thisTable.getRawRows() != null)
            {
                iNumRows = thisTable.getRawRows().Count;
            }
            if (lstColDefs != null)
            {
                iNumColumns = lstColDefs.Count;
                for (int iColIndex = 0; iColIndex < lstColDefs.Count; iColIndex++)
                {
                    thisColDef = (StagingColumnDefinition)lstColDefs[iColIndex];

                    // Get the column type.  If the type is "INPUT" OR "DESCRIPTION", then display the column.  Otherwise skip it.
                    cType = thisColDef.getType();
                    if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION))
                    {
                        // Add a new column to the table data view
                        sColumnName  = "ColumnName";
                        sColumnName += iColIndex;
                        sColumnLabel = thisColDef.getName();
                        dataGridViewPicker.Columns.Add(sColumnName, sColumnLabel);
                        iNumColumnsUsed++;

                        // keep track of descrption columns
                        if (cType == ColumnType.DESCRIPTION)
                        {
                            lstDescriptionColumns.Add(iColIndex);
                        }

                        // Need to keep track of the first INPUT column.  That column contains the information we pass back if a user
                        // selects the row or cell.
                        if ((cType == ColumnType.INPUT) && (miInputCol == -1))
                        {
                            miInputCol = iNumColumnsUsed - 1;
                        }

                        dataGridViewPicker.Columns[iNumColumnsUsed - 1].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                        dataGridViewPicker.Columns[iNumColumnsUsed - 1].SortMode = DataGridViewColumnSortMode.NotSortable;
                    }
                }
            }


            // Set the widths of the columns in the datagridview.  Set the input column to be small and the description columns to be large
            //  We do this so that if we only have an input and description will fill the entire grid view (no veritical scrolling).
            //  If we have 2 or more desription fields, then we need to fit them all in.
            //
            int iWidthDivisor  = 0;
            int iViewableWidth = dataGridViewPicker.Width - 50; // remove size of input column

            if (iNumColumnsUsed > 1)
            {
                iWidthDivisor = (int)((double)iViewableWidth / (double)(iNumColumnsUsed - 1));
            }
            else
            {
                iWidthDivisor = 300;
            }
            for (int i = 0; i < dataGridViewPicker.Columns.Count; i++)
            {
                if (i == miInputCol)
                {
                    if (iNumColumnsUsed == 1)
                    {
                        dataGridViewPicker.Columns[i].Width = 300;
                    }
                    else
                    {
                        dataGridViewPicker.Columns[i].Width = 50;
                    }
                }
                else
                {
                    dataGridViewPicker.Columns[i].Width = iWidthDivisor;
                }
            }

            // Now loop through the table rows and add each cell to the table
            String sCellValue = "";

            for (int iRowIndex = 0; iRowIndex < iNumRows; iRowIndex++)
            {
                dataGridViewPicker.RowCount++;
                dataGridViewPicker.Rows[iRowIndex].Height = 40;

                for (int iColIndex = 0; iColIndex < iNumColumns; iColIndex++)
                {
                    thisColDef = (StagingColumnDefinition)lstColDefs[iColIndex];
                    cType      = thisColDef.getType();

                    if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION))
                    {
                        sCellValue = thisTable.getRawRows()[iRowIndex][iColIndex];
                        dataGridViewPicker[iColIndex, iRowIndex].Value = sCellValue;
                    }
                }
            }

            // See if there are two or more description fields.  If so, see if we can find one
            // that has a label of "Description"
            miDescriptionColumn = -1;
            if (lstDescriptionColumns.Count > 1)
            {
                sColumnLabel = "";
                for (int iColIndex = 0; iColIndex < lstDescriptionColumns.Count; iColIndex++)
                {
                    sColumnLabel = ((StagingColumnDefinition)lstColDefs[lstDescriptionColumns[iColIndex]]).getName();
                    if (sColumnLabel == "Description")
                    {
                        miDescriptionColumn = lstDescriptionColumns[iColIndex];
                    }
                }
                if (miDescriptionColumn == -1)
                {
                    miDescriptionColumn = lstDescriptionColumns[0];
                }
            }
            else if (lstDescriptionColumns.Count == 0)
            {
                miDescriptionColumn = 0;  // for tables that do not have a description.  point to the code
            }
            else
            {
                miDescriptionColumn = lstDescriptionColumns[0];
            }
        }
示例#3
0
        public dlgTable(Staging pStaging, String sSchemaName, String sTableId)
        {
            InitializeComponent();

            mStaging     = pStaging;
            msSchemaName = sSchemaName;
            msTableId    = sTableId;

            lblSchemaName.Text  = msSchemaName;
            lblTableId.Text     = msTableId;
            lblTableName.Text   = "";
            lblTitle.Text       = "";
            lblSubtitle.Text    = "";
            lblDescription.Text = "";
            //webBrTableNotes.DocumentText = "";

            StagingTable thisTable = mStaging.getTable(msTableId);

            if (thisTable != null)
            {
                lblTableName.Text   = thisTable.getName();
                lblTitle.Text       = thisTable.getTitle();
                lblSubtitle.Text    = thisTable.getSubtitle();
                lblDescription.Text = thisTable.getDescription();

                String sNotes = thisTable.getNotes();
                if (sNotes == null)
                {
                    sNotes = "";
                }

                CommonMark.CommonMarkSettings settings = CommonMark.CommonMarkSettings.Default.Clone();
                settings.RenderSoftLineBreaksAsLineBreaks = true;
                String result = CommonMark.CommonMarkConverter.Convert(sNotes, settings);
                result = result.Replace("<p>", "<p style=\"font-family=Microsoft Sans Serif;font-size:11px\">");
                webBrTableNotes.DocumentText = result;

                // Set the rows to auto size to view the contents of larger text cells
                dataGridViewTable.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;

                // Obtain the number of columns and column labels for the table
                String     ColumnName  = "";
                String     ColumnLabel = "";
                ColumnType cType       = 0;
                int        iInputCol   = 0;

                List <IColumnDefinition> cols       = thisTable.getColumnDefinitions();
                StagingColumnDefinition  thisColDef = null;
                int iNumColumns = 0;
                int iNumRows    = 0;
                if (thisTable.getRawRows() != null)
                {
                    iNumRows = thisTable.getRawRows().Count;
                }
                if (cols != null)
                {
                    iNumColumns = cols.Count;
                    //int iNumRows = TNMStage_get_table_num_rows(sAlgorithmName.c_str(), sAlgorithmVersion.c_str(), strptrTableId);
                    for (int iColIndex = 0; iColIndex < cols.Count; iColIndex++)
                    {
                        thisColDef = (StagingColumnDefinition)cols[iColIndex];
                        // Add a new column to the table data view
                        ColumnName  = "ColumnName" + iColIndex + thisColDef.getName();
                        ColumnLabel = thisColDef.getName();
                        dataGridViewTable.Columns.Add(ColumnName, ColumnLabel);

                        // Get the column type.  If the type is "INPUT" OR "DESCRIPTION", then display the column.  Otherwise skip it.
                        cType = thisColDef.getType();
                        if ((cType == ColumnType.INPUT) && (iInputCol == -1))
                        {
                            iInputCol = iColIndex;
                        }
                    }
                }

                // Set widths of columns and their text wrap mode
                int iViewableWidth = dataGridViewTable.Width;
                int iWidthDivisor  = 0;
                if (iInputCol >= 0)
                {
                    iViewableWidth = dataGridViewTable.Width - 120; // remove size of input column
                }
                if (iNumColumns > 1)
                {
                    iWidthDivisor = (int)((double)iViewableWidth / (double)(iNumColumns - 1));
                }
                else
                {
                    iWidthDivisor = 300;
                }

                for (int i = 0; i < dataGridViewTable.Columns.Count; i++)
                {
                    if (i == iInputCol)
                    {
                        if (dataGridViewTable.Columns.Count == 1)
                        {
                            dataGridViewTable.Columns[i].Width = iWidthDivisor;
                        }
                        else
                        {
                            dataGridViewTable.Columns[i].Width = 100;
                        }
                    }
                    else
                    {
                        dataGridViewTable.Columns[i].Width = iWidthDivisor;
                    }
                    dataGridViewTable.Columns[i].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
                    dataGridViewTable.Columns[i].SortMode = DataGridViewColumnSortMode.NotSortable;
                }

                // Now loop through the table rows and add each cell to the table
                List <String> thisRow   = null;
                String        CellValue = "";
                for (int iRowIndex = 0; iRowIndex < iNumRows; iRowIndex++)
                {
                    dataGridViewTable.RowCount++;
                    dataGridViewTable.Rows[iRowIndex].Height = 40;

                    thisRow = null;
                    if (thisTable.getRawRows() != null)
                    {
                        thisRow = thisTable.getRawRows()[iRowIndex];
                    }


                    for (int iColIndex = 0; iColIndex < iNumColumns; iColIndex++)
                    {
                        thisColDef = (StagingColumnDefinition)cols[iColIndex];
                        // Get the column type.  If the type is "INPUT" OR "DESCRIPTION", then display the column.  Otherwise skip it.
                        cType = thisColDef.getType();

                        CellValue = "";
                        if (thisRow.Count > iColIndex)
                        {
                            CellValue = thisRow[iColIndex];
                        }
                        if ((cType == ColumnType.INPUT) || (cType == ColumnType.DESCRIPTION))
                        {
                            // Nothing to do here - just display the string obtained from the DLL
                            dataGridViewTable[iColIndex, iRowIndex].Value = CellValue;

                            if (cType == ColumnType.INPUT)
                            {
                                dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                            }
                            else
                            {
                                dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.TopLeft;
                            }
                        }
                        else if (cType == ColumnType.ENDPOINT)   // has to be TNM_COLUMN_ENDPOINT
                        {
                            // Endpoints need a small text adjustment in order to make the viewing a little nicer
                            // You need to remove the "VALUE:" string at the beginning of the string
                            if (CellValue.StartsWith("VALUE:"))
                            {
                                CellValue = CellValue.Replace("VALUE:", "");
                            }
                            dataGridViewTable[iColIndex, iRowIndex].Value = CellValue;

                            dataGridViewTable.Columns[iColIndex].DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;
                        }
                    }
                }
            }
        }