public cReportConnect add(cReportConnect c, String key)
        {
            try
            {
                if (c == null)
                {
                    c = new cReportConnect();
                }

                if (key == null)
                {
                    this.BaseAdd(getDummyKey(), c);
                }
                else
                {
                    Add(cReportGlobals.getKey(key), c);
                }

                return(c);
            }
            catch
            {
                return(null);
            }
        }
        internal bool save(CSXml.cXml xDoc, XmlNode nodeFather)
        {
            cReportConnect connect = null;

            if (nodeFather == null)
            {
                CSXml.cXmlProperty xProperty = null;
                xProperty = new CSXml.cXmlProperty();
                xProperty.setName(C_RPTCONNECTSAUX);
                nodeFather = xDoc.addNode(xProperty);
            }

            for (int _i = 0; _i < this.Count; _i++)
            {
                connect = item(_i);
                if (!connect.save(xDoc, nodeFather))
                {
                    return(false);
                }
            }

            return(true);
        }
		// TODO: reimplement
		/*
        private void form_KeyUp(Keys keyCode, bool ctrlKey) {
            // if we are in edit mode we do nothing
            //
            if (TxEdit.Visible) { return; }

            switch (keyCode) {

                case Keys.F2:
                    editText();

                    break;
                case Keys.Delete:
                    deleteObj();

                    break;
                case Keys.Escape:
                    endDraging();

                    break;
                case Keys.F11:
                    m_bMoveVertical = true;
                    m_bMoveHorizontal = false;
                    cGlobals.setStatus();

                    break;
                case Keys.F12:
                    m_bMoveHorizontal = true;
                    m_bMoveVertical = false;
                    cGlobals.setStatus();

                    break;
                case Keys.F8:
                    m_bMoveHorizontal = false;
                    m_bMoveVertical = false;
                    cGlobals.setStatus();

                    break;
                case Keys.F9:
                    m_bNoMove = !m_bNoMove;
                    cGlobals.setStatus();

                    break;
                case Keys.F4:
                    showProperties();

                    break;
                case Keys.C:
                    if (ctrlKey) {
                        copy();
                    }

                    break;
                case Keys.V:
                    if (ctrlKey) {
                        paste(false);
                    }

                    break;
            }

            Application.DoEvents();
        }
		*/

        // TODO: this functionality must to be moved to fConnectsAux
        //
        private void m_fConnectsAux_AddConnect() {
            try {

                cReportConnect rptConnect = null;
                rptConnect = new cReportConnect();

                if (!configConnection(rptConnect)) { return; }

                m_report.getConnectsAux().add(rptConnect);

                pAddConnectAuxToListView(rptConnect);

            } catch (Exception ex) {
                cError.mngError(ex, "m_fConnectsAux_AddConnect", C_MODULE, "");        
            }
        }
        private void pAddConnectAuxToListView(cReportConnect connect) {
			m_fConnectsAux.addConnect(connect.getDataSource(), connect.getStrConnect());
        }
        public bool configConnection(cReportConnect rptConnect) {
            try {

                CSConnect.cConnect connect = new CSConnect.cConnect();

				if (!connect.showOpenConnection())
					return false;

                refreshAll();

                if (!connect.getDataSourceColumnsInfo(
					connect.getDataSource(), 
					connect.getDataSourceType())) {
                    return false;
                }

                if (rptConnect == null) {
					cGlobals.setParametersAux(connect, m_report.getConnect());
                } 
                else {
                    cGlobals.setParametersAux(connect, rptConnect);
                }

                if (cGlobals.getToolBox(this) != null) { showToolBox(); }

                return true;

            } catch (Exception ex) {
                cError.mngError(ex, "configConnection", C_MODULE, "");
                return false;
            }
        }
        // public functions
        public void Dispose()
        {
            m_rows = null;
            m_collRows = null;
            m_vRowsIndexAux = null;
            m_vGroups = null;
            m_vRowsIndex = null;
            m_lastRowIndex = -1;
            m_lastRowPreEvalued = null;
            m_lastRowPostEvalued = null;

            m_controls.clear();
            m_controls = null;

            pDestroyCrossRef(m_headers);
            pDestroyCrossRef(m_details);
            pDestroyCrossRef(m_footers);
            pDestroyCrossRef(m_groups.getGroupsHeaders());
            pDestroyCrossRef(m_groups.getGroupsFooters());

            m_headers.clear();
            m_details.clear();
            m_footers.clear();
            m_groupsHeaders.clear();
            m_groupsFooters.clear();

            m_details.setCopyColl(null);
            m_headers.setCopyColl(null);
            m_footers.setCopyColl(null);
            m_groupsHeaders.setCopyColl(null);
            m_groupsFooters.setCopyColl(null);

            m_headers = null;
            m_details = null;
            m_footers = null;
            m_groupsHeaders = null;
            m_groupsFooters = null;

            m_paperInfo = null;

            m_formulas.clear();
            m_formulas = null;

            m_formulaTypes.clear();
            m_formulaTypes = null;

            m_connect = null;

            m_pages.clear();
            m_pages = null;

            m_pageSetting.clear();
            m_pageSetting = null;

            m_compiler = null;
            m_launchInfo = null;

            m_connectsAux.clear();
            m_connectsAux = null;

            pDestroyImages();
            m_images = null;
        }
        private bool pGetData(
            ref DataTable vRows,
            ref DataTable rs,
            cReportConnect connect,
            bool createIndexVector,
            List<object[]> recordsets)
        {
            String strConnect = "";
            bool saveInReport = false;
            CSDataBase.cDataBase cn = null;
            object[] varRs = null;
            DataTable rsAux = null;
            DbDataReader dr = null;

            // if we get an string connection
            //
            if (m_launchInfo.getStrConnect().Trim() != "")
            {
                strConnect = m_launchInfo.getStrConnect();
            }
            // if m_launchInfo.getStrConnect() is empty we will use
            // the connection of the connect object
            // 
            else
            {
                strConnect = connect.getStrConnect();
                saveInReport = true;
            }
            if (!getReportDisconnected())
            {
                if (strConnect.Trim() == "")
                {
                    cWindow.msgWarning("The connection settings were not defined."
                                        + "Both the LaunchInfo and the Connect object have their "
                                        + "strConnect property empty. Whitout this connection string "
                                        + "it will be imposible to open the connection to the database.",
                                        "CSReportEditor");
                    return false;
                }

                cn = new cDataBase(m_databaseEngine);

                if (m_isForWeb)
                {
                    cn.setSilent(true);
                }
                if (connect.getCommandTimeout() > 0)
                {
                    cn.setCommandTimeout(connect.getCommandTimeout());
                }
                if (connect.getConnectionTimeout() > 0)
                {
                    cn.setConnectionTimeout(connect.getConnectionTimeout());
                }

                // open the connection
                //
                if (!cn.initDb("", "", "", "", strConnect))
                {
                    if (!resumeDBAccessMissing(strConnect, saveInReport, cn))
                    {
                        return false;
                    }
                }

                // we need to prepare the first sentence
                //
                String sqlstmt = "";

                // if it was a select
                //
                if (m_launchInfo.getSqlstmt().Trim() != "")
                {
                    sqlstmt = m_launchInfo.getSqlstmt();
                }
                else
                {
                    if (connect.getDataSourceType() == csDataSourceType.CDDTPROCEDURE)
                    {
                        sqlstmt = "exec [" + connect.getDataSource() + "] " + connect.getSqlParameters();
                    }
                    else if (connect.getDataSourceType() == csDataSourceType.CSDTTABLE)
                    {
                        sqlstmt = "select * from [" + connect.getDataSource() + "]";
                    }
                    else
                    {
                        sqlstmt = connect.getDataSource();
                    }
                }

                // open the recordset
                //
                cn.setOpenRsExDescript(m_descripUser);

                if (!cn.loadDataTable(true,
                                        false,
                                        false,
                                        sqlstmt,
                                        out rs,
                                        out dr,
                                        "GetData",
                                        C_MODULE,
                                        ""))
                {
                    return false;
                }

                if (rs.Rows.Count == 0)
                {
                    vRows = null;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[0];
                        m_lastRowIndex = -1;
                    }
                }
                else
                {
                    vRows = rs;
                    if (createIndexVector)
                    {
                        m_vRowsIndex = new int[vRows.Rows.Count];
                        m_lastRowIndex = m_vRowsIndex.Length - 1;
                        int k = 0;
                        for (k = 0; k < m_vRowsIndex.Length; k++)
                        {
                            m_vRowsIndex[k] = k;
                        }
                    }
                }

                varRs = new object[2];
                varRs[0] = rs;
                varRs[1] = connect.getDataSource();
                recordsets.Add(varRs);

                // we need to load every recordset from every data source
                // in the recordset collection (this code suport multiples
                // recordset in the same reader)
                //
                while (!dr.IsClosed && dr.NextResult())
                {
                    rsAux = new DataTable();
                    rsAux.Load(dr);
                    
                    varRs = new object[2];
                    varRs[0] = rsAux;
                    varRs[1] = connect.getDataSource();
                    recordsets.Add(varRs);

                    // TODO: check if this works
                    //
                    // we add an empty element to m_collRows to avoid
                    // index of bounds exception
                    //
                    G.redimPreserve(ref m_collRows, m_collRows.Length + 1);
                }

                cn.closeDb();
            }
            else
            {
                vRows = null;
                if (createIndexVector)
                {
                    m_vRowsIndex = new int[0];
                    m_lastRowIndex = -1;
                }
            }
            if (m_rows != null)
            {
                m_recordCount = m_vRowsIndex.Length;
            }
            else
            {
                m_recordCount = 0;
            }
            m_iRow = 0;
            m_idxGroupHeader = -1;
            m_idxGroupFooter = -1;

            return true;
        }
 private bool pGetData(
     ref DataTable vRows,
     cReportConnect connect,
     bool createIndexVector,
     List<object[]> recordsets)
 {
     DataTable dummy = null;
     return pGetData(ref vRows, ref dummy, connect, createIndexVector, recordsets);
 }
        public cReport()
        {
            try
            {
                m_headers = new cReportSections();
                m_details = new cReportSections();
                m_footers = new cReportSections();
                m_groups = new cReportGroups();
                m_groupsHeaders = getGroups().getGroupsHeaders();
                m_groupsFooters = getGroups().getGroupsFooters();
                m_paperInfo = new cReportPaperInfo();
                m_controls = new cReportControls2();
                m_formulas = new cReportFormulas();
                m_formulaTypes = new cReportFormulaTypes();
                m_connect = new cReportConnect();
                m_pageSetting = new cReportPageSettings();
                m_pages = new cReportPages();

                m_compiler = new cReportCompiler();

                setConnectsAux(new cReportConnectsAux());

                m_details.setCopyColl(m_controls);
                m_headers.setCopyColl(m_controls);
                m_footers.setCopyColl(m_controls);
                m_groupsHeaders.setCopyColl(m_controls);
                m_groupsFooters.setCopyColl(m_controls);

                m_details.setTypeSection(csRptSectionType.DETAIL);
                m_headers.setTypeSection(csRptSectionType.HEADER);
                m_footers.setTypeSection(csRptSectionType.FOOTER);
                m_groupsHeaders.setTypeSection(csRptSectionType.GROUP_HEADER);
                m_groupsFooters.setTypeSection(csRptSectionType.GROUP_FOOTER);

                m_details.setMainTypeSection(csRptSectionType.MAIN_DETAIL);
                m_headers.setMainTypeSection(csRptSectionType.MAIN_HEADER);
                m_footers.setMainTypeSection(csRptSectionType.MAIN_FOOTER);
            }
            catch (Exception ex)
            {
                cError.mngError(ex, "Class_Initialize", C_MODULE, "");
            }
        }
		public static void setParametersAux(cConnect connect, cReportConnect rptConnect)
		{
            rptConnect.getColumns().clear();
            rptConnect.getParameters().clear();

            for (int i = 0; i < connect.getColumnsInfo().count(); i++)
            {
                CSConnect.cColumnInfo colInfo = connect.getColumnsInfo().item(i);
                CSReportDll.cColumnInfo rptColInfo = new CSReportDll.cColumnInfo();

                rptColInfo.setName(colInfo.getName());
                rptColInfo.setPosition(colInfo.getPosition());
                rptColInfo.setColumnType(colInfo.getColumnType());
                rptConnect.getColumns().add(rptColInfo, "");
            }

            for (int i = 0; i < connect.getParameters().count(); i++)
            {
                CSConnect.cParameter parameter = connect.getParameters().item(i);
                CSReportDll.cParameter rptParameter = new CSReportDll.cParameter();

                rptParameter.setName(parameter.getName());
                rptParameter.setPosition(parameter.getPosition());
                rptParameter.setColumnType(parameter.getColumnType());
                rptParameter.setValue(parameter.getValue());
                rptConnect.getParameters().add(rptParameter, "");
            }        
        }
        public cReportConnect add(cReportConnect c, String key)
        {
            try
            {
                if (c == null) 
                { 
                    c = new cReportConnect(); 
                }

                if (key == null)
                {
                    this.BaseAdd(getDummyKey(), c);
                }
                else
                {
                    Add(cReportGlobals.getKey(key), c);
                }

                return c;
            }
            catch
            {
                return null;
            }
        }
		public cReportConnect add(cReportConnect c) 
		{
			return add (c, null);
		}
 public cReportConnect add(cReportConnect c)
 {
     return(add(c, null));
 }