public static int SeekActiveUnitsCuenca(DataTable dtzone, int qty)
        {
            System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
            string UNIT_ID = (string)appSettings.GetValue("GroupsChilds.UnitId", typeof(string));

            string swhere = "";
            CmpGroupsChildsGisDB cGroupChildsDb = new CmpGroupsChildsGisDB();
            CmpGroupsDB          cGroupsDb      = new CmpGroupsDB();

            foreach (DataRow dr in dtzone.Rows)
            {
                // If there is not a UNIT we follow deeping in the tree...(Level 2)
                if (dr["CGRPG_TYPE"].ToString() != UNIT_ID)
                {
                    swhere = "CGRPG_ID	= "+ dr["CGRPG_CHILD"].ToString();
                    DataTable dtsubzone = cGroupChildsDb.GetData(null, swhere, null, null);
                    qty = SeekActiveUnits(dtsubzone, qty);
                }
                else
                {
                    CmpUnitsDB udb = new CmpUnitsDB();
                    swhere = "UNI_ID = " + dr["CGRPG_CHILD"].ToString() + " AND UNI_IP IS NOT NULL AND UNI_DSTA_ID IN (0,1,2)";
                    DataTable dtUnit = udb.GetData(null, swhere, null, null);
                    if (dtUnit.Rows.Count != 0)
                    {
                        qty++;
                    }
                }
            }
            return(qty);
        }
        public static string SeekUnitsString(DataTable dtzone)
        {
            System.Configuration.AppSettingsReader appSettings = new System.Configuration.AppSettingsReader();
            string UNIT_ID = (string)appSettings.GetValue("GroupsChilds.UnitId", typeof(string));
            string swhere  = "";
            CmpGroupsChildsGisDB cGroupChildsDb = new CmpGroupsChildsGisDB();
            CmpGroupsDB          cGroupsDb      = new CmpGroupsDB();
            string strRes  = "";
            string strTemp = "";

            foreach (DataRow dr in dtzone.Rows)
            {
                // If there is not a UNIT we follow deeping in the tree...(Level 2)
                if (dr["CGRPG_TYPE"].ToString() != UNIT_ID)
                {
                    swhere = "CGRPG_ID	= "+ dr["CGRPG_CHILD"].ToString();
                    DataTable dtsubzone = cGroupChildsDb.GetData(null, swhere, null, null);
                    strTemp = SeekUnitsString(dtsubzone);
                    if (strTemp != "")
                    {
                        if (strRes == "")
                        {
                            strRes = strTemp;
                        }
                        else
                        {
                            strRes += "," + strTemp;
                        }
                    }
                }
                else
                {
                    if (dr["CGRPG_CHILD"].ToString() != "")
                    {
                        CmpUnitsDB udb = new CmpUnitsDB();
                        swhere = "UNI_ID = " + dr["CGRPG_CHILD"].ToString() + " AND UNI_DPUNI_ID IN (1,2) ";
                        DataTable dtUnit = udb.GetData(null, swhere, null, null);
                        if (dtUnit.Rows.Count != 0)
                        {
                            if (strRes == "")
                            {
                                strRes = dr["CGRPG_CHILD"].ToString();
                            }
                            else
                            {
                                strRes += "," + dr["CGRPG_CHILD"].ToString();
                            }
                        }
                    }
                }
            }
            return(strRes);
        }