public IGenDataset Clone()
        {
            IGenDataset _cloneToDataset = new IGenDataset();

            try
            {
                // clone this properties to the passed dataset
                _cloneToDataset.cursorName = this.cursorName;
                _cloneToDataset.sql = this.sql;
                _cloneToDataset.fieldNames = this.fieldNames;
                _cloneToDataset.cursor = this.cursor;
                _cloneToDataset.pages = new List<IGenPage>();
                _cloneToDataset.results = this.results;
                _cloneToDataset.numRows = this.numRows;
                _cloneToDataset.currentPosition = this.currentPosition;
                _cloneToDataset.currentPageNo = this.currentPageNo;
                _cloneToDataset.createSymbolics = this.createSymbolics;
                _cloneToDataset.referenceDatasetOrdinal = this.referenceDatasetOrdinal;
                _cloneToDataset.pageBreak = this.pageBreak;
                _cloneToDataset.eof = this.eof;
                _cloneToDataset.bof = this.bof;
            }
            catch (Exception ex)
            {
                CommonRoutines.DisplayErrorMessage("$E:" + moduleName + ".Clone > " + ex.Message);
            }

            return _cloneToDataset;
        }
        /// <summary>
        /// int SelectCursor(string connectionString, string cursorName, string sql, bool loadCollection)
        /// Open a cursor for the passed sql on the passed connection
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public IGenDataset SelectCursor(string connectionString, string cursorName, string sql, bool loadCollection)
        {
            DataTable _dt = new DataTable();
            int _numRows = 0;
            int cursorOrdinal = -1;
            IGenDataset _cursor = new IGenDataset();

            try
            {
                if (sql.Trim() != "")
                {
                    lastConnection = connectionString;

                    // open the connection
                    using (SqlConnection _connection = new SqlConnection(connectionString))
                    {
                        _connection.Open();
                        // get the recordset
                        SqlCommand _cmd = _connection.CreateCommand();
                        _cmd.CommandText = sql;

                        // open an adapter and fill it
                        using (SqlDataAdapter _sda = new SqlDataAdapter(_cmd))
                        {
                            _sda.Fill(_dt);
                            _numRows = _dt.Rows.Count;
                            // fill in the structure
                            _cursor.cursorName = cursorName;
                            _cursor.dataAdapter = _sda;
                            _cursor.dataTable = _dt;
                            _cursor.numRows = _numRows;

                            if (_numRows > 0)
                            {
                                _cursor.currentPosition = 1;
                            }

                            _cursor.results = new List<string[]>();
                            // fill the fieldnames
                            if (_numRows > 0)
                            {
                                List<string> _fieldNames = new List<string>();

                                for (int n = 0; n < _dt.Columns.Count; n++)
                                {
                                    _fieldNames.Add(_dt.Columns[n].ColumnName);
                                }
                                _cursor.results.Add(_fieldNames.ToArray());
                            }

                            if (loadCollection && _numRows > 0)
                            {
                                for (int n = 0; n < maxRowsInCollection; n++)
                                {
                                    // see if the max rows have been reached
                                    if (n < _numRows)
                                    {
                                        List<string> _fieldValues = new List<string>();
                                        for (int m = 0; m < _dt.Columns.Count; m++)
                                        {
                                            _fieldValues.Add(_dt.Rows[n][m].ToString());
                                        }
                                        _cursor.results.Add(_fieldValues.ToArray());
                                    }
                                    else
                                    {
                                        break;
                                    }
                                }

                                //_cursor.numRows = _cursor.results.Count;
                            }
                        }

                        lastStatusMessage = "Success";
                        lastStatusCode = "0";
                        lastStatus = true;
                    }
                }
            }
            catch (Exception ex)
            {
                //LAP 20130506 Include SQL in error message
                CommonRoutines.DisplayErrorMessage("$E:" + moduleName + ".SelectCursor(s,s,s,b) > " + ex.Message + System.Environment.NewLine + " > SQL:  " + sql);
                lastStatus = false;
                lastStatusCode = "-999";
                lastStatusMessage = ex.Message;
            }

            return _cursor;
        }
        /// <summary>
        /// _cursor SelectCursor(string connectionString, string cursorName, string sql, bool loadCollection)
        /// Open a cursor for the passed sql on the passed connection
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public IGenDataset SelectCursor(string connectionString, string cursorName, string sql)
        {
            IGenDataset _cursor = new IGenDataset();

            try
            {
                _cursor = SelectCursor(connectionString, cursorName, sql, true);
            }
            catch (Exception ex)
            {
                //LAP 20130506 Include SQL in error message
                CommonRoutines.DisplayErrorMessage("$E:" + moduleName + ".SelectCursor(s,s,s) > " + ex.Message + System.Environment.NewLine + " > SQL:  " + sql);
                lastStatus = false;
                lastStatusCode = "-999";
                lastStatusMessage = ex.Message;
            }

            return _cursor;
        }
        /// <summary>
        /// string LoadFormGroup(string formFile)
        /// Load the form group
        /// </summary>
        /// <returns></returns>
        public int CreateForms(List<string> xmlRecords)
        {
            int _numForms = 0;
            string _tagName = "";
            string _tagValue = "";
            bool _formFlag = false;
            bool _fieldFlag = false;
            bool _ruleFlag = false;
            bool _datasetFlag = false;
            IGenForm _form = null;
            IGenField _field = null;
            IGenDataset _dataset = null;
            string _formGroupPath = "";
            bool _variableFlag = false;
            string _variableName = "";
            string _variableValue = "";

            try
            {
                // clear the forms collection
                forms.Clear();

                // clear the datasets
                datasets.Clear();

                // walk the XML and create the entities
                for (int _recNo=0;_recNo < xmlRecords.Count;_recNo++)
                //foreach (string _xmlRecord in xmlRecords)
                {
                    string _xmlRecord = xmlRecords[_recNo];

                    // parse the string
                    int _offset = _xmlRecord.IndexOf('=');
                    if (_offset > 0)
                    {
                        _tagName = _xmlRecord.Substring(0, _offset);
                        _tagValue = _xmlRecord.Substring(_offset + 1);
                    }
                    else
                    {
                        _tagName = _xmlRecord;
                        _tagValue = "";
                    }

                    _tagName = _tagName.Trim().ToUpper();
                    _tagValue = _tagValue.Trim();

                    if (_tagName != "")
                    {
                        // process the tag
                        switch (_tagName)
                        {

                            case "FORMGROUPPATH":
                                _formGroupPath = _tagValue;
                                break;

                            case "FORMS":
                                _formFlag = false;
                                _fieldFlag = false;
                                _ruleFlag = false;
                                _form = null;
                                break;

                            case "FORM":
                                _formFlag = true;
                                _fieldFlag = false;
                                _ruleFlag = false;
                                // create a form object
                                _form = new IGenForm();
                                _form.formGroupPath = _formGroupPath;
                                forms.Add(_form);
                                break;

                            case "FIELDS":
                                _formFlag = false;
                                _fieldFlag = false;
                                _ruleFlag = false;
                                _field = null;
                                break;

                            case "FIELD":
                                _formFlag = false;
                                _fieldFlag = true;
                                _ruleFlag = false;
                                _field = new IGenField();
                                _field.parentFormName = _form.name;
                                // add it
                                _form.AddField(_field);
                                break;

                            case "FONT":
                                break;

                            case "/FONT":
                                break;

                            case "PROPERTIES":
                                break;

                            case "/PROPERTIES":
                                break;

                            case "RULES":
                                break;

                            case "/RULES":
                                break;

                            case "RULE":
                                break;

                            case "/RULE":
                                break;

                            case "VARIABLES":
                                _variableFlag = true;
                                break;

                            case "/VARIABLES":
                                _variableFlag = false;
                                break;

                            case "VARIABLE":
                                break;

                            case "/VARIABLE":
                                // write the variable to the csa properties
                                if (_variableName != "")
                                {
                                    formVariables.Add(new string[] { _variableName, _variableValue });
                                }
                                break;

                            case "/FIELD":
                                _formFlag = false;
                                _fieldFlag = false;
                                _ruleFlag = false;
                                break;

                            case "/FORM":
                                _formFlag = false;
                                _fieldFlag = false;
                                _ruleFlag = false;
                                break;

                            case "/FORMS":
                                break;

                            // not the attribute tags
                            case "GROUP":
                                formGroupName = _tagValue;
                                break;

                            case "VERSION":
                                formGroupVersion = _tagValue;
                                break;

                            case "DATASOURCE":
                                // see if this datasource is valid by checking the connection pool.
                                originalDataSource = _tagValue;
                                dataSource = "";
                                for (int n = 0; n < DatabaseRoutines.connectionObjects.Count; n++)
                                {
                                    if (DatabaseRoutines.connectionObjects[n].connectionString.ToUpper() == _tagValue.ToUpper())
                                    {
                                        dataSource = _tagValue;
                                        break;
                                    }
                                }
                                // if datasource is blank, default to main connection
                                if (dataSource == "")
                                {
                                    dataSource = DatabaseRoutines.MainConnection;
                                }
                                break;

                            case "GROUPDATASET":
                                datasetName = "";
                                if (_tagValue != "")
                                {
                                    _dataset = new IGenDataset();
                                    _dataset.cursorName = formGroupName;
                                    datasetName = formGroupName;
                                    _dataset.sql = _tagValue;
                                    datasets.Add(_dataset);
                                    _dataset = new IGenDataset();
                                }
                                break;

                            case "FORMDATASET":
                                if (_formFlag)
                                {
                                    _form.datasetName = "";
                                    if (_tagValue != "")
                                    {
                                        _dataset = new IGenDataset();
                                        _dataset.cursorName = _form.name;
                                        _form.datasetName = _form.name;
                                        _dataset.sql = _tagValue;
                                        datasets.Add(_dataset);
                                        _dataset = new IGenDataset();
                                    }
                                }
                                break;

                            case "DATASET":
                                _datasetFlag = true;
                                _dataset = new IGenDataset();
                                break;

                            case "/DATASET":
                                _datasetFlag = false;
                                // add to the dataset collection
                                datasets.Add(_dataset);
                                _dataset = new IGenDataset();
                                break;

                            case "SQL":
                                if (_datasetFlag)
                                {
                                    _dataset.sql = _tagValue;
                                }
                                break;

                            case "DATASETNAME":
                                string _datasetName = _tagValue;
                                int _datasetOrdinal = -1;
                                // find it in the group datasets collection
                                for (int n = 0; n < datasets.Count; n++)
                                {
                                    if (datasets[n].cursorName.ToUpper() == _datasetName.ToUpper())
                                    {
                                        _datasetOrdinal = n;
                                        break;
                                    }
                                }
                                if (_formFlag)
                                {
                                    // add it to the datasetname list for the form
                                    _form.datasetOrdinals.Add(_datasetOrdinal);
                                    _form.datasetNames.Add(_datasetName);
                                    if (_form.datasetName == "")
                                    {
                                        // default name is the first one in the xml list
                                        _form.datasetName = _datasetName;
                                        _form.datasetOrdinal = _datasetOrdinal;
                                    }
                                }
                                else
                                {
                                    datasetName = _datasetName;        // for the GDS function
                                    datasetOrdinal = _datasetOrdinal;
                                }
                                break;

                            case "ROWSPERPAGE":
                                if (_formFlag)
                                {
                                    int _rowsPerPage = CommonRoutines.ConvertToInt(_tagValue);
                                    // check to see if this is a multipage form
                                    if (_form.multiPageForm.ToUpper() == "TRUE")
                                    {
                                        if (_rowsPerPage < 1)
                                        {
                                            // give an error!
                                            CommonRoutines.DisplayErrorMessage(_form.name + " - Rows per page must be greater than 0 if a multipage form");
                                        }
                                        else
                                        {
                                            _form.rowsPerPages.Add(_rowsPerPage);
                                            if (_form.rowsPerPage < 0)
                                            {
                                                _form.rowsPerPage = _rowsPerPage;
                                            }
                                        }
                                    }
                                }
                                break;

                            case "/SQL":
                                break;

                            case "IMAGE":
                                if (_formFlag)
                                {
                                    _form.imageName = _tagValue;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.imageName = _tagValue;
                                    }
                                    else
                                    {

                                    }
                                }
                                break;

                            case "COMMENTS":
                                if (_formFlag)
                                {
                                    _form.comments = _tagValue;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.comments = _tagValue;
                                    }
                                    else
                                    {
                                        comments = _tagValue;
                                    }
                                }
                                break;

                            case "NAME":
                                if (_formFlag)
                                {
                                    _form.name = _tagValue;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.name = _tagValue;
                                    }
                                    else
                                    {
                                        if (_datasetFlag)
                                        {
                                            _dataset.cursorName = _tagValue;
                                        }
                                        else
                                        {
                                            if (_variableFlag)
                                            {
                                                _variableName = _tagValue;
                                            }
                                        }
                                    }
                                }
                                break;

                            case "CREATESYMBOLICS":
                                if (_datasetFlag)
                                {
                                    _dataset.createSymbolics = CommonRoutines.ConvertToBool(_tagValue);
                                }
                                break;

                            case "FORMATMASK":
                                if (_formFlag)
                                {
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.formatMask = _tagValue;
                                    }
                                }
                                break;

                            case "VISIBLE":
                                if (_formFlag)
                                {
                                    _form.visible = (_tagValue.ToUpper() == "TRUE") ? true : false;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.visible = (_tagValue.ToUpper() == "TRUE") ? true : false;
                                    }
                                    else
                                    {

                                    }
                                }
                                break;

                            case "FORMTYPE":
                                if (_formFlag)
                                {
                                    _form.formType = _tagValue;
                                }
                                break;

                            case "TITLE":
                                if (_formFlag)
                                {
                                    _form.title = _tagValue;
                                }
                                break;

                            case "MULTIPAGEFORM":
                                if (_formFlag)
                                {
                                    _form.multiPageForm = (_tagValue.ToUpper() == "TRUE") ? "True" : "False";
                                }
                                break;

                            case "PAGEBREAKS":
                                if (_formFlag)
                                {
                                    _form.pageBreaks = _tagValue;
                                }
                                break;

                            case "PROCESSINGORDER":
                                if (_formFlag)
                                {
                                    _form.processingOrder = CommonRoutines.ConvertToInt(_tagValue);
                                    if (_form.processingOrder == 0)
                                    {
                                        _form.processingOrder = 999;
                                    }
                                }
                                break;

                            case "TYPE":
                                if (_fieldFlag)
                                {
                                    _field.type = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "DATATYPE":
                                if (_fieldFlag)
                                {
                                    _field.dataType = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "ALIGNMENT":
                                if (_fieldFlag)
                                {
                                    _field.alignment = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "TOP":
                                if (_fieldFlag)
                                {
                                    _field.top = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "LEFT":
                                if (_fieldFlag)
                                {
                                    _field.left = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "WIDTH":
                                if (_fieldFlag)
                                {
                                    _field.width = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "HEIGHT":
                                if (_fieldFlag)
                                {
                                    _field.height = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "TAG":
                                if (_fieldFlag)
                                {
                                    _field.tag = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "FONTNAME":
                                if (_fieldFlag)
                                {
                                    _field.fontName = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "FONTSIZE":
                                if (_fieldFlag)
                                {
                                    _field.fontSize = CommonRoutines.ConvertToFloat(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "FONTBOLD":
                                if (_fieldFlag)
                                {
                                    _field.fontBold = (_tagValue.ToUpper() == "TRUE") ? true : false; ;
                                }
                                else
                                {

                                }
                                break;

                            case "FONTITALIC":
                                if (_fieldFlag)
                                {
                                    _field.fontItalic = (_tagValue.ToUpper() == "TRUE") ? true : false; ;
                                }
                                else
                                {

                                }
                                break;

                            case "FONTUNDERLINE":
                                if (_fieldFlag)
                                {
                                    _field.fontUnderline = (_tagValue.ToUpper() == "TRUE") ? true : false; ;
                                }
                                else
                                {

                                }
                                break;

                            case "TABINDEX":
                                if (_fieldFlag)
                                {
                                    _field.tabIndex = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "LIST":
                                if (_fieldFlag)
                                {
                                    _field.list = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "VALUE":
                                if (_fieldFlag)
                                {
                                    // if it is not an expression
                                    if (_tagValue.IndexOf('=') < 0)
                                    {
                                        if (_field.type.ToUpper().IndexOf("CHECKBOX") >= 0)
                                        {
                                            bool _checkValue = CommonRoutines.ConvertToBool(_tagValue);
                                            _field.value = _checkValue.ToString();
                                            _field.checkedFlag = _checkValue;
                                        }
                                    }
                                    else
                                    {
                                        _field.value = _tagValue;
                                    }
                                    _field.originalValue = _field.value;
                                    _field.compiledValue = _field.value;
                                }
                                else
                                {
                                    if (_variableFlag)
                                    {
                                        _variableValue = _tagValue;
                                    }
                                }
                                break;

                            case "TEXT":
                                if (_fieldFlag)
                                {
                                    _field.text = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "CAPTION":
                                if (_fieldFlag)
                                {
                                    _field.caption = _tagValue;
                                }
                                else
                                {

                                }
                                break;

                            case "INSTRUCTIONS":
                                if (_formFlag)
                                {
                                    _form.instructions = _tagValue;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                        _field.instructions = _tagValue;
                                    }
                                    else
                                    {

                                    }
                                }
                                break;

                            case "PRINTORIENTATION":
                                if (_formFlag)
                                {
                                    _form.printOrientation = _tagValue;
                                }
                                else
                                {
                                    if (_fieldFlag)
                                    {
                                    }
                                    else
                                    {

                                    }
                                }
                                break;

                            case "LAYER":
                                if (_fieldFlag)
                                {
                                    _field.layer = CommonRoutines.ConvertToInt(_tagValue);
                                }
                                else
                                {

                                }
                                break;

                            case "EDIFLAG":
                                if (_fieldFlag)
                                {
                                    _field.ediFlag = (_tagValue + "N").Substring(0, 1);
                                }
                                else
                                {

                                }
                                break;

                            case "EDINAME":
                                if (_fieldFlag)
                                {
                                    _field.ediName = _tagValue.ToUpper();
                                }
                                else
                                {

                                }
                                break;

                            default:
                                // all other tags
                                if (_fieldFlag)
                                {
                                    _field.AddProperty(_tagName, _tagValue);
                                }
                                else
                                {

                                }
                                break;

                        }
                    }
                }

            }
            catch (Exception ex)
            {
                CommonRoutines.DisplayErrorMessage("$E:" + moduleName + ".CreateForms > " + ex.Message);
            }

            _numForms = forms.Count;

            return _numForms;
        }
        /// <summary>
        /// DBCursor SelectCursor(string connectionString, string dbms, string cursorName, string sql, bool loadCollection)
        /// Get the records for the passed sql on the passed connection
        /// </summary>
        /// <param name="connectionString"></param>
        /// <param name="sql"></param>
        /// <returns></returns>
        public static IGenDataset SelectCursor(string connectionString, string dbms, string cursorName, string sql, bool loadCollection)
        {
            IGenDataset _cursor = new IGenDataset();

            try
            {
                lastConnection = connectionString;

                // call the appropriate dbms method
                switch (dbms.ToUpper())
                {
                    case "SQLSERVER":
                        _cursor = dbSQLServer.SelectCursor(connectionString, cursorName, sql, loadCollection);
                        break;

                    case "ACCESS":
                        break;

                    case "SQLITE":
                        break;
                }

                SetStatusInfo(dbms);

            }
            catch (Exception ex)
            {
                CommonRoutines.DisplayErrorMessage("$E:" + moduleName + ".SelectCursor(s,s,s,s,b) > " + ex.Message);
                lastStatus = false;
                lastStatusCode = "-999";
                lastStatusMessage = ex.Message;
            }

            return _cursor;
        }