예제 #1
0
        internal static BldTreeData getTree(int parent, MySqlConnection con, BldTreeData par)
        {
            MySqlCommand    cmd = new MySqlCommand(@"SELECT b_id, b_name, Coalesce(b_farm,0) AS b_farm FROM buildings WHERE b_parent=" + parent.ToString() + " ORDER BY b_farm ASC;", con);
            MySqlDataReader rd  = cmd.ExecuteReader();
            BldTreeData     res = par;

            if (par == null)
            {
                res = new BldTreeData(0, 0, "farm");
            }

            List <BldTreeData> lst = new List <BldTreeData>();

            while (rd.Read())
            {
                int         frm = DBHelper.GetNullableInt(rd, "b_farm");
                String      nm  = rd.GetString("b_name");
                BldTreeData dt  = new BldTreeData(rd.GetInt32("b_id"), frm, (frm == 0 ? nm : "№" + Building.Format(nm.Remove(0, 1))), res.Path);
                lst.Add(dt);
            }
            rd.Close();

            if (lst.Count > 0)
            {
                foreach (BldTreeData td in lst)
                {
                    getTree(td.ID, con, td);
                }
                res.ChildNodes = lst;
            }
            return(res);
        }
예제 #2
0
        /// <summary>
        /// Подготовка перед получением данных
        /// </summary>
        protected override IDataGetter onPrepare(Filters f)
        {
            base.onPrepare(f);
            manual = false;
            treeView1.Nodes.Clear();
            _freeFarmsId.Clear();
            BldTreeData buildTree   = Engine.db().buildingsTree();
            List <int>  busyFarmsId = new List <int>();
            TreeNode    n           = this.makeNode(null, "Ферма", buildTree, busyFarmsId);

            MainForm.ProtectTest(busyFarmsId.Count);
            ///ищем предлагаемые имена
            _freeFarmsId = getNewFarmCandidates(busyFarmsId);
            int allowFarms = 0;

            if (allowFarms > 0 && _freeFarmsId.Count > allowFarms)
            {
                int last = _freeFarmsId[_freeFarmsId.Count - 1];
                _freeFarmsId = _freeFarmsId.GetRange(0, allowFarms - 1);
                _freeFarmsId.Add(last);
            }

            MainForm.ProtectTest(BuildingsPanel.GetFarmsCount(buildTree));
            manual = true;
            n.Expand();
            f[Filters.SHORT]       = Engine.opt().getOption(Options.OPT_ID.SHORT_NAMES);
            f[Filters.DBL_SURNAME] = Engine.opt().getOption(Options.OPT_ID.DBL_SURNAME);

            IDataGetter dg = Engine.db2().getBuildingsRows(f);

            _rsb.SetText(1, dg.getCount().ToString() + " ярусов");
            _rsb.SetText(2, dg.getCount2().ToString() + " МИНИферм");
            _runF = f;
            return(dg);
        }
예제 #3
0
        /// <summary>
        /// Создает ветку в дереве строений.
        /// </summary>
        /// <param name="parent">Ветка-родитель</param>
        /// <param name="name">Название ветки</param>
        /// <param name="treeData"></param>
        /// <returns></returns>
        private TreeNode makeNode(TreeNode parent, String name, BldTreeData treeData, List <int> idList)
        {
            TreeNode n = null;

            if (parent == null)
            {
                n = treeView1.Nodes.Add(name);
            }
            else
            {
                n = parent.Nodes.Add(name);
            }

            TreeNode child;

            if (treeData.ChildNodes != null)
            {
                while (treeData.ChildNodes.Count > 0)
                {
                    BldTreeData childTreeData = treeData.ChildNodes[0];
                    child = this.makeNode(n, childTreeData.Name, childTreeData, idList);
                    //child.Tag = treeData.ChildNodes[0];
                    if (childTreeData.FarmId != 0)
                    {
                        idList.Add(childTreeData.FarmId);
                    }
                    if (childTreeData.ID == preBuilding)
                    {
                        treeView1.SelectedNode = child;
                        treeView1.SelectedNode.Expand();
                    }

                    if (!this.farmAddresses.ContainsKey(childTreeData.FarmId))
                    {
                        this.farmAddresses.Add(childTreeData.FarmId, child.FullPath);
                    }
                    treeData.ChildNodes.RemoveAt(0);
                }
            }
            n.Tag = treeData;
            return(n);
        }
예제 #4
0
        //int _maxfarm = 0;

        /// <summary>
        /// Считает количество ферм в Дереве строений
        /// </summary>
        /// <param name="td"></param>
        /// <returns>Количество ферм</returns>
        public static int GetFarmsCount(BldTreeData td)
        {
            int res = 0;

            //String[] st = td.caption.Split(':');
            //if (st.Length == 3)
            if (td.FarmId != 0)
            {
                res++;
                return(res);
            }
            if (td.ChildNodes != null)
            {
                for (int i = 0; i < td.ChildNodes.Count; i++)
                {
                    res += GetFarmsCount(td.ChildNodes[i]);
                }
            }
            return(res);
        }
예제 #5
0
        private TreeNode searchFarm(int tierID, int bid, TreeNode nd)
        {
            BldTreeData td = (nd.Tag as BldTreeData);//.Split(':');

            if (td.FarmId == tierID || td.ID == bid)
            {
                return(nd);
            }

            TreeNode res = null;

            foreach (TreeNode n in nd.Nodes)
            {
                res = this.searchFarm(tierID, bid, n);
                if (res != null)
                {
                    return(res);
                }
            }
            return(null);
        }