Beispiel #1
0
        public void DynamicStuff()
        {
            int curCol = 0;
            _detailRow = _dataSources[0].Rows[0];
            _detailRow.BeginEdit();

            for (int i = 0; i < _columnNames.Count; i++)
            {
                string columnName = _columnNames[i];

                Label label1 = new Label();
                label1.Text = columnName.ToString();
                _table.Controls.Add(label1, curCol, i);

                //Primary key field assumed column 1 show label
                if (i == 0)
                {
                    label1 = new Label();
                    label1.Text = _detailRow[i].ToString();
                    _table.Controls.Add(label1, curCol + 1, i);
                    continue;
                }

                var drSpecial = _metaList.Find(x => x.FieldName == columnName);

                if (drSpecial != null)
                {
                    ColumnMetaData m = new ColumnMetaData();

                    if (drSpecial.ControlType.Contains("DropDownList"))
                    {
                        int resultTableIndex = 0;
                        int.TryParse(drSpecial.ControlType.Split(',')[1], out resultTableIndex);

                        ComboBox cmb = new ComboBox();
                        cmb.DataBindings.Add("Text", _dataSources[0], columnName);

                        foreach (DataRow item in _dataSources[resultTableIndex].Rows)
                        {
                            cmb.Items.Add(item["Text"].ToString());
                        }

                        cmb.SelectedText = _detailRow[i].ToString();

                        _table.Controls.Add(cmb, drSpecial.ColumnPosition + 1, i);
                    }
                }
                else //Just use standard textbox for input.
                {
                    TextBox textbox1 = new TextBox();

                    //Use BeginEdit and EndEdit on data table to change row state
                    //
                    //http://stackoverflow.com/q/14000592/139698
                    //http://www.pcreview.co.uk/forums/databinding-datarow-t1244411.html
                    textbox1.DataBindings.Add("Text", _dataSources[0], columnName);
                    textbox1.Text = _detailRow[i].ToString();
                    _table.Controls.Add(textbox1, curCol + 1, i);
                }
            }
        }
Beispiel #2
0
        public static DataPayload GetRecord(string tableName, string fieldKey, string recordKey)
        {
            string queryString = string.Format(
            @"

            --Detail Row
            SELECT * FROM {0} WHERE {1}=@search;

            --Supporting Data for detail page.
            DECLARE @tableName NVARCHAR(50) = 'Customers'
            DECLARE @stmt NVARCHAR(MAX);

            SELECT * FROM SpecialTable1 WHERE TableName = @tableName;

            DECLARE @SqlStatementCursor CURSOR
            SET @SqlStatementCursor = CURSOR FAST_FORWARD
            FOR
            SELECT SqlStatements
            FROM SpecialTable1 WHERE TableName = @tableName;
            OPEN @SqlStatementCursor
            FETCH NEXT FROM @SqlStatementCursor
            INTO @stmt
            WHILE @@FETCH_STATUS = 0
            BEGIN

            EXEC (@stmt)

            FETCH NEXT FROM @SqlStatementCursor
            INTO @stmt
            END
            CLOSE @SqlStatementCursor
            DEALLOCATE @SqlStatementCursor

            ", tableName, fieldKey);

            List<DataTable> list = GetDatabaseRecords(queryString, recordKey);

            List<ColumnMetaData> meta = new List<ColumnMetaData>();

            DataTable dt1 = list[1];
            //dt1.PrimaryKey = new DataColumn[] { dt1.Columns["FieldName"] };

            List<string> columnNames = new List<string>();

            //How do I get column names to print in this C# program?
            //http://stackoverflow.com/a/2557943/139698
            foreach (DataColumn item in list[0].Columns)
            {
                columnNames.Add(item.ColumnName);
            }

            foreach (DataRow dr in dt1.Rows)
            {
                ColumnMetaData c = new ColumnMetaData();
                c.FieldName = dr["FieldName"].ToString();
                int colPos = 0;
                int.TryParse(dr["ColumnPosition"].ToString(), out colPos);
                c.ColumnPosition = colPos;
                int rowPos = 0;
                int.TryParse(dr["RowPosition"].ToString(), out rowPos);
                c.RowPosition = rowPos;
                c.ControlType = dr["ControlType"].ToString();
                meta.Add(c);
            }

            DataPayload dataPayload = new DataPayload();
            dataPayload.DataSources = list;
            dataPayload.MetaList = meta;
            dataPayload.ColumnNames = columnNames;

            return dataPayload;
        }